/* AdvisorPPC Command Center — mobile-first, app-like design system.
 *
 * Philosophy: phone is the primary canvas (ChatGPT mobile in-app browser + phone
 * browsers). Base styles target a 375px viewport with ZERO horizontal overflow.
 * Desktop (the original left-sidebar layout) is layered on at >= 768px.
 *
 * Chrome model:
 *   mobile  -> .app-bar (top) + .tab-bar (bottom) + off-canvas .nav-drawer (hamburger)
 *   desktop -> sticky left .sidebar + main column (app-bar/tab-bar hidden)
 * The drawer and the sidebar render the SAME _sidebar.html markup.
 *
 * Pure CSS + the tiny inline JS toggle in base.html. No CDN, no framework.
 */

:root {
  /* Canonical AdvisorPPC palette: warm ink/paper, orange action, semantic green. */
  --bg: #FAF9F5;
  --surface: #FFFFFF;
  --sidebar-bg: #F5F4EF;
  --sidebar-active: #FFFFFF;
  --ink: #1F1E1D;
  --muted: #6D6C66;
  --soft: #89867E;
  --line: #E4E1D8;
  --line-strong: #D4D0C6;
  --accent: #B84B28;
  --accent-hover: #963A1D;
  --accent-ink: #FFFFFF;
  --accent-soft: #F7ECE7;
  --ok: #277A4C;
  --ok-soft: #EDF5F0;
  --warn: #b08a3a;
  --warn-soft: #faf3e0;
  --danger: #b04848;
  --danger-soft: #f8eaea;
  --info: #4a6b88;
  --info-soft: #ecf1f6;

  /* Spacing scale (4px base). */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;

  --sidebar-width: 240px;
  --app-bar-h: 56px;
  --tab-bar-h: 60px;
  --tap: 44px; /* minimum touch target */

  /* Safe-area insets (notch / home indicator). */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --shadow-card: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-pop: 0 8px 30px rgba(0,0,0,0.16);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  /* 16px base prevents iOS zoom-on-focus. */
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden; /* belt-and-suspenders against rogue wide children */
}
img, svg, video, canvas { max-width: 100%; height: auto; }

/* =======================================================================
   APP BAR (mobile top bar) + BOTTOM TAB BAR + OFF-CANVAS DRAWER
   Shown on mobile; hidden at >= 768px (desktop uses the sidebar).
   ======================================================================= */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: calc(var(--app-bar-h) + var(--safe-t));
  padding: var(--safe-t) max(var(--sp-3), var(--safe-r)) 0 max(var(--sp-3), var(--safe-l));
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--line);
}
.app-bar-burger {
  flex: 0 0 auto;
  width: var(--tap);
  height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: -6px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--ink);
  cursor: pointer;
}
.app-bar-burger:hover { background: rgba(0,0,0,0.05); }
.app-bar-burger svg { width: 24px; height: 24px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; }
.app-bar-brand {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.app-bar-brand img { width: 30px; height: 30px; border-radius: 8px; }
.app-bar-action {
  position: relative;
  flex: 0 0 auto;
  width: var(--tap);
  height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  text-decoration: none;
}
.app-bar-action svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.app-bar-badge {
  position: absolute;
  top: 4px; right: 2px;
  min-width: 17px; height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 17px;
  text-align: center;
}

/* Backdrop behind the open drawer. */
.nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.2s ease;
}
body.drawer-open .nav-backdrop { opacity: 1; }
.nav-backdrop[hidden] { display: none; }

/* The drawer is the wrapper around _sidebar.html; on mobile it slides in. */
.nav-drawer {
  position: fixed;
  top: 0; left: 0;
  z-index: 50;
  width: 84%;
  max-width: 300px;
  height: 100%;
  transform: translateX(-100%);
  transition: transform 0.24s ease;
  will-change: transform;
}
body.drawer-open .nav-drawer { transform: translateX(0); box-shadow: var(--shadow-pop); }

/* Bottom tab bar — 5 primary destinations, thumb-reachable. */
.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  height: calc(var(--tab-bar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab-bar .tab {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.tab-bar .tab svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tab-bar .tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-bar .tab.active { color: var(--accent); }
.tab-bar .tab:active { background: rgba(0,0,0,0.03); }
.tab-bar .tab-badge {
  position: absolute;
  top: 4px;
  left: calc(50% + 6px);
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
}

/* =======================================================================
   APP SHELL + SIDEBAR (sidebar styling is shared by desktop + mobile drawer)
   ======================================================================= */
.app-shell { display: block; min-height: 100vh; }

.sidebar {
  height: 100%;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: max(var(--sp-4), var(--safe-t)) var(--sp-3) max(var(--sp-4), var(--safe-b));
  overflow-y: auto;
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2) var(--sp-4);
}
.sidebar .brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.sidebar .brand img { width: 32px; height: 32px; border-radius: 8px; }
.sidebar .brand:hover { color: var(--accent); }

/* Drawer close button: only visible inside the mobile drawer. */
.drawer-close {
  width: 40px; height: 40px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
}
.drawer-close:hover { background: rgba(0,0,0,0.05); color: var(--ink); }
.drawer-close svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; }
.nav-drawer .drawer-close { display: inline-flex; }

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: 10px var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: background 0.12s, color 0.12s;
}
.sidebar-nav a:hover { color: var(--ink); background: rgba(0,0,0,0.03); text-decoration: none; }
.sidebar-nav a.active {
  background: var(--sidebar-active);
  color: var(--ink);
  font-weight: 500;
  box-shadow: var(--shadow-card);
  text-decoration: none;
}
.sidebar-nav a, .sidebar .brand, .sidebar .brand:hover { text-decoration: none; }
.sidebar-nav a svg {
  width: 18px; height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  stroke-width: 1.6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sidebar-nav .badge {
  margin-left: auto;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 500;
}
.sidebar-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--soft);
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  margin-top: var(--sp-1);
}

.sidebar-footer {
  border-top: 1px solid var(--line);
  padding: var(--sp-3) var(--sp-1) 0;
  margin-top: var(--sp-3);
  font-size: 0.86rem;
}
.sidebar-footer .who {
  color: var(--muted);
  padding: var(--sp-1) var(--sp-3) var(--sp-2);
  word-break: break-all;
  line-height: 1.3;
}
.sidebar-footer form { margin: 0; }
.sidebar-footer .signout {
  width: 100%;
  min-height: var(--tap);
  text-align: left;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.92rem;
  padding: 10px var(--sp-3);
  border-radius: var(--radius-sm);
  font-family: inherit;
}
.sidebar-footer .signout:hover { color: var(--ink); background: rgba(0,0,0,0.03); }

/* Main column. On mobile, leave room for the fixed bottom tab bar. */
.main {
  min-width: 0;
}
.main .inner {
  max-width: 980px;
  margin: 0 auto;
  padding: var(--sp-5) max(var(--sp-4), var(--safe-l)) calc(var(--tab-bar-h) + var(--safe-b) + var(--sp-5)) max(var(--sp-4), var(--safe-r));
}

/* =======================================================================
   TYPOGRAPHY
   ======================================================================= */
h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 var(--sp-2); line-height: 1.25; }
h2 { font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 var(--sp-2); }
h3 { font-size: 1rem; font-weight: 600; margin: 0 0 var(--sp-2); }
p { margin: 0 0 var(--sp-3); }
.lede { color: var(--muted); margin: 0 0 var(--sp-5); font-size: 1rem; max-width: 70ch; }

/* =======================================================================
   CARDS
   ======================================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--sp-5);
  margin: 0 0 var(--sp-4);
  box-shadow: var(--shadow-card);
}
.card.flush { padding: 0; overflow: hidden; }
.card-head {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.card-body { padding: var(--sp-4) var(--sp-5); }
.card-head h2 { margin: 0; }
.card-head .muted { font-size: 0.9rem; }

/* =======================================================================
   GRID + KPI strip — 1 col on mobile, auto-fit on wider screens
   ======================================================================= */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
  margin: 0 0 var(--sp-5);
}
.kpi-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
  margin: 0 0 var(--sp-5);
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--sp-4);
  box-shadow: var(--shadow-card);
}
.kpi .label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: var(--sp-1); }
.kpi .value { font-size: 1.45rem; font-weight: 600; letter-spacing: -0.02em; }
.kpi .delta { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.kpi .delta.up { color: var(--ok); }
.kpi .delta.down { color: var(--danger); }

/* =======================================================================
   TABLES — wrap in .table-wrap for horizontal scroll; never force page wide.
   ======================================================================= */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* bleed to card edges when placed inside .card.flush */
  border-radius: inherit;
}
table.tbl { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table-wrap table.tbl { min-width: 560px; } /* let wide tables scroll, not crush */
table.tbl th, table.tbl td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
table.tbl th {
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: transparent;
  white-space: nowrap;
}
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr:hover td { background: #fbfaf8; }
table.tbl td.right, table.tbl th.right { text-align: right; }
table.tbl td.tight { white-space: nowrap; }

/* Tree-style account list. */
table.tbl-tree tr.row-manager td:first-child { font-weight: 600; }
table.tbl-tree tr.row-child td:first-child { padding-left: 34px; position: relative; }
table.tbl-tree tr.row-child td:first-child::before {
  content: "";
  position: absolute;
  left: 14px; top: 0; bottom: 0;
  border-left: 1px solid var(--line);
}
table.tbl-tree tr.row-child + tr.row-direct td:first-child::before { display: none; }
table.tbl-tree .tree-branch {
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85rem;
  margin-right: 4px;
}
table.tbl-tree tr.row-direct td:first-child { padding-left: 12px; }

/* =======================================================================
   FORMS — 16px inputs (no iOS zoom), full-width on mobile, 44px controls
   ======================================================================= */
form label { display: block; margin: var(--sp-3) 0 var(--sp-1); font-size: 0.9rem; color: var(--muted); }
input[type=email], input[type=password], input[type=text], input[type=number],
input[type=url], input[type=search], input[type=tel], textarea, select,
.input {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 16px; /* prevents iOS zoom-on-focus */
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
textarea { min-height: 96px; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%236b6862' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
input:focus, textarea:focus, select:focus, .input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
/* Checkboxes/radios get a comfortable hit area without forcing full width. */
input[type=checkbox], input[type=radio] {
  width: 20px; height: 20px;
  min-height: 0;
  accent-color: var(--accent);
  vertical-align: middle;
}
.form-field { margin-bottom: var(--sp-4); }

button, .btn {
  min-height: var(--tap);
  padding: 11px var(--sp-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  transition: background 0.15s, border-color 0.15s;
}
button:hover, .btn:hover { background: #fbfaf8; border-color: var(--soft); text-decoration: none; }
button.primary, .btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
button.ghost:hover, .btn.ghost:hover { color: var(--accent-hover); background: transparent; }
/* Inline text-style buttons (Revoke, Edit, Cancel…) keep a tap target but read as links. */
button.link {
  min-height: 0;
  background: none;
  border: none;
  color: var(--accent);
  padding: 6px 2px;
  cursor: pointer;
  font-size: inherit;
  display: inline;
}
button.link:hover { text-decoration: underline; background: none; }
button.link.danger { color: var(--danger); }
.btn-block { display: flex; width: 100%; }
.inline { display: inline; }
.btn-large { padding: 13px var(--sp-5); font-size: 1rem; }

/* =======================================================================
   PILLS + STATUS CHIPS
   ======================================================================= */
.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.pill-active { background: var(--ok-soft); color: var(--ok); }
.pill-paused { background: var(--warn-soft); color: var(--warn); }
.pill-archived { background: var(--danger-soft); color: var(--danger); }
.pill-mcc { background: var(--info-soft); color: var(--info); margin-right: 6px; }
.dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  vertical-align: middle; margin-right: 6px;
}
.dot.high { background: var(--danger); }
.dot.medium { background: var(--warn); }
.dot.low { background: var(--ok); }
.dot.info { background: var(--soft); }

/* =======================================================================
   HELPERS
   ======================================================================= */
.muted { color: var(--muted); }
.soft { color: var(--soft); }
.ok { color: var(--ok); }
.small { font-size: 0.86rem; }
.tiny { font-size: 0.76rem; }
.right { text-align: right; }
.center { text-align: center; }
/* Generic flex row: full-width children on mobile, wraps to columns wider. */
.row { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.row > * { flex: 1 1 100%; }
.stack-sm > * + * { margin-top: var(--sp-3); }
.stack-md > * + * { margin-top: var(--sp-4); }

/* Bordered tile used inside .row on dashboard/settings ("Connect services"). */
.box {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--sp-4);
  background: #fbfaf8;
}
.box h3 { margin: 0 0 var(--sp-2); }

code, .mono {
  background: var(--sidebar-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 0.85em;
  word-break: break-word;
}

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

hr.sep { border: none; border-top: 1px solid var(--line); margin: var(--sp-5) 0 var(--sp-4); }

/* =======================================================================
   FLASH MESSAGES
   ======================================================================= */
.flash {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  margin: var(--sp-3) 0;
  font-size: 0.95rem;
}
.flash.ok-flash { background: var(--ok-soft); color: var(--ok); border: 1px solid #d4e5d4; }
.flash.warn-flash { background: var(--warn-soft); color: var(--warn); border: 1px solid #ecdfb6; }
.flash.error, .error { background: var(--danger-soft); color: var(--danger); border: 1px solid #e8c7c7; padding: var(--sp-3); border-radius: var(--radius-sm); margin: var(--sp-3) 0; }

/* =======================================================================
   CONNECT BUNDLES
   ======================================================================= */
.bundle-row { display: flex; flex-direction: column; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.bundle {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.bundle-complete { background: var(--ok-soft); border-color: #d4e5d4; }
.bundle-main { flex: 1; }
.bundle-main h3 { margin: 0 0 2px; }
.bundle-main p { margin: 2px 0; }
.bundle .btn-large { white-space: nowrap; text-align: center; }

h3.sub { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 500; margin: 0 0 var(--sp-2); }
dl.kv { display: grid; grid-template-columns: 1fr; gap: 2px var(--sp-4); margin: var(--sp-3) 0; font-size: 0.95rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0 0 var(--sp-2); }

/* =======================================================================
   EMPTY STATE
   ======================================================================= */
.empty { text-align: center; padding: var(--sp-7) var(--sp-5); color: var(--muted); }
.empty h3 { color: var(--ink); margin: 0 0 var(--sp-2); font-size: 1.05rem; }
.empty p { margin: 0 0 var(--sp-3); }

/* =======================================================================
   SUGGESTIONS (Today "Ask Claude")
   ======================================================================= */
.suggestions { display: grid; grid-template-columns: 1fr; gap: var(--sp-2); }
.suggestion {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 0.92rem;
  color: var(--ink);
  cursor: default;
  transition: border-color 0.15s;
}
.suggestion:hover { border-color: var(--accent); }
.suggestion .ic { color: var(--accent); font-weight: 600; margin-right: 4px; }

/* =======================================================================
   TOP NAV partial (_topnav.html) — coexists with the app-bar shell
   ======================================================================= */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) max(var(--sp-4), var(--safe-l));
}
.topbar .brand { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 600; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.topbar .brand img { width: 32px; height: 32px; border-radius: 8px; }
.topbar-user { display: flex; align-items: center; gap: var(--sp-3); font-size: 0.88rem; color: var(--muted); }
.topbar-email { display: none; }
.topbar .signout {
  min-height: 0;
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 0.88rem; font-family: inherit; padding: 6px 2px;
}
.topbar .signout:hover { color: var(--ink); text-decoration: underline; background: none; }
.tabs {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 0 max(var(--sp-3), var(--safe-l)) 0 max(var(--sp-3), var(--safe-r));
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 0 0 auto;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  padding: 0 var(--sp-3);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }
.tabs .spacer { display: none; }

/* =======================================================================
   AUTH PAGES (login / signup): no shell
   ======================================================================= */
.auth-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6) max(var(--sp-4), var(--safe-l)) calc(var(--sp-6) + var(--safe-b)) max(var(--sp-4), var(--safe-r));
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--sp-6) var(--sp-5);
  box-shadow: var(--shadow-card);
}
.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-1);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.02em;
  text-decoration: none;
}
.auth-brand:hover { color: var(--ink); text-decoration: none; }
.auth-brand img { width: 46px; height: 46px; border-radius: 12px; }
.auth-context { margin: 0 0 var(--sp-5); color: var(--muted); font-size: .86rem; }
.auth-legal {
  display: flex;
  justify-content: center;
  gap: var(--sp-2);
  margin: var(--sp-5) 0 0;
  color: var(--muted);
  font-size: .78rem;
}

/* =======================================================================
   Reduced motion
   ======================================================================= */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* =======================================================================
   DESKTOP (>= 768px): restore the left-sidebar layout; hide mobile chrome.
   ======================================================================= */
@media (min-width: 768px) {
  /* Mobile-only chrome off. */
  .app-bar, .tab-bar, .nav-backdrop { display: none !important; }

  .app-shell { display: flex; }

  /* Drawer wrapper becomes the static sticky sidebar column. */
  .nav-drawer {
    position: sticky;
    top: 0;
    left: auto;
    z-index: auto;
    width: var(--sidebar-width);
    max-width: none;
    height: 100vh;
    flex-shrink: 0;
    transform: none !important;
    box-shadow: none !important;
  }
  .sidebar {
    height: 100vh;
    padding: var(--sp-5) var(--sp-3);
  }
  .sidebar-top { padding: 4px var(--sp-2) var(--sp-4); }
  .drawer-close { display: none !important; }
  .nav-drawer .drawer-close { display: none !important; }

  .main { flex: 1; min-width: 0; }
  .main .inner {
    padding: var(--sp-6) var(--sp-7) var(--sp-7);
  }

  h1 { font-size: 1.6rem; }

  /* Multi-column layouts on wider screens. */
  .grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .suggestions { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
  .row > * { flex: 1 1 280px; }
  dl.kv { grid-template-columns: auto 1fr; gap: 6px var(--sp-4); }
  dl.kv dd { margin: 0; }

  /* Bundles go back to a horizontal layout. */
  .bundle { flex-direction: row; align-items: center; justify-content: space-between; gap: 18px; }
  .bundle .btn-large { width: auto; }

  /* Tables no longer need a forced min-width once there's room. */
  .table-wrap table.tbl { min-width: 0; }

  /* Top-nav partial: roomier, email visible, spacer pushes Settings right. */
  .topbar-email { display: inline; }
  .tabs .spacer { display: block; flex: 1 1 auto; }
}
