/* ============================================================================
   PORTAL.CSS — Paideia Reports internal/admin portal design system
   Notion-approach refactor (exploration, off the brand guidelines).

   Architecture (one-way dependency: components -> roles -> primitives):
     1. PRIMITIVES  raw scales, no meaning
     2. ROLES       semantic tokens; the ONLY thing components may read
     3. COMPONENTS  built on roles

   Dark mode is architected-for: redefine the role block under
   :root[data-theme="dark"] (stub at the bottom) — components never change.
   Self-contained: the admin portal depends on this file only, not app.css.
   ============================================================================ */

/* ============================================================================
   1. PRIMITIVES
   ============================================================================ */
:root {
  /* Neutral alpha ramp — composes over any surface (Notion's key idea) */
  --black-04: rgba(0, 0, 0, 0.04);
  --black-06: rgba(0, 0, 0, 0.06);
  --black-09: rgba(0, 0, 0, 0.09);
  --black-13: rgba(0, 0, 0, 0.13);
  --black-45: rgba(0, 0, 0, 0.45);
  --black-56: rgba(0, 0, 0, 0.56);
  --black-73: rgba(0, 0, 0, 0.73);
  --black-90: rgba(0, 0, 0, 0.90);

  /* Blue ramp — reverse-engineered from notion.com/product */
  --blue-50:  #f2f9ff;
  --blue-100: #e6f3fe;
  --blue-200: #93cdfe;
  --blue-300: #62aef0;
  --blue-400: #097fe8;
  --blue-500: #0075de;
  --blue-600: #005bab;
  --blue-700: #00396b;

  /* Status ramps (soft bg / solid text), AA-tuned */
  --green-soft: #e7f5eb;  --green-text: #14832b;
  --amber-soft: #fdefe0;  --amber-text: #a1560d;
  --red-soft:   #fdecea;  --red-text:   #c0271a;

  /* Solid neutrals used where alpha would double up on a tint */
  --white:        #ffffff;
  --warm-50:      #fbfbfa;   /* near-white canvas */
  --warm-100:     #f7f7f5;   /* sunken / sidebar */
  --warm-200:     #efeeec;

  /* Type */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
               Helvetica, Arial, sans-serif;
  --font-serif: 'Lyon Text', Georgia, 'Times New Roman', serif; /* display accent */

  --text-xs:   0.75rem;   /* 12 */
  --text-sm:   0.8125rem; /* 13 — Notion's UI base */
  --text-base: 0.875rem;  /* 14 */
  --text-md:   0.9375rem; /* 15 */
  --text-lg:   1.0625rem; /* 17 */
  --text-xl:   1.3125rem; /* 21 */
  --text-2xl:  1.625rem;  /* 26 */
  --text-3xl:  2rem;      /* 32 */

  --weight-regular:  400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;

  --leading-tight: 1.25;
  --leading-snug:  1.4;
  --leading-normal:1.55;

  /* Spacing (4px base) */
  --space-1: 0.25rem; --space-2: 0.5rem;  --space-3: 0.75rem;
  --space-4: 1rem;    --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem;    --space-10:2.5rem;  --space-12:3rem;  --space-16:4rem;

  /* Radius (Notion: button 8, card 12) */
  --radius-xs: 0.25rem;   /* 4  icon buttons */
  --radius-sm: 0.375rem;  /* 6  inputs */
  --radius-md: 0.5rem;    /* 8  buttons */
  --radius-lg: 0.75rem;   /* 12 cards */
  --radius-xl: 1rem;      /* 16 dialogs */
  --radius-pill: 624px;

  /* Shadow — Notion neutral, ultra-soft */
  --shadow-1: 0 0 0 1px var(--black-04), 0 1px 2px rgba(0,0,0,.04);
  --shadow-2: 0 .7px 1.5px rgba(0,0,0,.015), 0 3px 9px rgba(0,0,0,.03);
  --shadow-3: 0 .2px 1px rgba(0,0,0,.013), 0 .8px 2.9px rgba(0,0,0,.02),
              0 2px 7.8px rgba(0,0,0,.027), 0 4px 18px rgba(0,0,0,.05);
  --shadow-pop: 0 4px 18px rgba(0,0,0,.06), 0 24px 52px rgba(0,0,0,.05);

  /* Focus ring */
  --ring: 0 0 0 3px rgba(0, 117, 222, 0.16);
}

/* ============================================================================
   2. SEMANTIC ROLES (light) — the contract components read
   ============================================================================ */
:root {
  /* Text */
  --text-primary:    var(--black-90);
  --text-secondary:  var(--black-56);  /* >= AA on --surface */
  --text-tertiary:   var(--black-45);
  --text-on-accent:  var(--white);
  --text-accent:     var(--blue-500);
  --text-link:       var(--blue-500);
  --text-link-hover: var(--blue-700);

  /* Surfaces */
  --surface:          var(--white);      /* raised: menus, inputs, dialogs */
  --surface-sunken:   var(--warm-100);   /* sidebar, wells */
  --surface-canvas:   var(--white);      /* content sits directly on white — no card-on-grey */
  --surface-hover:    var(--black-04);
  --surface-selected: var(--black-06);

  /* Borders */
  --border:        var(--black-09);
  --border-strong: var(--black-13);
  --border-focus:  var(--blue-500);

  /* Accent */
  --accent:            var(--blue-500);
  --accent-hover:      var(--blue-600);
  --accent-soft:       var(--blue-100);
  --accent-soft-hover: var(--blue-50);
  --accent-soft-text:  var(--blue-600);

  /* Status (soft bg + text) */
  --status-success-bg: var(--green-soft); --status-success-text: var(--green-text);
  --status-warning-bg: var(--amber-soft); --status-warning-text: var(--amber-text);
  --status-danger-bg:  var(--red-soft);   --status-danger-text:  var(--red-text);
  --status-neutral-bg: var(--warm-100);   --status-neutral-text: var(--text-secondary);
}

/* ============================================================================
   3. BASE
   ============================================================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--surface-canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: -0.017em;
  color: var(--text-primary);
}
h1 { font-size: var(--text-2xl); font-weight: var(--weight-bold); letter-spacing: -0.022em; }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-md); }

p { color: var(--text-primary); }

a { color: var(--text-link); text-decoration: none; }
a:hover { color: var(--text-link-hover); text-decoration: underline; }

img, svg, video, iframe { max-width: 100%; height: auto; }
svg { display: block; }

::selection { background: var(--accent-soft); }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-xs); }

/* Shared typographic helpers */
.u-text-secondary { color: var(--text-secondary); }
.u-text-tertiary  { color: var(--text-tertiary); }
.u-text-sm        { font-size: var(--text-sm); }
.u-text-xs        { font-size: var(--text-xs); }
.u-tabular        { font-variant-numeric: tabular-nums; }
.u-mono-nums      { font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }

/* ============================================================================
   4. BUTTONS — ghost-first
   ============================================================================ */
.btn {
  --_bg: transparent;
  --_fg: var(--text-primary);
  --_bd: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 32px;
  padding: 0 var(--space-3);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: 1;
  color: var(--_fg);
  background: var(--_bg);
  border: 1px solid var(--_bd);
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn svg { width: 16px; height: 16px; }

.btn-primary   { --_bg: var(--accent); --_fg: var(--text-on-accent); --_bd: var(--accent); }
.btn-primary:hover { --_bg: var(--accent-hover); --_bd: var(--accent-hover); color: var(--text-on-accent); }

.btn-secondary { --_bg: var(--accent-soft); --_fg: var(--accent-soft-text); --_bd: var(--accent-soft); }
.btn-secondary:hover { --_bg: var(--accent-soft-hover); --_bd: var(--accent-soft-hover); }

.btn-default   { --_bg: var(--surface); --_fg: var(--text-primary); --_bd: var(--border-strong); }
.btn-default:hover { --_bg: var(--surface-hover); }

.btn-ghost     { --_bg: transparent; --_fg: var(--text-secondary); --_bd: transparent; }
.btn-ghost:hover { --_bg: var(--surface-hover); --_fg: var(--text-primary); }

.btn-danger    { --_bg: transparent; --_fg: var(--status-danger-text); --_bd: var(--border-strong); }
.btn-danger:hover { --_bg: var(--status-danger-bg); --_bd: var(--status-danger-bg); }

.btn-sm { height: 28px; padding: 0 var(--space-2); font-size: var(--text-sm); }
.btn-lg { height: 38px; padding: 0 var(--space-4); font-size: var(--text-md); }
.btn-icon { width: 32px; height: 32px; padding: 0; --_fg: var(--text-secondary); --_bd: var(--border); border-radius: var(--radius-sm); }
.btn-icon:hover { --_bg: var(--surface-hover); --_fg: var(--text-primary); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ============================================================================
   5. FORMS
   ============================================================================ */
.field { margin-bottom: var(--space-4); }
.label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}
.input, .select, .textarea {
  width: 100%;
  min-height: 34px;
  padding: var(--space-2) var(--space-3);
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--ring);
}
.input::placeholder { color: var(--text-tertiary); }
.textarea { min-height: 96px; resize: vertical; line-height: var(--leading-snug); }
.hint { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: var(--space-1); }
.field-error { font-size: var(--text-xs); color: var(--status-danger-text); margin-top: var(--space-1); }

.input-group { position: relative; }
.input-group .input { padding-right: 2.5rem; }
.input-affix {
  position: absolute; top: 50%; right: var(--space-2); transform: translateY(-50%);
  display: flex; align-items: center; padding: var(--space-1);
  color: var(--text-tertiary); background: none; border: none; cursor: pointer; line-height: 0;
}
.input-affix:hover { color: var(--text-secondary); }

/* ============================================================================
   6. CARDS & SURFACES
   ============================================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .03);   /* whisper of lift on white canvas */
}
.card-pad-lg { padding: var(--space-6); }
.card-hover { transition: box-shadow .15s ease, border-color .15s ease; }
.card-hover:hover { box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card-title { font-size: var(--text-md); font-weight: var(--weight-semibold); color: var(--text-primary); }

.well {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

/* ============================================================================
   7. STAT TILE
   ============================================================================ */
.stat { display: flex; flex-direction: column; gap: var(--space-1); }
.stat-label { font-size: var(--text-sm); color: var(--text-secondary); }
.stat-value { font-size: var(--text-3xl); font-weight: var(--weight-bold); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-meta  { font-size: var(--text-xs); color: var(--text-tertiary); }
.stat-meta.up { color: var(--status-success-text); }

/* ============================================================================
   8. TABLES — quiet header, hairline rows
   ============================================================================ */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.table thead th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--black-06);
  color: var(--text-primary);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .1s ease; }
.table.table-rows tbody tr:hover { background: var(--surface-hover); }
.cell-strong { font-weight: var(--weight-medium); }
.cell-muted  { color: var(--text-secondary); }
.cell-num    { font-variant-numeric: tabular-nums; }

/* ============================================================================
   9. BADGES / PILLS — soft-tint, normal case
   ============================================================================ */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  line-height: 1.5; border-radius: var(--radius-pill); white-space: nowrap;
}
.badge-neutral { background: var(--status-neutral-bg); color: var(--status-neutral-text); }
.badge-accent  { background: var(--accent-soft);       color: var(--accent-soft-text); }
.badge-success { background: var(--status-success-bg); color: var(--status-success-text); }
.badge-warning { background: var(--status-warning-bg); color: var(--status-warning-text); }
.badge-danger  { background: var(--status-danger-bg);  color: var(--status-danger-text); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ============================================================================
   10. ALERTS
   ============================================================================ */
.alert {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md); font-size: var(--text-base);
  border: 1px solid transparent;
}
.alert-info    { background: var(--accent-soft);       color: var(--accent-soft-text); }
.alert-success { background: var(--status-success-bg); color: var(--status-success-text); }
.alert-warning { background: var(--status-warning-bg); color: var(--status-warning-text); }
.alert-danger  { background: var(--status-danger-bg);  color: var(--status-danger-text); }

/* ============================================================================
   11. AVATAR
   ============================================================================ */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-selected); color: var(--text-secondary);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; flex-shrink: 0;
}
.avatar-accent { background: var(--accent-soft); color: var(--accent-soft-text); }

/* ============================================================================
   12. MENU / DROPDOWN
   ============================================================================ */
.menu {
  min-width: 180px; padding: var(--space-1);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-pop);
}
.menu-item {
  display: flex; align-items: center; gap: var(--space-2);
  width: 100%; padding: var(--space-2) var(--space-2);
  font-size: var(--text-base); color: var(--text-primary);
  background: none; border: none; border-radius: var(--radius-sm);
  cursor: pointer; text-align: left; text-decoration: none;
}
.menu-item:hover { background: var(--surface-hover); text-decoration: none; }
.menu-item svg { width: 15px; height: 15px; color: var(--text-tertiary); }
.menu-item.danger { color: var(--status-danger-text); }
.menu-item.danger:hover { background: var(--status-danger-bg); }
.menu-sep { height: 1px; background: var(--border); margin: var(--space-1) 0; }

/* ============================================================================
   13. APP SHELL — light sidebar + main column
   ============================================================================ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; align-self: flex-start;
  width: 248px; height: 100vh; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--surface-sunken);
  border-right: 1px solid var(--border);
}
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-4) var(--space-4) var(--space-2); }
.sidebar-nav { padding: var(--space-2); display: flex; flex-direction: column; gap: 1px; overflow-y: auto; }
.nav-label {
  padding: var(--space-3) var(--space-2) var(--space-1);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  color: var(--text-tertiary); text-transform: none;
}
.nav-item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  font-size: var(--text-base); font-weight: var(--weight-medium);
  color: var(--text-secondary); border-radius: var(--radius-sm);
  text-decoration: none;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text-primary); text-decoration: none; }
.nav-item.active { background: var(--surface-selected); color: var(--text-primary); }
.nav-item svg { width: 17px; height: 17px; opacity: .6; flex-shrink: 0; }
.nav-item.active svg { opacity: .9; }
.sidebar-foot { margin-top: auto; padding: var(--space-2); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: var(--space-1); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page { width: 100%; max-width: 1200px; margin: 0 auto; padding: var(--space-12) var(--space-10) var(--space-16); }
/* Full-width pages (data tables): use the whole main area, not a reading column */
.page-wide { max-width: none; }

/* Sidebar collapse (desktop): hides the rail, widens the content column */
.sidebar-collapse { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: none; background: none; border-radius: var(--radius-sm); color: var(--text-tertiary); cursor: pointer; flex-shrink: 0; }
.sidebar-collapse:hover { background: var(--surface-hover); color: var(--text-secondary); }
/* Desktop-only: on mobile the off-canvas mechanism governs, so `collapsed`
   must not hide the sidebar there (it would break the ☰ open toggle). */
@media (min-width: 721px) {
  .shell.collapsed .sidebar { display: none; }
  .shell.collapsed .page { max-width: 1600px; }
  .shell.collapsed .sidebar-toggle { display: inline-flex; }
}

/* Page header — a Notion page title, generous space beneath */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-8); }
.page-title { font-size: var(--text-3xl); font-weight: var(--weight-bold); letter-spacing: -0.028em; }

/* Notion-style bare sections (no cards) */
.section { margin-top: var(--space-12); }
.section:first-child { margin-top: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); }
.section-label { font-size: var(--text-base); font-weight: var(--weight-semibold); color: var(--text-primary); }

/* Borderless stat row — numbers on canvas, no boxes */
.stat-row { display: flex; flex-wrap: wrap; gap: var(--space-10) var(--space-12); }
.stat-row .stat { gap: 2px; }
.stat-row .stat-value { font-size: var(--text-2xl); }

/* Flat table — no card wrapper, hairline rows only */
.table-flat { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.table-flat thead th { text-align: left; padding: var(--space-2) var(--space-3); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-tertiary); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table-flat thead th:first-child, .table-flat tbody td:first-child { padding-left: 0; }
.table-flat thead th:last-child,  .table-flat tbody td:last-child  { padding-right: 0; }
.table-flat tbody td { padding: var(--space-3); border-bottom: 1px solid var(--black-06); color: var(--text-primary); vertical-align: middle; white-space: nowrap; }
.table-flat tbody tr:last-child td { border-bottom: none; }
.table-flat tbody tr { transition: background .1s ease; }
.table-flat tbody tr:hover td { background: var(--surface-hover); }
.page-sub { font-size: var(--text-base); color: var(--text-secondary); margin-top: var(--space-1); }
.page-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

/* Auth shell */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--surface-sunken); padding: var(--space-5); }
.auth-card { width: 100%; max-width: 360px; padding: var(--space-8); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-3); }
.auth-brand { display: flex; justify-content: center; margin-bottom: var(--space-6); }
.brand-logo { display: block; height: auto; max-width: 100%; }
.auth-brand .brand-logo { width: 172px; }
.sidebar-brand .brand-logo { width: 132px; }
.auth-title { text-align: center; margin-bottom: var(--space-1); }
.auth-sub { text-align: center; color: var(--text-secondary); font-size: var(--text-base); margin-bottom: var(--space-6); }

/* ============================================================================
   14. LAYOUT UTILITIES
   ============================================================================ */
.stack { display: flex; flex-direction: column; }
.stack-2 { gap: var(--space-2); } .stack-3 { gap: var(--space-3); }
.stack-4 { gap: var(--space-4); } .stack-6 { gap: var(--space-6); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--space-6); }

/* List row (reused: reports, users, logs, access) */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--black-06); }
.list-row:last-child { border-bottom: none; }
.list-body { flex: 1; min-width: 0; }
.list-title { font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--text-primary); }
.list-sub { font-size: var(--text-sm); color: var(--text-secondary); }

/* Empty state */
.empty { text-align: center; padding: var(--space-12) var(--space-5); }
.empty-title { font-size: var(--text-md); font-weight: var(--weight-semibold); margin-bottom: var(--space-1); }
.empty-text { font-size: var(--text-base); color: var(--text-secondary); }

/* Code chip */
.chip { font-size: var(--text-xs); padding: 2px 6px; background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius-xs); font-variant-numeric: tabular-nums; }

/* ============================================================================
   15. DIALOG
   ============================================================================ */
.dialog {
  inset: 0; margin: auto;                 /* re-center: the global reset zeroes the UA margin:auto */
  max-width: 520px; width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  padding: 0; border: none; border-radius: var(--radius-xl);
  background: var(--surface); color: var(--text-primary);
  box-shadow: var(--shadow-pop);
}
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.dialog-body { padding: var(--space-5); overflow-y: auto; flex: 1; }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) 0 0; margin-top: var(--space-5); border-top: 1px solid var(--border); }

/* ============================================================================
   15b. EXTENDED FORMS, COPY, MISC (needed by admin pages)
   ============================================================================ */
.form-actions { display: flex; gap: var(--space-2); margin-top: var(--space-5); }
.required-mark { color: var(--status-danger-text); }
.field-note { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-tertiary); margin-left: var(--space-1); }
.field-row { display: flex; align-items: center; gap: var(--space-2); }
.field-row .input { flex: 1; }
.field-prefix { font-size: var(--text-sm); color: var(--text-tertiary); white-space: nowrap; }

/* Toggle row (native checkbox + label) */
.toggle-field { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--text-primary); cursor: pointer; }
.toggle-checkbox { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.toggle-hint { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: var(--space-1); }

/* Nested sub-section panel inside a form */
.form-subsection { margin: var(--space-3) 0; padding: var(--space-4); border: 1px solid var(--accent-soft); background: var(--accent-soft); border-radius: var(--radius-md); }
.form-subsection--warning { border-color: var(--status-warning-bg); background: var(--status-warning-bg); }

/* Dialog close button */
.dialog-close { width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border: none; background: none; border-radius: var(--radius-sm); color: var(--text-tertiary); font-size: var(--text-md); line-height: 1; cursor: pointer; }
.dialog-close:hover { background: var(--surface-hover); color: var(--text-primary); }

/* Copy button + tooltip */
.btn-copy { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); color: var(--text-tertiary); cursor: pointer; transition: background .12s, color .12s, border-color .12s; }
.btn-copy:hover { background: var(--surface-hover); color: var(--text-primary); border-color: var(--border-strong); }
.copy-tooltip { display: none; position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); max-width: 280px; padding: var(--space-1) var(--space-2); background: var(--text-primary); color: var(--surface); font-size: var(--text-xs); border-radius: var(--radius-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; z-index: 5; }
.btn-copy:hover .copy-tooltip { display: block; }

/* Table cell helpers */
.cell-link { font-weight: var(--weight-medium); color: var(--text-primary); }
.cell-link:hover { color: var(--text-link); }
/* One flexible column that truncates to a single line instead of wrapping to
   3-4 lines. max-width:0 + width:100% makes it grab remaining space; the
   other columns size to their content. */
.cell-truncate { max-width: 0; width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-truncate .cell-link { display: block; overflow: hidden; text-overflow: ellipsis; }
/* Name column: takes the largest share and wraps to stay fully readable
   (overrides .table-flat's nowrap). Widest column in the table. */
.cell-name { width: 100%; white-space: normal; }
.cell-name .cell-link { display: block; }

/* Avatar status variant + empty-state icon */
.avatar-warn { background: var(--status-danger-bg); color: var(--status-danger-text); }
.empty-icon { width: 44px; height: 44px; margin: 0 auto var(--space-4); color: var(--text-tertiary); opacity: .5; }

/* Utilities */
.is-hidden { display: none; }
.mt-4 { margin-top: var(--space-4); }
.w-narrow { max-width: 560px; }

/* ============================================================================
   16. RESPONSIVE
   ============================================================================ */
.sidebar-toggle { display: none; }
.scrim { display: none; }

@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
  .sidebar-toggle { display: inline-flex; }
  .page { padding: var(--space-5); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}

/* ============================================================================
   18. LEGACY VOCABULARY + ADMIN COMPONENTS
   Maps the existing admin templates' class names onto the Notion role
   system so every page renders on portal.css. JS-coupled names
   (.dropdown/.open/.action-item, vault ids, chips) are kept verbatim.
   ============================================================================ */

/* ---- Forms (legacy names) ---- */
.form-group { margin-bottom: var(--space-4); }
.form-label { display: block; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-secondary); margin-bottom: var(--space-2); }
.form-input { width: 100%; min-height: 34px; padding: var(--space-2) var(--space-3); font-family: inherit; font-size: var(--text-base); color: var(--text-primary); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); transition: border-color .12s ease, box-shadow .12s ease; }
.form-input:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--ring); }
.form-input::placeholder { color: var(--text-tertiary); }
.form-hint { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: var(--space-1); }
.password-field { position: relative; }
.password-field .form-input { padding-right: 2.5rem; }
.password-toggle { position: absolute; top: 50%; right: var(--space-2); transform: translateY(-50%); display: flex; align-items: center; padding: var(--space-1); background: none; border: none; color: var(--text-tertiary); cursor: pointer; line-height: 0; }
.password-toggle:hover { color: var(--text-secondary); }

/* ---- Buttons (legacy names) ---- */
.btn-outline { background: var(--surface); color: var(--text-primary); border-color: var(--border-strong); }
.btn-outline:hover { background: var(--surface-hover); }
.btn-nowrap { white-space: nowrap; }

/* ---- Text / cell utilities ---- */
.text-muted { font-size: var(--text-sm); color: var(--text-secondary); }
.text-danger { color: var(--status-danger-text); }
.text-black { color: var(--text-primary); }
.font-regular { font-weight: var(--weight-regular); }
.tabular-nums { font-variant-numeric: tabular-nums; }
.cell-xs { font-size: var(--text-xs); }
.cell-nowrap { white-space: nowrap; }
.cell-title { font-weight: var(--weight-medium); color: var(--text-primary); }
a.cell-title:hover { color: var(--text-link); }
.cell-value { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ml-1 { margin-left: var(--space-1); }

/* ---- Tables (legacy container + bare table): borderless, hairline rows ---- */
.table-container { width: 100%; overflow-x: auto; }
.table-container table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.table-container thead th { text-align: left; padding: var(--space-3); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-tertiary); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table-container tbody td { padding: var(--space-3); border-bottom: 1px solid var(--black-06); color: var(--text-primary); vertical-align: middle; }
.table-container thead th:first-child, .table-container tbody td:first-child { padding-left: 0; }
.table-container thead th:last-child,  .table-container tbody td:last-child  { padding-right: 0; }
.table-container tbody tr:last-child td { border-bottom: none; }
.table-container tbody tr:hover td { background: var(--surface-hover); }

/* Page-action button cluster (report detail Preview/Edit) */
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); }

/* ---- Cards (legacy names) ---- */
.card-header { font-size: var(--text-md); font-weight: var(--weight-semibold); color: var(--text-primary); }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card-link { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.card--danger { border-left: 3px solid var(--status-danger-text); }
.card--info { border-left: 3px solid var(--accent); }

/* ---- Layout (legacy) ---- */
.narrow { max-width: 560px; }
.stack-5 { display: flex; flex-direction: column; gap: var(--space-5); }

/* ---- Empty state (legacy names) ---- */
.empty-state { text-align: center; padding: var(--space-12) var(--space-5); color: var(--text-secondary); }
.empty-state-icon { width: 44px; height: 44px; margin: 0 auto var(--space-4); color: var(--text-tertiary); opacity: .5; }
.empty-state-title { font-size: var(--text-md); font-weight: var(--weight-semibold); color: var(--text-primary); margin-bottom: var(--space-1); }

/* ---- Badges (legacy names) ---- */
.badge-grey { background: var(--status-neutral-bg); color: var(--status-neutral-text); }
.badge-primary { background: var(--accent-soft); color: var(--accent-soft-text); }
.badge-dark { background: var(--surface-selected); color: var(--text-primary); }

/* ---- Code chip ---- */
.code-chip { font-size: var(--text-xs); padding: 2px 6px; background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius-xs); font-variant-numeric: tabular-nums; }
.tracking-wide { letter-spacing: .04em; }
.tracking-widest { letter-spacing: .1em; }

/* ---- Credentials box ---- */
.credentials-box { background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-5); margin-bottom: var(--space-5); }
.credentials-label { font-size: var(--text-sm); color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; margin-bottom: var(--space-3); }
.credential-value { font-size: var(--text-lg); font-weight: var(--weight-bold); color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* ---- Row action menu (⋯) — JS sets .open + fixed top/left ---- */
.action-menu { position: relative; display: inline-block; }
.action-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-tertiary); cursor: pointer; transition: background .12s, color .12s, border-color .12s; }
.action-btn:hover { background: var(--surface-hover); color: var(--text-primary); border-color: var(--border-strong); }
.action-btn svg { width: 14px; height: 14px; }
.dropdown { display: none; position: fixed; min-width: 180px; padding: var(--space-1); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-pop); z-index: 1000; }
.dropdown.open { display: block; }
.action-item { display: flex; align-items: center; gap: var(--space-2); width: 100%; padding: var(--space-2); font-family: inherit; font-size: var(--text-base); font-weight: var(--weight-regular); color: var(--text-primary); background: none; border: none; border-radius: var(--radius-sm); cursor: pointer; text-align: left; text-decoration: none; }
.action-item:hover { background: var(--surface-hover); text-decoration: none; }
.action-item svg { width: 15px; height: 15px; opacity: .7; flex-shrink: 0; }
.action-item.danger { color: var(--status-danger-text); }
.action-item.danger:hover { background: var(--status-danger-bg); }
.action-item.disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.dropdown-divider { height: 1px; background: var(--border); margin: var(--space-1) 0; }
.dropdown-item { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); cursor: pointer; border-radius: var(--radius-sm); }
.dropdown-item:hover { background: var(--surface-hover); }

/* ---- Dialog (legacy header/footer names) ---- */
.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.dialog-footer { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); }

/* ---- People-with-access list (report detail) ---- */
.access-list { display: flex; flex-direction: column; }
.access-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--black-06); }
.access-item:last-child { border-bottom: none; }
.access-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-selected); color: var(--text-secondary); display: flex; align-items: center; justify-content: center; font-size: var(--text-xs); font-weight: var(--weight-semibold); text-transform: uppercase; flex-shrink: 0; }
.access-avatar.client, .dropdown-avatar.client { background: var(--status-success-bg); color: var(--status-success-text); }
.access-body { flex: 1; min-width: 0; }
.access-name { font-weight: var(--weight-medium); font-size: var(--text-base); }
.access-sub { font-size: var(--text-sm); color: var(--text-secondary); }
.access-empty, .logs-empty { color: var(--text-secondary); font-size: var(--text-base); text-align: center; padding: var(--space-6) 0; }
.access-revoke-btn, .remove-btn { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); background: none; cursor: pointer; color: var(--text-tertiary); display: flex; align-items: center; justify-content: center; line-height: 1; transition: all .12s; }
.access-revoke-btn:hover, .remove-btn:hover { background: var(--status-danger-bg); border-color: var(--status-danger-bg); color: var(--status-danger-text); }
.access-share-section { margin-top: var(--space-4); border-top: 1px solid var(--border); padding-top: var(--space-4); }
.grant-actions { display: flex; justify-content: flex-end; margin-top: var(--space-3); }

/* ---- Role pills + share chips ---- */
.role-badge { display: inline-flex; align-items: center; margin-left: 6px; padding: 1px 7px; border-radius: var(--radius-pill); font-size: .7rem; font-weight: var(--weight-medium); border: 1px solid transparent; }
.role-badge-sm { font-size: .65rem; padding: 1px 6px; margin-left: 0; }
.role-badge-client, .chip-client { background: var(--status-success-bg); color: var(--status-success-text); }
.role-badge-admin, .chip-admin { background: var(--surface-selected); color: var(--text-primary); }
.role-badge-super { background: var(--status-warning-bg); color: var(--status-warning-text); }
.chips-box { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 40px; padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: text; }
.chips-search { border: none; outline: none; font: inherit; font-size: var(--text-base); min-width: 160px; flex: 1; background: transparent; padding: 2px 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-medium); white-space: nowrap; }
.chip-remove { background: none; border: none; cursor: pointer; color: currentColor; font-size: .85rem; line-height: 1; padding: 0 1px; opacity: .6; }
.admin-dropdown { display: none; position: fixed; z-index: 9999; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-pop); max-height: 220px; overflow-y: auto; }
.dropdown-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-selected); color: var(--text-secondary); display: flex; align-items: center; justify-content: center; font-size: .7rem; font-weight: var(--weight-bold); flex-shrink: 0; text-transform: uppercase; }

/* ---- Report detail meta + share + vault ---- */
.report-meta { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-6); align-items: center; }
.share-text { font-size: var(--text-sm); background: var(--surface-sunken); padding: var(--space-4); border-radius: var(--radius-md); white-space: pre-wrap; color: var(--text-primary); }
.vault-viewer { margin-top: var(--space-3); }
.vault-frame { width: 100%; height: 80vh; border: 1px solid var(--border-strong); border-radius: var(--radius-md); }
.vault-error { font-size: var(--text-xs); margin-top: var(--space-2); color: var(--status-danger-text); }

/* ---- Access logs filter bar ---- */
.filter-bar { display: flex; gap: var(--space-3); align-items: flex-end; flex-wrap: wrap; margin-bottom: var(--space-5); }
.filter-field { flex: 1; min-width: 200px; }
.filter-field-fixed { min-width: 160px; }
.logs-count { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: var(--space-3); text-align: right; }

/* ---- users/create bulk table ---- */
.users-create-table th:nth-child(1) { width: 36px; }
.users-create-table td:nth-child(1) { color: var(--text-tertiary); font-size: var(--text-xs); text-align: center; }

/* ============================================================================
   17. DARK MODE — architecture stub (role remap only; not shipped)
   Uncomment + tune to enable. Components require NO changes.
   ============================================================================ */
/*
:root[data-theme="dark"] {
  --text-primary: rgba(255,255,255,.92);
  --text-secondary: rgba(255,255,255,.60);
  --text-tertiary: rgba(255,255,255,.45);
  --surface: #202020;
  --surface-sunken: #191919;
  --surface-canvas: #191919;
  --surface-hover: rgba(255,255,255,.055);
  --surface-selected: rgba(255,255,255,.09);
  --border: rgba(255,255,255,.11);
  --border-strong: rgba(255,255,255,.16);
  --accent: #2a8fff; --accent-hover: #4c9fff;
  --accent-soft: rgba(35,131,226,.20); --accent-soft-text: #6cb2ff;
}
*/
