/* ─────────────────────────────────────────────────────────────────────────────
   Fleet — main stylesheet
   Layout: sidebar (fixed) + topbar (sticky) + main scroll
   ───────────────────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

* { box-sizing: border-box; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,.06); border-radius: 5px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.12); }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overflow-x: hidden;            /* defeat any rogue horizontal scroll */
}
html {
  /* iOS notch / Dynamic Island safe areas */
  padding-left:  env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Atmospheric radial bg */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 800px 600px at 0% 0%, rgba(59,91,219,.06), transparent 60%),
    radial-gradient(ellipse 600px 800px at 100% 100%, rgba(168,85,247,.04), transparent 60%);
  pointer-events: none;
  z-index: -1;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }

.mono { font-family: var(--font-mono); }
.dim { color: var(--text-dim); }
.muted { color: var(--text-muted); }

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

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-lt);
}
.sidebar-logo-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(55, 174, 226, .25), 0 0 16px rgba(55, 174, 226, .25);
  flex-shrink: 0;
}
.sidebar-logo-badge img,
.sidebar-logo-badge svg {
  width: 100%;
  height: 100%;
  display: block;
}
.sidebar-logo-text {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -.01em;
}
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 14px 12px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  color: var(--text-dim);
  font-size: 13.5px;
  transition: var(--transition);
  position: relative;
}
.nav-item:hover {
  background: var(--card);
  color: var(--text);
}
.nav-item.active {
  background: var(--primary-lt);
  color: white;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--primary);
  border-radius: 2px;
  box-shadow: 0 0 8px var(--primary);
}
.nav-item .nav-ico {
  width: 16px;
  text-align: center;
  font-size: 13px;
  opacity: .85;
}
.nav-item .nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-lt);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.sidebar-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

/* Account switcher block in sidebar */
.acct-switcher {
  margin: 12px 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition);
}
.acct-switcher:hover { background: var(--card-hover); border-color: var(--border-hi); }
.acct-switcher-label {
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.acct-switcher-phone {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  min-height: var(--topbar-h);
  background: rgba(5, 6, 10, .85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  padding-top: env(safe-area-inset-top);
  gap: 16px;
  z-index: var(--z-topbar);
}
.topbar-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-crumb {
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-crumb a:hover { color: var(--text); }
.topbar-spacer { flex: 1; }
.topbar-search {
  position: relative;
  width: 280px;
}
.topbar-search input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 7px 12px 7px 32px;
  color: var(--text);
  font-size: 13px;
  transition: var(--transition);
}
.topbar-search input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--card-hover);
}
.topbar-search i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 12px;
}

/* Main scroll area */
.main {
  padding: 24px 32px 48px;
  max-width: 1400px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-dk);
  box-shadow: var(--glow-prim);
}
.btn-secondary {
  background: var(--card);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--card-hover);
  border-color: var(--border-hi);
}
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover { background: var(--card); color: var(--text); }
.btn-danger {
  background: var(--danger-lt);
  color: var(--danger);
  border-color: rgba(244, 63, 94, .25);
}
.btn-danger:hover { background: rgba(244, 63, 94, .18); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-xs);
  display: grid;
  place-items: center;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;              /* containment for nested canvas / SVG */
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-lt);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -.005em;
}
.card-title small {
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 6px;
}
.card-body { padding: 18px; }

/* ── KPI strip ───────────────────────────────────────────────────────────── */
.kpi-grid-6 {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.kpi-cell {
  background: var(--bg-elev);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  transition: var(--transition);
}
.kpi-cell:hover { background: var(--card-hover); }
.kpi-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: .02em;
  text-transform: uppercase;
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.02em;
}
.kpi-delta {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}
.kpi-delta.up { color: var(--success); }
.kpi-delta.dn { color: var(--danger); }
.kpi-delta.flat { color: var(--text-muted); }

/* ── Pills / badges ──────────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  border: 1px solid transparent;
}
.pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill-ok { background: var(--success-lt); color: var(--success); border-color: rgba(52,211,153,.2); }
.pill-warn { background: var(--warning-lt); color: var(--warning); border-color: rgba(251,191,36,.2); }
.pill-bad { background: var(--danger-lt); color: var(--danger); border-color: rgba(244,63,94,.2); }
.pill-off { background: rgba(255,255,255,.04); color: var(--text-muted); border-color: var(--border); }

.warmup {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-mono);
  text-transform: lowercase;
}
.warmup-cold    { background: rgba(107,114,128,.15); color: var(--warmup-cold); }
.warmup-warming { background: rgba(245,158,11,.15);  color: var(--warmup-warming); }
.warmup-warm    { background: rgba(16,185,129,.15);  color: var(--warmup-warm); }

.scope-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  font-size: 10.5px;
  font-weight: 500;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.scope-pill.own { color: var(--accent-vio); background: rgba(168,85,247,.08); border-color: rgba(168,85,247,.2); }

/* ── Quota bar ───────────────────────────────────────────────────────────── */
.quota {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.quota-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.quota-bar {
  height: 4px;
  background: rgba(255,255,255,.05);
  border-radius: 99px;
  overflow: hidden;
}
.quota-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--success), var(--success));
  transition: width .35s ease;
}
.quota-fill[data-level="mid"] { background: linear-gradient(90deg, var(--success), var(--warning)); }
.quota-fill[data-level="hi"]  { background: linear-gradient(90deg, var(--warning), var(--danger)); }
.quota-fill[data-level="max"] { background: var(--danger); }

/* ── Accounts grid (Fleet) ───────────────────────────────────────────────── */
.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 28px 0 14px;
}
.section-head h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -.01em;
}
.section-head .toolbar {
  margin-left: auto;
  display: flex;
  gap: 8px;
}
.view-toggle {
  display: inline-flex;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 2px;
}
.view-toggle button {
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text-muted);
  border-radius: 4px;
  transition: var(--transition);
}
.view-toggle button.active {
  background: var(--card-hover);
  color: var(--text);
}

.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.acct-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.acct-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  opacity: 0;
  transition: var(--transition);
}
.acct-card:hover {
  background: var(--card-hover);
  border-color: var(--border-hi);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}
.acct-card:hover::after { opacity: .6; }

.acct-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.acct-card-phone {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
}
.acct-card-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  margin-top: 2px;
}
.acct-card-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.acct-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: rgba(0,0,0,.2);
  border-radius: var(--radius-sm);
  padding: 10px;
}
.acct-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.acct-stat-lbl {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.acct-stat-val {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.sparkline {
  width: 100%;
  height: 32px;
  max-height: 32px;
  display: block;
  flex-shrink: 0;
}
.sparkline:empty { display: none; }   /* prevent an empty SVG from inflating the card */
.sparkline path.line { fill: none; stroke: var(--primary); stroke-width: 1.5; }
.sparkline path.area { fill: url(#sparkGrad); }

/* ── Activity feed ───────────────────────────────────────────────────────── */
.activity-list {
  display: flex;
  flex-direction: column;
}
.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-lt);
  font-size: 13px;
  transition: var(--transition);
}
.activity-item:hover { background: var(--card-hover); }
.activity-item:last-child { border-bottom: none; }
.act-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  display: grid;
  place-items: center;
  font-size: 12px;
  flex-shrink: 0;
}
.act-icon.ok   { background: var(--success-lt); color: var(--success); }
.act-icon.warn { background: var(--warning-lt); color: var(--warning); }
.act-icon.bad  { background: var(--danger-lt); color: var(--danger); }
.act-icon.info { background: var(--info-lt); color: var(--info); }
.act-body { flex: 1; min-width: 0; }
.act-title {
  color: var(--text);
  font-weight: 500;
}
.act-title .mono { color: var(--text-dim); }
.act-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}
.act-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,.15);
}
.tbl tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-lt);
}
.tbl tbody tr:hover { background: var(--card); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .num { font-family: var(--font-mono); }

/* ── Tabs (intra-page) ───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: var(--transition);
}
.tab:hover { color: var(--text-dim); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--primary);
}
.tab .tab-count {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  background: var(--card);
  border-radius: 99px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ── Account header (sticky) ─────────────────────────────────────────────── */
.acct-header {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  margin-bottom: 22px;
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
  z-index: 30;
  backdrop-filter: blur(8px);
}
.acct-header-id {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.acct-header-phone {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
}
.acct-header-meta {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.acct-header-quota {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .icon {
  font-size: 28px;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.empty-state .title {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 14px;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  backdrop-filter: blur(6px);
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fade-in .15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slide-up .2s cubic-bezier(.4,0,.2,1);
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.modal-close {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  display: grid;
  place-items: center;
  transition: var(--transition);
}
.modal-close:hover { background: var(--card); color: var(--text); }
.modal-body { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.steps {
  display: flex;
  gap: 8px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border-lt);
}
.step-dot {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  transition: var(--transition);
}
.step-dot.active { background: var(--primary); box-shadow: 0 0 8px var(--primary); }
.step-dot.done   { background: var(--success); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: .03em;
  text-transform: uppercase;
}
.field-input {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font-mono);
  transition: var(--transition);
}
.field-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--card-hover);
  box-shadow: var(--glow-prim);
}
.field-hint {
  font-size: 11px;
  color: var(--text-muted);
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ── Chart wrappers ──────────────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 240px;
  padding: 18px;
}
.chart-wrap-sm { height: 160px; }

/* ── Layout helpers ──────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ─────────────────────────────────────────────────────────────────────────────
   Hamburger / mobile drawer
   ───────────────────────────────────────────────────────────────────────────── */
.hamburger {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-xs);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  align-items: center;
  justify-content: center;
}
.hamburger:hover { background: var(--card-hover); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(4px);
  z-index: calc(var(--z-sidebar) - 1);
  opacity: 0;
  transition: opacity .2s ease;
}
.sidebar-overlay.open { display: block; opacity: 1; }

/* ─────────────────────────────────────────────────────────────────────────────
   Responsive — mobile-first breakpoints
   Touch targets ≥ 44px ; sidebar collapses to drawer on <960px.
   ───────────────────────────────────────────────────────────────────────────── */

/* Tablet — sidebar still visible but kpi/grid simplify */
@media (max-width: 1100px) {
  .kpi-grid-6 { grid-template-columns: repeat(3, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .topbar-search { width: 200px; }
  .main { padding: 20px 22px 40px; }
}

/* Mobile / small tablet — sidebar becomes a slide-in drawer */
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    width: 280px;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4, 0, .2, 1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-nav { padding-bottom: 24px; }

  .hamburger { display: inline-flex; }

  .topbar {
    padding: 0 14px;
    gap: 10px;
  }
  .topbar-search { display: none; }
  .topbar-title { font-size: 14px; min-width: 0; flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .main { padding: 16px 14px 40px; max-width: 100%; }

  /* KPI strip: clean horizontal carousel — each cell ~70% wide with its own card chrome */
  .kpi-grid-6 {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 14px;
    -webkit-overflow-scrolling: touch;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    gap: 10px;
    margin: 0 -14px;
    padding: 0 14px;
  }
  .kpi-grid-6::-webkit-scrollbar { display: none; }
  .kpi-cell {
    flex: 0 0 auto;
    width: clamp(170px, 70vw, 240px);
    min-width: 0;
    scroll-snap-align: start;
    padding: 14px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }
  .kpi-cell:first-child, .kpi-cell:last-child { border-radius: var(--radius); }
  .kpi-value { font-size: 20px; }

  /* Account cards full-width with denser internal stats */
  .accounts-grid { grid-template-columns: 1fr; gap: 12px; }
  .acct-card { padding: 14px; gap: 12px; }
  .acct-stats { grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; }
  .acct-stat { min-width: 0; }   /* prevent overflow forcing single-column collapse */
  .acct-stat-val { font-size: 15px; }
  .acct-card-meta { flex-wrap: wrap; gap: 6px 10px; }

  /* Activity feed: more breathing room, smaller meta */
  .activity-item { padding: 12px 14px; gap: 10px; }
  .act-meta { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

  /* Section heads stack toolbar below title */
  .section-head { flex-wrap: wrap; gap: 8px; margin: 22px 0 12px; }
  .section-head h2 { font-size: 14px; }
  .section-head .toolbar { margin-left: 0; width: 100%; }
  .view-toggle button { padding: 8px 14px; font-size: 12.5px; min-height: 36px; }

  /* Account dossier header stacks; quota goes full width below identity */
  .acct-header {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px 16px;
    position: static; /* avoid sticky overlap with the drawer trigger */
  }
  .acct-header-quota { min-width: 0; }
  .acct-header-phone { font-size: 16px; }
  .acct-header-meta { gap: 10px 14px; font-size: 11.5px; }

  /* Tabs scroll horizontally */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tab { white-space: nowrap; padding: 10px 12px; min-height: 44px; }

  /* Tables remain scrollable */
  .table-wrap, .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tbl thead th, .tbl tbody td { padding: 10px 12px; font-size: 12.5px; }

  /* Buttons hit ≥ 44 px on small screens */
  .btn { min-height: 40px; padding: 9px 14px; font-size: 13px; }
  .btn-sm { min-height: 36px; padding: 7px 12px; }
  .btn-icon { width: 40px; height: 40px; }

  /* Modal goes near-fullscreen */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92dvh;
    animation: slide-up-sheet .25s cubic-bezier(.4, 0, .2, 1);
  }
  @keyframes slide-up-sheet {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
  .modal-body { max-height: calc(92dvh - 200px); overflow-y: auto; }
  .field-input { font-size: 16px; /* prevent iOS zoom */ }
  .field-row { grid-template-columns: 1fr; }

  /* Chart wrappers can breathe */
  .chart-wrap { height: 200px; padding: 14px; }
}

/* Very small phones */
@media (max-width: 480px) {
  .topbar-title { font-size: 13px; }
  .topbar-title small, .topbar-crumb span:not(.mono) { display: none; }
  .acct-header-phone { font-size: 15px; }
  .kpi-cell { flex: 0 0 78%; }
  .kpi-value { font-size: 18px; }
  .acct-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .acct-stat-val { font-size: 15px; }
  .main { padding: 14px 12px 32px; }
}

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