/* =====================================================================
   ZeroSMS design system
   One stylesheet, one visual language, used by both the customer and
   admin dashboards. Tokens first, then primitives, then components.
   ===================================================================== */

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

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

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

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; line-height: 1.25; letter-spacing: -0.011em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

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

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

  /* Brand, taken from the ZeroSMS mark. */
  --brand:         #1d8fc4;
  --brand-strong:  #17739e;
  --brand-soft:    #e8f4fb;
  --brand-border:  #b9ddf1;
  --brand-text:    #145b7e;

  /* Neutrals */
  --bg:            #f5f7fa;
  --surface:       #ffffff;
  --surface-2:     #fafbfc;
  --surface-3:     #f1f4f8;
  --border:        #e3e8ef;
  --border-strong: #cfd7e3;

  --text:          #1a2230;
  --text-muted:    #5b6779;
  --text-subtle:   #8794a8;
  --text-inverse:  #ffffff;

  /* Status. Each has a solid, a soft background and a readable text tone,
     so a badge never relies on colour alone being legible. */
  --ok:            #17864b;
  --ok-soft:       #e6f6ed;
  --ok-border:     #b5e3c9;

  --warn:          #9a6200;
  --warn-soft:     #fdf3e2;
  --warn-border:   #f2d9a8;

  --danger:        #c02b2b;
  --danger-soft:   #fdeceb;
  --danger-border: #f5c2bf;

  --info:          #2159b8;
  --info-soft:     #ebf1fd;
  --info-border:   #c2d5f5;

  --neutral:       #5b6779;
  --neutral-soft:  #f1f4f8;
  --neutral-border:#dde4ed;

  /* Chart series - distinguishable in both themes and for common CVD. */
  --c1: #1d8fc4;
  --c2: #17864b;
  --c3: #b8860b;
  --c4: #9a4bb8;
  --c5: #c02b2b;
  --c6: #0f7b8a;

  --radius-sm: 5px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-xs: 0 1px 2px rgba(16, 26, 40, .06);
  --shadow-sm: 0 1px 3px rgba(16, 26, 40, .08), 0 1px 2px rgba(16, 26, 40, .04);
  --shadow:    0 4px 12px rgba(16, 26, 40, .08), 0 1px 3px rgba(16, 26, 40, .05);
  --shadow-lg: 0 12px 32px rgba(16, 26, 40, .14), 0 4px 8px rgba(16, 26, 40, .06);

  --sidebar-w: 248px;
  --imp-h: 40px;
  --topbar-h: 60px;

  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;
  --space-12: 48px;
}

:root[data-theme="dark"],
html:not([data-theme="light"]) body.theme-dark {
  --bg:            #10151d;
  --surface:       #171d27;
  --surface-2:     #1c2330;
  --surface-3:     #222b3a;
  --border:        #2a3444;
  --border-strong: #3a4657;

  --text:          #e6ebf2;
  --text-muted:    #9aa7ba;
  --text-subtle:   #6e7c92;

  --brand:         #4bb3e8;
  --brand-strong:  #6cc4f0;
  --brand-soft:    #142c3b;
  --brand-border:  #1f4f6b;
  --brand-text:    #8ed0f2;

  --ok:            #4ecb87;  --ok-soft:     #112e1f;  --ok-border:     #1f5638;
  --warn:          #e0a94a;  --warn-soft:   #2e2413;  --warn-border:   #5c4620;
  --danger:        #f07b74;  --danger-soft: #331817;  --danger-border: #62302c;
  --info:          #7aa7f0;  --info-soft:   #161f33;  --info-border:   #2c3f66;
  --neutral:       #9aa7ba;  --neutral-soft:#1c2330;  --neutral-border:#2f3a4a;

  --c1: #4bb3e8; --c2: #4ecb87; --c3: #e0a94a;
  --c4: #b98ae0; --c5: #f07b74; --c6: #4bc0cf;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .36);
  --shadow:    0 4px 14px rgba(0, 0, 0, .42);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
}

/* ------------------------------------------------------------- utilities */
.u-muted   { color: var(--text-muted); }
.u-subtle  { color: var(--text-subtle); }
.u-mono    { font-family: var(--font-mono); font-size: .92em; }
.u-nowrap  { white-space: nowrap; }
.u-right   { text-align: right; }
.u-center  { text-align: center; }
.u-bold    { font-weight: 600; }
.u-small   { font-size: 12.5px; }
.u-xs      { font-size: 11.5px; }
.u-break   { word-break: break-word; overflow-wrap: anywhere; }
.u-tnum    { font-variant-numeric: tabular-nums; }
.u-hide    { display: none !important; }
.u-flex    { display: flex; }
.u-between { display: flex; align-items: center; justify-content: space-between; }
.u-gap-1 { gap: var(--space-1); } .u-gap-2 { gap: var(--space-2); }
.u-gap-3 { gap: var(--space-3); } .u-gap-4 { gap: var(--space-4); }
.u-mt-2 { margin-top: var(--space-2); } .u-mt-4 { margin-top: var(--space-4); }
.u-mt-6 { margin-top: var(--space-6); } .u-mb-4 { margin-bottom: var(--space-4); }
.u-mb-6 { margin-bottom: var(--space-6); }
.u-w-full { width: 100%; }
.u-items-center { align-items: center; }
.u-wrap { flex-wrap: wrap; }
.u-grow { flex: 1 1 auto; min-width: 0; }

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

/* ---------------------------------------------------------------- layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar__brand {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar__brand img { width: 30px; height: 30px; border-radius: 7px; }
.sidebar__brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.01em; color: var(--text); }
.sidebar__brand-sub { font-size: 11px; color: var(--text-subtle); margin-top: -2px; }

.sidebar__nav { padding: var(--space-3) var(--space-3) var(--space-6); flex: 1; }

.nav-group { margin-bottom: var(--space-5); }
.nav-group__label {
  font-size: 10.5px; font-weight: 650; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-subtle);
  padding: 0 var(--space-3); margin-bottom: var(--space-2);
}

.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 8px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13.5px; font-weight: 500;
  margin-bottom: 1px;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.nav-item.is-active .icon { color: var(--brand); }
.nav-item .icon { width: 17px; height: 17px; flex-shrink: 0; color: var(--text-subtle); }
.nav-item__badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 10.5px; font-weight: 650; padding: 1px 6px; border-radius: 10px;
  min-width: 18px; text-align: center;
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-6);
  position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-size: 15px; font-weight: 600; }
.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.content { padding: var(--space-6); flex: 1; max-width: 1560px; width: 100%; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6);
}
.page-head__title { font-size: 21px; font-weight: 650; letter-spacing: -.02em; }
.page-head__sub { color: var(--text-muted); font-size: 13.5px; margin-top: 3px; }
.page-head__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card__head {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  flex-wrap: wrap;
}
.card__title { font-size: 14.5px; font-weight: 620; }
.card__sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.card__body { padding: var(--space-5); }
.card__body--flush { padding: 0; }
.card__foot {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  font-size: 12.5px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  flex-wrap: wrap;
}

.grid { display: grid; gap: var(--space-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 1fr) 340px; }
.grid--main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

/* ------------------------------------------------------------ stat tiles */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-xs);
  min-width: 0;
}
.stat__label {
  font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-subtle);
  display: flex; align-items: center; gap: 6px;
}
.stat__value {
  font-size: 25px; font-weight: 660; letter-spacing: -.02em;
  margin-top: 6px; font-variant-numeric: tabular-nums; line-height: 1.15;
}
.stat__value--sm { font-size: 20px; }
.stat__meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; display: flex; align-items: center; gap: 5px; }
.stat__delta { font-weight: 600; }
.stat__delta--up { color: var(--ok); }
.stat__delta--down { color: var(--danger); }
.stat--accent { border-left: 3px solid var(--brand); }
.stat--ok     { border-left: 3px solid var(--ok); }
.stat--warn   { border-left: 3px solid var(--warn); }
.stat--danger { border-left: 3px solid var(--danger); }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px; font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn .icon { width: 15px; height: 15px; }

.btn--primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn--primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }

.btn--secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn--secondary:hover { background: var(--surface-3); }

.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }

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

.btn--danger-soft { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.btn--danger-soft:hover { background: var(--danger); color: #fff; }

.btn--ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn--ok:hover { filter: brightness(.93); }

.btn--sm { padding: 4px 10px; font-size: 12.5px; }
.btn--lg { padding: 10px 20px; font-size: 14.5px; }
.btn--block { width: 100%; }
.btn--icon { padding: 6px; }
.btn--icon .icon { width: 16px; height: 16px; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.5;
}
.badge::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}
.badge--plain::before { display: none; }

.badge--ok      { background: var(--ok-soft);      color: var(--ok);      border-color: var(--ok-border); }
.badge--warn    { background: var(--warn-soft);    color: var(--warn);    border-color: var(--warn-border); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger);  border-color: var(--danger-border); }
.badge--info    { background: var(--info-soft);    color: var(--info);    border-color: var(--info-border); }
.badge--neutral { background: var(--neutral-soft); color: var(--neutral); border-color: var(--neutral-border); }
.badge--brand   { background: var(--brand-soft);   color: var(--brand-text); border-color: var(--brand-border); }

/* ---------------------------------------------------------------- tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left;
  font-size: 11.5px; font-weight: 640; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-subtle);
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.table td {
  padding: 11px var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--surface-2); }
.table--clickable tbody tr { cursor: pointer; }
.table td.u-right, .table th.u-right { text-align: right; }
.table__actions { display: flex; gap: 4px; justify-content: flex-end; }

.table__primary { font-weight: 560; color: var(--text); }
.table__secondary { font-size: 12px; color: var(--text-subtle); margin-top: 1px; }

/* Card-style rows on narrow screens: admin tables stay usable on a phone
   instead of forcing a horizontal scroll across a dozen columns. */
@media (max-width: 720px) {
  .table--responsive thead { display: none; }
  .table--responsive, .table--responsive tbody, .table--responsive tr, .table--responsive td {
    display: block; width: 100%;
  }
  .table--responsive tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--space-3);
    padding: var(--space-2);
    background: var(--surface);
  }
  .table--responsive td {
    border: 0;
    padding: 5px var(--space-2);
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
    text-align: right;
  }
  .table--responsive td::before {
    content: attr(data-label);
    font-size: 11.5px; font-weight: 640; text-transform: uppercase;
    letter-spacing: .04em; color: var(--text-subtle);
    text-align: left; flex-shrink: 0;
  }
  .table--responsive td:not([data-label]) { justify-content: flex-end; }
  .table--responsive .table__actions { justify-content: flex-end; width: 100%; }
}

/* ----------------------------------------------------------------- forms */
.form-grid { display: grid; gap: var(--space-4); }
.form-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field--span { grid-column: 1 / -1; }

.label { font-size: 12.5px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 5px; }
.label__required { color: var(--danger); }
.label__optional { color: var(--text-subtle); font-weight: 450; font-size: 11.5px; }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  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 color-mix(in srgb, var(--brand) 18%, transparent);
}
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-3); color: var(--text-muted); cursor: not-allowed;
}
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--danger); }
.textarea { min-height: 96px; resize: vertical; font-family: inherit; }
.textarea--mono { font-family: var(--font-mono); font-size: 12.5px; }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235b6779' d='M6 8.5 2 4.5h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.help { font-size: 12px; color: var(--text-muted); line-height: 1.45; }
.error-text { font-size: 12px; color: var(--danger); font-weight: 500; }

.checkbox, .radio {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 13.5px; cursor: pointer; padding: 3px 0;
}
.checkbox input, .radio input {
  width: 15px; height: 15px; margin: 2px 0 0; accent-color: var(--brand);
  flex-shrink: 0; cursor: pointer;
}
.checkbox__text { min-width: 0; }
.checkbox__title { font-weight: 500; }
.checkbox__help { font-size: 12px; color: var(--text-muted); }

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 36px; height: 20px; border-radius: 20px;
  background: var(--border-strong); position: relative;
  transition: background .16s; flex-shrink: 0;
}
.switch__track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-xs);
  transition: transform .16s;
}
.switch input:checked + .switch__track { background: var(--brand); }
.switch input:checked + .switch__track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--brand); outline-offset: 2px; }

.input-group { display: flex; }
.input-group .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: 0; }

.input-prefix {
  display: flex; align-items: center; padding: 0 10px;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  color: var(--text-muted); font-size: 13px; white-space: nowrap;
}
.input-prefix + .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* --------------------------------------------------------------- filters */
.filters {
  display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: flex-end;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.filters .field { min-width: 150px; }
.filters .field--search { flex: 1 1 220px; }

/* ---------------------------------------------------------------- alerts */
.alert {
  display: flex; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid;
  font-size: 13.5px;
  margin-bottom: var(--space-4);
  align-items: flex-start;
}
.alert .icon { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; }
.alert__body { min-width: 0; flex: 1; }
.alert__title { font-weight: 620; margin-bottom: 2px; }
.alert--ok     { background: var(--ok-soft);     border-color: var(--ok-border);     color: var(--ok); }
.alert--warn   { background: var(--warn-soft);   border-color: var(--warn-border);   color: var(--warn); }
.alert--danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.alert--info   { background: var(--info-soft);   border-color: var(--info-border);   color: var(--info); }
.alert--brand  { background: var(--brand-soft);  border-color: var(--brand-border);  color: var(--brand-text); }
.alert a { color: inherit; text-decoration: underline; }

/* ---------------------------------------------------------------- toasts */
.toasts {
  position: fixed; bottom: var(--space-5); right: var(--space-5);
  z-index: 200; display: flex; flex-direction: column; gap: var(--space-2);
  max-width: 380px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: var(--space-3) var(--space-4);
  display: flex; gap: var(--space-3); align-items: flex-start;
  animation: toast-in .2s ease-out;
  font-size: 13.5px;
}
.toast--ok     { border-left-color: var(--ok); }
.toast--warn   { border-left-color: var(--warn); }
.toast--danger { border-left-color: var(--danger); }
.toast__close { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--text-subtle); padding: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12, 18, 28, .5);
  backdrop-filter: blur(2px);
  z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  animation: fade-in .14s ease-out;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px;
  max-height: calc(100vh - 2 * var(--space-8));
  display: flex; flex-direction: column;
  animation: modal-in .18s cubic-bezier(.2, .8, .3, 1);
}
.modal--lg { max-width: 760px; }
.modal--sm { max-width: 400px; }
.modal__head {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3);
}
.modal__title { font-size: 15.5px; font-weight: 620; }
.modal__sub { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.modal__body { padding: var(--space-5); overflow-y: auto; }
.modal__foot {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: var(--space-2);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  flex-wrap: wrap;
}
.modal__close { background: none; border: 0; cursor: pointer; color: var(--text-subtle); padding: 2px; }
.modal__close:hover { color: var(--text); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(-10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------- dropdowns */
.dropdown { position: relative; display: inline-block; }
.dropdown__menu {
  position: absolute; right: 0; top: calc(100% + 5px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 200px; padding: 5px;
  z-index: 50; display: none;
}
.dropdown.is-open .dropdown__menu { display: block; }
.dropdown__item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  font-size: 13.5px; color: var(--text); width: 100%;
  background: none; border: 0; cursor: pointer; text-align: left;
}
.dropdown__item:hover { background: var(--surface-3); text-decoration: none; }
.dropdown__item--danger { color: var(--danger); }
.dropdown__divider { height: 1px; background: var(--border); margin: 5px 0; }
.dropdown__header {
  padding: 8px 10px; font-size: 11.5px; font-weight: 640;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-subtle);
}

/* ------------------------------------------------------------ pagination */
.pagination { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.pagination__item {
  min-width: 30px; height: 30px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text-muted); background: var(--surface);
}
.pagination__item:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.pagination__item.is-active {
  background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600;
}
.pagination__item.is-disabled { opacity: .4; pointer-events: none; }
.pagination__gap { padding: 0 4px; color: var(--text-subtle); }

/* ----------------------------------------------------------------- empty */
.empty {
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--text-muted);
}
.empty__icon {
  width: 42px; height: 42px; margin: 0 auto var(--space-4);
  color: var(--text-subtle); opacity: .7;
}
.empty__title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 5px; }
.empty__text { font-size: 13.5px; max-width: 400px; margin: 0 auto var(--space-4); line-height: 1.55; }

/* --------------------------------------------------------------- loading */
.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn.is-loading { pointer-events: none; opacity: .75; }

/* ---------------------------------------------------------------- charts */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart__legend {
  display: flex; gap: var(--space-4); flex-wrap: wrap;
  font-size: 12.5px; color: var(--text-muted);
  margin-top: var(--space-3);
}
.chart__legend-item { display: flex; align-items: center; gap: 6px; }
.chart__swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.chart__grid { stroke: var(--border); stroke-width: 1; }
.chart__axis { fill: var(--text-subtle); font-size: 10.5px; }
.chart__tooltip {
  position: absolute; pointer-events: none; z-index: 60;
  background: var(--text); color: var(--surface);
  padding: 7px 10px; border-radius: var(--radius-sm);
  font-size: 12px; box-shadow: var(--shadow); white-space: nowrap;
  opacity: 0; transition: opacity .1s;
}
.chart__tooltip.is-visible { opacity: 1; }

/* ------------------------------------------------------------ mini meter */
.meter { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.meter__fill { height: 100%; border-radius: 3px; transition: width .3s; }
.meter__fill--ok { background: var(--ok); }
.meter__fill--warn { background: var(--warn); }
.meter__fill--danger { background: var(--danger); }
.meter__fill--brand { background: var(--brand); }

/* ------------------------------------------------------------------ misc */
.divider { height: 1px; background: var(--border); margin: var(--space-5) 0; border: 0; }

.kv { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 10px var(--space-4); font-size: 13.5px; }
.kv__key { color: var(--text-muted); }
.kv__val { min-width: 0; word-break: break-word; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 9px var(--space-4);
  font-size: 13.5px; font-weight: 550; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-text);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 650; flex-shrink: 0;
}
.avatar--sm { width: 26px; height: 26px; font-size: 10.5px; }
.avatar--lg { width: 46px; height: 46px; font-size: 16px; }

.code-block {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-mono); font-size: 12.5px;
  overflow-x: auto; white-space: pre;
  color: var(--text);
}

.copy-field {
  display: flex; align-items: center; gap: var(--space-2);
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 10px;
  font-family: var(--font-mono); font-size: 12.5px;
}
.copy-field__value { flex: 1; overflow-x: auto; white-space: nowrap; }

.timeline { position: relative; padding-left: 22px; }
.timeline::before {
  content: ""; position: absolute; left: 5px; top: 5px; bottom: 5px;
  width: 2px; background: var(--border);
}
.timeline__item { position: relative; padding-bottom: var(--space-4); }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__dot {
  position: absolute; left: -22px; top: 3px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border-strong);
}
.timeline__dot--ok { border-color: var(--ok); background: var(--ok); }
.timeline__dot--danger { border-color: var(--danger); background: var(--danger); }
.timeline__dot--brand { border-color: var(--brand); background: var(--brand); }
.timeline__title { font-size: 13.5px; font-weight: 560; }
.timeline__meta { font-size: 12px; color: var(--text-subtle); margin-top: 1px; }

/* ------------------------------------------------------------ auth pages */
.auth {
  min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
.auth__panel {
  display: flex; flex-direction: column; justify-content: center;
  padding: var(--space-12) var(--space-8);
}
.auth__form { width: 100%; max-width: 380px; margin: 0 auto; }
.auth__brand { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-8); }
.auth__brand img { width: 38px; height: 38px; border-radius: 9px; }
.auth__brand-name { font-size: 18px; font-weight: 660; letter-spacing: -.02em; }
.auth__title { font-size: 22px; font-weight: 650; letter-spacing: -.02em; margin-bottom: 6px; }
.auth__sub { color: var(--text-muted); font-size: 13.5px; margin-bottom: var(--space-6); }
.auth__foot { margin-top: var(--space-6); font-size: 13px; color: var(--text-muted); text-align: center; }

.auth__aside {
  background: linear-gradient(150deg, var(--brand-strong), var(--brand) 55%, #0f6f9c);
  color: #fff;
  display: flex; flex-direction: column; justify-content: center;
  padding: var(--space-12);
  position: relative; overflow: hidden;
}
.auth__aside::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 78% 18%, rgba(255,255,255,.16), transparent 52%);
}
.auth__aside-inner { position: relative; z-index: 1; max-width: 420px; }
.auth__tagline { font-size: 25px; font-weight: 640; line-height: 1.3; letter-spacing: -.02em; margin-bottom: var(--space-4); }
.auth__points { list-style: none; display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-6); }
.auth__point { display: flex; gap: 11px; align-items: flex-start; font-size: 14px; opacity: .95; }
.auth__point .icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

/* ------------------------------------------------------- composer widget */
.composer__preview {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}
.composer__bubble {
  background: var(--brand); color: #fff;
  padding: 9px 13px; border-radius: 16px 16px 4px 16px;
  font-size: 13.5px; line-height: 1.45;
  max-width: 280px; margin-left: auto;
  word-break: break-word; white-space: pre-wrap;
}
.composer__counter {
  display: flex; gap: var(--space-4); font-size: 12px;
  color: var(--text-muted); margin-top: var(--space-2); flex-wrap: wrap;
}
.composer__counter strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------- impersonation */
.impersonation-bar {
  background: var(--warn); color: #23190a;
  padding: 0 var(--space-6);
  font-size: 13px; font-weight: 550;
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  /* Pinned above the fixed sidebar/topbar so its message is never hidden. */
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  height: var(--imp-h, 40px); box-sizing: border-box;
}
.impersonation-bar > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.impersonation-bar a { color: inherit; text-decoration: underline; font-weight: 650; }

/* When impersonating, offset the fixed sidebar, sticky topbar and content so
   nothing sits under the pinned bar. */
.has-impersonation .sidebar { top: var(--imp-h, 40px); }
.has-impersonation .main { padding-top: var(--imp-h, 40px); }
.has-impersonation .topbar { top: var(--imp-h, 40px); }

/* ------------------------------------------------------------ responsive */
.sidebar__toggle { display: none; }
.sidebar__backdrop { display: none; }

@media (max-width: 1200px) {
  .grid--5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid--sidebar, .grid--main { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 960px) {
  .grid--4, .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth { grid-template-columns: 1fr; }
  .auth__aside { display: none; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease-out;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .sidebar__backdrop {
    display: block; position: fixed; inset: 0;
    background: rgba(12, 18, 28, .45); z-index: 39;
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .sidebar__backdrop.is-visible { opacity: 1; pointer-events: auto; }
  .sidebar__toggle { display: inline-flex; }
  .main { margin-left: 0; }
  .content { padding: var(--space-4); }
  .topbar { padding: 0 var(--space-4); }
  .grid--5, .grid--4, .grid--3, .grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid--2, .form-grid--3 { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px var(--space-4); }
  .kv__key { margin-top: var(--space-2); }
  .page-head__title { font-size: 19px; }
  .toasts { left: var(--space-3); right: var(--space-3); bottom: var(--space-3); max-width: none; }
}

@media (max-width: 520px) {
  .grid--5, .grid--4, .grid--3, .grid--2 { grid-template-columns: minmax(0, 1fr); }
  .stat__value { font-size: 22px; }
  .filters { padding: var(--space-3); }
  .filters .field { min-width: 100%; }
}

@media print {
  .sidebar, .topbar, .page-head__actions, .filters, .pagination { display: none !important; }
  .main { margin-left: 0; }
  .card { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}

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

/* ----- searchable flag select (progressive enhancement for data-flag-select) ----- */
.flag-select { position: relative; }
.flag-select__native {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.flag-select__button {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 8px 30px 8px 11px; text-align: left;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: 13.5px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235b6779' d='M6 8.5 2 4.5h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  transition: border-color .12s, box-shadow .12s;
}
.flag-select.is-open .flag-select__button,
.flag-select__button:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.flag-select__button.is-invalid { border-color: var(--danger); }
.flag-select__flag { font-size: 17px; line-height: 1; flex-shrink: 0; }
.flag-select__value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flag-select__value.is-placeholder { color: var(--text-subtle); }
.flag-select__panel {
  position: absolute; z-index: 50; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md, 0 10px 30px rgba(16,26,40,.14));
  overflow: hidden;
}
.flag-select__search-wrap { padding: 8px; border-bottom: 1px solid var(--border); }
.flag-select__search {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: 13px;
}
.flag-select__search:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.flag-select__list { list-style: none; margin: 0; padding: 4px; max-height: 244px; overflow-y: auto; }
.flag-select__option {
  display: flex; align-items: center; gap: 9px; padding: 7px 9px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; color: var(--text);
}
.flag-select__option:hover, .flag-select__option.is-active { background: var(--surface-3); }
.flag-select__option[aria-selected="true"] { font-weight: 600; }
.flag-select__empty { padding: 14px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* Base icon size so any icon() used without a contextual size rule (e.g. inside
   dropdown menu items) renders at a sane size instead of expanding to fill.
   More specific rules (.nav-item .icon, .btn .icon, …) still override this. */
.icon { width: 16px; height: 16px; flex-shrink: 0; }
.dropdown__item .icon { width: 16px; height: 16px; flex-shrink: 0; }

/* Clickable rows (data-href) — replaces CSP-blocked inline onclick. */
[data-href] { cursor: pointer; }
[data-href]:hover { background: var(--surface-3); }
