/* ============================================================================
   LUMA TV — account dashboard
   Dark (OLED-leaning) surface stack, brand blue accent, Manrope.
   Tokens only: no raw hex below the :root block.
   ========================================================================== */

:root {
  /* --- surfaces: a 5-step ramp so elevation reads without heavy shadows --- */
  --bg:            #08090C;
  --bg-2:          #0B0D12;
  --surface:       #101218;
  --surface-2:     #161922;
  --surface-3:     #1D212C;
  --border:        #232838;
  --border-strong: #303649;

  /* --- text --- */
  --text:          #F2F4F8;   /* 17.4:1 on --bg */
  --text-2:        #B7BECE;   /* 10.0:1 */
  --text-3:        #838C9F;   /*  5.3:1 — smallest allowed for body */
  --text-on-accent:#FFFFFF;

  /* --- brand: sampled from the LUMA mark (cyan → blue → violet) --- */
  --brand-cyan:    #03C8FD;
  --brand-blue:    #0185FB;
  --brand-violet:  #6E45FD;
  --brand-grad:    linear-gradient(135deg, var(--brand-violet) 0%, var(--brand-blue) 52%, var(--brand-cyan) 100%);

  /* --- accent: darkened brand blue so white label clears 4.5:1 (5.1:1) --- */
  --accent:        #1668E3;
  --accent-hover:  #2A7AF2;
  --accent-press:  #1157C4;
  --accent-text:   #4FA8FF;   /* 7.5:1 on --bg — accent used AS text */
  --accent-soft:   rgba(22, 104, 227, .14);
  --accent-ring:   rgba(79, 168, 255, .55);

  /* --- semantic --- */
  --ok:            #34D399;
  --ok-soft:       rgba(52, 211, 153, .13);
  --warn:          #FBBF24;
  --warn-soft:     rgba(251, 191, 36, .13);
  --danger:        #FF6B6B;
  --danger-soft:   rgba(255, 107, 107, .13);
  --danger-strong: #C6303B;

  /* --- geometry --- */
  --r-sm: 8px;  --r-md: 12px;  --r-lg: 16px;  --r-xl: 22px;  --r-pill: 999px;
  --sidebar-w: 264px;
  --gutter: clamp(16px, 3.2vw, 40px);
  --maxw: 1320px;

  /* --- motion --- */
  --t-fast: 140ms;
  --t: 200ms;
  --ease: cubic-bezier(.2, .8, .3, 1);

  /* --- elevation: dark UI reads better with border + inner highlight --- */
  --lift: inset 0 1px 0 rgba(255,255,255,.045);
  --shadow-1: 0 1px 2px rgba(0,0,0,.5);
  --shadow-2: 0 12px 32px -8px rgba(0,0,0,.7), 0 2px 6px rgba(0,0,0,.4);
  --shadow-3: 0 32px 64px -16px rgba(0,0,0,.8), 0 2px 8px rgba(0,0,0,.5);

  --z-nav: 40; --z-sticky: 30; --z-scrim: 90; --z-modal: 100; --z-toast: 200;
}

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

/* class rules outrank the UA [hidden] default; make it win again */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.55 Manrope, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-feature-settings: "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Ambient brand wash: one fixed, GPU-cheap radial pair. No blur filters. */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 420px at 18% -8%, rgba(110, 69, 253, .16), transparent 65%),
    radial-gradient(760px 380px at 88% 4%,  rgba(3, 200, 253, .09),  transparent 62%);
  z-index: 0;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

svg.ico {
  width: 20px; height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ico-sm { width: 16px; height: 16px; stroke-width: 2; }
.ico-lg { width: 24px; height: 24px; }

img { max-width: 100%; height: auto; display: block; }

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.018em; line-height: 1.22; }
h1 { font-size: clamp(24px, 2.6vw, 30px); font-weight: 800; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p  { margin: 0; }

a { color: var(--accent-text); text-decoration-color: color-mix(in srgb, var(--accent-text) 40%, transparent); text-underline-offset: 3px; }

/* Numeric columns must not jitter as values change. */
.num { font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------- focus & a11y */

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.skip-link {
  position: fixed; top: 8px; left: 8px;
  z-index: var(--z-toast);
  padding: 10px 16px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  transform: translateY(-160%);
  transition: transform var(--t) var(--ease);
}
.skip-link:focus { transform: none; }

.vh {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ================================================================= LOGIN == */

.auth {
  position: relative; z-index: 1;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) var(--gutter) max(24px, env(safe-area-inset-bottom));
}

.auth-card {
  width: min(100%, 440px);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3), var(--lift);
  padding: clamp(24px, 4vw, 38px);
}

.auth-logo { width: 148px; margin-bottom: 26px; }

.auth-card h1 { font-size: 26px; margin-bottom: 8px; }
.auth-sub { color: var(--text-2); font-size: 14.5px; margin-bottom: 26px; }

/* OTP: six boxes, one hidden field would break paste + SR, so real inputs. */
.otp {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 6px;
}
.otp input {
  -moz-appearance: textfield;
  width: 100%; height: 62px;
  text-align: center;
  font: 700 26px/1 Manrope, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--bg-2);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.otp input::-webkit-outer-spin-button,
.otp input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.otp input:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border-strong)); }
.otp input:focus {
  outline: none;
  border-color: var(--accent-text);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.otp input[data-filled="1"] { border-color: color-mix(in srgb, var(--accent) 70%, var(--border-strong)); }
.auth[data-error="1"] .otp input { border-color: var(--danger); }

.auth-hint {
  display: flex; gap: 9px; align-items: flex-start;
  margin: 22px 0 0;
  padding: 13px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-2); font-size: 13.5px; line-height: 1.5;
}
.auth-hint .ico { color: var(--accent-text); margin-top: 1px; }

/* ================================================================= SHELL == */

.shell {
  position: relative; z-index: 1;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

/* --------------------------------------------------------------- sidebar */

.sidebar {
  position: sticky; top: 0;
  align-self: start;
  height: 100dvh;
  display: flex; flex-direction: column;
  gap: 6px;
  padding: 26px 16px max(18px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border-right: 1px solid var(--border);
  z-index: var(--z-nav);
}

.brand { display: flex; align-items: center; justify-content: center; gap: 11px; padding: 0 10px 24px; }
.brand img { width: 122px; }

.nav-label {
  padding: 16px 12px 8px;
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-3);
}

.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 46px;
  padding: 0 12px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: 14.5px; font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.nav-item[aria-current="page"] .ico { color: var(--accent-text); }
.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute; left: -16px; top: 50%;
  width: 3px; height: 24px;
  margin-top: -12px;
  border-radius: 0 3px 3px 0;
  background: var(--brand-grad);
}
.nav-item .badge { margin-left: auto; }

.sidebar-foot {
  margin-top: auto;
  display: flex; align-items: center; gap: 11px;
  padding: 14px 0 0 12px;   /* flush right: aligns with the nav pills' right edge */
  border-top: 1px solid var(--border);
}

.avatar {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--brand-grad);
  color: #fff; font-size: 13px; font-weight: 800;
}
.acct-meta { flex: 1; min-width: 0; }
.acct-meta b { display: block; font-size: 13.5px; font-weight: 700; }
.acct-meta span { display: block; font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.signout { flex: none; margin-left: auto; color: var(--text-3); }
.signout:hover {
  background: var(--danger-soft); color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 34%, transparent);
}

/* ------------------------------------------------------------------ main */

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

.topbar {
  position: sticky; top: 0;
  z-index: var(--z-sticky);
  display: flex; align-items: center; gap: 14px;
  min-height: 68px;
  padding: 12px var(--gutter);
  padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; font-weight: 700; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* .btn sets display:inline-flex further down at equal specificity — outrank it,
   and keep the same specificity on the mobile counterpart below. */
.topbar .menu-btn { display: none; }

.page {
  flex: 1;
  width: 100%; max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px var(--gutter) 96px;
}
.page > * + * { margin-top: 22px; }

.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-2); font-size: 14.5px; margin-top: 6px; }
.page-head .spacer { margin-left: auto; }

/* ============================================================== PRIMITIVES */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1), var(--lift);
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 15px; font-weight: 700; }
.card-head .spacer { margin-left: auto; }
.card-body { padding: 18px; }

/* ---- buttons ---- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;                       /* touch target */
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font: 600 14.5px/1 Manrope, system-ui, sans-serif;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(.5px); }

.btn-primary { background: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-press); }

.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 34%, transparent); }
.btn-danger:hover { background: var(--danger-strong); color: #fff; border-color: transparent; }

.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13.5px; }
.btn-icon { min-height: 40px; width: 40px; padding: 0; }

.btn[disabled], .btn[aria-disabled="true"] {
  opacity: .45; cursor: not-allowed; pointer-events: none;
}
.btn[data-busy="1"] { pointer-events: none; }
.btn[data-busy="1"] .ico-spin { display: block; }
.ico-spin { display: none; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- pills / badges ---- */

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 11px 4px 9px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
/* an interactive pill still owes the user a 44px hit area */
a.pill, button.pill { min-height: 44px; padding-inline: 14px; text-decoration: none; cursor: pointer; }
a.pill:hover, button.pill:hover { background: var(--surface-3); }
.pill-ok     { background: var(--ok-soft);     color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.pill-warn   { background: var(--warn-soft);   color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.pill-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

.badge {
  min-width: 22px; height: 20px;
  display: inline-grid; place-items: center;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--text-2);
  font-size: 11.5px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---- form fields ---- */

.field { display: block; }
.field + .field, .form > * + * { margin-top: 16px; }
.field > .lbl {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 7px;
  font-size: 13.5px; font-weight: 600; color: var(--text-2);
}
.req { color: var(--danger); }

.input {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font: 400 15px/1.4 Manrope, system-ui, sans-serif;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.input::placeholder { color: var(--text-3); }
.input:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border-strong)); }
.input:focus {
  outline: none;
  border-color: var(--accent-text);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.help { margin-top: 7px; font-size: 12.5px; color: var(--text-3); line-height: 1.45; }

.err {
  display: none;
  align-items: center; gap: 6px;
  margin-top: 7px;
  font-size: 12.5px; font-weight: 600; color: var(--danger);
}
.field[data-invalid="1"] .err { display: flex; }
.field[data-invalid="1"] .input { border-color: var(--danger); }

.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; }

/* file drop */
.drop {
  display: grid; place-items: center; gap: 10px;
  padding: 30px 20px;
  text-align: center;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--bg-2);
  color: var(--text-2);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.drop:hover, .drop[data-over="1"] { border-color: var(--accent-text); background: var(--accent-soft); }
.drop .ico { color: var(--accent-text); }
.drop b { color: var(--text); font-size: 14.5px; }
.drop small { color: var(--text-3); font-size: 12.5px; }

/* toggle switch */
.switch {
  display: inline-flex; align-items: center; gap: 11px;
  cursor: pointer; user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 44px; height: 26px; flex: none;
  padding: 3px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.switch .thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform var(--t) var(--ease), background var(--t-fast) var(--ease);
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent-ring); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .45; }

/* checkbox */
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check .box {
  position: relative;
  width: 20px; height: 20px; flex: none;
  display: grid; place-items: center;
  border: 1.5px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg-2);
  color: transparent;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.check input:checked + .box { background: var(--accent); border-color: var(--accent); color: #fff; }
.check input:indeterminate + .box { background: var(--accent); border-color: var(--accent); color: #fff; }
/* indeterminate reads as a dash, not a tick — "some", not "all" */
.check input:indeterminate + .box .ico { visibility: hidden; }
.check input:indeterminate + .box::after {
  content: ""; position: absolute;
  width: 10px; height: 2px; border-radius: 1px; background: #fff;
}
.check input:focus-visible + .box { outline: 2px solid var(--accent-ring); outline-offset: 2px; }
.check .box .ico { width: 14px; height: 14px; stroke-width: 3; }

/* ---- tabs ---- */

.tabs {
  display: flex; gap: 4px;
  padding: 4px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.tab {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 0; border-radius: 9px;
  background: transparent;
  color: var(--text-3);
  font: 600 13.5px/1 Manrope, system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
/* narrow phones: the label carries the meaning, the icon is the first thing to go */
@media (max-width: 420px) { .tab .ico { display: none; } }
.tab:hover { color: var(--text-2); }
.tab[aria-selected="true"] { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-1); }
.tab[aria-selected="true"] .ico { color: var(--accent-text); }

/* ============================================================ HOME WIDGETS */

.grid { display: grid; gap: 16px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(212px, 1fr)); }
/* stats sitting inside a .split column, where 212px would collapse to one file */
.grid-tight { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.split { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
@media (max-width: 1080px) { .split { grid-template-columns: 1fr; } }

.stat {
  position: relative;
  overflow: hidden;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1), var(--lift);
}
.stat::after {
  content: "";
  position: absolute; inset: 0 0 auto; height: 2px;
  background: var(--brand-grad);
  opacity: .55;
}
.stat .chip {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-text);
  margin-bottom: 13px;
}
.stat .k { font-size: 12.5px; font-weight: 600; color: var(--text-3); letter-spacing: .01em; }
.stat .v {
  display: block;
  margin: 3px 0 0;
  font-size: 27px; font-weight: 800; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.stat .foot { margin-top: 11px; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-3); }

/* device / key-value list */
.kv { display: grid; gap: 0; }
.kv > div {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.kv > div:first-child { border-top: 0; }
.kv dt { color: var(--text-3); font-weight: 600; font-size: 13.5px; }
.kv dd {
  margin: 0 0 0 auto;
  color: var(--text);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* subscription meter */
.meter {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.meter > i {
  display: block; height: 100%;
  border-radius: inherit;
  background: var(--brand-grad);
  transition: width 420ms var(--ease);
}

/* ================================================================= TABLES */

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

table.t { width: 100%; border-collapse: collapse; min-width: 640px; }
table.t th, table.t td { padding: 12px 14px; text-align: left; }
table.t thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
}
table.t tbody tr { border-bottom: 1px solid var(--border); transition: background var(--t-fast) var(--ease); }
table.t tbody tr:last-child { border-bottom: 0; }
table.t tbody tr:hover { background: var(--surface-2); }
table.t td { font-size: 14px; color: var(--text-2); vertical-align: middle; }
table.t td.strong { color: var(--text); font-weight: 700; }
table.t td.mono { font-variant-numeric: tabular-nums; }
table.t .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
/* action + name columns take only what they need; host/status absorb the rest */
table.t .act { width: 1px; white-space: nowrap; }
table.t td.strong { white-space: nowrap; }
/* host is the only elastic column: it absorbs slack and truncates under pressure */
table.t .host,
table.t .ell { width: 30%; max-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

th.sortable > button {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 0;
  color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit;
  cursor: pointer;
}
th.sortable > button:hover { color: var(--text-2); }
th.sortable .ico { width: 13px; height: 13px; opacity: 0; transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease); }
th[aria-sort] .ico { opacity: 1; color: var(--accent-text); }
th[aria-sort="ascending"] .ico { transform: rotate(180deg); }

.src {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--text-2);
  font-size: 13.5px;
  overflow-wrap: anywhere;
}
.src .ico { color: var(--text-3); }

/* ==================================================== CATEGORY MANAGEMENT */

.cat-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.search { position: relative; flex: 1; min-width: 200px; }
.search .ico { position: absolute; left: 12px; top: 13px; color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 40px; }

.cat-list { display: grid; }
.cat {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  transition: background var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
}
.cat:hover { background: var(--surface-2); }
.cat[data-hidden="1"] { opacity: .45; }
.cat[data-hidden="1"] .cat-name { text-decoration: line-through; text-decoration-color: var(--text-3); }
.cat-name { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.lock-btn {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 36px; padding: 0 11px;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  color: var(--text-3);
  font: 600 12.5px/1 Manrope, system-ui, sans-serif;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.lock-btn:hover { color: var(--text); border-color: var(--text-3); }
.lock-btn[aria-pressed="true"] {
  background: var(--warn-soft); color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 34%, transparent);
}

.bulkbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 11px 18px;
  background: var(--accent-soft);
  border-top: 1px solid color-mix(in srgb, var(--accent-text) 26%, transparent);
  font-size: 13.5px; font-weight: 600;
}
.bulkbar .spacer { margin-left: auto; }

/* ================================================== EMPTY / LOADING STATES */

.empty {
  display: grid; place-items: center; gap: 12px;
  padding: 56px 24px;
  text-align: center;
}
.empty .chip {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent-text);
}
.empty h3 { font-size: 16px; }
.empty p { color: var(--text-3); font-size: 14px; max-width: 46ch; }

.skel {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.35s var(--ease) infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ================================================================= MODALS */

.scrim {
  position: fixed; inset: 0;
  z-index: var(--z-scrim);
  background: rgba(3, 4, 7, .68);
  animation: fade var(--t) var(--ease);
}
@keyframes fade { from { opacity: 0; } }

.modal {
  position: fixed; inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--gutter);
  overflow-y: auto;
}
.modal-card {
  width: min(100%, 560px);
  max-height: calc(100dvh - 2 * var(--gutter));
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  animation: pop 220ms var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.985); } }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 17px; }
.modal-head .spacer { margin-left: auto; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
@media (max-width: 560px) {
  .modal { place-items: end center; padding: 0; }
  .modal-card { width: 100%; max-height: 92dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; }
  @keyframes pop { from { opacity: 0; transform: translateY(24px); } }
  .modal-foot { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
}

/* ================================================================= TOASTS */

.toasts {
  position: fixed;
  right: var(--gutter); bottom: max(var(--gutter), env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  display: grid; gap: 10px; justify-items: end;
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  width: min(94vw, 380px);
  padding: 13px 15px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent-text);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  font-size: 14px;
  animation: slide-in 240ms var(--ease);
}
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } }
.toast[data-out="1"] { animation: slide-out 160ms var(--ease) forwards; }
@keyframes slide-out { to { opacity: 0; transform: translateX(16px); } }
.toast .ico { margin-top: 2px; }
.toast-ok     { border-left-color: var(--ok); }
.toast-ok .ico { color: var(--ok); }
.toast-err    { border-left-color: var(--danger); }
.toast-err .ico { color: var(--danger); }
.toast-info .ico { color: var(--accent-text); }

/* =========================================================== RESPONSIVE == */

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: min(84vw, var(--sidebar-w));
    background: var(--surface);
    transform: translateX(-101%);
    transition: transform var(--t) var(--ease);
    box-shadow: var(--shadow-3);
  }
  /* the drawer sits under the fixed bottom nav — keep its footer reachable */
  .sidebar {
    padding-top: max(26px, env(safe-area-inset-top));
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
    overflow-y: auto;
  }
  body[data-drawer] .sidebar { transform: none; }

  /* tap-outside scrim for the drawer */
  body[data-drawer] .main::before {
    content: "";
    position: fixed; inset: 0;
    z-index: calc(var(--z-nav) - 1);
    background: rgba(3, 4, 7, .6);
    animation: fade var(--t) var(--ease);
  }

  .topbar .menu-btn { display: inline-flex; }

  /* content must clear the fixed bottom nav */
  .page { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: var(--z-nav);
    display: grid;
    grid-auto-flow: column; grid-auto-columns: 1fr;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a {
    display: grid; justify-items: center; gap: 4px;
    min-height: 58px;
    padding: 9px 4px;
    color: var(--text-3);
    text-decoration: none;
    font-size: 11px; font-weight: 700;
    transition: color var(--t-fast) var(--ease);
  }
  .bottom-nav a[aria-current="page"] { color: var(--accent-text); }
  .bottom-nav a:active { background: var(--surface-2); }

  .toasts { bottom: calc(74px + env(safe-area-inset-bottom)); left: var(--gutter); justify-items: stretch; }
}

@media (min-width: 901px) { .bottom-nav { display: none; } }

@media (max-width: 560px) {
  .otp { gap: 7px; }
  .otp input { height: 54px; font-size: 22px; }
  .page-head .spacer { flex-basis: 100%; margin: 0; }
  .page-head > .btn { width: 100%; }
  .stat .v { font-size: 24px; }
}

/* ======================================================= reduced motion == */

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


/* ==================================================== PANELS (reseller/admin) */

/* credit balance hero */
.balance {
  position: relative; overflow: hidden;
  padding: 22px;
  border-radius: var(--r-lg);
  border: 1px solid color-mix(in srgb, var(--accent-text) 24%, var(--border));
  background:
    radial-gradient(520px 200px at 88% -30%, rgba(110, 69, 253, .26), transparent 70%),
    linear-gradient(140deg, var(--surface-2), var(--surface));
  box-shadow: var(--shadow-1), var(--lift);
}
.balance .k { font-size: 12.5px; font-weight: 600; color: var(--text-3); }
.balance .v {
  display: flex; align-items: baseline; gap: 8px;
  margin: 6px 0 0;
  font-size: 40px; font-weight: 800; letter-spacing: -.035em;
  font-variant-numeric: tabular-nums;
}
.balance .v small { font-size: 15px; font-weight: 600; color: var(--text-3); letter-spacing: 0; }
.balance .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }

/* identity cell: avatar + name/email stacked, used in every panel table */
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who .avatar { width: 30px; height: 30px; flex: none; font-size: 11px; }
/* scope to the meta block: a bare `.who span` also matched the avatar and
   stripped its grid centring and white text */
.who > div { min-width: 0; }
.who > div b { display: block; font-size: 14px; font-weight: 700; color: var(--text); }
.who > div span { display: block; font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* credit ledger amounts */
.amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt-in  { color: var(--ok); }
.amt-out { color: var(--text-2); }

/* package picker inside the activation dialog */
.plans { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
.plan {
  position: relative;
  display: grid; gap: 2px;
  padding: 14px 14px 13px;
  text-align: left;
  background: var(--bg-2);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.plan:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border-strong)); }
.plan[aria-pressed="true"] { border-color: var(--accent-text); background: var(--accent-soft); }
.plan b { font-size: 15px; font-weight: 700; }
.plan span { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.plan[aria-pressed="true"] span { color: var(--accent-text); }
.plan[data-afford="0"] { opacity: .45; cursor: not-allowed; }

/* cost summary line above a dialog's confirm button */
.cost {
  display: flex; align-items: center; gap: 10px;
  margin-top: 18px; padding: 13px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 13.5px; color: var(--text-2);
}
.cost .spacer { margin-left: auto; }
.cost b { color: var(--text); font-variant-numeric: tabular-nums; }

/* segmented filter above long tables */
.segments { display: flex; gap: 4px; padding: 4px; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: var(--r-md); }
.segments button {
  min-height: 34px; padding: 0 12px;
  border: 0; border-radius: 9px; background: transparent;
  color: var(--text-3); font: 600 13px/1 Manrope, system-ui, sans-serif;
  white-space: nowrap; cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.segments button:hover { color: var(--text-2); }
.segments button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }

/* two-up detail header (subscriber / reseller pages) */
.detail-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.detail-head .avatar { width: 46px; height: 46px; font-size: 16px; }
.detail-head .spacer { margin-left: auto; }

/* Notifications (shared by reseller + admin panels) */
.notif-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.notif-list > li + li { border-top: 1px solid var(--line, rgba(255,255,255,.08)); }
.notif-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.notif-item:hover { background: var(--bg-2, rgba(255,255,255,.03)); }
.notif-item.unread { background: var(--bg-2, rgba(255,255,255,.05)); }
.notif-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.notif-main strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-main .sub { font-size: 13px; color: var(--text-3); }
.notif-list .empty { padding: 20px 16px; color: var(--text-3); font-size: 14px; display: block; text-align: left; }
.dot-unread { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--warn, #f5a623); }
.notif-img { display: block; max-width: 100%; max-height: 320px; margin: 0 auto 14px; border-radius: var(--r-md); object-fit: contain; }
.notif-img-pick { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.notif-img-pick .notif-img { margin: 0; max-height: 180px; }

/* notification body: markdown rendered by the backend */
.md { font-size: 14.5px; line-height: 1.6; color: var(--text); overflow-wrap: anywhere; }
.md p, .md h3, .md h4, .md h5, .md ul, .md ol, .md blockquote, .md hr { margin: 0; }
.md > * + * { margin-top: .7em; }
.md h3 { font-size: 18px; } .md h4 { font-size: 16px; } .md h5 { font-size: 14.5px; }
.md ul, .md ol { padding-left: 1.4em; }
.md blockquote { padding-left: 12px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md code { padding: 1px 5px; border-radius: 5px; background: var(--bg-2); font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.md a { color: var(--accent-text); }
.md hr { border: 0; border-top: 1px solid var(--border-strong); }
