/* =====================================================================
   Polarix WMS — unified theme
   Clean, modern, professional. Mobile-first; enhances on larger screens.
   ===================================================================== */

:root {
  /* Type */
  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas,
               "Liberation Mono", monospace;

  /* Surfaces */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --surface-3: #e7ebf2;
  --border: #d9dfe9;
  --border-strong: #c3ccda;

  /* Text */
  --text: #1b2230;
  --text-2: #56627a;
  --text-3: #8b95a8;
  --on-accent: #ffffff;

  /* Brand accent — calm "ocean" blue-teal */
  --accent: #0d6e8c;
  --accent-600: #0a5d78;
  --accent-700: #084a60;
  --accent-50: #e6f2f6;
  --accent-100: #cde6ee;

  /* Semantic */
  --ok: #1f9d57;        --ok-bg: #e6f6ec;
  --warn: #b9790c;      --warn-bg: #fbf1dd;
  --danger: #cb3b3b;    --danger-bg: #fbe9e9;
  --info: #2563a8;      --info-bg: #e7eefa;

  /* Geometry */
  --radius: 9px;
  --radius-sm: 6px;
  --radius-pill: 999px;
  --shadow-1: 0 1px 2px rgba(16,28,48,.06), 0 1px 3px rgba(16,28,48,.04);
  --shadow-2: 0 4px 14px rgba(16,28,48,.10);
  --shadow-pop: 0 10px 30px rgba(16,28,48,.18);

  --topbar-h: 54px;
  --rail-w: 224px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.mono { font-family: var(--font-mono); }
a { color: var(--accent); text-decoration: none; }
h1,h2,h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* ---- Buttons ---- */
.btn {
  appearance: none; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500;
  padding: 9px 14px; border-radius: var(--radius-sm);
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  transition: background .12s ease, border-color .12s ease, transform .04s ease;
  user-select: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-600); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.95); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-lg { padding: 14px 18px; font-size: 16px; }

/* ---- Inputs ---- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12px; font-weight: 600;
  color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 11px 12px;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-50); }
.input-lg { padding: 14px 14px; font-size: 16px; }

/* ---- Badges / status ---- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; line-height: 1;
  padding: 4px 8px; border-radius: var(--radius-pill);
  border: 1px solid transparent; white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-RELS  { color: var(--ok);     background: var(--ok-bg); }
.st-PROD  { color: var(--info);   background: var(--info-bg); }
.st-ALLOC { color: var(--warn);   background: var(--warn-bg); }
.st-RECV  { color: var(--text-2); background: var(--surface-3); }
.st-SHIP  { color: #6b4ea0;       background: #efeafa; }
.st-HOLD  { color: var(--danger); background: var(--danger-bg); }
.badge-hold { color: var(--danger); background: var(--danger-bg); }
.badge-mut  { color: var(--text-2); background: var(--surface-2); border-color: var(--border); }
.lock-ico { color: var(--danger); }

/* ---- Toasts ---- */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 9999;
  display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.toast { background: var(--text); color: #fff; padding: 11px 14px; border-radius: var(--radius);
  box-shadow: var(--shadow-pop); font-size: 13.5px; animation: toastin .18s ease; }
.toast.ok { background: #15623a; }
.toast.err { background: #8f2b2b; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* =====================================================================
   AUTH / CHOOSER pages
   ===================================================================== */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 80% -10%, #e9f2f6 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #eef1f6 0%, transparent 55%),
    var(--bg);
}
.auth-card { width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-2);
  padding: 28px 26px; }
.brand { display: flex; align-items: center; gap: 11px; margin-bottom: 4px; }
.brand .mark { width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(150deg, var(--accent) 0%, var(--accent-700) 100%);
  display: grid; place-items: center; color: #fff; font-weight: 700; box-shadow: var(--shadow-1); }
.brand .name { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.brand .sub { color: var(--text-3); font-size: 12px; }
.auth-card h1 { font-size: 17px; margin: 18px 0 16px; }
.auth-msg { font-size: 13px; padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 14px; }
.auth-msg.err { color: #8f2b2b; background: var(--danger-bg); border: 1px solid #f0cccc; }
.auth-foot { margin-top: 16px; color: var(--text-3); font-size: 11.5px; text-align: center; }

.chooser { display: grid; gap: 14px; grid-template-columns: 1fr; margin-top: 8px; }
@media (min-width: 560px) { .chooser { grid-template-columns: 1fr 1fr; } }
.choose-card { border: 1px solid var(--border-strong); border-radius: 12px; padding: 20px;
  background: var(--surface); cursor: pointer; text-align: left;
  transition: border-color .12s, box-shadow .12s, transform .05s; display: block; }
.choose-card:hover { border-color: var(--accent); box-shadow: var(--shadow-2); }
.choose-card:active { transform: translateY(1px); }
.choose-card .ico { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-50);
  color: var(--accent); display: grid; place-items: center; margin-bottom: 12px; }
.choose-card .t { font-weight: 700; font-size: 15px; }
.choose-card .d { color: var(--text-2); font-size: 12.5px; margin-top: 3px; }

/* =====================================================================
   PC ENVIRONMENT
   ===================================================================== */
.pc-topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 14px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.pc-topbar .brand .name { font-size: 15px; }
.pc-topbar .mark { width: 28px; height: 28px; border-radius: 7px; }
.topbar-spacer { flex: 1; }
.live-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px;
  color: var(--text-2); padding: 5px 10px; border: 1px solid var(--border); border-radius: var(--radius-pill); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 rgba(31,157,87,.5); animation: livepulse 2s infinite; }
.live-pill.stale .live-dot { background: var(--text-3); animation: none; }
@keyframes livepulse { 0% { box-shadow: 0 0 0 0 rgba(31,157,87,.45);} 70% { box-shadow: 0 0 0 6px rgba(31,157,87,0);} 100% { box-shadow: 0 0 0 0 rgba(31,157,87,0);} }

.user-menu { position: relative; }
.user-btn { display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 5px 8px; border-radius: var(--radius-sm); }
.user-btn:hover { background: var(--surface-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.menu-pop { position: absolute; right: 0; top: 40px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  min-width: 200px; padding: 6px; display: none; z-index: 50; }
.menu-pop.open { display: block; }
.menu-pop .who { padding: 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-pop .who .nm { font-weight: 600; }
.menu-pop .who .rl { color: var(--text-3); font-size: 12px; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: none;
  font: inherit; padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text); }
.menu-item:hover { background: var(--surface-2); }

.pc-body { display: flex; height: calc(100vh - var(--topbar-h)); overflow: hidden; }

/* left rail */
.pc-rail { width: var(--rail-w); flex: 0 0 var(--rail-w); background: var(--surface);
  border-right: 1px solid var(--border); padding: 12px 10px; overflow-y: auto; }
.rail-group-title { font-size: 11px; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .06em; padding: 12px 10px 6px; }
.rail-item { display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: var(--radius-sm); border: none; background: none;
  font: inherit; color: var(--text); cursor: pointer; text-align: left; }
.rail-item:hover { background: var(--surface-2); }
.rail-item .ri-ico { width: 18px; display: grid; place-items: center; color: var(--text-2); }
.rail-item.active { background: var(--accent-50); color: var(--accent-700); font-weight: 600; }
.rail-item.active .ri-ico { color: var(--accent); }
.rail-item.disabled { color: var(--text-3); cursor: default; }
.rail-item.disabled:hover { background: none; }
.rail-item .soon { margin-left: auto; font-size: 10px; color: var(--text-3);
  border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 1px 7px; }

/* rail drawer toggle (mobile) */
.rail-toggle { display: inline-flex; }
.rail-backdrop { display: none; }
@media (max-width: 860px) {
  .pc-rail { position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 45;
    transform: translateX(-100%); transition: transform .18s ease; box-shadow: var(--shadow-pop); }
  .pc-rail.open { transform: none; }
  .rail-backdrop.show { display: block; position: fixed; inset: var(--topbar-h) 0 0 0;
    background: rgba(16,28,48,.35); z-index: 44; }
}
@media (min-width: 861px) { .rail-toggle { display: none; } }

/* main */
.pc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* tab strip */
.tabstrip { display: flex; align-items: stretch; gap: 2px; padding: 8px 10px 0;
  background: var(--bg); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { display: inline-flex; align-items: center; gap: 8px; padding: 9px 12px;
  border: 1px solid var(--border); border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0; background: var(--surface-2);
  color: var(--text-2); cursor: pointer; white-space: nowrap; position: relative; top: 1px; }
.tab:hover { background: var(--surface); }
.tab.active { background: var(--surface); color: var(--text); font-weight: 600;
  border-color: var(--border); box-shadow: 0 -2px 0 var(--accent) inset; }
.tab .x { display: inline-grid; place-items: center; width: 18px; height: 18px;
  border-radius: 4px; color: var(--text-3); }
.tab .x:hover { background: var(--surface-3); color: var(--danger); }
.tab.dragging { opacity: .4; }

/* detached floating window (drag a tab down) */
.float-win { position: fixed; z-index: 60; width: min(560px, 92vw); height: 60vh;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-pop); display: flex; flex-direction: column; }
.float-win .fw-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--border); cursor: move; background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0; }
.float-win .fw-title { font-weight: 600; font-size: 13px; }
.float-win .fw-x { margin-left: auto; }
.float-win .fw-body { flex: 1; min-height: 0; overflow: auto; }

/* tab close drop-zone shown while dragging a tab */
.tab-dropzone { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 70; background: var(--surface); border: 2px dashed var(--border-strong);
  border-radius: var(--radius); padding: 16px 26px; color: var(--text-2);
  box-shadow: var(--shadow-pop); display: none; align-items: center; gap: 10px; }
.tab-dropzone.show { display: inline-flex; }
.tab-dropzone.hot { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }

/* screen panel */
.screen { flex: 1; min-height: 0; display: none; flex-direction: column; padding: 12px; }
.screen.active { display: flex; }
.screen-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.screen-title { font-size: 15px; font-weight: 600; }
.toolbar-spacer { flex: 1; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }

/* group bar */
.group-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  min-height: 44px; padding: 8px 10px; background: var(--surface-2);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); margin-bottom: 8px; }
.group-bar.dragover { border-color: var(--accent); background: var(--accent-50); }
.group-hint { color: var(--text-3); font-size: 12.5px; display: inline-flex; align-items: center; gap: 7px; }
.group-pill { display: inline-flex; align-items: center; gap: 7px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  padding: 5px 6px 5px 11px; font-size: 12.5px; font-weight: 600; cursor: grab; }
.group-pill .lvl { color: var(--text-3); font-weight: 700; font-size: 11px; }
.group-pill .pill-x { display: inline-grid; place-items: center; width: 18px; height: 18px;
  border-radius: 50%; color: var(--text-3); }
.group-pill .pill-x:hover { background: var(--danger-bg); color: var(--danger); }
.group-pill .arrow { color: var(--text-3); }
.group-add { position: relative; }
.group-add .gmenu { position: absolute; top: 32px; left: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  padding: 6px; z-index: 30; display: none; max-height: 280px; overflow: auto; min-width: 200px; }
.group-add .gmenu.open { display: block; }

/* totals footer */
.grid-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 18px; flex: 0 0 auto;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--border);
  border-top: none; border-radius: 0 0 var(--radius-sm) var(--radius-sm); font-size: 13px; }
.grid-foot .tot { display: inline-flex; align-items: baseline; gap: 7px; }
.grid-foot .tot .lab { color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.grid-foot .tot .val { font-weight: 700; font-variant-numeric: tabular-nums; }

.grid-host { flex: 1 1 0; min-height: 200px; }

/* =====================================================================
   Tabulator overrides — match the theme
   ===================================================================== */
.tabulator { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0; font-size: 13px; }
.tabulator .tabulator-header { background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-weight: 600; color: var(--text-2); }
.tabulator .tabulator-header .tabulator-col { background: transparent;
  border-right: 1px solid var(--border); }
.tabulator .tabulator-header .tabulator-col .tabulator-col-title {
  text-transform: none; font-size: 12px; letter-spacing: .01em; padding: 9px 8px; }
.tabulator .tabulator-col.draggable-head { cursor: grab; }
.tabulator .tabulator-row { border-bottom: 1px solid var(--surface-3); }
.tabulator .tabulator-row.tabulator-row-even { background: #fbfcfe; }
.tabulator .tabulator-row:hover { background: var(--accent-50); }
.tabulator .tabulator-row.tabulator-selected { background: var(--accent-100); }
.tabulator .tabulator-cell { border-right: 1px solid var(--surface-3); padding: 7px 8px;
  font-variant-numeric: tabular-nums; }
.tabulator .tabulator-cell.num { text-align: right; }
.tabulator .tabulator-group { background: var(--surface-3); font-weight: 600; color: var(--text);
  border-bottom: 1px solid var(--border); padding: 7px 8px; }
.tabulator .tabulator-group.tabulator-group-level-1 { background: #eaeef5; padding-left: 22px; }
.tabulator .tabulator-group.tabulator-group-level-2 { background: #eef1f7; padding-left: 38px; }
.tabulator .tabulator-group.tabulator-group-level-3 { background: #f2f4f9; padding-left: 54px; }
.tabulator .tabulator-group .tabulator-arrow { border-left-color: var(--accent); }
.tabulator .tabulator-group .gcount { color: var(--text-3); font-weight: 600; margin-left: 8px; font-size: 12px; }
.tabulator-edit-select-list, .tabulator-menu { border: 1px solid var(--border) !important;
  box-shadow: var(--shadow-pop) !important; border-radius: var(--radius) !important; }

/* cell helpers */
.cell-lpn { font-family: var(--font-mono); font-weight: 600; }
.cell-code { font-family: var(--font-mono); }
.row-act { border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: var(--radius-pill); font-size: 11px; padding: 3px 9px; cursor: pointer; }
.row-act:hover { background: var(--surface-2); }
.row-act.release { color: var(--danger); border-color: #e7b9b9; }

/* =====================================================================
   RF ENVIRONMENT (handheld)
   ===================================================================== */
.rf-shell { min-height: 100vh; display: flex; flex-direction: column;
  max-width: 520px; margin: 0 auto; background: var(--surface);
  box-shadow: 0 0 0 1px var(--border); }
.rf-top { background: linear-gradient(150deg, var(--accent) 0%, var(--accent-700) 100%);
  color: #fff; padding: 12px 14px; display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 10; }
.rf-back { width: 36px; height: 36px; border-radius: 9px; border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.12); color: #fff; cursor: pointer; display: grid; place-items: center; font-size: 18px; }
.rf-back:disabled { opacity: .35; cursor: default; }
.rf-titles { line-height: 1.2; }
.rf-titles .rf-h { font-size: 16px; font-weight: 700; }
.rf-titles .rf-s { font-size: 12px; opacity: .85; }
.rf-userchip { margin-left: auto; font-size: 12px; opacity: .9; display: flex; align-items: center; gap: 7px; }
.rf-live { width: 8px; height: 8px; border-radius: 50%; background: #8ff0b6; box-shadow: 0 0 0 0 rgba(143,240,182,.6); animation: livepulse 2s infinite; }

.rf-content { flex: 1; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.rf-menu { display: flex; flex-direction: column; gap: 10px; }
.rf-tile { display: flex; align-items: center; gap: 14px; padding: 16px;
  border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface);
  cursor: pointer; text-align: left; transition: border-color .12s, box-shadow .12s, transform .05s; }
.rf-tile:hover { border-color: var(--accent); box-shadow: var(--shadow-1); }
.rf-tile:active { transform: translateY(1px); }
.rf-tile .ti { width: 44px; height: 44px; border-radius: 11px; background: var(--accent-50);
  color: var(--accent); display: grid; place-items: center; flex: 0 0 44px; }
.rf-tile .tt { font-weight: 700; font-size: 16px; }
.rf-tile .td { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.rf-tile.soon { opacity: .55; }
.rf-tile.soon .badge { margin-left: auto; }
.rf-tile .chev { margin-left: auto; color: var(--text-3); }

.rf-field > span { font-size: 13px; font-weight: 600; color: var(--text-2); display: block; margin-bottom: 7px; }

.rf-card { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.rf-result { padding: 13px 14px; border-bottom: 1px solid var(--surface-3); }
.rf-result:last-child { border-bottom: none; }
.rf-result .r1 { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.rf-result .lpn { font-family: var(--font-mono); font-weight: 700; font-size: 15px; }
.rf-result .r2 { color: var(--text-2); font-size: 13px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.rf-result .kv b { color: var(--text); font-weight: 600; }
.rf-totals { position: sticky; bottom: 0; display: flex; gap: 0; border-top: 1px solid var(--border);
  background: var(--surface); }
.rf-totals .cell { flex: 1; text-align: center; padding: 12px 6px; border-right: 1px solid var(--surface-3); }
.rf-totals .cell:last-child { border-right: none; }
.rf-totals .cell .lab { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.rf-totals .cell .val { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rf-foot { padding: 12px 14px; display: flex; gap: 10px; border-top: 1px solid var(--border); background: var(--surface-2); }
.rf-empty { text-align: center; color: var(--text-2); padding: 36px 16px; }
.rf-empty .ico { font-size: 30px; margin-bottom: 8px; color: var(--text-3); }
.seg { display: flex; gap: 8px; }
.seg .btn { flex: 1; justify-content: center; }
.seg .btn.sel { background: var(--accent); border-color: var(--accent); color: #fff; }

.center-note { color: var(--text-3); text-align: center; padding: 40px 16px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--surface-3);
  border-top-color: var(--accent); animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Phase 2 — modal form, toggles, checklists, permission grid
   (master-data + security CRUD screens)
   ============================================================ */
@keyframes modalBackIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalCardIn { from { opacity: 0; transform: translateY(6px) scale(.99); } to { opacity: 1; transform: none; } }

.modal-back {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(16,28,48,.42);
  display: grid; place-items: center; padding: 20px;
  overflow-y: auto; animation: modalBackIn .14s ease-out;
}
.modal-card {
  width: min(640px, 100%); max-height: 90vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-pop);
  overflow: hidden; animation: modalCardIn .15s ease-out;
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 17px; font-weight: 700; color: var(--text); line-height: 1.25; }
.modal-sub { font-size: 12.5px; color: var(--text-2); margin-top: 3px; font-family: var(--font-mono); }
.modal-x { flex: none; }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1 1 auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 13px 18px; border-top: 1px solid var(--border); background: var(--surface-2);
}

/* form layout */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 560px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.form-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-field.span2 { grid-column: 1 / -1; }
.form-field.is-check { justify-content: flex-end; }
.form-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.form-label .req { color: var(--danger); margin-left: 1px; }
.field-help { font-size: 12px; color: var(--text-3); margin-top: 2px; line-height: 1.4; }
.input.mono { font-family: var(--font-mono); }
.modal-card select.input { appearance: none; background-image:
  linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
  linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

/* toggle switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; padding: 4px 0; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-ui { flex: none; width: 38px; height: 22px; border-radius: var(--radius-pill);
  background: var(--surface-3); border: 1px solid var(--border-strong); position: relative; transition: background .15s, border-color .15s; }
.switch-ui::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform .15s ease; }
.switch input:checked + .switch-ui { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-ui { box-shadow: 0 0 0 3px var(--accent-100); }
.switch-label { font-size: 13.5px; color: var(--text); }

/* checklists (multiselect) + permission grid */
.check-list { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface); }
.check-row { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.check-row input { flex: none; width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.check-row input:disabled { opacity: .5; cursor: default; }
.check-row input:disabled + span { color: var(--text-3); }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.perm-block { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.perm-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-3); padding-bottom: 5px; border-bottom: 1px solid var(--surface-3); }

@media (max-width: 559px) { .modal-back { padding: 12px; } .modal-card { max-height: 94vh; } }

/* =====================================================================
   Right-click context menu (grids) + pallet editor
   ===================================================================== */
.ctx-menu { position: fixed; z-index: 300; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-pop); padding: 5px; min-width: 170px; }
.ctx-item { display: block; width: 100%; text-align: left; background: none; border: none; font: inherit;
  padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text); }
.ctx-item:hover { background: var(--surface-2); }
.ctx-item.danger { color: var(--danger); }
.ctx-item.danger:hover { background: var(--danger-bg); }

.pallet-card { width: min(820px, 100%); }
.pallet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.pallet-grid .form-label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.pallet-grid .form-label .input { font-weight: 400; }
.pallet-grid .span2 { grid-column: 1 / -1; }
.pallet-sec { display: flex; align-items: center; gap: 12px; margin: 18px 0 8px; font-weight: 700; color: var(--text);
  border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.pallet-sec .btn { margin-left: auto; }
.pallet-hold { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 34px; }
.mini-grid { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mini-grid th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); color: var(--text-3);
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.mini-grid td { padding: 6px 8px; border-bottom: 1px solid var(--surface-3); }
.mini-grid td.num, .mini-grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mini-grid .mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }
.mini-acts { white-space: nowrap; text-align: right; }

/* ---------- transaction-log filter bar ---------- */
.filter-bar {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.filter-bar .flt-field {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .03em;
}
.filter-bar .flt {
  font-size: 13px; font-weight: 400; text-transform: none; letter-spacing: 0;
  padding: 6px 8px; border: 1px solid var(--border-strong);
  border-radius: 6px; background: var(--surface); color: var(--text);
  min-width: 150px; height: 32px;
}
.filter-bar .flt:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.filter-bar .flt-from, .filter-bar .flt-to { min-width: 140px; }
.filter-bar .btn { height: 32px; }
