/* ==========================================================================
   TP-mail — design system
   Truckopedia palette: petrol teal #006C89, CTA orange #E64B35,
   deep navy #161F30, on a neutral gray scale. 8px rhythm, light + dark.
   ========================================================================== */

:root {
  color-scheme: light dark;

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

  /* surfaces */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e8ebf0;
  --surface-inset: #fafbfc;

  /* lines */
  --border: #e2e5ea;
  --border-strong: #cbd1da;

  /* text */
  --text: #14171c;
  --text-muted: #5a6472;
  --text-faint: #8a93a2;
  --text-invert: #ffffff;

  /* accent */
  --accent: #006c89;          /* Truckopedia petrol teal */
  --accent-hover: #005a73;
  --accent-active: #00485d;
  --accent-soft: #e4eef3;
  --accent-border: #b3d3de;
  --accent-text: #005a73;

  /* Truckopedia CTA orange — reserved for the primary action on a screen */
  --brand: #e64b35;
  --brand-hover: #d13f2b;
  --brand-active: #b73523;
  --brand-soft: #fdf0e9;
  --brand-border: #f6c5b9;
  --brand-text: #b73523;

  /* Truckopedia deep navy — app chrome */
  --navy: #161f30;
  --navy-2: #1e2939;

  /* semantic */
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #b91c1c;

  --success: #16a34a;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;
  --success-text: #15803d;

  --warning: #d97706;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #b45309;

  --info: #0284c7;
  --info-soft: #f0f9ff;
  --info-border: #bae6fd;
  --info-text: #0369a1;

  /* chart series */
  --c-sent: #006c89;
  --c-open: #4aa3bd;
  --c-click: #e64b35;
  --c-reply: #1f9d6b;

  /* shape */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 14px;
  --r-pill: 999px;

  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-2: 0 4px 12px rgba(16, 24, 40, 0.08);
  --shadow-3: 0 16px 40px rgba(16, 24, 40, 0.16);

  --sidebar-w: 236px;
  --topbar-h: 56px;
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 32%, transparent);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f13;
    --surface: #14171d;
    --surface-2: #1a1e26;
    --surface-3: #232833;
    --surface-inset: #10131a;

    --border: #252a33;
    --border-strong: #39404d;

    --text: #e9ebef;
    --text-muted: #99a2b1;
    --text-faint: #6a7383;
    --text-invert: #0d0f13;

    --accent: #38a8c6;
    --accent-hover: #58bcd6;
    --accent-active: #7ccde3;
    --accent-soft: #0e2630;
    --accent-border: #1c4756;
    --accent-text: #7fcde1;

    --brand: #f0614b;
    --brand-hover: #f47a67;
    --brand-active: #f79684;
    --brand-soft: #2b1611;
    --brand-border: #4d2a20;
    --brand-text: #f8a08e;

    --navy: #0f1622;
    --navy-2: #18212f;

    --danger: #ef4444;
    --danger-hover: #f87171;
    --danger-soft: #2a1517;
    --danger-border: #4d2225;
    --danger-text: #fca5a5;

    --success: #22c55e;
    --success-soft: #10231a;
    --success-border: #1d4030;
    --success-text: #6ee7a5;

    --warning: #f59e0b;
    --warning-soft: #2a1f0e;
    --warning-border: #4a361a;
    --warning-text: #fbbf24;

    --info: #38bdf8;
    --info-soft: #0d2029;
    --info-border: #1b3c4c;
    --info-text: #7dd3fc;

    --c-sent: #38a8c6;
    --c-open: #7fcde1;
    --c-click: #f0614b;
    --c-reply: #3fcf96;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 4px 12px rgba(0, 0, 0, 0.45);
    --shadow-3: 0 16px 40px rgba(0, 0, 0, 0.6);
  }
}

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

html, body { height: 100%; }

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

h1, h2, h3, h4, p, figure { margin: 0; }
img, svg { vertical-align: middle; }
svg { flex: none; }

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

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }

.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;
}

/* ------------------------------------------------------------- typography */
.h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.015em; }
.h2 { font-size: 17px; font-weight: 620; letter-spacing: -0.01em; }
.h3 { font-size: 14px; font-weight: 620; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.right { text-align: right; }

/* ------------------------------------------------------------------ layout */
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.col-16 { display: flex; flex-direction: column; gap: 16px; }
.col-24 { display: flex; flex-direction: column; gap: 24px; }
.spacer { flex: 1 1 auto; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.gap-4 { gap: 4px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }

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

.sidebar {
  grid-column: 1;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 16px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--navy);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--brand) 85%, transparent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 750; font-size: 11px;
  flex: none;
  letter-spacing: -0.02em;
}
.brand-name { font-size: 15.5px; font-weight: 650; letter-spacing: -0.02em; }

.nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-section {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 14px 8px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13.5px;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-link.active svg { color: var(--accent); }
.nav-link svg { color: var(--text-faint); }
.nav-link .count {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.sidebar-foot {
  flex: none;
  border-top: 1px solid var(--border);
  padding: 10px;
}

.ws-switch {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px;
  border-radius: var(--r-md);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}
.ws-switch:hover { background: var(--surface-2); border-color: var(--border); }
.ws-avatar {
  width: 26px; height: 26px; flex: none;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--text-muted);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 650;
  text-transform: uppercase;
}
.ws-meta { min-width: 0; flex: 1; }
.ws-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-sub { font-size: 11.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { grid-column: 2; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .page-title { font-size: 15px; font-weight: 620; letter-spacing: -0.01em; }
.menu-btn { display: none; }

.view { padding: 24px 20px 64px; min-width: 0; }
.view-inner { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.page-head .h1 + .muted { margin-top: 2px; }

/* ----------------------------------------------------------------- buttons */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s, opacity 0.12s;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { background: var(--surface-3); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn:disabled:hover { background: var(--btn-bg); }

.btn-primary { --btn-bg: var(--brand); --btn-fg: #fff; --btn-bd: var(--brand); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-primary:active { background: var(--brand-active); }

/* teal alternative for secondary emphasis (save, apply, verify) */
.btn-accent { --btn-bg: var(--accent); --btn-fg: #fff; --btn-bd: var(--accent); }
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-accent:active { background: var(--accent-active); }

.btn-danger { --btn-bg: var(--surface); --btn-fg: var(--danger-text); --btn-bd: var(--danger-border); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: var(--danger); }
.btn-danger-solid:hover { background: var(--danger-hover); border-color: var(--danger-hover); }

.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-sm { height: 28px; padding: 0 9px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn-lg { height: 40px; padding: 0 18px; font-size: 14.5px; }
.btn-block { width: 100%; }
.btn-icon { width: 30px; height: 30px; padding: 0; }
.btn-icon.btn-sm { width: 26px; height: 26px; }

.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: var(--btn-fg);
  animation: spin 0.6s linear infinite;
}
.btn-primary.loading::after { color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ inputs */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label {
  font-size: 12.5px;
  font-weight: 570;
  color: var(--text-muted);
}
.field .hint { font-size: 12px; color: var(--text-faint); }
.field .err { font-size: 12px; color: var(--danger-text); }
.req { color: var(--danger); margin-left: 2px; }

.input, .select, .textarea {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 7px 10px;
  transition: border-color 0.12s, box-shadow 0.12s;
  appearance: none;
}
.input, .select { height: 34px; }
.textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.textarea.code { font-family: var(--font-mono); font-size: 12.5px; }

.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-2);
  color: var(--text-faint);
  cursor: not-allowed;
}

.select {
  padding-right: 30px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237b8494' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 9px center;
}
select.select[multiple] { height: auto; background-image: none; padding: 6px; }

.input-icon { position: relative; display: flex; align-items: center; }
.input-icon svg { position: absolute; left: 9px; color: var(--text-faint); pointer-events: none; }
.input-icon .input { padding-left: 30px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  font-size: 13.5px;
  user-select: none;
}
.check input[type="checkbox"], .check input[type="radio"] {
  width: 16px; height: 16px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  flex: none;
  cursor: pointer;
}
.check .check-sub { display: block; font-size: 12px; color: var(--text-faint); }

.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  font-size: 12.5px;
  cursor: pointer;
  background: var(--surface);
  user-select: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.chip-check:hover { background: var(--surface-2); }
.chip-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip-check:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-text);
  font-weight: 560;
}
.chip-check:has(input:focus-visible) { box-shadow: var(--ring); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: 0; }

.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface-inset);
}
.fieldset > legend, .fieldset-title {
  font-size: 12.5px;
  font-weight: 620;
  color: var(--text-muted);
  padding: 0 4px;
}

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.card-head .h2 { flex: 1; min-width: 0; }
.card-body { padding: 16px; }
.card-body.tight { padding: 12px; }
.card-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-inset);
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  box-shadow: var(--shadow-1);
}
.stat-label {
  font-size: 11.5px;
  font-weight: 580;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.stat-value {
  font-size: 24px;
  font-weight: 640;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-sub { font-size: 12px; color: var(--text-muted); }

/* ------------------------------------------------------------------ badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 11.5px;
  font-weight: 570;
  line-height: 18px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-success { background: var(--success-soft); border-color: var(--success-border); color: var(--success-text); }
.badge-danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger-text); }
.badge-warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning-text); }
.badge-info { background: var(--info-soft); border-color: var(--info-border); color: var(--info-text); }
.badge-accent { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent-text); }

.tag {
  display: inline-flex;
  padding: 1px 7px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ tables */
.table-wrap {
  overflow: auto;
  max-height: min(66vh, 780px);
  border-radius: 0;
}
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
.table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-inset);
  text-align: left;
  font-size: 11.5px;
  font-weight: 620;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: var(--surface-2); }
.table td.shrink { width: 1%; white-space: nowrap; }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-inset);
  font-size: 12.5px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

/* -------------------------------------------------------------- progress */
.progress {
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.3s ease;
}
.progress.warn > span { background: var(--warning); }
.progress.danger > span { background: var(--danger); }

/* ------------------------------------------------------------------- tabs */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 9px 12px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--accent-text); border-bottom-color: var(--accent); }

.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.segmented button {
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* ---------------------------------------------------------------- overlays */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 15, 22, 0.45);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px 16px;
  overflow-y: auto;
  animation: fade 0.14s ease;
}
@keyframes fade { from { opacity: 0; } }

.modal {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  display: flex;
  flex-direction: column;
  max-height: 88vh;
  animation: pop 0.16s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
.modal.wide { max-width: 820px; }
.modal.xwide { max-width: 1020px; }
.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.modal-head .h2 { flex: 1; min-width: 0; }
.modal-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-inset);
  flex: none;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 15, 22, 0.4);
  z-index: 100;
  display: flex;
  justify-content: flex-end;
  animation: fade 0.14s ease;
}
.drawer {
  width: min(520px, 100%);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-3);
  display: flex;
  flex-direction: column;
  animation: slide 0.18s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes slide { from { transform: translateX(24px); opacity: 0.4; } }
.drawer-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.drawer-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; flex: 1; }
.drawer-foot {
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-inset);
  display: flex;
  gap: 8px;
  flex: none;
}

/* ------------------------------------------------------------------ toasts */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 12px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  font-size: 13.5px;
  animation: toast-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.16s, transform 0.16s; }
.toast-error { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger-text); }
.toast-success { border-color: var(--success-border); background: var(--success-soft); color: var(--success-text); }
.toast-info { border-color: var(--info-border); background: var(--info-soft); color: var(--info-text); }
.toast p { flex: 1; min-width: 0; word-break: break-word; }
.toast button {
  appearance: none; border: 0; background: none; cursor: pointer;
  color: inherit; opacity: 0.6; padding: 0; display: grid; place-items: center;
}
.toast button:hover { opacity: 1; }

/* ------------------------------------------------------------ empty/error */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-icon {
  width: 44px; height: 44px;
  border-radius: var(--r-lg);
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-faint);
}
.empty .h3 { color: var(--text); }
.empty p { max-width: 46ch; font-size: 13px; }

.notice {
  display: flex;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-muted);
}
.notice svg { flex: none; margin-top: 1px; }
.notice-warning { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning-text); }
.notice-danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger-text); }
.notice-info { background: var(--info-soft); border-color: var(--info-border); color: var(--info-text); }
.notice-success { background: var(--success-soft); border-color: var(--success-border); color: var(--success-text); }
.notice strong { color: inherit; }

/* ---------------------------------------------------------------- skeleton */
.skel {
  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: var(--r-sm);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.skel-line { height: 12px; }
.skel-tile { height: 84px; border-radius: var(--r-lg); }
.skel-block { height: 220px; border-radius: var(--r-xl); }
@media (prefers-reduced-motion: reduce) {
  .skel { animation: none; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ------------------------------------------------------------------- chart */
.chart { width: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--text-faint); font-size: 10.5px; font-family: var(--font-sans); }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-area { stroke: none; opacity: 0.13; }
.chart .hover-band { fill: transparent; }
.chart .hover-band:hover { fill: color-mix(in srgb, var(--accent) 8%, transparent); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--text-muted); }
.legend span.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; }

/* ------------------------------------------------------------------- misc */
.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; word-break: break-word; }

.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item {
  display: flex;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.timeline-item:last-child { border-bottom: 0; }
.timeline-dot {
  width: 22px; height: 22px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-faint);
}

.code-box {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--surface-inset);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 10px 12px;
  word-break: break-all;
  user-select: all;
}

.preview-frame {
  width: 100%;
  min-height: 340px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: #fff;
}

.acct-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }

.rule-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.1fr) minmax(120px, 0.9fr) minmax(140px, 1.4fr) auto;
  gap: 8px;
  align-items: center;
}

.step-card { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.step-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-inset);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.step-num {
  width: 24px; height: 24px; flex: none;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent-text);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 650;
}
.step-body { padding: 14px; display: flex; flex-direction: column; gap: 12px; }

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border: 1px solid var(--border-strong);
  border-bottom: 0;
  border-radius: var(--r-md) var(--r-md) 0 0;
  background: var(--surface-inset);
}
.editor-toolbar + .textarea { border-radius: 0 0 var(--r-md) var(--r-md); }

.checklist { display: flex; flex-direction: column; gap: 10px; }
.checklist-item { display: flex; gap: 10px; font-size: 13px; }
.checklist-item svg { color: var(--success); flex: none; margin-top: 2px; }
.checklist-item strong { display: block; color: var(--text); }
.checklist-item span { color: var(--text-muted); }

/* ------------------------------------------------------------------- auth */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(1200px 520px at 50% -140px, color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-2);
  padding: 28px 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; }
.auth-foot { text-align: center; font-size: 13px; color: var(--text-muted); }
.auth-foot button {
  appearance: none; background: none; border: 0; padding: 0;
  font: inherit; color: var(--accent-text); cursor: pointer; text-decoration: underline;
}

/* ------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 268px;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow-3);
  }
  .sidebar.open { transform: none; }
  .main { grid-column: 1; }
  .menu-btn { display: inline-flex; }
  .view { padding: 16px 14px 56px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .rule-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .rule-row > *:nth-child(3) { grid-column: span 2; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
  .drawer { width: 100%; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .stat-value { font-size: 21px; }
  .backdrop { padding: 12px; align-items: flex-start; }
}
.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(12, 15, 22, 0.4);
  z-index: 35;
}
.scrim.on { display: block; }
@media (min-width: 901px) { .scrim { display: none !important; } }

/* ------------------------------------------------- simulated-data indicator */
.sim-badge {
  display: inline-flex; align-items: center; gap: 5px;
  margin-left: 10px; padding: 3px 9px;
  border-radius: var(--r-pill);
  background: var(--brand-soft);
  color: var(--brand-text);
  border: 1px solid var(--brand-border);
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
  white-space: nowrap;
}
.sim-badge svg { flex: none; }
@media (max-width: 560px) { .sim-badge span { display: none; } }

/* ------------------------------------------ team, invites & email domains */
.member-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.member-id { min-width: 0; }
.member-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-weight: 550;
  color: var(--text);
}
.member-name .tag {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10px;
  font-weight: 620;
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-text);
}
.member-email { font-size: 12px; color: var(--text-muted); }

/* role picker inside the members table: `td.shrink` is 1% wide, so the select
   has to size itself rather than inherit the 100% of a form field */
.select-sm {
  width: auto;
  min-width: 118px;
  padding: 5px 30px 5px 9px;
  font-size: 12.5px;
}

/* role picker help — one line on what each role may do */
.role-help {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-inset);
}
.role-help-item {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--text-faint);
}
.role-help-item.on {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.role-help-name {
  flex: none;
  min-width: 58px;
  font-weight: 620;
  color: var(--text-muted);
}
.role-help-item.on .role-help-name { color: var(--accent-text); }
.role-help-text { flex: 1 1 220px; min-width: 0; }

/* the one-time invite link */
.invite-reveal {
  margin-bottom: 16px;
  border-color: var(--brand-border);
  box-shadow: var(--shadow-2);
}
.invite-reveal .card-head { background: var(--brand-soft); }
.invite-reveal .card-head .h2 { color: var(--brand-text); }
.invite-link {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-wrap: wrap;
}
.invite-link .code-box {
  flex: 1 1 260px;
  min-width: 0;
  display: flex;
  align-items: center;
  background: var(--surface-inset);
}
.invite-link .btn { flex: none; align-self: stretch; height: auto; }

/* public invite-acceptance screen */
.invite-screen .kv.invite-kv {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-inset);
  align-items: start;
}
.invite-screen .invite-kv dd { display: flex; flex-direction: column; gap: 3px; }
.invite-screen .invite-kv dd .mono { word-break: break-all; }
.invite-screen .invite-kv .badge { align-self: flex-start; }
.invite-screen .h2 strong { font-weight: 700; }

/* allowed domains — the primary, and the single extra slot */
.domain-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-inset);
  min-height: 44px;
}
.domain-row-empty {
  border-style: dashed;
  border-color: var(--border);
  background: transparent;
}
.domain-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
  min-width: 0;
}
.domain-row .tag {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10px;
  font-weight: 620;
}
.domain-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.domain-form .input { flex: 1 1 200px; }
.domain-form .btn { flex: none; }

@media (max-width: 560px) {
  .invite-link .btn { width: 100%; }
  .role-help-name { min-width: 0; }
  .domain-row .spacer { display: none; }
  .domain-row > .row { width: 100%; }
  .domain-row > .row .btn { flex: 1 1 auto; }
  .domain-form .input { flex: 1 1 100%; }
  .domain-form .btn { flex: 1 1 auto; }
}
