/* ============================================================================
   Unilam Production Manager — web theme
   Light + dark, switchable. Palette derived from the desktop app (slate +
   indigo) so the web app reads as the same product. No external fonts.
   ============================================================================ */

:root {
  /* Brand constants (same in both themes) */
  --brand-indigo: #6366f1;
  --topbar-bg: #1e293b;          /* slate-800 — dark bar anchors the brand */
  --topbar-text: #e2e8f0;
  --topbar-muted: #94a3b8;

  /* Light theme (default) */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e9eef5;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-soft: #fff7ed;
  --on-accent: #ffffff;

  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --info: #2563eb;
  --info-soft: #dbeafe;

  /* Row highlight tints (light) */
  --row-mr: #dcfce7;
  --row-mr-text: #14532d;
  --row-fr: #fce7f3;
  --row-fr-text: #831843;
  --row-pvl: #fef9c3;
  --row-pvl-text: #713f12;
  --row-plain: #e5e7eb;
  --row-plain-text: #1f2937;
  --row-deleted: #fee2e2;
  --row-deleted-text: #b91c1c;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .10);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .18);

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", "Consolas", "Liberation Mono", monospace;

  --sidebar-w: 232px;
  --topbar-h: 56px;

  /* Motion — shared 1:1 with the Sales Assistant so the two apps move identically.
     Animate transform + opacity only; ease-out on enter, ease-in on exit, spring on confirmations. */
  --ease-out: cubic-bezier(.32, .72, 0, 1);
  --ease-in:  cubic-bezier(.4, 0, 1, 1);
  --spring:   cubic-bezier(.34, 1.56, .64, 1);
  --t-fast: .18s;
  --t: .34s;
  --t-slow: .5s;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #16213a;
  --surface-3: #1e293b;
  --border: #2a3650;
  --border-strong: #3a4a6b;
  --text: #e8edf5;
  --text-muted: #9aa8c0;
  --text-faint: #6b7a96;

  --accent: #fb923c;
  --accent-hover: #fdba74;
  --accent-soft: #3a2310;
  --on-accent: #0b1120;

  --success: #4ade80;
  --success-soft: #16331f;
  --danger: #f87171;
  --danger-soft: #3a1818;
  --warn: #fbbf24;
  --warn-soft: #3a2c12;
  --info: #60a5fa;
  --info-soft: #15233f;

  --row-mr: #14331f;
  --row-mr-text: #86efac;
  --row-fr: #3a1730;
  --row-fr-text: #f9a8d4;
  --row-pvl: #3a3112;
  --row-pvl-text: #fde68a;
  --row-plain: #232c3e;
  --row-plain-text: #cbd5e1;
  --row-deleted: #3a1818;
  --row-deleted-text: #fca5a5;

  --topbar-bg: #0d1424;
  --topbar-text: #e8edf5;
  --topbar-muted: #8092ad;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .5);
  --shadow-lg: 0 14px 40px rgba(0, 0, 0, .6);
}

/* ── Accent themes (global, admin-selected via data-accent on <html>) ──────────
   Default (no data-accent) is orange, set in :root above. These override per choice. */
[data-accent="orange"] { --accent:#ea580c; --accent-hover:#c2410c; --accent-soft:#fff7ed; --on-accent:#ffffff; }
[data-accent="blue"]   { --accent:#4f46e5; --accent-hover:#4338ca; --accent-soft:#eef2ff; --on-accent:#ffffff; }
[data-accent="slate"]  { --accent:#475569; --accent-hover:#334155; --accent-soft:#f1f5f9; --on-accent:#ffffff; }
[data-accent="teal"]   { --accent:#0d9488; --accent-hover:#0f766e; --accent-soft:#f0fdfa; --on-accent:#ffffff; }

[data-theme="dark"][data-accent="orange"] { --accent:#fb923c; --accent-hover:#fdba74; --accent-soft:#3a2310; --on-accent:#0b1120; }
[data-theme="dark"][data-accent="blue"]   { --accent:#818cf8; --accent-hover:#a5b4fc; --accent-soft:#1e2747; --on-accent:#0b1120; }
[data-theme="dark"][data-accent="slate"]  { --accent:#94a3b8; --accent-hover:#cbd5e1; --accent-soft:#1e293b; --on-accent:#0b1120; }
[data-theme="dark"][data-accent="teal"]   { --accent:#2dd4bf; --accent-hover:#5eead4; --accent-soft:#0f2e2b; --on-accent:#0b1120; }

/* ── Base ─────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
::selection { background: var(--accent); color: var(--on-accent); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ── App shell ────────────────────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 40;
  display: flex; align-items: center; gap: 16px;
  padding: 0 18px;
  background: var(--topbar-bg); color: var(--topbar-text);
  box-shadow: var(--shadow-sm);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.02em; font-size: 15px; }
.topbar .brand .logo {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover)); color: var(--on-accent, #fff); font-weight: 800; font-size: 14px;
}
.topbar .spacer { flex: 1; }
.topbar .topbar-item { display: flex; align-items: center; gap: 8px; color: var(--topbar-muted); font-size: 13px; }
.topbar .topbar-item strong { color: var(--topbar-text); font-weight: 600; }

.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 30;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 12px 10px; gap: 2px; overflow-y: auto;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 550; font-size: 13.5px;
  cursor: pointer; user-select: none; border: 1px solid transparent;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.nav-link .ico { width: 18px; height: 18px; flex: 0 0 18px; opacity: .9; }
.nav-section { padding: 14px 12px 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
.nav-group-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 14px 12px 6px; font-family: inherit; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); background: none; border: 0; cursor: pointer; text-align: left; }
.nav-group-head:hover { color: var(--text); }
.nav-group-head .nav-chev { width: 13px; height: 13px; flex: 0 0 13px; opacity: .7; transition: transform .2s ease; }
.nav-group-head.open .nav-chev { transform: rotate(90deg); }
.nav-group { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .25s ease; }
.nav-group.open { grid-template-rows: 1fr; }
.nav-group-inner { overflow: hidden; min-height: 0; }

.content {
  margin-left: var(--sidebar-w); margin-top: var(--topbar-h);
  flex: 1; min-width: 0; padding: 22px 26px 80px; position: relative;
}

/* Desktop sidebar collapse (« / ») — slide the nav off-canvas and reclaim the space. */
@media (min-width: 821px) {
  .sidebar { transition: transform .22s ease; }
  .content { transition: margin-left .22s ease; }
  .app-shell.nav-collapsed .sidebar { transform: translateX(-100%); }
  .app-shell.nav-collapsed .content { margin-left: 0; }
}
.nav-collapse-row { display: flex; justify-content: flex-end; padding: 0 2px 2px; }
.nav-collapse-btn {
  background: none; border: 0; cursor: pointer; color: var(--text-muted);
  font-size: 18px; line-height: 1; padding: 2px 8px; border-radius: var(--radius-sm);
}
.nav-collapse-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-reopen-btn {
  position: fixed; top: calc(var(--topbar-h) + 10px); left: 10px; z-index: 35;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-muted); font-size: 18px; line-height: 1;
  padding: 5px 10px; box-shadow: var(--shadow-sm);
}
.nav-reopen-btn:hover { background: var(--surface-2); color: var(--text); }
@media (max-width: 820px) { .nav-collapse-row, .nav-reopen-btn { display: none; } }
.page-head { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--text-muted); font-size: 13px; }
.page-head .head-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.footer-bar {
  position: fixed; left: var(--sidebar-w); right: 0; bottom: 0; z-index: 20;
  min-height: 30px; padding: 6px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 11.5px; color: var(--text-faint); line-height: 1.5;
  background: var(--surface); border-top: 1px solid var(--border);
}
.footer-bar .foot-left { min-width: 0; }
.footer-bar .foot-right { flex: 0 0 auto; white-space: nowrap; font-weight: 600; }
.footer-bar a { color: inherit; text-decoration: none; }
.footer-bar a:hover { text-decoration: underline; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card.pad { padding: 18px; }
.card-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }

/* Report cards: equal height per row, action row pinned to the bottom so the
   Generate buttons line up across each row. */
.report-grid > .card { display: flex; flex-direction: column; }
.report-grid > .card > :last-child { margin-top: auto; }

.tile {
  display: flex; flex-direction: column; gap: 6px; padding: 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); cursor: pointer; transition: transform .08s ease, box-shadow .12s ease, border-color .12s ease;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); text-decoration: none; }
.tile .tile-ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 4px; }
.tile .tile-title { font-weight: 650; color: var(--text); }
.tile .tile-desc { font-size: 12.5px; color: var(--text-muted); }

.metric { display: flex; flex-direction: column; gap: 2px; }
.metric .value { font-size: 26px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.metric .label { font-size: 12px; color: var(--text-muted); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  font-family: inherit; font-size: 13px; font-weight: 600; line-height: 1;
  padding: 9px 14px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: transform var(--t-fast) var(--ease-out), background var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out), opacity var(--t-fast) var(--ease-out);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0) scale(.975); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.icon { padding: 8px; }
.btn.sync { color: #fff; border: none; background: linear-gradient(135deg, #f59e0b, #d97706); }
.btn.sync:hover { background: linear-gradient(135deg, #fbbf24, #f59e0b); }

/* ── Inputs ───────────────────────────────────────────────────────────────── */
.input, .select, textarea.input {
  font-family: inherit; font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 11px; width: 100%;
}
.input::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, textarea.input:focus, .btn:focus-visible, .nav-link:focus-visible, .pill:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.input-icon { position: relative; }
.input-icon .input { padding-left: 32px; }

/* Searchable dropdown (type-to-filter combobox) */
.ss-wrap { position: relative; }
.ss-input { width: 100%; padding-right: 24px; }
.ss-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: none; background: transparent; color: var(--text-faint); cursor: pointer; font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
.ss-clear:hover { color: var(--text); background: var(--surface-2); }
.ss-menu { position: absolute; z-index: 60; left: 0; right: 0; margin-top: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 4px; max-height: 260px; overflow: auto; }
.ss-opt { padding: 6px 9px; border-radius: 6px; font-size: 13px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-opt:hover { background: var(--surface-2); }
.ss-opt.sel { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ss-all { color: var(--text-muted); }
.ss-empty { padding: 8px 9px; font-size: 12.5px; color: var(--text-faint); }
.input-icon svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-faint); pointer-events: none; }

/* ── Segmented pill filters (iOS-style, like the SA gate) ─────────────────── */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.segmented .pill {
  border: none; background: transparent; color: var(--text-muted);
  font: inherit; font-size: 12.5px; font-weight: 600; padding: 6px 13px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.segmented .pill.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
.seg-group { display: flex; flex-direction: column; gap: 5px; }
.seg-group .seg-label { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }

.toolbar { display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: flex-end; }

/* ── Chips ────────────────────────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); user-select: none;
}
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 650; padding: 3px 9px; border-radius: 999px; }
.badge.muted { background: var(--surface-3); color: var(--text-muted); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.mini { font-size: 10px; padding: 2px 6px; font-weight: 600; }

/* ── Data grid ────────────────────────────────────────────────────────────── */
.grid-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow-sm); max-height: calc(100vh - 290px); }
table.data-grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; }
table.data-grid th, table.data-grid td { padding: 7px 11px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
table.data-grid thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--text-muted);
  font-weight: 700; font-size: 11px; letter-spacing: .03em; text-transform: uppercase;
  border-bottom: 1px solid var(--border-strong); cursor: pointer; user-select: none;
}
table.data-grid thead th:hover { color: var(--text); }
table.data-grid tbody tr:hover { background: var(--surface-2); }
table.data-grid td.num, table.data-grid th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
table.data-grid td.mono { font-family: var(--font-mono); font-size: 12px; }
table.data-grid .col-sort-asc::after { content: " ▲"; font-size: 9px; color: var(--accent); }
table.data-grid .col-sort-desc::after { content: " ▼"; font-size: 9px; color: var(--accent); }

/* Row category highlights — SO# cell only (faithful to the desktop). Deleted stays whole-row. */
td.son-mr { background: var(--row-mr); color: var(--row-mr-text); font-weight: 650; }
td.son-fr { background: var(--row-fr); color: var(--row-fr-text); font-weight: 650; }
td.son-pvl { background: var(--row-pvl); color: var(--row-pvl-text); font-weight: 650; }
td.son-plain { background: var(--row-plain); color: var(--row-plain-text); font-weight: 650; }
tr.row-deleted td { color: var(--row-deleted-text) !important; background: var(--row-deleted) !important; }
tr.row-aged-warn td { background: var(--warn-soft); }
tr.row-aged-block td { background: var(--danger-soft); }
table.data-grid tbody tr:hover td { background: var(--surface-2); }
.row-actions { display: inline-flex; gap: 4px; }

.empty { padding: 48px 20px; text-align: center; color: var(--text-muted); }
.empty .big { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(2, 6, 23, .55); display: grid; place-items: center; padding: 20px; animation: fade var(--t-fast) var(--ease-out); }
/* Blocking progress overlay shown while a bulk assemble / scrap job runs (sits above topbar + sidebar). */
.bulk-modal-backdrop { position: fixed; inset: 0; z-index: 150; background: rgba(2, 6, 23, .62); display: grid; place-items: center; padding: 20px; animation: fade var(--t-fast) var(--ease-out); }
.bulk-modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 18px 20px; max-width: 420px; width: 100%; animation: pop var(--t) var(--ease-out); }
.modal {
  width: 100%; max-width: 560px; max-height: 86vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: pop var(--t) var(--ease-out);
}
.modal.lg { max-width: 860px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-head .x { margin-left: auto; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes toastIn { from { opacity: 0; transform: translateX(16px); } }
/* Spring — confirmations only (a ✓, a count roll). Opt in with .badge-pop. */
@keyframes confirmPop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
.badge-pop { animation: confirmPop var(--t) var(--spring); }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toasts { position: fixed; right: 18px; bottom: 42px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); padding: 11px 14px; box-shadow: var(--shadow-md); min-width: 240px; max-width: 380px; font-size: 13px; animation: toastIn var(--t) var(--ease-out); }
.toast.success { border-left-color: var(--success); }
.toast.danger { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

/* ── Misc helpers ─────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.row { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.right { margin-left: auto; }
.spin { width: 16px; height: 16px; border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); border-top-color: var(--accent); border-radius: 50%; animation: rot .7s linear infinite; display: inline-block; }
@keyframes rot { to { transform: rotate(360deg); } }
.divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }
.cols-popover { position: absolute; z-index: 60; margin-top: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 10px; width: 260px; max-height: 360px; overflow: auto; transform-origin: top left; animation: popoverIn var(--t) var(--ease-out); }
.popover-backdrop { position: fixed; inset: 0; z-index: 55; background: transparent; }
.cols-popover-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 2px 6px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.actions-col { width: 1%; white-space: nowrap; }
.col-toggle { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; font-size: 13px; cursor: pointer; animation: rowIn var(--t) var(--ease-out) both; }
.col-toggle:hover { background: var(--surface-2); }
@keyframes popoverIn { from { opacity: 0; transform: scale(.92) translateY(-4px); } }
@keyframes rowIn { from { opacity: 0; transform: translateY(-5px); } }

/* ── Auth / login ─────────────────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background:
  radial-gradient(1200px 600px at 80% -10%, color-mix(in srgb, var(--brand-indigo) 14%, transparent), transparent),
  var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 30px 28px; }
.auth-card .logo-lg { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-hover)); color: var(--on-accent, #fff); font-weight: 800; font-size: 22px; margin-bottom: 16px; }
.auth-card h1 { font-size: 19px; margin-bottom: 3px; }
.auth-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 22px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .err { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 12.5px; margin-bottom: 16px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 11.5px; color: var(--text-faint); }

/* Theme toggle */
.theme-toggle { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; cursor: pointer; color: var(--topbar-text); background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); }
.theme-toggle:hover { background: rgba(255,255,255,.12); }

/* Org picker in the topbar */
.org-picker select {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--topbar-text);
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.14); border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.org-picker select option { color: #0f172a; }

@media (max-width: 820px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); width: 232px; }
  .sidebar.open { transform: translateX(0); }
  .footer-bar { left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Per-row "open in Zoho" menu (#11) */
.opener-wrap { position: relative; display: inline-block; }
.opener-menu { position: absolute; right: 0; z-index: 60; margin-top: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; min-width: 168px; display: flex; flex-direction: column; gap: 2px; transform-origin: top right; animation: popoverIn var(--t) var(--ease-out); }
.opener-link { display: block; width: 100%; text-align: left; padding: 6px 8px; border-radius: 6px; font-size: 13px; cursor: pointer; background: transparent; border: 0; color: inherit; }
.opener-link:hover { background: var(--surface-2); }

/* ── Theme picker (User Management → global accent) ──────────────────────────── */
.theme-pick { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 13.5px; font-weight: 600; cursor: pointer; }
.theme-pick:hover { border-color: var(--accent); }
.theme-pick.on { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent-soft); }
.theme-pick:disabled { opacity: .6; cursor: default; }
.theme-dot { width: 16px; height: 16px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.theme-check { color: var(--accent); font-weight: 800; animation: confirmPop var(--t) var(--spring); }

/* ── Toggle switch ───────────────────────────────────────────────────────── */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.switch > input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 42px; height: 24px; border-radius: 999px; background: var(--border-strong); position: relative; flex: 0 0 auto; transition: background var(--t-fast) var(--ease-out); }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--t-fast) var(--ease-out); }
.switch > input:checked + .track { background: var(--accent); }
.switch > input:checked + .track::after { transform: translateX(18px); }
.switch > input:focus-visible + .track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.switch > input:disabled + .track { opacity: .5; cursor: not-allowed; }

/* ── Collapsible card (HTML <details>) ───────────────────────────────────── */
.fold-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.fold-card > summary { list-style: none; cursor: pointer; padding: 14px 16px; font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; user-select: none; }
.fold-card > summary::-webkit-details-marker { display: none; }
.fold-card > summary::before { content: "\25B8"; color: var(--text-muted); display: inline-block; transition: transform var(--t-fast) var(--ease-out); }
.fold-card[open] > summary::before { transform: rotate(90deg); }
.fold-card > summary:hover { background: var(--surface-2); }
.fold-body { padding: 4px 16px 16px; border-top: 1px solid var(--border); }

/* ── Column drag-to-reorder (drag handle in each header) ──────────────────── */
.grip { cursor: grab; color: var(--text-muted); opacity: .4; margin-right: 6px; font-size: 11px; user-select: none; display: inline-block; vertical-align: middle; line-height: 1; transition: opacity var(--t-fast) var(--ease-out); }
table.data-grid thead th:hover .grip { opacity: .85; }
.grip:hover { opacity: 1 !important; }
.grip:active { cursor: grabbing; }
table.data-grid thead th.col-dragging { opacity: .4; }
table.data-grid thead th.col-drag-over { box-shadow: inset 3px 0 0 var(--accent); }

/* Cheque Writing — payment picker rows: hover + selected marking */
.pick-row { transition: background .12s ease; }
.pick-row:hover { background: var(--surface-2); }
.pick-row.sel { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.pick-row.sel .muted { color: var(--accent); opacity: .85; }

/* Setting page — area navigation cards */
.set-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(260px,1fr)); gap:12px; margin-bottom:16px; }
.set-card { display:flex; align-items:center; gap:12px; text-align:left; background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:14px 16px; cursor:pointer; transition:background .12s, border-color .12s, transform .05s; }
.set-card:hover { background:var(--surface-2); border-color:var(--accent); }
.set-card:active { transform:translateY(1px); }
.set-ic { font-size:22px; line-height:1; }
.set-tx { display:flex; flex-direction:column; gap:2px; flex:1; min-width:0; }
.set-tt { font-weight:600; }
.set-ss { font-size:12px; color:var(--text-muted); line-height:1.4; }
.set-go { color:var(--text-muted); font-size:18px; }
