/* ==========================================================================
   MaintainIQ — Super Admin console
   --------------------------------------------------------------------------
   One token layer at the top. Every colour, radius and shadow below refers to
   a token, so the whole console can be re-skinned for a different operator
   without touching a rule.
   ========================================================================== */

:root {
  color-scheme: light dark;

  --brand:        #1d4ed8;
  --brand-ink:    #ffffff;
  --brand-soft:   #eff4ff;
  --brand-line:   #c7d7fe;

  --bg:           #f6f7f9;
  --surface:      #ffffff;
  --surface-2:    #fbfcfd;
  --sunken:       #f1f3f6;

  --ink:          #111827;
  --ink-2:        #4b5563;
  --ink-3:        #6b7280;
  --ink-4:        #9ca3af;

  --line:         #e5e7eb;
  --line-2:       #d7dbe0;

  --ok:           #047857;  --ok-soft:   #e7f6ef;  --ok-line:   #a7e0c6;
  --warn:         #b45309;  --warn-soft: #fdf3e3;  --warn-line: #f2d49b;
  --danger:       #b42318;  --danger-soft:#fdeceb; --danger-line:#f5b5b0;
  --info:         #0369a1;  --info-soft: #e6f3fb;  --info-line: #a8d5ee;
  --muted-soft:   #f0f1f3;  --muted-line:#dfe2e6;

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

  --shadow-1: 0 1px 2px rgba(16,24,40,.05);
  --shadow-2: 0 4px 12px rgba(16,24,40,.08), 0 1px 3px rgba(16,24,40,.06);
  --shadow-3: 0 18px 48px rgba(16,24,40,.18), 0 4px 12px rgba(16,24,40,.08);

  --sidebar-w: 248px;
  --header-h:  60px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand:      #5b8bff;
    --brand-ink:  #0b1020;
    --brand-soft: #182444;
    --brand-line: #2c4074;

    --bg:         #0d1117;
    --surface:    #151b23;
    --surface-2:  #1a212b;
    --sunken:     #10161d;

    --ink:        #e6edf3;
    --ink-2:      #b3bec9;
    --ink-3:      #8b97a3;
    --ink-4:      #6b7683;

    --line:       #262e38;
    --line-2:     #333c48;

    --ok:      #46c793;  --ok-soft:     #10251d;  --ok-line:     #1e4536;
    --warn:    #e0a54a;  --warn-soft:   #261d0f;  --warn-line:   #4a381a;
    --danger:  #f4776a;  --danger-soft: #2a1412;  --danger-line: #542420;
    --info:    #57b6e8;  --info-soft:   #0f2130;  --info-line:   #1d3f57;
    --muted-soft: #1b222b; --muted-line: #2b343f;

    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 4px 14px rgba(0,0,0,.45);
    --shadow-3: 0 20px 56px rgba(0,0,0,.6);
  }
}

/* --------------------------------------------------------------------------
   Reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* A closed element must not intercept clicks, whatever display rule a class
   later gives it. This is not decorative — an invisible open overlay swallows
   every click on the page beneath it. */
[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-4); background-clip: content-box; }

/* ==========================================================================
   Sign in
   ========================================================================== */
.signin {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 15% -10%, var(--brand-soft), transparent 60%),
    var(--bg);
}

.signin__card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: 32px;
}

.signin__mark {
  display: flex; align-items: center; gap: 10px; margin-bottom: 24px;
}
.signin__logo {
  width: 36px; height: 36px; border-radius: 9px;
  background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  letter-spacing: -0.03em;
}
.signin__name { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.signin__sub { font-size: 12px; color: var(--ink-3); }

.signin h1 { font-size: 20px; margin-bottom: 4px; }
.signin__lede { color: var(--ink-3); font-size: 13px; margin-bottom: 22px; }

.signin__tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px;
  background: var(--sunken); border-radius: var(--radius-sm);
  padding: 3px; margin-bottom: 20px;
}
.signin__tab {
  border: 0; background: transparent; padding: 7px 10px;
  border-radius: 5px; font-size: 13px; font-weight: 500;
  color: var(--ink-3); cursor: pointer;
}
.signin__tab[aria-selected="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-1); font-weight: 600;
}

.signin__hint {
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--ink-3); line-height: 1.7;
}
.signin__hint code {
  font-family: var(--mono); font-size: 11.5px;
  background: var(--sunken); padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--line);
}

/* ==========================================================================
   Shell
   ========================================================================== */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

/* --- Sidebar -------------------------------------------------------------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  z-index: 30;
}

.sidebar__head {
  height: var(--header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sidebar__logo {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  letter-spacing: -0.03em;
}
.sidebar__title { font-size: 13.5px; font-weight: 650; letter-spacing: -0.01em; }
.sidebar__scope { font-size: 11px; color: var(--ink-3); }

.sidebar__nav { padding: 12px 10px; flex: 1; }
.sidebar__group { margin-bottom: 18px; }
.sidebar__label {
  font-size: 10.5px; font-weight: 650; letter-spacing: .07em;
  text-transform: uppercase; color: var(--ink-4);
  padding: 0 8px; margin-bottom: 6px;
}

.navlink {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-size: 13.5px; font-weight: 500;
  cursor: pointer; text-decoration: none; margin-bottom: 1px;
  border: 0; background: transparent; width: 100%; text-align: left;
}
.navlink:hover { background: var(--sunken); color: var(--ink); text-decoration: none; }
.navlink[aria-current="page"] {
  background: var(--brand-soft); color: var(--brand); font-weight: 600;
}
.navlink__icon { width: 16px; height: 16px; flex-shrink: 0; opacity: .85; }
.navlink__count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  color: var(--ink-4); font-variant-numeric: tabular-nums;
}

.sidebar__foot { padding: 12px 10px; border-top: 1px solid var(--line); flex-shrink: 0; }
.whoami { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.whoami__body { min-width: 0; flex: 1; }
.whoami__name { font-size: 13px; font-weight: 600; }
.whoami__role { font-size: 11px; color: var(--ink-3); }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center;
  font-size: 11.5px; font-weight: 650;
  border: 1px solid var(--brand-line);
}
.avatar--sm { width: 24px; height: 24px; font-size: 10px; }
.avatar--lg { width: 44px; height: 44px; font-size: 15px; }

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

.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 20;
}
.topbar__title { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.topbar__sub { font-size: 12px; color: var(--ink-3); }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.content { padding: 22px; flex: 1; max-width: 1480px; width: 100%; }

/* --- Impersonation banner ------------------------------------------------- */
.impersonation {
  background: var(--warn-soft);
  border-bottom: 1px solid var(--warn-line);
  color: var(--warn);
  padding: 9px 22px;
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; font-weight: 500;
  position: sticky; top: var(--header-h); z-index: 19;
}
.impersonation strong { font-weight: 650; }
.impersonation .btn { margin-left: auto; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink); font-size: 13px; font-weight: 550;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover:not(:disabled) { background: var(--sunken); border-color: var(--ink-4); }
.btn:active:not(:disabled) { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--brand); border-color: var(--brand); }

.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover:not(:disabled) { filter: brightness(1.08); background: var(--danger); border-color: var(--danger); }

.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover:not(:disabled) { background: var(--sunken); border-color: transparent; }

.btn--sm { padding: 4px 9px; font-size: 12px; }
.btn--icon { padding: 6px; width: 30px; height: 30px; }
.btn--block { width: 100%; }

.btn__spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Form fields
   ========================================================================== */
.field { margin-bottom: 14px; }
.field__label {
  display: block; font-size: 12.5px; font-weight: 600;
  margin-bottom: 5px; color: var(--ink-2);
}
.field__label .req { color: var(--danger); margin-left: 2px; }
.field__hint { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; line-height: 1.5; }
.field__error { font-size: 11.5px; color: var(--danger); margin-top: 4px; font-weight: 500; }

.input, .select, .textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-size: 13.5px; transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 76px; resize: vertical; line-height: 1.55; }

.select {
  appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}

.field-row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.field-row--3 { grid-template-columns: repeat(3, 1fr); }

.checkbox { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; padding: 3px 0; }
.checkbox input { margin: 2px 0 0; width: 15px; height: 15px; accent-color: var(--brand); cursor: pointer; }
.checkbox__body { min-width: 0; }
.checkbox__title { font-size: 13px; font-weight: 500; }
.checkbox__hint { font-size: 11.5px; color: var(--ink-3); }

.switch { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 9px 0; }
.switch + .switch { border-top: 1px solid var(--line); }
.switch__body { min-width: 0; }
.switch__title { font-size: 13px; font-weight: 550; }
.switch__hint { font-size: 11.5px; color: var(--ink-3); }
.switch__control {
  width: 38px; height: 21px; border-radius: 11px; flex-shrink: 0;
  background: var(--line-2); border: 0; position: relative; cursor: pointer;
  transition: background .15s;
}
.switch__control::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 17px; height: 17px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow-1); transition: transform .15s;
}
.switch__control[aria-checked="true"] { background: var(--brand); }
.switch__control[aria-checked="true"]::after { transform: translateX(17px); }

/* ==========================================================================
   Cards, panels, layout helpers
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.card__head {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.card__title { font-size: 13.5px; font-weight: 650; }
.card__sub { font-size: 11.5px; color: var(--ink-3); }
.card__actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.card__body { padding: 16px; }
.card__body--flush { padding: 0; }
.card__foot {
  padding: 11px 16px; border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
  display: flex; align-items: center; gap: 10px;
}

.grid { display: grid; gap: 14px; }
.grid--kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
/* A six-tile row reads as two rows of three rather than five-and-an-orphan. */
.grid--kpi6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1080px) { .grid--kpi6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px)  { .grid--kpi6 { grid-template-columns: minmax(0, 1fr); } }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
/* Cards size to their own content instead of stretching to match the tallest
   in the row — a short card should not carry a block of empty space. */
.grid--top { align-items: start; }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stack { display: grid; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; }
.row--wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.section-title {
  font-size: 12px; font-weight: 650; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-4); margin-bottom: 10px;
}

/* --------------------------------------------------------------------------
   KPI tile
   --------------------------------------------------------------------------
   Flex siblings, never absolutely positioned. An absolutely positioned aside
   overlaps the value at narrow widths and the number becomes unreadable.
   -------------------------------------------------------------------------- */
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-1);
  padding: 15px 16px;
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.kpi__top { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.kpi__label {
  font-size: 11.5px; font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .04em;
  min-width: 0; overflow-wrap: anywhere;
}
.kpi__badge { margin-left: auto; flex-shrink: 0; }
.kpi__value {
  font-size: 27px; font-weight: 680; letter-spacing: -0.025em;
  line-height: 1.1; font-variant-numeric: tabular-nums;
}
.kpi__foot {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--ink-3); min-width: 0; flex-wrap: wrap;
}
.kpi__delta { font-weight: 600; }
.kpi__delta--up { color: var(--ok); }
.kpi__delta--down { color: var(--danger); }

/* --------------------------------------------------------------------------
   Bars — a share-of-total readout that needs no charting library
   -------------------------------------------------------------------------- */
.bars { display: grid; gap: 11px; }
.bar__head { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; margin-bottom: 5px; }
.bar__name { font-weight: 550; }
.bar__value { margin-left: auto; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bar__track { height: 7px; border-radius: 4px; background: var(--sunken); overflow: hidden; }
.bar__fill { height: 100%; border-radius: 4px; background: var(--brand); transition: width .35s ease; }
.bar__fill--ok { background: var(--ok); }
.bar__fill--warn { background: var(--warn); }
.bar__fill--danger { background: var(--danger); }
.bar__fill--info { background: var(--info); }
.bar__fill--muted { background: var(--ink-4); }

/* --------------------------------------------------------------------------
   Sparkline / column chart
   -------------------------------------------------------------------------- */
.columns { display: flex; align-items: flex-end; gap: 8px; padding-top: 6px; }
.column {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center;
  justify-content: flex-end; gap: 5px;
}
.column__bar {
  width: 100%; background: var(--brand-soft); border: 1px solid var(--brand-line);
  border-radius: 4px 4px 2px 2px; min-height: 3px;
  transition: height .35s ease;
}
.column__bar--solid { background: var(--brand); border-color: var(--brand); }
.column__label {
  font-size: 10.5px; color: var(--ink-4); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.column__value { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Badges and pills
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.badge--ok     { background: var(--ok-soft);     color: var(--ok);     border-color: var(--ok-line); }
.badge--warn   { background: var(--warn-soft);   color: var(--warn);   border-color: var(--warn-line); }
.badge--danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }
.badge--info   { background: var(--info-soft);   color: var(--info);   border-color: var(--info-line); }
.badge--brand  { background: var(--brand-soft);  color: var(--brand);  border-color: var(--brand-line); }
.badge--muted  { background: var(--muted-soft);  color: var(--ink-3);  border-color: var(--muted-line); }

.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 6px;
  background: var(--sunken); border: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-2); font-weight: 500;
}
.chip--scope { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand); }

.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.tnum { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; padding: 9px 14px;
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-4); background: var(--surface-2);
  border-bottom: 1px solid var(--line); white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--ink-2); }
.table th .sort-arrow { opacity: .4; margin-left: 3px; }
.table th[aria-sort] .sort-arrow { opacity: 1; color: var(--brand); }

.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table td.nowrap { white-space: nowrap; }
.table td.right { text-align: right; font-variant-numeric: tabular-nums; }

.cell-primary { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-primary__body { min-width: 0; }
.cell-primary__title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-primary__sub { font-size: 11.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Toolbar above a table ------------------------------------------------ */
.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.toolbar__search { position: relative; flex: 1; min-width: 190px; max-width: 340px; }
.toolbar__search .input { padding-left: 32px; }
.toolbar__search svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--ink-4); pointer-events: none;
}
.toolbar .select { width: auto; min-width: 128px; }

/* --- Pagination ----------------------------------------------------------- */
.pager { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--ink-3); }
.pager__pages { margin-left: auto; display: flex; gap: 4px; align-items: center; }

/* --- Empty / loading / error states --------------------------------------- */
.empty { padding: 44px 24px; text-align: center; }
.empty__icon {
  width: 40px; height: 40px; margin: 0 auto 12px;
  color: var(--ink-4); opacity: .55;
}
.empty__title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.empty__text { font-size: 12.5px; color: var(--ink-3); max-width: 330px; margin: 0 auto 14px; line-height: 1.6; }

.skeleton {
  background: linear-gradient(90deg, var(--sunken) 25%, var(--line) 50%, var(--sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite; border-radius: 5px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton--line { height: 11px; margin: 7px 0; }
.skeleton--row { height: 42px; margin: 0; border-radius: 0; border-bottom: 1px solid var(--line); }

.notice {
  padding: 11px 13px; border-radius: var(--radius-sm);
  font-size: 12.5px; display: flex; gap: 9px; align-items: flex-start;
  border: 1px solid transparent; line-height: 1.55;
}
.notice svg { width: 15px; height: 15px; flex-shrink: 0; margin-top: 1px; }
.notice--danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.notice--warn   { background: var(--warn-soft);   border-color: var(--warn-line);   color: var(--warn); }
.notice--info   { background: var(--info-soft);   border-color: var(--info-line);   color: var(--info); }
.notice--ok     { background: var(--ok-soft);     border-color: var(--ok-line);     color: var(--ok); }

/* ==========================================================================
   Overlays

   One explicit z-index scale, so a dialog opened from a drawer is never
   decided by DOM order: scrim 100/200, drawer 110, modal 210, toast 300.
   ========================================================================== */
.scrim {
  position: fixed; inset: 0; background: rgba(16,24,40,.45);
  backdrop-filter: blur(1.5px);
  animation: fade .15s ease;
}
.scrim--drawer { z-index: 100; }
.scrim--modal  { z-index: 200; }
@keyframes fade { from { opacity: 0; } }

/* --- Drawer --------------------------------------------------------------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 110;
  width: min(760px, 100vw);
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column;
  animation: slide-in .22s cubic-bezier(.32,.72,0,1);
}
@keyframes slide-in { from { transform: translateX(22px); opacity: .4; } }

.drawer__head {
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; gap: 12px; flex-shrink: 0;
}
.drawer__title { font-size: 16px; font-weight: 650; letter-spacing: -0.015em; }
.drawer__sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.drawer__close { margin-left: auto; flex-shrink: 0; }
.drawer__body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer__foot {
  padding: 13px 20px; border-top: 1px solid var(--line);
  background: var(--surface-2); display: flex; gap: 8px; align-items: center;
  flex-shrink: 0;
}

/* --- Modal ---------------------------------------------------------------- */
.modal {
  position: fixed; z-index: 210;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-3);
  display: flex; flex-direction: column;
  animation: pop .18s cubic-bezier(.32,.72,0,1);
}
.modal--wide { width: min(860px, calc(100vw - 32px)); }
@keyframes pop { from { transform: translate(-50%, calc(-50% + 10px)); opacity: 0; } }

.modal__head { padding: 18px 20px 14px; display: flex; align-items: flex-start; gap: 12px; flex-shrink: 0; }
.modal__title { font-size: 15.5px; font-weight: 650; }
.modal__sub { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; line-height: 1.5; }
.modal__body { padding: 0 20px 4px; overflow-y: auto; flex: 1; }
.modal__foot {
  padding: 14px 20px 18px; display: flex; gap: 8px; align-items: center;
  flex-shrink: 0;
}

/* --- Tabs ----------------------------------------------------------------- */
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--line);
  padding: 0 20px; overflow-x: auto; flex-shrink: 0;
}
.tab {
  border: 0; background: transparent; cursor: pointer;
  padding: 10px 12px; font-size: 13px; font-weight: 550;
  color: var(--ink-3); border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* --- Toasts --------------------------------------------------------------- */
.toasts {
  position: fixed; bottom: 18px; right: 18px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(400px, calc(100vw - 36px));
}
.toast {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-2);
  padding: 11px 13px; display: flex; gap: 10px; align-items: flex-start;
  animation: toast-in .2s cubic-bezier(.32,.72,0,1);
}
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.toast--ok     { border-left-color: var(--ok); }
.toast--danger { border-left-color: var(--danger); }
.toast--warn   { border-left-color: var(--warn); }
.toast__body { flex: 1; min-width: 0; }
.toast__title { font-size: 13px; font-weight: 600; }
.toast__text { font-size: 12px; color: var(--ink-3); margin-top: 1px; line-height: 1.5; overflow-wrap: anywhere; }

/* ==========================================================================
   Organisation tree
   ========================================================================== */
.tree { font-size: 13px; }
.tree__node { border-bottom: 1px solid var(--line); }
.tree__node:last-child { border-bottom: 0; }

.tree__row {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 14px; cursor: pointer; min-width: 0;
}
.tree__row:hover { background: var(--surface-2); }
.tree__toggle {
  width: 18px; height: 18px; flex-shrink: 0; border: 0; padding: 0;
  background: transparent; color: var(--ink-4); cursor: pointer;
  display: grid; place-items: center; border-radius: 4px;
}
.tree__toggle:hover { background: var(--sunken); color: var(--ink); }
.tree__toggle svg { width: 12px; height: 12px; transition: transform .15s; }
.tree__toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
.tree__toggle--leaf { visibility: hidden; }

.tree__icon {
  width: 24px; height: 24px; border-radius: 6px; flex-shrink: 0;
  background: var(--sunken); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 11px; color: var(--ink-3);
}
.tree__name { font-weight: 550; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree__type { font-size: 11px; color: var(--ink-4); flex-shrink: 0; }
.tree__meta { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.tree__children { padding-left: 22px; border-left: 1px solid var(--line); margin-left: 22px; }

/* ==========================================================================
   Permission matrix
   ========================================================================== */
.matrix { display: grid; gap: 14px; }
.matrix__group { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.matrix__head {
  padding: 9px 13px; background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.matrix__title { font-size: 12.5px; font-weight: 650; }
.matrix__items { padding: 9px 13px; display: grid; gap: 4px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

/* ==========================================================================
   Key/value list
   ========================================================================== */
.kv { display: grid; gap: 0; font-size: 13px; }
.kv__row {
  display: grid; grid-template-columns: 170px 1fr; gap: 14px;
  padding: 9px 0; border-bottom: 1px solid var(--line); align-items: baseline;
}
.kv__row:last-child { border-bottom: 0; }
.kv__key { color: var(--ink-3); font-size: 12.5px; }
.kv__val { min-width: 0; overflow-wrap: anywhere; }

/* ==========================================================================
   Wizard
   ========================================================================== */
.steps { display: flex; gap: 0; padding: 0 20px 14px; flex-shrink: 0; }
.step { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.step__dot {
  width: 23px; height: 23px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 11px; font-weight: 650;
  background: var(--sunken); color: var(--ink-4); border: 1px solid var(--line);
}
.step[data-state="current"] .step__dot { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.step[data-state="done"] .step__dot { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.step__label { font-size: 12px; font-weight: 550; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step[data-state="current"] .step__label { color: var(--ink); font-weight: 600; }
.step__line { flex: 1; height: 1px; background: var(--line); margin: 0 8px; min-width: 10px; }

/* --- Selectable card (template picker) ------------------------------------ */
.picker { display: grid; gap: 9px; }
.pick {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 12px 13px; border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); cursor: pointer; background: var(--surface);
  text-align: left; width: 100%; transition: border-color .12s, background .12s;
}
.pick:hover { border-color: var(--ink-4); background: var(--surface-2); }
.pick[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.pick__radio {
  width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; margin-top: 1px;
  border: 1.5px solid var(--line-2); display: grid; place-items: center;
}
.pick[aria-pressed="true"] .pick__radio { border-color: var(--brand); }
.pick[aria-pressed="true"] .pick__radio::after {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--brand);
}
.pick__body { min-width: 0; flex: 1; }
.pick__title { font-size: 13px; font-weight: 600; }
.pick__desc { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; line-height: 1.5; }
.pick__levels { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 7px; }

/* ==========================================================================
   Audit / activity feed
   ========================================================================== */
.feed { display: grid; }
.feed__item {
  display: flex; gap: 11px; padding: 11px 16px;
  border-bottom: 1px solid var(--line); align-items: flex-start;
}
.feed__item:last-child { border-bottom: 0; }
.feed__icon {
  width: 26px; height: 26px; border-radius: 7px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--sunken); border: 1px solid var(--line); color: var(--ink-3);
}
.feed__icon svg { width: 13px; height: 13px; }
.feed__icon--ok     { background: var(--ok-soft);     border-color: var(--ok-line);     color: var(--ok); }
.feed__icon--warn   { background: var(--warn-soft);   border-color: var(--warn-line);   color: var(--warn); }
.feed__icon--danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.feed__icon--info   { background: var(--info-soft);   border-color: var(--info-line);   color: var(--info); }
.feed__body { flex: 1; min-width: 0; }
.feed__title { font-size: 13px; }
.feed__title strong { font-weight: 600; }
.feed__meta { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }

.diff { display: grid; gap: 6px; margin-top: 8px; font-size: 12px; }
.diff__row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: baseline; }
.diff__key { color: var(--ink-3); }
.diff__from { color: var(--danger); text-decoration: line-through; opacity: .8; }
.diff__to { color: var(--ok); font-weight: 550; }

pre.json {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.6;
  background: var(--sunken); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 11px 13px;
  overflow-x: auto; margin: 8px 0 0; white-space: pre-wrap; word-break: break-word;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1000px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
    transform: translateX(-100%); transition: transform .2s cubic-bezier(.32,.72,0,1);
    z-index: 130;
  }
  .sidebar[data-open="true"] { transform: none; }
  .sidebar-scrim { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 120; }
  .menu-btn { display: inline-flex !important; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .kv__row { grid-template-columns: 1fr; gap: 2px; }
  .field-row, .field-row--3 { grid-template-columns: 1fr; }
}

.menu-btn { display: none; }

@media (max-width: 620px) {
  .toolbar { padding: 10px 12px; }
  .toolbar__search { max-width: none; }
  .drawer { width: 100vw; }
  .table th, .table td { padding: 9px 11px; }
  .kpi__value { font-size: 23px; }
  .steps { display: none; }
}

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