/* JTL aaa mobile v4 — design tokens */
:root {
  --c-brand:        #1F3864;
  --c-brand-2:      #2E75B6;
  --c-accent:       #1D4ED8;
  --c-bg:           #F4F6F9;
  --c-surface:      #FFFFFF;
  --c-text:         #1B1E26;
  --c-text-muted:   #5E6470;
  --c-border:       #E2E5EB;
  --c-danger:       #B91C1C;
  --c-success:      #15803D;
  --c-warn:         #B45309;
  --c-purple:       #7C3AED;
  --radius:         12px;
  --shadow-sm:      0 1px 2px rgba(0,0,0,0.05);
  --shadow:         0 2px 8px rgba(0,0,0,0.08);
  --safe-bottom:    env(safe-area-inset-bottom, 0px);
  --safe-top:       env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  color: var(--c-text);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--c-bg); min-height: 100%; }

.hidden { display: none !important; }
.view { display: none; }
.view.active { display: block; }

/* ─── Login ─────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
  background: linear-gradient(160deg, #1F3864 0%, #2E75B6 100%);
}
.brand { text-align: center; color: #fff; margin-bottom: 28px; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px; height: 64px;
  border-radius: 18px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff; font-weight: 700; font-size: 22px;
  letter-spacing: 1px; margin-bottom: 14px;
}
.brand h1 { margin: 0; font-size: 28px; font-weight: 600; }
.brand-sub { margin: 4px 0 0; opacity: .85; font-size: 14px; }
#login-form {
  background: var(--c-surface);
  padding: 20px; border-radius: var(--radius); box-shadow: var(--shadow);
}
#login-form label { display: block; font-size: 13px; color: var(--c-text-muted); margin-bottom: 14px; }
#login-form input {
  width: 100%; margin-top: 6px; padding: 12px 14px;
  font-size: 16px; border: 1px solid var(--c-border);
  border-radius: 10px; background: #fff; color: var(--c-text);
}
#login-form input:focus {
  outline: none; border-color: var(--c-brand-2);
  box-shadow: 0 0 0 3px rgba(46,117,182,.18);
}
.hint { color: rgba(255,255,255,.85); font-size: 13px; text-align: center; margin-top: 18px; }
.hint a { color: #fff; text-decoration: underline; }

/* ─── Register / self-onboarding form ────────────────────────────────────
 * Same chrome as #login-form so the page doesn't visually fall apart when
 * the user clicks "Register your realm".  Slightly tighter spacing because
 * there are more fields and we don't want it to look like a wall.
 * ----------------------------------------------------------------------- */
#register-form {
  background: var(--c-surface);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#register-form h3 {
  margin: 0 0 14px;
  color: var(--c-text);
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  letter-spacing: .2px;
}
#register-form label {
  display: block;
  font-size: 12px;
  color: var(--c-text-muted);
  margin-bottom: 10px;
}
#register-form input {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: #fff;
  color: var(--c-text);
}
#register-form input:focus {
  outline: none;
  border-color: var(--c-brand-2);
  box-shadow: 0 0 0 3px rgba(46,117,182,.18);
}
#register-form code {
  background: rgba(31,56,100,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--c-brand);
}
#register-form .btn { margin-top: 4px; }
#register-form .error,
#register-form .result {
  margin-top: 10px;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
}
#register-form .error  { background: #fee2e2; color: #991b1b; }
#register-form .result { background: #dcfce7; color: #166534; }

/* The hint chip below the login form keeps its white text but the link
 * needs visible focus styles for keyboard users. */
#login-register-hint a:focus { outline: 2px dashed #fff; outline-offset: 2px; }

/* ─── Plan price pill ────────────────────────────────────────────────────
 * Shown to the right of plan list items + dropdown labels.  Designed to
 * sit next to the existing product-type-badge without competing visually
 * (uses a more muted brand colour so the type badge remains primary).
 * ----------------------------------------------------------------------- */
.price-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-brand);
  background: rgba(31,56,100,0.08);
  border: 1px solid rgba(31,56,100,0.18);
  white-space: nowrap;
  margin-left: 6px;
}

/* ─── App chrome ──────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  height: calc(54px + var(--safe-top));
  padding: var(--safe-top) 14px 0;
  background: var(--c-brand); color: #fff;
  box-shadow: var(--shadow-sm);
}
.topbar .title { flex: 1; font-size: 17px; font-weight: 600; }
.icon-btn {
  background: none; border: 0; color: #fff;
  font-size: 22px; padding: 0 4px; cursor: pointer; line-height: 1;
}
.icon-btn[hidden] { display: none; }

main { padding: 14px 14px calc(78px + var(--safe-bottom)); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--c-surface); border-top: 1px solid var(--c-border);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -2px 8px rgba(0,0,0,.03);
}
.tab {
  background: none; border: 0; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; font-size: 11px; font-weight: 500;
  color: var(--c-text-muted); cursor: pointer;
}
.tab span { font-size: 20px; line-height: 1; }
.tab.active { color: var(--c-brand); }

/* ─── Card / List ────────────────────────────────────── */
.card {
  background: var(--c-surface); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow-sm); margin-bottom: 14px;
}
.card h3 { margin: 0 0 12px; font-size: 14px; color: var(--c-text-muted); text-transform: uppercase; letter-spacing: .5px; }
.row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; font-size: 14px; border-bottom: 1px solid var(--c-border);
}
.row:last-child { border-bottom: 0; }
.label { color: var(--c-text-muted); font-size: 13px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  padding: 12px 4px; border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; gap: 10px; cursor: pointer;
}
.list li:last-child { border-bottom: 0; }
.list .item-main { flex: 1; min-width: 0; }
.list .item-main b { display: block; font-weight: 600; font-size: 15px; }
.list .item-main span { display: block; color: var(--c-text-muted); font-size: 12px; }
.list .item-end { font-size: 12px; color: var(--c-text-muted); flex-shrink: 0; }

/* ─── KPI grid ───────────────────────────────────────── */
.kpi-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  background: transparent; padding: 0; box-shadow: none; margin-bottom: 14px;
}
.kpi { background: var(--c-surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-sm); }
.kpi-label { font-size: 11px; color: var(--c-text-muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi-val { font-size: 24px; font-weight: 700; color: var(--c-brand); margin-top: 4px; }

/* ─── Buttons ────────────────────────────────────────── */
.btn {
  display: block; width: 100%; padding: 12px; margin-top: 10px;
  font-size: 15px; font-weight: 600; background: var(--c-surface);
  color: var(--c-text); border: 1px solid var(--c-border);
  border-radius: 10px; cursor: pointer; text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--c-brand) 0%, var(--c-brand-2) 100%);
  color: #fff; border-color: transparent;
}
.btn.danger { color: var(--c-danger); border-color: rgba(185,28,28,.4); }
.btn.danger:active { background: rgba(185,28,28,.08); }
.btn.sm { padding: 8px 12px; font-size: 13px; margin-top: 6px; }

.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action {
  background: var(--c-bg); border: 1px solid var(--c-border);
  border-radius: 10px; padding: 12px 10px;
  font-size: 13px; text-align: left; cursor: pointer;
}

/* ─── Field labels (forms) ───────────────────────────── */
.field-label {
  display: block; font-size: 13px; color: var(--c-text-muted); margin-bottom: 12px;
}
.field-label input,
.field-label select {
  display: block; width: 100%; margin-top: 5px;
  padding: 10px 12px; font-size: 15px;
  border: 1px solid var(--c-border); border-radius: 10px;
  background: var(--c-bg); color: var(--c-text);
}
.field-label input:focus,
.field-label select:focus {
  outline: none; border-color: var(--c-brand-2);
  box-shadow: 0 0 0 3px rgba(46,117,182,.15);
}
.field-row { display: flex; gap: 10px; }
.section-divider {
  font-size: 12px; font-weight: 600; color: var(--c-text-muted);
  text-transform: uppercase; letter-spacing: .5px;
  border-top: 1px solid var(--c-border); padding-top: 10px; margin: 6px 0 10px;
}

/* ─── Search / filter ────────────────────────────────── */
.search-wrap {
  background: var(--c-surface); padding: 10px 14px;
  margin: -14px -14px 12px; border-bottom: 1px solid var(--c-border);
  position: sticky; top: calc(54px + var(--safe-top)); z-index: 20;
  /* Flex layout so the input expands and inline action buttons stay compact */
  display: flex; gap: 8px; align-items: center;
}
.search-wrap input[type="search"],
.search-wrap input:not([type]) {
  flex: 1 1 auto; min-width: 0;
  padding: 10px 14px; font-size: 15px;
  border: 1px solid var(--c-border); border-radius: 10px; background: var(--c-bg);
}
.filter-row { padding: 6px 0 12px; }
.chk { font-size: 13px; color: var(--c-text-muted); }

/* ─── Pills ──────────────────────────────────────────── */
.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}
.pill[data-state="ok"]      { background: rgba(21,128,61,.12);  color: var(--c-success); }
.pill[data-state="warn"]    { background: rgba(180,83,9,.12);   color: var(--c-warn); }
.pill[data-state="danger"]  { background: rgba(185,28,28,.12);  color: var(--c-danger); }
.pill[data-state="muted"]   { background: rgba(30,58,138,.08);  color: var(--c-text-muted); }
.pill[data-state="info"]    { background: rgba(46,117,182,.12); color: var(--c-brand-2); }
.pill[data-state="purple"]  { background: rgba(124,58,237,.12); color: var(--c-purple); }

/* ─── Usage bar ──────────────────────────────────────── */
.usage-bar { height: 8px; border-radius: 999px; background: var(--c-border); overflow: hidden; margin: 8px 0 10px; }
.usage-fill { height: 100%; background: linear-gradient(90deg, var(--c-brand-2) 0%, var(--c-brand) 100%); width: 0%; transition: width 250ms ease; }
.usage-fill.warn    { background: linear-gradient(90deg, #F59E0B 0%, #B45309 100%); }
.usage-fill.danger  { background: linear-gradient(90deg, #EF4444 0%, #B91C1C 100%); }

/* ─── User detail ─────────────────────────────────────── */
.user-header { display: flex; align-items: center; justify-content: space-between; }
.user-header h2 { margin: 0; font-size: 18px; }

/* ─── Product type badge ──────────────────────────────── */
.product-type-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  margin-bottom: 10px;
}
.pt-uncapped_volume { background: rgba(124,58,237,.12); color: var(--c-purple); }
.pt-capped_speed    { background: rgba(46,117,182,.12); color: var(--c-brand-2); }
.pt-fixed_internet  { background: rgba(21,128,61,.12);  color: var(--c-success); }

/* ─── Wizard ──────────────────────────────────────────── */
.wizard-step { animation: fadein 180ms ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.wizard-header { text-align: center; margin-bottom: 18px; }
.wizard-header h3 { margin: 8px 0 4px; font-size: 18px; }
.wizard-sub { margin: 0; color: var(--c-text-muted); font-size: 13px; }

.step-dots { display: flex; justify-content: center; gap: 6px; margin-bottom: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c-border); }
.dot.active { background: var(--c-brand-2); }

.product-cards { display: flex; flex-direction: column; gap: 10px; }
.product-card {
  background: var(--c-surface); border: 2px solid var(--c-border);
  border-radius: var(--radius); padding: 16px; cursor: pointer;
  display: flex; align-items: flex-start; gap: 12px;
  transition: border-color 150ms, box-shadow 150ms;
}
.product-card:hover, .product-card:active { border-color: var(--c-brand-2); box-shadow: 0 0 0 3px rgba(46,117,182,.1); }
.product-card.selected { border-color: var(--c-brand); background: rgba(31,56,100,.03); }
.pc-icon { font-size: 28px; line-height: 1; flex-shrink: 0; }
.pc-name { font-weight: 700; font-size: 15px; margin-bottom: 3px; }
.pc-desc { font-size: 13px; color: var(--c-text-muted); line-height: 1.4; }

.wizard-nav { display: flex; gap: 8px; margin-top: 14px; }
.wizard-nav .btn { flex: 1; margin-top: 0; }

/* ─── Loader / Toast / Modal ──────────────────────────── */
.loader { text-align: center; padding: 20px; color: var(--c-text-muted); font-size: 13px; }
.error { background: rgba(185,28,28,.08); color: var(--c-danger); padding: 10px; border-radius: 8px; font-size: 13px; margin-top: 10px; }
.result { padding: 10px; border-radius: 8px; font-size: 13px; margin-top: 10px; }
.result.ok  { background: rgba(21,128,61,.08);  color: var(--c-success); }
.result.bad { background: rgba(185,28,28,.08);  color: var(--c-danger); }

.toast {
  position: fixed; bottom: calc(80px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%); background: #1B1E26; color: #fff;
  padding: 10px 16px; border-radius: 999px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow); z-index: 10050; animation: toast-in 200ms ease;
  white-space: normal; max-width: min(92vw, 460px); text-align: center;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal-card {
  background: var(--c-surface); border-radius: 14px;
  padding: 22px; width: 100%; max-width: 360px; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 10px; }
.modal-card p  { margin: 0 0 14px; color: var(--c-text-muted); font-size: 14px; }
.modal-input input,
.modal-select select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--c-border);
  border-radius: 8px; font-size: 15px; margin-bottom: 14px; background: var(--c-bg);
}
.modal-actions { display: flex; gap: 8px; }
.modal-actions .btn { margin-top: 0; }

/* ─── Package summary banner ─────────────────────────────────────────────── */
.pkg-banner {
  background: linear-gradient(135deg, var(--c-brand) 0%, var(--c-brand-2) 100%);
  color: #fff;
  padding: 18px 16px 14px;
  border-radius: var(--radius);
}
.pkg-speed-line {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 2px;
}
.pkg-speed-val {
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -1px;
}
.pkg-speed-unit {
  font-size: 18px;
  font-weight: 600;
  opacity: .85;
  padding-bottom: 2px;
}
.pkg-name {
  font-size: 13px;
  opacity: .80;
  margin-top: 2px;
  font-weight: 500;
  letter-spacing: .3px;
}
.optimized-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 5px 12px;
  border-radius: 20px;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.35);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  letter-spacing: .2px;
}
.optimized-badge.throttled {
  background: rgba(251,191,36,0.22);
  border-color: rgba(251,191,36,0.5);
  color: #fef3c7;
}

/* ─── FUP bar (enhanced) ─────────────────────────────────────────────────── */
.fup-bar-wrap { margin: 10px 0 6px; }
.fup-bar-track {
  height: 10px;
  background: var(--c-border);
  border-radius: 6px;
  overflow: hidden;
}
.fup-bar-track .usage-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--c-brand-2);
  transition: width .4s ease, background .3s;
  min-width: 2px;
}
.usage-fill.warn   { background: #D97706; }
.usage-fill.danger { background: var(--c-danger); }
.fup-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--c-text-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* ─── Reset note ─────────────────────────────────────────────────────────── */
.fup-reset-note {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  padding: 7px 10px;
  background: #EFF6FF;
  border-left: 3px solid var(--c-brand-2);
  border-radius: 0 6px 6px 0;
  font-size: 12px;
  color: var(--c-brand);
  font-weight: 500;
}
.fup-reset-note.warn {
  background: #FFFBEB;
  border-left-color: #D97706;
  color: #92400E;
}
.fup-reset-note.danger {
  background: #FEF2F2;
  border-left-color: var(--c-danger);
  color: var(--c-danger);
}

/* ─── Search bar ─────────────────────────────────────── */
.search-bar { padding: 8px 12px; background: var(--c-bg); border-bottom: 1px solid var(--c-border); }
.search-bar input[type="search"] {
  width: 100%; box-sizing: border-box;
  padding: 8px 12px; border-radius: 20px;
  border: 1px solid var(--c-border); background: var(--c-surface);
  font-size: 14px; color: var(--c-text); outline: none;
}
.search-bar input[type="search"]:focus { border-color: var(--c-brand-2); }

/* ─── Bundle subscription UI ─────────────────────────── */
.bundle-tabs { display:flex; gap:8px; padding:12px 12px 0; }
.bundle-tab { flex:1; padding:10px; border:2px solid var(--c-border); border-radius:10px;
  background:var(--c-surface); font-weight:600; font-size:14px; cursor:pointer; transition:.2s; }
.bundle-tab.active { border-color:var(--c-brand-2); background:var(--c-brand-2); color:#fff; }
.pkg-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:8px; margin:12px 0; }
.pkg-btn { border:2px solid var(--c-border); border-radius:10px; padding:10px 6px;
  text-align:center; cursor:pointer; font-size:12px; transition:.2s;
  display:flex; flex-direction:column; gap:2px; background:var(--c-surface); }
.pkg-btn b { font-size:13px; color:var(--c-text); }
.pkg-btn .pkg-rate { font-size:11px; color:var(--c-muted); }
.pkg-btn:hover { border-color:var(--c-brand-2); }
.pkg-btn.active { border-color:var(--c-brand); background:var(--c-brand); color:#fff; }
.pkg-btn.active b, .pkg-btn.active .pkg-rate { color:#fff; }
.validity-display { background:var(--c-surface); border:1px solid var(--c-border);
  border-radius:10px; padding:12px; text-align:center; font-size:16px;
  font-weight:600; color:var(--c-brand); margin:8px 0; }
.bundle-total-bar { background:var(--c-brand); color:#fff; border-radius:10px;
  padding:10px 14px; font-size:14px; margin:8px 0; }
.card-title { font-size:14px; font-weight:700; text-transform:uppercase;
  letter-spacing:.5px; color:var(--c-brand); margin-bottom:8px; }

/* ─── Tablet / desktop ────────────────────────────────── */
@media (min-width: 720px) {
  main { max-width: 720px; margin: 0 auto; padding: 18px 18px calc(82px + var(--safe-bottom)); }
  .topbar .title { max-width: 720px; margin: 0 auto; width: 100%; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .product-cards { flex-direction: row; }
  .product-card { flex: 1; }
}

/* ─── License banner (login) ───────────────────────────── */
.license-banner {
  padding: 12px 14px;
  border-radius: 10px;
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.4;
  border: 1px solid transparent;
}
.license-banner.info   { background: #e8f5e9; border-color: #43a047; color: #1b5e20; }
.license-banner.warn   { background: #fff4e0; border-color: #f0b400; color: #6a4500; }
.license-banner.danger { background: #ffe0e0; border-color: #d94747; color: #6a1a1a; }
.license-banner b      { display: block; font-size: 14px; margin-bottom: 2px; }

/* ─── License badge (topbar) ───────────────────────────── */
.license-badge {
  border: none;
  background: rgba(255,255,255,.18);
  color: #fff;
  font: 600 11px/1 system-ui, sans-serif;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  margin-right: 4px;
}
.license-badge.info   { background: rgba(255,255,255,.18); color: #fff; }
.license-badge.warn   { background: #f0b400; color: #2a1d00; }
.license-badge.danger { background: #d94747; color: #fff; }

/* Disable the login button when license is dead. */
#login-submit[disabled] { opacity: .55; cursor: not-allowed; }

/* =========================================================================
 * View-mode infrastructure
 * =========================================================================
 * Body class       Layout
 * ─────────────    ──────────────────────────────────────────────────────────
 * .view-mobile     Bottom tabbar, single-column cards, full-bleed main.
 * .view-desktop    Left sidebar, multi-column grid, no tabbar, max-width main.
 *
 * Mobile is the base.  Everything below is desktop-only.
 */

/* Always-hidden topbar brand in mobile; only appears in desktop. */
.topbar-brand { display: none; align-items: center; gap: 8px; }
.topbar-logo  { font-weight: 700; letter-spacing: 1px; font-size: 16px;
                background: rgba(255,255,255,.18); padding: 4px 10px; border-radius: 6px; }
.topbar-app   { font-weight: 600; opacity: .85; font-size: 14px; }

/* Realm chip — always visible (mobile + desktop) after login. */
.topbar-realm {
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  padding: 3px 8px; border-radius: 999px;
  display: none;          /* JS reveals once we know the user's realm */
  white-space: nowrap;
}
.topbar-realm.superadmin { background: rgba(255,255,255,0.20); }
body.view-mobile .topbar-realm { font-size: 10px; padding: 2px 6px; }

/* Sidebar is hidden by default (mobile). */
.sidebar { display: none; }

/* =========================================================================
 * Daily usage chart card — works in both modes
 * ========================================================================= */
.chart-card { padding-top: 14px; }
.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 8px;
}
.chart-head h3 { margin: 0; }
/* Controls take their own full-width row and wrap freely — never overflow. */
.chart-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  flex: 1 1 100%;
  min-width: 0;
}
.cc-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: var(--c-text-muted);
  flex: 1 1 130px;
  min-width: 0;
}
.cc-field > span { padding-left: 2px; }
/* Fields fill their labelled column; kill the old fixed min-width that overflowed. */
.chart-head .filter-select,
.cc-field .filter-select { width: 100%; min-width: 0; box-sizing: border-box; }
.cc-clear { flex: 0 0 auto; align-self: flex-end; padding: 8px 14px; }
body.view-desktop .cc-field { flex: 0 1 190px; }
body.view-desktop .cc-field .filter-select { max-width: none; }
.chart-wrap {
  position: relative;
  width: 100%;
  /* Slightly taller in desktop via override below. */
  height: 220px;
}
.chart-wrap canvas { display: block; width: 100% !important; height: 100% !important; }

/* =========================================================================
 * Desktop view  (body.view-desktop)
 * ========================================================================= */
body.view-desktop {
  /* Reset the "tap-friendly" mobile font size up slightly. */
  font-size: 15px;
}

/* App becomes a CSS grid: topbar across the top, sidebar on left, main on right. */
body.view-desktop #app {
  display: grid;
  grid-template-columns: 232px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  min-height: 100vh;
}
body.view-desktop .topbar  { grid-area: topbar; position: sticky; }
body.view-desktop .sidebar { grid-area: sidebar; }
/* Cap + centre the content column so wide monitors don't sprawl edge-to-edge. */
body.view-desktop main     { grid-area: main; padding: 28px 40px 40px; max-width: 1120px; margin-inline: auto; width: 100%; box-sizing: border-box; }

/* Brand visible in topbar, mobile title hidden (replaced by breadcrumb-style title). */
body.view-desktop .topbar-brand { display: inline-flex; }
body.view-desktop .topbar .title { font-size: 15px; font-weight: 500; opacity: .9; }
body.view-desktop .topbar { padding-left: 24px; padding-right: 24px; height: 56px; }
body.view-desktop .topbar .icon-btn { font-size: 20px; padding: 6px 10px; border-radius: 6px; }
body.view-desktop .topbar .icon-btn:hover { background: rgba(255,255,255,.10); }

/* Back button is irrelevant in desktop (sidebar always visible) — leave behaviour
   but de-emphasise. */
body.view-desktop #back-btn { opacity: .7; }

/* Hide the mobile bottom tabbar in desktop. */
body.view-desktop .tabbar { display: none; }

/* Sidebar */
body.view-desktop .sidebar {
  display: block;
  background: #FAFBFD;
  border-right: 1px solid var(--c-border);
  padding: 16px 10px;
  position: sticky;
  top: 56px;
  align-self: start;
  height: calc(100vh - 56px);
  overflow-y: auto;
}
body.view-desktop .sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
body.view-desktop .sidebar-link {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0;
  text-align: left; padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px; font-weight: 500;
  color: var(--c-text-muted);
  cursor: pointer;
  width: 100%;
}
body.view-desktop .sidebar-link:hover { background: rgba(31, 56, 100, 0.06); color: var(--c-text); }
body.view-desktop .sidebar-link.active {
  background: var(--c-brand); color: #fff;
}
body.view-desktop .sidebar-link.active:hover { background: var(--c-brand); }
body.view-desktop .sidebar-icon { font-size: 18px; width: 22px; text-align: center; }

/* Main content area: cap the inner width and centre cards. */
body.view-desktop main { padding-bottom: 32px; }

/* Cards — slightly more breathing room, hover lift. */
body.view-desktop .card {
  padding: 20px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease;
}
body.view-desktop .card:hover { box-shadow: var(--shadow); }

/* Dashboard KPIs go from 2-col to 4-col. */
body.view-desktop .kpi-grid {
  grid-template-columns: repeat(4, 1fr);
}
body.view-desktop .kpi { padding: 18px 20px; }
body.view-desktop .kpi-val { font-size: 26px; }

/* Quick-action grid in dashboard — more columns. */
body.view-desktop .actions-grid {
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

/* List rows: bigger, table-like. Users / Plans / FUP all use .list. */
body.view-desktop .list li {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border-radius: 8px;
  margin-bottom: 4px;
  transition: background .12s ease;
}
body.view-desktop .list li:hover { background: rgba(31, 56, 100, 0.04); }
body.view-desktop .list li b { font-size: 15px; }
body.view-desktop .list li span { font-size: 13px; color: var(--c-text-muted); }

/* Search/filter as a clean full-width bar sitting ON TOP of the list (not
   sticky, no negative bleed margins, no width cap on the input). */
body.view-desktop .search-wrap,
body.view-desktop .search-bar {
  position: static;
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface);
  display: flex;
  gap: 10px;
  align-items: center;
}
body.view-desktop .search-wrap input[type="search"],
body.view-desktop .search-wrap input:not([type]),
body.view-desktop .search-bar input {
  padding: 10px 14px;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--c-border);
  flex: 1 1 auto;
  width: auto;
  max-width: none;
  background: var(--c-bg);
}
/* List pages are always a single column: search bar on top, full-width list. */
body.view-desktop main:not(:has(#pd-type-badge)):not(:has(.user-header)) { display: block; }
body.view-desktop .list { width: 100%; }
body.view-desktop .list li { width: 100%; box-sizing: border-box; }

/* User-detail layout: 2-column grid (info left, chart + actions right). */
body.view-desktop main {
  /* Container query polyfill: rely on plain grid for the user-detail view.
     We wrap descendant sections directly. */
}
body.view-desktop .user-header { grid-column: 1 / -1; }

/* Make the chart taller on desktop. */
body.view-desktop .chart-wrap { height: 320px; }

/* User-detail in desktop mode: 2-column grid.
   Cards flow into a 2-column layout — first card (user-header) spans both. */
body.view-desktop main:has(.user-header) {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 18px;
  align-items: start;
}
body.view-desktop main:has(.user-header) > section.user-header { grid-column: 1 / -1; }
body.view-desktop main:has(.user-header) > section.pkg-banner { grid-column: 1 / -1; }
body.view-desktop main:has(.user-header) > section.chart-card { grid-column: 1 / -1; }

/* Profile-detail also benefits from the 2-column layout.
   NOTE: target the detail page's unique #pd-type-badge — NOT the .product-type-badge
   class, which also appears in plans/FUP *list* rows and would wrongly turn those
   list pages into two columns (search bar beside a narrow list). */
body.view-desktop main:has(#pd-type-badge) {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 18px;
  align-items: start;
}
body.view-desktop main:has(#pd-type-badge) > section.card { grid-column: auto; }

/* Pkg banner (user-detail) — bigger headline figure. */
body.view-desktop .pkg-speed-val { font-size: 48px; }
body.view-desktop .pkg-speed-unit { font-size: 16px; }
body.view-desktop .pkg-name { font-size: 16px; }

/* Buttons inside cards: inline rather than stacked in desktop. */
body.view-desktop .card .btn {
  display: inline-block;
  width: auto;
  margin-right: 8px;
  margin-bottom: 8px;
  padding: 9px 18px;
  font-size: 14px;
}
body.view-desktop .card .btn.primary { font-weight: 600; }

/* Topbar action FAB (+) becomes an inline labelled button in desktop. */
body.view-desktop #topbar-action-btn {
  font-size: 18px;
  background: rgba(255,255,255,.18);
  border-radius: 8px;
  padding: 4px 12px;
}
body.view-desktop #topbar-action-btn:hover { background: rgba(255,255,255,.28); }

/* Login page on desktop — centre a card rather than full-bleed gradient. */
body.view-desktop .login-wrap {
  padding: 0;
  align-items: center;
}
body.view-desktop .login-wrap > * { max-width: 420px; width: 100%; }

/* Wizard (create-profile) — keep single column but wider. */
body.view-desktop .wizard-step { max-width: 720px; margin-inline: auto; }
body.view-desktop .product-cards {
  grid-template-columns: repeat(2, 1fr);
}

/* ── Desktop polish pass ───────────────────────────────────────────────── */
/* Headings: clearer hierarchy, tidy spacing. */
body.view-desktop .card h3 {
  font-size: 16px; font-weight: 600; margin: 0 0 14px;
  letter-spacing: .2px; color: var(--c-text);
}
body.view-desktop .card > h3:first-child { margin-top: 0; }

/* Forms: consistent, comfortable field controls. */
body.view-desktop .field-label { font-size: 13px; color: var(--c-text-muted); font-weight: 500; }
body.view-desktop .field-label input,
body.view-desktop .field-label select,
body.view-desktop #modal-input,
body.view-desktop #modal-select {
  padding: 10px 12px; font-size: 14px; border-radius: 8px;
  border: 1px solid var(--c-border); background: var(--c-surface);
  margin-top: 4px;
}
/* Cards stay full-width (lists need the room). Forms stay readable by capping
   the field controls, not the whole card. */
body.view-desktop #main > section.card { width: 100%; }
body.view-desktop .field-label { display: block; max-width: 560px; }
body.view-desktop .field-row { max-width: 560px; }
body.view-desktop .field-row .field-label { max-width: none; }
body.view-desktop form .btn, body.view-desktop .card > .btn { max-width: 560px; }

/* KPI cards: subtle accent + even sizing. */
body.view-desktop .kpi {
  border: 1px solid var(--c-border); border-radius: 10px;
  background: var(--c-surface);
}
body.view-desktop .kpi-label { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }

/* List rows: a touch more contrast on the divider + rounded hover. */
body.view-desktop .list { display: flex; flex-direction: column; gap: 2px; }
body.view-desktop .list li { border: 1px solid transparent; }
body.view-desktop .list li:hover { border-color: var(--c-border); }

/* Price/status pills line up neatly at the row end. */
body.view-desktop .price-pill, body.view-desktop .pill { white-space: nowrap; }

/* FUP / Boosters subscriptions list pager — align right. */
body.view-desktop #boost-subs-pager { justify-content: flex-end; }

/* Modal — wider, centred. */
body.view-desktop .modal-card { max-width: 520px; }

/* Toast — top-right on desktop. */
body.view-desktop .toast {
  bottom: auto;
  top: 70px;
  right: 24px;
  left: auto;
  max-width: 360px;
}

/* View-toggle button — always visible icon, slightly larger hit-area in desktop. */
#view-toggle-btn { display: inline-flex; align-items: center; justify-content: center; }
body.view-mobile #view-toggle-btn { font-size: 18px; }
body.view-desktop #view-toggle-btn { font-size: 18px; }

/* ─── Export button + inline search-bar actions ───────────────────────── */
.export-btn,
.add-btn {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-brand);
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.export-btn:hover, .add-btn:hover { background: rgba(31,56,100,0.06); }
.export-btn:disabled              { opacity: .55; cursor: wait; }
/* The [hidden] attribute must always win over display rules on nav items —
   otherwise admin-only links (Realms / Pending signups) leak to tenants on
   desktop (sidebar-link{display:flex}) and mobile (tab{display}). */
.sidebar-link[hidden], .tab[hidden] { display: none !important; }

/* Root-only realm switcher in the topbar. */
.root-realm-switcher {
  margin-left: 8px; max-width: 170px;
  padding: 5px 8px; font-size: 13px; font-weight: 600;
  border-radius: 8px; border: 1px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.14); color: #fff; cursor: pointer;
}
.root-realm-switcher option { color: #1a1a1a; }
body.view-desktop .root-realm-switcher { max-width: 220px; font-size: 14px; }

.add-btn { color: var(--c-success); border-color: rgba(21,128,61,0.25); }
.add-btn:hover { background: rgba(21,128,61,0.06); }

/* Filter dropdown next to a search input — compact */
.filter-select {
  flex: 0 0 auto;
  height: 42px;
  padding: 0 10px;
  font-size: 13px;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  border-radius: 10px;
  cursor: pointer;
  max-width: 130px;
}
body.view-desktop .filter-select { font-size: 14px; max-width: 180px; }

/* Desktop — slightly wider so labels fit alongside the icon */
body.view-desktop .export-btn,
body.view-desktop .add-btn { width: auto; padding: 0 14px; font-size: 13px; gap: 6px; }
body.view-desktop .export-btn::after { content: ' CSV'; }
body.view-desktop .add-btn::after    { content: ' Add'; }

.item-actions { display: flex; gap: 6px; align-items: center; }
.btn-mini {
  width: 30px; height: 30px;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.btn-mini:hover { background: rgba(31,56,100,0.06); }
.btn-mini.danger { color: var(--c-danger); border-color: rgba(185,28,28,0.25); }
.btn-mini.danger:hover { background: rgba(185,28,28,0.06); }

/* small inline labelled action button (icon + text) */
.btn-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; min-height: 30px;
  border: 1px solid var(--c-border); background: var(--c-surface);
  color: var(--c-brand); border-radius: 8px;
  font-size: 13px; font-weight: 600; line-height: 1; white-space: nowrap;
  cursor: pointer;
}
.btn-chip:hover  { background: rgba(31,56,100,0.06); border-color: var(--c-brand-2); }
.btn-chip:active { transform: translateY(1px); }
.btn-chip .ic    { font-size: 14px; line-height: 1; }

/* Alarm-bell notifications (superadmin topbar) */
.notif-bell { position: relative; }
.notif-badge {
  position: absolute; top: 1px; right: 1px; min-width: 16px; height: 16px;
  padding: 0 4px; border-radius: 8px; background: var(--c-danger); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  box-sizing: border-box; pointer-events: none;
}
.notif-badge.hidden { display: none !important; }
.notif-panel {
  position: absolute; top: 54px; right: 8px; z-index: 1200; width: 330px; max-width: 92vw;
  max-height: 72vh; overflow-y: auto; background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.notif-panel h4 {
  margin: 8px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--c-text-muted); font-weight: 700;
}
.notif-item { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; line-height: 1.35; }
.notif-item:hover { background: rgba(31,56,100,0.06); }
.notif-empty { padding: 16px; text-align: center; color: var(--c-text-muted); font-size: 13px; }

/* Login-screen view toggle — floats at top-right of the gradient page. */
.login-view-toggle {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 100;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background .15s ease, transform .1s ease;
}
.login-view-toggle:hover  { background: rgba(255,255,255,0.30); }
.login-view-toggle:active { transform: scale(0.95); }

/* ─── Print: hide chrome ──────────────────────────────── */
@media print {
  .topbar, .sidebar, .tabbar, .modal, .toast { display: none !important; }
  main { padding: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd; }
}
