/* ===========================================================
   IT Asset & Subscription Manager — enterprise design system
   Light / Dark via [data-theme]

   Structure:
     1. Tokens        2. Base / utilities   3. Login
     4. App shell     5. Forms & buttons    6. Cards & layout
     7. Stat cards    8. Tables & actions   9. Badges
    10. Toolbar       11. Pagination       12. Modal
    13. Detail / tabs 14. Toast            15. Charts / loading
    16. Responsive
   =========================================================== */

/* ---------------- 1. Tokens ---------------- */
:root {
  --brand: #1f3a5f;
  --brand-2: #2c5282;
  --accent: #3b82f6;
  --accent-soft: #dbeafe;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #0891b2;
  --info-soft: #cffafe;
  --violet: #7c3aed;
  --violet-soft: #ede9fe;

  /* badge/label text colours: darker than the accents above so small bold text
     on the *-soft fills clears WCAG AA 4.5:1. The accents stay as-is for
     borders, spinners and stat rails where 3:1 non-text contrast is enough. */
  --ok-ink: #166534;
  --warn-ink: #92400e;
  --danger-ink: #991b1b;
  --info-ink: #155e75;
  --violet-ink: #5b21b6;
  --blue-ink: #1e40af;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-soft: #475569;
  --muted: #94a3b8;
  --sidebar-bg: #16273f;
  --sidebar-text: #c7d2e0;
  --sidebar-active: #2c5282;
  --sidebar-label: #6f82a0;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .15);
  --overlay: rgba(15, 23, 42, .55);

  /* geometry — one scale, used everywhere */
  --radius: 10px;
  --radius-sm: 7px;
  --radius-pill: 999px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --control-h: 38px;          /* inputs, selects, buttons, icon buttons */
  --control-h-sm: 30px;       /* .btn-sm */
  --cell-y: 10px;             /* table cell padding */
  --cell-x: 14px;
  --fs-xs: 11.5px;
  --fs-sm: 12.5px;
  --fs-base: 13.5px;
  --fs-md: 15px;
  --fs-lg: 18px;
  --ico: 16px;
}
[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #0f1727;
  --surface-3: #1a2438;
  --border: #243049;
  --border-strong: #34405c;
  --text: #e6edf6;
  --text-soft: #a8b6cc;
  --muted: #8496b0;
  --sidebar-bg: #0a1020;
  --sidebar-text: #aebacf;
  --sidebar-active: #1d3a63;
  --sidebar-label: #7c8dab;
  /* brighter foregrounds so badges/labels stay readable on dark soft fills */
  --ok: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --info: #22d3ee;
  --violet: #c4b5fd;
  --brand-2: #93c5fd;
  /* on dark, the bright accents already read well as badge text */
  --ok-ink: #4ade80;
  --warn-ink: #fbbf24;
  --danger-ink: #f87171;
  --info-ink: #22d3ee;
  --violet-ink: #c4b5fd;
  --blue-ink: #93c5fd;
  --accent-soft: #1e3a5f;
  --ok-soft: #0f2e1d;
  --warn-soft: #3a2a08;
  --danger-soft: #3a1414;
  --info-soft: #0a2c33;
  --violet-soft: #2b2150;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-lg: 0 14px 40px rgba(0, 0, 0, .55);
  --overlay: rgba(2, 6, 16, .68);
}

/* ---------------- 2. Base / utilities ---------------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: var(--fs-sm); }
h1, h2, h3, h4 { line-height: 1.3; }

/* visible keyboard focus everywhere (a11y §24) */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.btn:focus-visible, .icon-btn:focus-visible, .pill-tabs button:focus-visible { outline-offset: 2px; }

/* screen-reader-only text for icon-only controls */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* keyboard users can jump past the sidebar */
.skip-link {
  position: absolute; left: -9999px; top: var(--sp-2); z-index: 300;
  background: var(--surface); color: var(--text); border: 1px solid var(--accent);
  padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); font-weight: 600;
}
.skip-link:focus { left: var(--sp-2); }

/* layout utilities — these exist so page code doesn't need inline styles */
.u-row { display: flex; align-items: center; gap: var(--sp-2); }
.u-row-top { display: flex; align-items: flex-start; gap: var(--sp-2); }
.u-between { justify-content: space-between; }
.u-end { justify-content: flex-end; }
.u-wrap { flex-wrap: wrap; }
.u-flex1 { flex: 1; min-width: 0; }
.u-gap-1 { gap: var(--sp-1); } .u-gap-2 { gap: var(--sp-2); } .u-gap-3 { gap: var(--sp-3); }
.u-mt-0 { margin-top: 0; } .u-mt-2 { margin-top: var(--sp-2); } .u-mt-3 { margin-top: var(--sp-3); } .u-mt-4 { margin-top: var(--sp-4); }
.u-mb-0 { margin-bottom: 0; } .u-mb-2 { margin-bottom: var(--sp-2); } .u-mb-3 { margin-bottom: var(--sp-3); } .u-mb-4 { margin-bottom: var(--sp-4); }
.u-right { text-align: right; }
.u-nowrap { white-space: nowrap; }
.u-break { word-break: break-word; }
.u-mono { font-variant-numeric: tabular-nums; }

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

/* ---------------- 3. Login ---------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand) 0%, #0b1f38 100%); padding: var(--sp-5);
}
.login-card {
  background: var(--surface); border-radius: 16px; padding: 36px; width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; gap: var(--sp-3); align-items: center; margin-bottom: var(--sp-6); }
.login-brand h1 { font-size: 19px; margin: 0; color: var(--text); }
.brand-mark {
  width: 46px; height: 46px; border-radius: 12px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: var(--fs-lg); flex: none;
}
#login-form label { display: block; margin-bottom: var(--sp-3); font-weight: 600; color: var(--text-soft); font-size: 13px; }
#login-form input { margin-top: 6px; }
.login-hint { margin-top: 22px; padding-top: var(--sp-4); border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.login-hint ul { margin: var(--sp-2) 0 0; padding-left: var(--sp-4); color: var(--text-soft); }
.login-hint li { margin: 3px 0; }
.btn-block { width: 100%; justify-content: center; }

/* --- API Keys ------------------------------------------------------------ */
.key-box { display: flex; gap: var(--sp-2); }
.key-box input { flex: 1; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.code-block { margin: 0; padding: 12px 14px; overflow-x: auto; white-space: pre;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius, 8px);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

/* --- Payment Planner ------------------------------------------------------ */
.pay-date { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-soft); }
.pay-check { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); }
/* .toolbar input (defined later) gives every input 150px; a checkbox must opt out */
.toolbar .pay-check input { width: auto; min-width: 0; }
.pay-totals { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.pay-total { display: flex; flex-direction: column; gap: 2px; min-width: 200px; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius, 8px); }
.pay-total b { font-size: 1.35rem; }
.pay-total.main { border-color: var(--primary, #2563eb); }
.pay-total.warn { border-color: var(--warn); background: var(--warn-soft); }
.pay-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.pay-chip { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 8px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius, 8px);
  cursor: pointer; color: inherit; font: inherit; text-align: left; }
.pay-chip:hover { border-color: var(--border-strong); }
.pay-chip.active { border-color: var(--primary, #2563eb); background: var(--surface); }
.pay-note { margin-bottom: var(--sp-3); display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* --- read-only status rows + banners (Settings → Sign-in) ----------------- */
.kv { display: flex; flex-direction: column; gap: var(--sp-2); }
.kv-row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: 8px 0; border-bottom: 1px solid var(--border); }
.kv-row:last-child { border-bottom: 0; }
.kv-row > .muted:first-child { flex: 0 0 210px; }
@media (max-width: 560px) { .kv-row > .muted:first-child { flex-basis: 100%; } }
.banner { padding: 10px 14px; border-radius: var(--radius, 6px); border: 1px solid var(--border);
  background: var(--surface-2); font-size: var(--fs-sm); }
.banner-ok { border-color: var(--ok); background: var(--ok-soft); color: var(--ok-ink); }
.banner-warn { border-color: var(--warn); background: var(--warn-soft); color: var(--warn-ink); }

/* --- Microsoft sign-in ---------------------------------------------------
   Microsoft's brand guidance fixes the mark (never recoloured, never resized
   against the label) and the wording. The frame follows this application's
   own controls so it does not read as a pasted-in widget. */
.login-sso { margin-top: var(--sp-4); }
.login-or { display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-4) 0;
  color: var(--text-soft); font-size: var(--fs-sm); }
.login-or::before, .login-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.ms-btn {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; min-height: 41px; padding: 10px 12px; box-sizing: border-box;
  border: 1px solid var(--border-strong, #8c8c8c); border-radius: var(--radius, 6px);
  background: #fff; color: #5e5e5e; text-decoration: none;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.ms-btn:hover { background: #f3f3f3; }
.ms-btn:focus-visible { outline: 2px solid var(--primary, #2563eb); outline-offset: 2px; }
.ms-btn[aria-disabled="true"] { opacity: .6; pointer-events: none; }
.ms-logo { width: 20px; height: 20px; flex: 0 0 20px; }
/* The button stays light in dark mode: the mark is designed against white and
   loses its contrast on a dark ground. */
[data-theme="dark"] .ms-btn { background: #fff; color: #5e5e5e; border-color: #8c8c8c; }
[data-theme="dark"] .ms-btn:hover { background: #ededed; }
.form-error {
  background: var(--danger-soft); color: var(--danger); padding: 9px var(--sp-3);
  border-radius: var(--radius-sm); margin-bottom: var(--sp-3); font-size: 13px;
}
.form-warn {
  background: var(--warn-soft); color: var(--warn); padding: 9px var(--sp-3);
  border-radius: var(--radius-sm); margin-bottom: var(--sp-3); font-size: 13px;
}

/* ---------------- 4. App shell ---------------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; flex: none; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-5) var(--sp-4); border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-name { font-weight: 700; color: #fff; font-size: var(--fs-md); }
.nav { flex: 1; overflow-y: auto; padding: var(--sp-3) 10px; }
.nav-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--sidebar-label); padding: var(--sp-3) var(--sp-3) 6px; font-weight: 700;
}
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px var(--sp-3); border-radius: var(--sp-2);
  color: var(--sidebar-text); font-weight: 500; font-size: var(--fs-base); margin-bottom: 2px;
}
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav a.active .ico { opacity: 1; }
.nav a .ico { width: 20px; text-align: center; font-size: var(--fs-md); opacity: .9; }
.sidebar-footer { padding: var(--sp-3) var(--sp-4); border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-5); height: 60px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
}
.topbar h2 { font-size: 17px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1; }
.menu-toggle { display: none; }
.global-search input { width: 240px; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  width: var(--control-h); height: var(--control-h);
  border-radius: 9px; cursor: pointer; font-size: var(--ico); color: var(--text);
  display: grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.content { padding: 22px; flex: 1; min-width: 0; }

/* user + bell */
.bell-wrap, .user-wrap { position: relative; }
.bell-badge {
  position: absolute; top: -4px; right: -4px; background: var(--danger); color: #fff;
  border-radius: 10px; min-width: 17px; height: 17px; font-size: 10px;
  display: grid; place-items: center; padding: 0 var(--sp-1); font-weight: 700;
}
[data-theme="dark"] .bell-badge { color: #1a0505; }
.user-btn {
  display: flex; align-items: center; gap: 9px; background: none; border: none; cursor: pointer;
  color: var(--text); padding: var(--sp-1) 6px; border-radius: 9px; font-family: inherit;
}
.user-btn:hover { background: var(--surface-2); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.user-meta { display: flex; flex-direction: column; text-align: left; line-height: 1.2; }
.user-meta span:first-child { font-weight: 600; font-size: 13px; }
.dropdown {
  position: absolute; right: 0; top: 48px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); min-width: 220px; padding: 6px; z-index: 60;
}
.dropdown a, .dropdown button {
  display: block; width: 100%; text-align: left; padding: 9px var(--sp-3); border-radius: var(--radius-sm);
  color: var(--text); font-size: var(--fs-base); background: none; border: none; cursor: pointer; font-family: inherit;
}
.dropdown a:hover, .dropdown button:hover { background: var(--surface-2); text-decoration: none; }
.dropdown hr { border: none; border-top: 1px solid var(--border); margin: 6px var(--sp-1); }
.bell-dropdown-wide { width: 360px; max-height: 460px; overflow-y: auto; }
.notif-item { display: block; padding: var(--cell-y) var(--sp-3); border-radius: var(--sp-2); border-left: 3px solid var(--border); margin-bottom: var(--sp-1); }
.notif-item:hover { background: var(--surface-2); }
.notif-item .nt { font-weight: 600; font-size: 13px; }
.notif-item .nm { font-size: var(--fs-sm); color: var(--text-soft); }
.notif-item.sev-critical { border-left-color: var(--danger); }
.notif-item.sev-warning { border-left-color: var(--warn); }
.notif-item.sev-info { border-left-color: var(--info); }
.notif-item.unread { background: var(--accent-soft); }

/* ---------------- 5. Forms & buttons ---------------- */
input, select, textarea {
  width: 100%; padding: 0 11px; height: var(--control-h);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: var(--fs-base); font-family: inherit;
}
select { padding-right: var(--sp-2); }
textarea { resize: vertical; min-height: 72px; height: auto; padding: 9px 11px; line-height: 1.5; }
input[type="checkbox"], input[type="radio"] { width: auto; height: auto; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
input::placeholder, textarea::placeholder { color: var(--muted); }
label { font-size: 13px; }

/* field wrapper: label / control / hint / inline error */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field > span.fl {
  font-weight: 600; color: var(--text-soft); font-size: var(--fs-sm);
  display: flex; align-items: center; gap: var(--sp-1);
}
.field > span { font-weight: 600; color: var(--text-soft); font-size: var(--fs-sm); }
.field .req { color: var(--danger); font-weight: 700; }
/* help text must not inherit the label's weight/colour — it is guidance, not a label */
.field .hint, .field > .muted.small { font-weight: 400; color: var(--muted); font-size: 12px; }
.field .field-error { color: var(--danger); font-size: var(--fs-sm); font-weight: 600; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field.has-error input:focus, .field.has-error select:focus, .field.has-error textarea:focus { box-shadow: 0 0 0 3px var(--danger-soft); }

/* grouped form sections (§9) */
.form-section { border: none; padding: 0; margin: 0 0 var(--sp-5); }
.form-section > legend, .form-section-title {
  font-size: var(--fs-sm); font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-soft); padding: 0 0 var(--sp-2); margin-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border); width: 100%;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 0 var(--sp-4); height: var(--control-h); border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  font-weight: 600; font-size: var(--fs-base); font-family: inherit; white-space: nowrap;
  transition: filter .12s, background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { filter: brightness(.97); border-color: var(--border-strong); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
[data-theme="dark"] .btn-danger { color: #1a0505; }
.btn-ghost { background: transparent; }
.btn-sm { height: var(--control-h-sm); padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn-icon { padding: 0 9px; }
.btn-link { background: none; border: none; color: var(--accent); padding: 0; height: auto; font-weight: 600; }
.btn-link:hover { text-decoration: underline; }

/* busy state: spinner replaces content, prevents double-submit (§16) */
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy > * { visibility: hidden; }
.btn.is-busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 15px; height: 15px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  animation: spin .6s linear infinite; color: var(--text);
}
.btn-primary.is-busy::after, .btn-accent.is-busy::after, .btn-danger.is-busy::after { border-color: #fff; border-top-color: transparent; }

/* tooltip for icon-only controls */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--surface); padding: 4px var(--sp-2); border-radius: 6px;
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; z-index: 70; pointer-events: none;
}

/* ---------------- 6. Cards & layout ---------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: var(--sp-4) var(--sp-5); }
.card-head {
  display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.card-head h4 { margin: 0; font-size: 14px; }

.page-head { display: flex; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.page-head h3 { margin: 0; font-size: var(--fs-lg); }
.page-head .spacer { flex: 1; }
.page-head-titles { min-width: 0; }
.page-desc { color: var(--text-soft); font-size: var(--fs-sm); margin: 3px 0 0; max-width: 78ch; }
.page-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }

.row { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.grid { display: grid; gap: var(--sp-4); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3) var(--sp-4); }
.form-grid .full { grid-column: 1 / -1; }

/* ---------------- 7. Stat cards ---------------- */
.stat { padding: var(--sp-4); display: flex; flex-direction: column; gap: 6px; border-left: 4px solid var(--accent); }
.stat .stat-val { font-size: 26px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .stat-label { color: var(--text-soft); font-size: var(--fs-sm); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .stat-ico { font-size: 22px; }
.stat .stat-sub { color: var(--muted); font-size: var(--fs-sm); }
.stat.b-blue { border-left-color: var(--accent); }
.stat.b-green { border-left-color: var(--ok); }
.stat.b-amber { border-left-color: var(--warn); }
.stat.b-red { border-left-color: var(--danger); }
.stat.b-cyan { border-left-color: var(--info); }
.stat.b-violet { border-left-color: var(--violet); }
.stat.b-gray { border-left-color: var(--border-strong); }
.stat-top { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-2); }
.stat.is-link { cursor: pointer; }
.stat.is-link:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }

/* ---------------- 8. Tables & row actions ---------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
table.data th, table.data td {
  padding: var(--cell-y) var(--cell-x); text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle;
}
table.data th {
  background: var(--surface-2); font-weight: 700; color: var(--text-soft);
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  position: sticky; top: 0; z-index: 1; cursor: default; user-select: none;
}
/* only columns wired for sorting look clickable (§4) */
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--text); background: var(--surface-3); }
table.data th.sortable .sort-ind { opacity: .55; font-size: 10px; margin-left: 3px; }
table.data th[aria-sort="ascending"], table.data th[aria-sort="descending"] { color: var(--text); }
table.data th[aria-sort] .sort-ind { opacity: 1; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data td.actions { text-align: right; white-space: nowrap; }
table.data td.wrap { white-space: normal; min-width: 200px; }
table.data .row-click { cursor: pointer; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

/* row actions menu — replaces 3+ inline buttons (§4) */
.act-wrap { position: relative; display: inline-block; }
.act-menu {
  position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  min-width: 190px; padding: var(--sp-1); z-index: 50; text-align: left;
}
.act-menu.up { top: auto; bottom: calc(100% + 4px); }
.act-menu button {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; text-align: left;
  padding: 8px 10px; border: none; background: none; border-radius: 6px; cursor: pointer;
  color: var(--text); font-size: 13px; font-family: inherit; font-weight: 500; white-space: nowrap;
}
.act-menu button:hover { background: var(--surface-2); }
.act-menu button.danger { color: var(--danger); }
.act-menu button:disabled { opacity: .45; cursor: not-allowed; }
.act-menu hr { border: none; border-top: 1px solid var(--border); margin: var(--sp-1) 6px; }

/* empty states (§15) */
.empty-state { text-align: center; padding: 44px var(--sp-5); color: var(--muted); }
.empty-state .big { font-size: 38px; margin-bottom: var(--sp-2); }
.empty-state .em-title { color: var(--text); font-weight: 600; font-size: 14px; margin-bottom: var(--sp-1); }
.empty-state .em-msg { max-width: 46ch; margin: 0 auto; }
.empty-state .em-action { margin-top: var(--sp-4); }

/* ---------------- 9. Badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
  border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 700;
  white-space: nowrap; line-height: 1.6;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; flex: none; }
.badge.green { background: var(--ok-soft); color: var(--ok-ink); }
.badge.amber { background: var(--warn-soft); color: var(--warn-ink); }
.badge.red { background: var(--danger-soft); color: var(--danger-ink); }
.badge.blue { background: var(--accent-soft); color: var(--blue-ink); }
.badge.cyan { background: var(--info-soft); color: var(--info-ink); }
.badge.violet { background: var(--violet-soft); color: var(--violet-ink); }
.badge.gray { background: var(--surface-3); color: var(--text-soft); }
.badge.gray::before, .badge.no-dot::before { display: none; }
.badge-lg { font-size: var(--fs-sm); padding: 4px 11px; }

/* ---------------- 10. Toolbar / filters ---------------- */
.toolbar { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; margin-bottom: var(--sp-3); }
.toolbar input, .toolbar select { width: auto; min-width: 150px; max-width: 100%; }
.toolbar .search { min-width: 230px; }
.toolbar .spacer { flex: 1; }

/* multi-select filter (UI.multiSelect): looks like a select, opens a list of checkboxes */
.ms { position: relative; display: inline-block; min-width: 150px; max-width: 100%; }
.ms-btn {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; height: var(--control-h);
  padding: 0 var(--sp-2) 0 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: var(--fs-base); font-family: inherit;
  cursor: pointer; text-align: left;
}
.ms-btn:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ms-text { flex: 1; min-width: 0; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-caret { color: var(--muted); font-size: 11px; }
.ms.ms-on .ms-btn { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.ms-menu {
  position: absolute; left: 0; top: calc(100% + 4px); z-index: 60; min-width: 100%; width: max-content; max-width: min(340px, 90vw);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: var(--sp-1);
}
.ms-menu[hidden] { display: none; }
.ms-menu.up { top: auto; bottom: calc(100% + 4px); }
.ms-find { height: var(--control-h-sm); margin: 2px 0 var(--sp-1); font-size: var(--fs-sm); }
.toolbar .ms-find { min-width: 0; width: 100%; }
.ms-list { max-height: 280px; overflow-y: auto; }
.ms-opt { display: flex; align-items: center; gap: var(--sp-2); padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.ms-opt[hidden] { display: none; }
.ms-opt:hover { background: var(--surface-2); }
.ms-opt input, .toolbar .ms .ms-opt input { margin: 0; flex: none; width: auto; min-width: 0; }
.ms-none { padding: 8px 10px; }
/* a list floated under a column header (UI.popFilter): no select-like button of its own */
.ms.ms-pop { position: absolute; z-index: 80; min-width: 0; width: 0; height: 0; display: block; }
.ms-pop .ms-btn { visibility: hidden; height: 0; min-height: 0; padding: 0; border: 0; overflow: hidden; }
.ms-pop .ms-menu { min-width: 230px; }
/* column header filter button, and the "Filtered by" bar above a filtered table */
.th-in { display: inline-flex; align-items: center; gap: 4px; }
.th-filter {
  display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; padding: 0;
  border: 1px solid transparent; border-radius: 5px; background: none; color: var(--muted); cursor: pointer; flex: none;
}
.th-filter:hover { background: var(--surface-2); color: var(--text); }
.th-filter:focus-visible { outline: none; border-color: var(--accent); }
.th-filter.on { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.colf-bar {
  display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; padding: 8px 12px;
  border-bottom: 1px solid var(--border); background: var(--accent-soft); font-size: var(--fs-sm);
}
.colf-bar span { flex: 1; min-width: 0; }
.ms-foot { display: flex; justify-content: space-between; gap: var(--sp-2); border-top: 1px solid var(--border); margin-top: var(--sp-1); padding: var(--sp-1) 2px 0; }
.result-count { color: var(--text-soft); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 0 0 var(--sp-3); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--brand-2);
  border-radius: var(--radius-pill); padding: 3px 6px 3px 10px; font-size: var(--fs-xs); font-weight: 700;
}
.chip button { background: none; border: none; cursor: pointer; color: inherit; font-size: 13px; line-height: 1; padding: 0 2px; }

/* ---------------- 11. Pagination ---------------- */
.pager {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-3) var(--cell-x); border-top: 1px solid var(--border);
}
.pager .pager-info { color: var(--text-soft); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.pager .spacer { flex: 1; }
.pager .pager-btns { display: flex; gap: var(--sp-1); align-items: center; }
.pager select { width: auto; min-width: 72px; height: var(--control-h-sm); font-size: var(--fs-sm); }
.pager-page { font-size: var(--fs-sm); font-weight: 700; padding: 0 var(--sp-2); font-variant-numeric: tabular-nums; }

/* ---------------- 12. Modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; background: var(--overlay); display: flex;
  align-items: flex-start; justify-content: center; padding: 40px var(--sp-4); z-index: 100; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px;
  box-shadow: var(--shadow-lg); animation: pop .15s ease; display: flex; flex-direction: column;
  max-height: calc(100vh - 80px);
}
.modal.wide { max-width: 880px; }
.modal.narrow { max-width: 460px; }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); flex: none; }
.modal-head h3 { margin: 0; font-size: var(--fs-md); }
.modal-head .close {
  margin-left: auto; background: none; border: none; font-size: 22px; cursor: pointer;
  color: var(--muted); line-height: 1; padding: 0 var(--sp-1); border-radius: 6px; flex: none;
}
.modal-head .close:hover { color: var(--text); background: var(--surface-2); }
.modal-body { padding: var(--sp-5); overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border); flex: none; flex-wrap: wrap;
}
/* confirmation dialog consequence list (§11) */
.confirm-msg { margin: 0 0 var(--sp-3); }
.confirm-list { margin: 0; padding-left: var(--sp-5); color: var(--text-soft); font-size: 13px; }
.confirm-list li { margin: var(--sp-1) 0; }
.confirm-note { margin: var(--sp-3) 0 0; font-size: var(--fs-sm); color: var(--muted); }

/* ---------------- 13. Detail / tabs / timeline ---------------- */
.detail-head { display: flex; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.detail-head-main { min-width: 0; flex: 1; }
.detail-head h3 { margin: 0 0 var(--sp-1); font-size: var(--fs-lg); display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.detail-head .sub { color: var(--text-soft); font-size: var(--fs-sm); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--sp-3) var(--sp-4); }
.detail-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.detail-item .dl { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }
.detail-item .dv { font-size: 14px; word-break: break-word; }
.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-soft); margin: var(--sp-5) 0 var(--sp-3); display: flex; align-items: center; gap: var(--sp-2);
}
.section-title:first-child { margin-top: 0; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: var(--cell-y) 0 var(--cell-y) var(--sp-4); border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline li.muted-dot::before { background: var(--border-strong); }

.pill-tabs {
  display: flex; gap: 6px; flex-wrap: nowrap; margin-bottom: var(--sp-4);
  overflow-x: auto; padding-bottom: 3px; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}
.pill-tabs button {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 0 var(--sp-4); height: var(--control-h-sm); cursor: pointer; font-weight: 600;
  font-size: 13px; color: var(--text-soft); font-family: inherit; white-space: nowrap; flex: none;
}
.pill-tabs button:hover { color: var(--text); border-color: var(--border-strong); }
.pill-tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
[data-theme="dark"] .pill-tabs button.active { background: var(--sidebar-active); border-color: var(--sidebar-active); }

/* audit change table (§18) */
.diff-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.diff-table th, .diff-table td { padding: 5px var(--sp-2); text-align: left; border-bottom: 1px solid var(--border); white-space: normal; }
.diff-table th { color: var(--muted); font-weight: 700; font-size: var(--fs-xs); text-transform: uppercase; }
.diff-old { color: var(--danger); text-decoration: line-through; opacity: .85; }
.diff-new { color: var(--ok); font-weight: 600; }

/* ---------------- 14. Toast ---------------- */
.toast-root { position: fixed; bottom: var(--sp-5); right: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); z-index: 200; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); padding: var(--sp-3) var(--sp-4); box-shadow: var(--shadow-lg);
  min-width: 260px; max-width: 380px; animation: pop .15s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast .tt { font-weight: 700; font-size: var(--fs-base); }
.toast .tm { font-size: var(--fs-sm); color: var(--text-soft); }

/* ---------------- 15. Charts / loading ---------------- */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 320px; }
.qr-box { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); }
.qr-box svg, .qr-box img { width: 200px; height: 200px; background: #fff; padding: var(--sp-2); border-radius: var(--sp-2); }

.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin: 40px auto; }
.spinner-sm { width: 16px; height: 16px; border-width: 2px; margin: 0; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { text-align: center; padding: 30px; color: var(--muted); }

/* skeleton rows keep layout stable while loading (§16) */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: 6px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.skel-row { height: 14px; margin: var(--sp-3) 0; }
.skel-table { padding: var(--sp-4); }

/* ---------------- 16. Responsive ---------------- */
@media (max-width: 1100px) {
  .global-search input { width: 170px; }
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 90; transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow-lg); width: 268px;
  }
  .sidebar.open { transform: none; }
  .menu-toggle { display: grid; }
  .global-search { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .user-meta { display: none; }
  .content { padding: var(--sp-4); }
  .topbar { padding: 0 var(--sp-3); gap: var(--sp-2); }
  .modal-overlay { padding: var(--sp-4) var(--sp-2); }
  .modal { max-height: calc(100vh - 32px); }
  .grid-cards { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
@media (max-width: 640px) {
  .page-head { gap: var(--sp-2); }
  .page-head .spacer { display: none; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .toolbar input, .toolbar select, .toolbar .search, .toolbar .ms { min-width: 0; width: 100%; }
  .ms-text { max-width: none; }
  .toolbar { gap: var(--sp-2); }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .grid-cards { grid-template-columns: 1fr 1fr; }
  .stat { padding: var(--sp-3); }
  .stat .stat-val { font-size: 22px; }
  .toast-root { left: var(--sp-3); right: var(--sp-3); bottom: var(--sp-3); }
  .toast { max-width: none; min-width: 0; }
  .content { padding: var(--sp-3); }

  /* wide tables become stacked cards using data-label from the cell (§19) */
  table.data.stack-sm thead { display: none; }
  table.data.stack-sm tbody tr {
    display: block; border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: var(--sp-2); padding: var(--sp-2) var(--sp-3); background: var(--surface);
  }
  table.data.stack-sm tbody td {
    display: flex; justify-content: space-between; gap: var(--sp-3);
    border-bottom: 1px dashed var(--border); padding: 6px 0; white-space: normal; text-align: right;
  }
  table.data.stack-sm tbody td:last-child { border-bottom: none; }
  table.data.stack-sm tbody td::before {
    content: attr(data-label); color: var(--muted); font-size: var(--fs-xs); font-weight: 700;
    text-transform: uppercase; letter-spacing: .03em; text-align: left; flex: none;
  }
  table.data.stack-sm tbody td.actions { justify-content: flex-end; }
  table.data.stack-sm tbody td.actions::before { content: ""; }
}
@media (max-width: 420px) {
  .detail-grid, .grid-cards { grid-template-columns: 1fr; }
}
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 80; }

@media print {
  .sidebar, .topbar, .toolbar, .page-actions, .pager, .toast-root { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border-color: #ccc; }
}

/* ---- bulk edit: row checkboxes, the selection bar, the edit form ---- */
table.data .bulk-col { width: 34px; text-align: center; padding-right: 0; }
table.data .bulk-col input { width: auto; min-width: 0; margin: 0; cursor: pointer; }
.bulk-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; margin-bottom: 12px;
  border: 1px solid var(--accent); border-radius: 10px; background: var(--accent-soft); color: var(--text); }
.bulk-bar .spacer { flex: 1; }
.bulk-fields { display: grid; gap: 10px; }
.bulk-field { display: grid; grid-template-columns: minmax(150px, 210px) 1fr; gap: 10px; align-items: center; }
.bulk-field label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.bulk-field label input { width: auto; min-width: 0; }
.bulk-field select:disabled, .bulk-field input:disabled { opacity: .5; }
@media (max-width: 640px) { .bulk-field { grid-template-columns: 1fr; } }

/* ---- tasks ---- */
tr.row-overdue > td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.clamp-1 { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-details { white-space: pre-wrap; line-height: 1.5; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
