/* ClientDesk — light / dark design tokens ------------------------------------------------ */
:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --surface-3: #f0efeb;
  --border: #e4e2dc;
  --border-strong: #d2cfc7;
  --grid-line: #ebe9e4;
  --text: #1c1c1a;
  --text-2: #4a4945;
  --muted: #7a7872;
  --accent: #0e7c66;
  --accent-hover: #0b6a57;
  --accent-soft: #e3f3ee;
  --accent-ink: #ffffff;
  --sel: #0e7c66;
  --sel-bg: #e9f6f2;
  --row-hover: #f7f7f3;
  --danger: #c0352b;
  --danger-soft: #fbeceb;
  --warn: #b26a00;
  --warn-soft: #fdf3e2;
  --ok: #1e7d3c;
  --ok-soft: #e7f5ec;
  --shadow-sm: 0 1px 2px rgba(20, 20, 15, .06);
  --shadow: 0 6px 24px rgba(20, 20, 15, .08), 0 1px 3px rgba(20, 20, 15, .06);
  --shadow-lg: 0 18px 50px rgba(20, 20, 15, .18);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 232px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  /* badge palette: bg / text */
  --b-gray-bg: #eeede9;   --b-gray: #55534d;
  --b-blue-bg: #e5eefc;   --b-blue: #1f4fa3;
  --b-purple-bg: #efe9fb; --b-purple: #5b3aa6;
  --b-green-bg: #e3f4e8;  --b-green: #1d6b35;
  --b-amber-bg: #fcf1d9;  --b-amber: #8a5a00;
  --b-orange-bg: #fde9dc; --b-orange: #a5470f;
  --b-red-bg: #fbe5e3;    --b-red: #a8261c;
  --b-teal-bg: #dff3f1;   --b-teal: #0d6560;
  --b-pink-bg: #fbe6f0;   --b-pink: #9c2560;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111312; --surface: #181b1a; --surface-2: #1c201e; --surface-3: #232826;
    --border: #2b302e; --border-strong: #3a403d; --grid-line: #262b29;
    --text: #e8ebe9; --text-2: #c2c7c4; --muted: #8c938f;
    --accent: #2fbf9c; --accent-hover: #4fd1b0; --accent-soft: #163a31; --accent-ink: #07130f;
    --sel: #2fbf9c; --sel-bg: #15302a; --row-hover: #1d2220;
    --danger: #ff7b6e; --danger-soft: #3a1c19; --warn: #f0b44c; --warn-soft: #3a2c12; --ok: #5fd38a; --ok-soft: #15301f;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 8px 28px rgba(0,0,0,.45); --shadow-lg: 0 20px 60px rgba(0,0,0,.6);
    --b-gray-bg: #2a2e2c;   --b-gray: #c3c8c5;
    --b-blue-bg: #1a2a45;   --b-blue: #9cc0ff;
    --b-purple-bg: #2a2142; --b-purple: #c6b2ff;
    --b-green-bg: #163222;  --b-green: #8ee0a8;
    --b-amber-bg: #3a2d10;  --b-amber: #f5cd75;
    --b-orange-bg: #3d2314; --b-orange: #ffb086;
    --b-red-bg: #401c19;    --b-red: #ff9d93;
    --b-teal-bg: #123533;   --b-teal: #7fe0d6;
    --b-pink-bg: #3c1a2b;   --b-pink: #ff9cc8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111312; --surface: #181b1a; --surface-2: #1c201e; --surface-3: #232826;
  --border: #2b302e; --border-strong: #3a403d; --grid-line: #262b29;
  --text: #e8ebe9; --text-2: #c2c7c4; --muted: #8c938f;
  --accent: #2fbf9c; --accent-hover: #4fd1b0; --accent-soft: #163a31; --accent-ink: #07130f;
  --sel: #2fbf9c; --sel-bg: #15302a; --row-hover: #1d2220;
  --danger: #ff7b6e; --danger-soft: #3a1c19; --warn: #f0b44c; --warn-soft: #3a2c12; --ok: #5fd38a; --ok-soft: #15301f;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 8px 28px rgba(0,0,0,.45); --shadow-lg: 0 20px 60px rgba(0,0,0,.6);
  --b-gray-bg: #2a2e2c;   --b-gray: #c3c8c5;
  --b-blue-bg: #1a2a45;   --b-blue: #9cc0ff;
  --b-purple-bg: #2a2142; --b-purple: #c6b2ff;
  --b-green-bg: #163222;  --b-green: #8ee0a8;
  --b-amber-bg: #3a2d10;  --b-amber: #f5cd75;
  --b-orange-bg: #3d2314; --b-orange: #ffb086;
  --b-red-bg: #401c19;    --b-red: #ff9d93;
  --b-teal-bg: #123533;   --b-teal: #7fe0d6;
  --b-pink-bg: #3c1a2b;   --b-pink: #ff9cc8;
  color-scheme: dark;
}

/* Base ----------------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
code, kbd { font-family: var(--mono); font-size: .86em; }
code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
kbd { border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--surface); color: var(--text-2); }
.ic { flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
.c { text-align: center; }
.lead { margin: 0 0 16px; max-width: 760px; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Shell ---------------------------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 14px 10px; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-weight: 700;
  background: var(--accent); color: var(--accent-ink); font-size: 15px;
}
.brand-name { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-3); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav-label { margin: 18px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 4px 0; border-top: 1px solid var(--border); }
.theme-switch { display: flex; width: 100%; background: var(--surface-3); border-radius: 8px; padding: 3px; gap: 2px; }
.theme-switch button {
  flex: 1; border: 0; background: transparent; color: var(--muted); border-radius: 6px; height: 28px; display: grid; place-items: center; cursor: pointer;
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.me { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; color: var(--text); padding: 4px; border-radius: 8px; }
.me:hover { background: var(--surface-3); color: var(--text); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); font-size: 12px; font-weight: 700; color: var(--text-2); flex: none; }
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.me-text b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { color: var(--muted); font-size: 11px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px; min-height: 60px;
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 19px; font-weight: 650; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.content { padding: 20px 24px 40px; flex: 1; min-width: 0; }
.menu-btn { display: none; }
.scrim { display: none; }

/* Buttons & forms ------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 500 13px var(--font);
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-3); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; height: 40px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); width: 32px; height: 32px; border-radius: 7px;
  display: inline-grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 550; color: var(--text-2); }
.form label small { font-weight: 400; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
input, select, textarea {
  font: 14px var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 7px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); padding: 0; }
input[readonly].locked { background: var(--surface-3); color: var(--muted); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-row > label { flex: 0 1 auto; }
.form-row .grow { flex: 1 1 180px; }
.w-110 { width: 110px; } .w-150 { width: 170px; } .w-sort { width: 64px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.narrow { max-width: 760px; }
.note { background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--text-2); line-height: 1.7; }
.default-submit { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; white-space: pre-line; }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-info { background: var(--accent-soft); color: var(--accent); }
.alert-error { background: var(--danger-soft); color: var(--danger); }

/* Panels / tables ------------------------------------------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; font-weight: 650; }
.link { font-size: 13px; font-weight: 500; }
.sub-h { font-size: 13px; font-weight: 650; margin: 18px 0 8px; color: var(--text-2); }
.empty { padding: 22px; text-align: center; color: var(--muted); background: var(--surface-2); border-radius: 8px; }
.empty-state { text-align: center; padding: 80px 20px; }
.table-scroll { overflow-x: auto; }
table.simple { width: 100%; border-collapse: collapse; font-size: 13px; }
table.simple th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.simple th small { display: block; font-weight: 400; font-size: 11px; }
table.simple td, table.simple tbody th { padding: 9px 10px; border-bottom: 1px solid var(--grid-line); vertical-align: middle; }
table.simple tbody tr:last-child td, table.simple tbody tr:last-child th { border-bottom: 0; }
table.simple tbody th { color: var(--text); font-size: 13px; }
table.simple.compact td { padding: 4px 6px; }
table.simple.compact input, table.simple.compact select { padding: 5px 8px; font-size: 13px; width: 100%; }
table.simple td.clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.money-table td { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-table td.pos { color: var(--ok); }
.money-table td.neg { color: var(--danger); font-weight: 600; }
.cur { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .02em; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding-top: 14px; }
.plain-list { margin: 0; padding-left: 18px; line-height: 1.9; }
.lists-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 18px; align-items: start; }
.lists-grid .panel { margin: 0; }
.list-card .form-actions { margin-top: 10px; }
.new-row input { border-style: dashed; }
.list-card table.simple.compact .color-select { width: 108px; }
.list-card table.simple.compact input.w-sort { width: 58px; }
.list-card table.simple.compact td:nth-last-child(2) { width: 44px; }
.list-card table.simple.compact td:last-child { width: 36px; }
.perm-table td:first-child { white-space: nowrap; }
.inline-form { margin-top: 6px; }
.role-tools { margin-top: 16px; gap: 10px; }
.role-tools form.form-row { flex: 1 1 520px; }
.role-tools label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 550; color: var(--text-2); }

/* Badges ---------------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  line-height: 20px; white-space: nowrap; background: var(--b-gray-bg); color: var(--b-gray);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-gray { background: var(--b-gray-bg); color: var(--b-gray); }
.badge-blue { background: var(--b-blue-bg); color: var(--b-blue); }
.badge-purple { background: var(--b-purple-bg); color: var(--b-purple); }
.badge-green { background: var(--b-green-bg); color: var(--b-green); }
.badge-amber { background: var(--b-amber-bg); color: var(--b-amber); }
.badge-orange { background: var(--b-orange-bg); color: var(--b-orange); }
.badge-red { background: var(--b-red-bg); color: var(--b-red); }
.badge-teal { background: var(--b-teal-bg); color: var(--b-teal); }
.badge-pink { background: var(--b-pink-bg); color: var(--b-pink); }
.due { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.due-soon { color: var(--warn); }
.due-today { color: var(--warn); }
.due-late { color: var(--danger); }

/* Dashboard ------------------------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px; color: var(--text); box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi:hover { border-color: var(--border-strong); color: var(--text); }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.kpi-warn::before { background: var(--warn); }
.kpi-bad::before { background: var(--danger); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.dash-grid .panel { margin: 0; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 32px; align-items: center; gap: 10px; color: var(--text-2); font-size: 13px; padding: 2px 4px; border-radius: 6px; }
.bar-row:hover { background: var(--surface-2); color: var(--text); }
.bar-track { height: 10px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 99px; background: var(--b-gray); }
.bar-blue { background: var(--b-blue); } .bar-purple { background: var(--b-purple); } .bar-green { background: var(--b-green); }
.bar-amber { background: var(--b-amber); } .bar-orange { background: var(--b-orange); } .bar-red { background: var(--b-red); }
.bar-teal { background: var(--b-teal); } .bar-pink { background: var(--b-pink); }
.bar-n { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.prio-row { display: flex; gap: 10px; flex-wrap: wrap; }
.prio { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.prio:hover { border-color: var(--border-strong); color: var(--text); }

/* Auth ------------------------------------------------------------------------------------ */
body.auth { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.auth-main { width: 100%; padding: 20px; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 30px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 22px; margin-top: 6px; }
.auth-card p { margin: 4px 0 20px; }
.brand-lg { padding: 0 0 14px; }

/* Grid page ------------------------------------------------------------------------------- */
body.grid-page .content { display: flex; flex-direction: column; padding-bottom: 12px; height: calc(100vh - 60px); }
.toolbar { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .filters { order: 3; flex-basis: 100%; }
.toolbar .filters:empty { display: none; }
.search { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 0 10px; height: 34px; color: var(--muted); width: 260px; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { border: 0; padding: 0; height: 100%; background: transparent; flex: 1; box-shadow: none !important; font-size: 13px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter {
  height: 30px; border-radius: 8px; padding: 0 28px 0 10px; font-size: 13px; color: var(--text-2); max-width: 190px;
  appearance: none; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' fill='none' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
}
.filter.on { border-color: var(--accent); color: var(--accent); background-color: var(--accent-soft); font-weight: 600; }
.clear-filters { font-size: 12px; }
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.count { font-size: 12px; color: var(--muted); margin-right: 6px; white-space: nowrap; }
.dropdown { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; min-width: 220px; max-height: 60vh; overflow: auto; z-index: 60;
}
.menu label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.menu label:hover { background: var(--surface-3); }
.menu .menu-foot { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }

.grid-wrap {
  flex: 1; min-height: 240px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); position: relative; outline: none;
}
.grid-wrap:focus-visible { outline: none; border-color: var(--border-strong); }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 13px; table-layout: fixed; width: max-content; min-width: 100%; }
.grid th, .grid td {
  height: 36px; padding: 0 10px; border-right: 1px solid var(--grid-line); border-bottom: 1px solid var(--grid-line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; vertical-align: middle; background: var(--surface);
}
.grid thead th {
  position: sticky; top: 0; z-index: 3; background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 650;
  user-select: none; cursor: pointer; height: 38px; border-bottom-color: var(--border);
}
.grid thead th:hover { color: var(--text); background: var(--surface-3); }
.grid thead th .th-in { display: flex; align-items: center; gap: 4px; }
.grid thead th .th-label { overflow: hidden; text-overflow: ellipsis; }
.grid thead th .sort-ind { color: var(--accent); font-size: 10px; }
.grid thead th .req { color: var(--danger); }
.grid thead th.ro .th-label { font-style: italic; font-weight: 600; }
.grid .rownum {
  width: 46px; text-align: center; color: var(--muted); font-size: 11px; background: var(--surface-2); position: sticky; left: 0; z-index: 2;
  padding: 0; font-variant-numeric: tabular-nums;
}
.grid thead .rownum { z-index: 5; cursor: default; }
.grid td.frozen, .grid th.frozen { position: sticky; left: 46px; z-index: 1; box-shadow: 1px 0 0 var(--border); }
.grid thead th.frozen { z-index: 4; }
.grid td.frozen { font-weight: 600; }
.grid tbody tr:hover td { background: var(--row-hover); }
.grid tbody tr:hover td.rownum { background: var(--surface-3); }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid td.center { text-align: center; }
.grid td .cur { margin-right: 4px; }
.grid td.ro { color: var(--text-2); background: var(--surface-2); }
.grid tbody tr:hover td.ro { background: var(--surface-3); }
.grid td.neg-val { color: var(--danger); font-weight: 600; }
.grid td.warn-val { color: var(--warn); font-weight: 600; }
.grid td.ok-val { color: var(--ok); }
.grid td.empty-req { box-shadow: inset 0 0 0 1px var(--danger-soft); background: var(--danger-soft); }
.grid td .placeholder { color: var(--muted); opacity: .6; font-weight: 400; }
.grid td.sel { box-shadow: inset 0 0 0 2px var(--sel); background: var(--sel-bg) !important; }
.grid td.frozen.sel { z-index: 2; }
.grid tr.row-active td.rownum { color: var(--accent); font-weight: 700; }
.grid td.saving { background-image: linear-gradient(90deg, transparent, var(--accent-soft), transparent); background-size: 200% 100%; animation: shimmer 1s linear infinite; }
.grid td.saved { animation: flash 0.9s ease-out; }
.grid td.err { box-shadow: inset 0 0 0 2px var(--danger); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes flash { from { background: var(--ok-soft); } to { background: inherit; } }
.grid tr.is-new td { animation: newrow 1.4s ease-out; }
@keyframes newrow { from { background: var(--accent-soft); } }
.grid td.editing { padding: 0; overflow: visible; box-shadow: inset 0 0 0 2px var(--sel); z-index: 6; position: relative; }
.grid td.editing.frozen { position: sticky; }
.grid td.editing > .cell-editor {
  width: 100%; height: 100%; border: 0; border-radius: 0; padding: 0 9px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--sel); font-size: 13px; outline: none;
}
.grid td.editing > select.cell-editor { padding: 0 6px; cursor: pointer; }
.grid td.editing > textarea.cell-editor {
  position: absolute; top: 0; left: 0; width: max(100%, 340px); height: 140px; padding: 8px 10px; resize: both;
  border: 2px solid var(--sel); border-radius: 0 6px 6px 6px; box-shadow: var(--shadow); line-height: 1.45; z-index: 7;
}
.grid td.editing > input[type="date"].cell-editor { padding: 0 6px; }
.grid tr.ghost td { color: var(--muted); cursor: pointer; background: var(--surface); border-bottom: 0; }
.grid tr.ghost td:hover, .grid tr.ghost.sel-ghost td { color: var(--accent); background: var(--accent-soft); }
.grid tr.ghost td.add-cell { font-weight: 550; overflow: visible; box-shadow: none; }
.grid tr.ghost td { border-right-color: transparent; }
.grid tfoot td {
  position: sticky; bottom: 0; z-index: 2; background: var(--surface-2); border-top: 1px solid var(--border); font-size: 12px;
  color: var(--text-2); font-weight: 600; white-space: normal; line-height: 1.35; height: auto; padding: 7px 10px;
}
.grid tfoot td.rownum { z-index: 3; }
.grid tfoot td.frozen { z-index: 3; }
.grid tfoot .tot { display: block; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-del {
  display: none; border: 0; background: transparent; color: var(--muted); width: 100%; height: 100%; cursor: pointer; align-items: center; justify-content: center;
}
.grid tbody tr:not(.ghost):hover .rownum .rn { display: none; }
.grid tbody tr:not(.ghost):hover .row-del { display: flex; }
.row-del:hover { color: var(--danger); background: var(--danger-soft); }
.chip-bool {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 46px; height: 22px; padding: 0 8px;
  border-radius: 99px; font-size: 12px; font-weight: 600; border: 1px solid transparent; cursor: pointer; user-select: none;
}
.chip-bool.yes { background: var(--b-green-bg); color: var(--b-green); }
.chip-bool.no { background: transparent; color: var(--muted); border-color: var(--border); }
.chip-bool.disabled { cursor: default; }
.cell-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-2); font: 600 12px var(--font); cursor: pointer; max-width: 100%;
}
.cell-btn:hover { border-color: var(--accent); color: var(--accent); }
.cell-btn.primary { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.cell-btn .nm { overflow: hidden; text-overflow: ellipsis; }
.cell-link { color: var(--accent); font-weight: 550; overflow: hidden; text-overflow: ellipsis; display: inline-block; max-width: 100%; vertical-align: middle; }
.file-cell { display: flex; align-items: center; gap: 4px; }
.file-cell .icon-btn { width: 22px; height: 22px; }
.grid-hint { font-size: 11.5px; color: var(--muted); padding: 8px 2px 0; }
.grid-empty td { text-align: center; color: var(--muted); padding: 40px; height: auto; white-space: normal; }

/* Toasts ---------------------------------------------------------------------------------- */
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(420px, calc(100vw - 36px)); }
.toast {
  display: flex; align-items: center; gap: 12px; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 9px;
  box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 500; animation: toastin .18s ease-out; white-space: pre-line;
}
.toast.error { background: var(--danger); color: #fff; }
.toast button { margin-left: auto; background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 6px; padding: 2px 9px; font: 600 12px var(--font); cursor: pointer; opacity: .9; }
@keyframes toastin { from { transform: translateY(8px); opacity: 0; } }

/* Drawer & modal -------------------------------------------------------------------------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 12, 11, .38); z-index: 100; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); background: var(--surface); z-index: 101; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; animation: slidein .2s ease-out;
}
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { padding: 18px 22px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.drawer-head h2 { font-size: 18px; }
.drawer-head .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; align-items: center; }
.drawer-head .icon-btn { margin-left: auto; }
.drawer-body { padding: 16px 22px 30px; overflow: auto; flex: 1; }
.drawer-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; display: flex; justify-content: space-between; align-items: center; }
.drawer-body h3:first-child { margin-top: 4px; }
.drawer-body h3 a { text-transform: none; letter-spacing: 0; font-weight: 550; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.fact { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; }
.fact > span { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.fact b { font-variant-numeric: tabular-nums; font-size: 14px; }
.doc-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.doc-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--grid-line); }
.doc-item:last-child { border-bottom: 0; }
.doc-item .doc-main { flex: 1; min-width: 0; }
.doc-item .doc-main a { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item .doc-main small { color: var(--muted); }
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: 10px; padding: 16px; text-align: center; color: var(--muted); background: var(--surface-2);
  transition: border-color .12s, background .12s; margin-top: 10px;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone .dz-row { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.dropzone select, .dropzone input[type="text"] { height: 32px; padding: 0 8px; font-size: 13px; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table td { padding: 7px 8px; border-bottom: 1px solid var(--grid-line); }
.mini-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.modal {
  position: fixed; left: 50%; top: 12vh; transform: translateX(-50%); width: min(480px, calc(100vw - 32px)); background: var(--surface);
  border-radius: 14px; z-index: 101; box-shadow: var(--shadow-lg); padding: 22px; animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateX(-50%) scale(.97); opacity: 0; } }
.modal h2 { font-size: 17px; margin-bottom: 14px; }
.modal .form-actions { justify-content: flex-end; margin-top: 6px; }

/* Responsive ------------------------------------------------------------------------------ */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .menu-btn { display: inline-grid; margin-left: -8px; }
  .topbar { padding: 10px 16px; min-height: 54px; }
  .topbar h1 { font-size: 17px; }
  .content { padding: 14px 16px 30px; }
  body.grid-page .content { height: calc(100vh - 54px); }
  .search { width: 100%; }
  .toolbar .filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  .toolbar .filters .filter { flex: none; }
  .toolbar-right { margin-left: 0; width: 100%; justify-content: flex-end; }
  .btn span { display: none; }
  .top-actions .btn span { display: inline; }
  .grid-hint { display: none; }
  .facts { grid-template-columns: repeat(2, 1fr); }
  .lists-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .kpis { gap: 10px; }
  .kpi-value { font-size: 22px; }
  .bar-row { grid-template-columns: 96px 1fr 28px; }
  .grid td.frozen, .grid th.frozen { position: static; box-shadow: none; }
}
@media print {
  .sidebar, .toolbar, .grid-hint, .topbar .top-actions, .menu-btn { display: none !important; }
  .grid-wrap { overflow: visible; border: 0; }
  body.grid-page .content { height: auto; }
}
