/* Billing dashboard — vanilla CSS, system fonts only. Light + dark themes. */
/* The dashboard toggles visibility with the `hidden` attribute everywhere
   (More sheet, shell, bottom nav, Sign out). Author display rules
   (.more-sheet, .shell, .btn, .bottom-nav) beat the browser's built-in
   [hidden] display:none, so without this the More sheet was permanently
   visible and could never be dismissed. This rule must stay first. */
[hidden] { display: none !important; }

/* UX round (Nov 16): ONE visual system with the public pages — slate
   surfaces + the teal accent the storefront already uses (#0e7490 light /
   #22d3ee dark, see app/routers/public_pages.py), 8px spacing rhythm,
   12px card radius, one soft shadow, larger type hierarchy. */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0e7490;
  --accent-hover: #155e75;
  --accent-text: #ffffff;
  --accent-soft: #ecfeff;
  --danger: #b91c1c;
  --bad-bg: #fee2e2;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --chip-bg: #f1f5f9;
  --shadow: 0 1px 2px rgba(15,23,42,.05), 0 1px 3px rgba(15,23,42,.07);
  --header-h: 56px;
  --radius: 12px;
}
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273549;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --accent: #22d3ee;
  --accent-hover: #67e8f9;
  --accent-text: #082f49;
  --accent-soft: #164e63;
  --danger: #f87171;
  --bad-bg: #7f1d1d;
  --warn-bg: #713f12;
  --warn-text: #fcd34d;
  --ok: #4ade80;
  --ok-bg: #14532d;
  --chip-bg: #273549;
  --shadow: 0 1px 2px rgba(0,0,0,.45);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15.5px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
#view:focus { outline: none; } /* render() focuses #view for a11y; no black box */
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 24px; font-weight: 700; letter-spacing: -.01em; margin: 26px 0 12px; }
h2:first-child { margin-top: 2px; }
h3 { font-size: 17px; font-weight: 650; margin: 26px 0 10px; }
p { margin: 8px 0; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 20;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.header-left, .header-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 22px; line-height: 1; color: var(--accent); display: inline-flex; }
.logo svg { width: 23px; height: 23px; }
.tenant-label {
  font-size: 13px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px;
  white-space: nowrap; background: var(--surface-2);
}

/* ── Shell / sidebar ────────────────────────────────────────────────────── */
.shell { display: flex; align-items: stretch; min-height: calc(100vh - var(--header-h)); }
.sidebar {
  width: 228px; flex: 0 0 228px;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 14px 10px; display: flex; flex-direction: column; gap: 2px;
}
.sidebar a {
  display: flex; align-items: center; gap: 11px;
  min-height: 43px; padding: 8px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 15px; white-space: nowrap;
}
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active {
  background: var(--accent-soft); color: var(--accent); font-weight: 650;
  box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar .nav-icon { width: 22px; text-align: center; flex: 0 0 22px; display: inline-flex; justify-content: center; }
.nav-icon svg { width: 20px; height: 20px; display: block; }
.content { flex: 1; min-width: 0; padding: 24px 28px 100px; max-width: 1120px; margin: 0 auto; width: 100%; }
.content-login { max-width: 560px; margin: 0 auto; padding: 48px 20px; }

/* ── Buttons, inputs, forms ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; text-decoration: none; font-size: 15px; font-weight: 550;
}
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--surface); }
.btn-primary {
  min-height: 52px; background: var(--accent); color: var(--accent-text);
  border-color: transparent; font-weight: 650; padding: 10px 22px;
}
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-text); border-color: transparent; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--bad-bg); color: var(--danger); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; align-items: center; }
input[type="text"], input[type="email"], input[type="number"], input[type="date"],
input[type="datetime-local"], input[type="search"], select, textarea {
  min-height: 44px; padding: 8px 12px; width: 100%;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
label.field { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.form-card, .card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin: 14px 0;
  box-shadow: var(--shadow);
}
.form-card h3, .card h3 { margin-top: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0; }
.toolbar input[type="text"], .toolbar input[type="search"], .toolbar select { width: auto; flex: 1 1 160px; }
.toolbar .btn { flex: 0 0 auto; }

/* ── Cards, tables, chips ───────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; margin: 16px 0; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.stat-card .stat-label { font-size: 12.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.stat-card .stat-value { font-size: 28px; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; margin-top: 5px; }
.stat-card .stat-sub { font-size: 13px; color: var(--muted); margin-top: auto; padding-top: 7px; }
a.stat-card { color: var(--text); text-decoration: none; }
a.stat-card:hover { border-color: var(--accent); }
a.stat-card .stat-sub { color: var(--accent); font-weight: 600; }
.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); gap: 14px; margin: 16px 0; }
.qa-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow);
}
.qa-card:hover { border-color: var(--accent); color: var(--text); }
.qa-card svg { width: 22px; height: 22px; flex: none; color: var(--accent); margin-top: 1px; }
.qa-card strong { display: block; font-size: 15px; }
.qa-card span { font-size: 13px; color: var(--muted); line-height: 1.4; display: block; }
.table-wrap { overflow-x: auto; margin: 12px 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { font-size: 12.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.rowlink { cursor: pointer; }
tbody tr.rowlink:hover { background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.chip {
  display: inline-block; padding: 2.5px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; background: var(--chip-bg); white-space: nowrap;
  border: 1px solid var(--border); margin: 1px 2px 1px 0;
}
.chip-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip-warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.chip-bad { background: var(--bad-bg); color: var(--danger); border-color: transparent; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); font-weight: 550; }
.kv dd { margin: 0; }
ul.plain { list-style: none; padding: 0; margin: 8px 0; }
ul.plain li { padding: 9px 0; border-bottom: 1px solid var(--border); }
ul.plain li:last-child { border-bottom: none; }

/* ── Banners, notes, confirm ────────────────────────────────────────────── */
.banner { border-radius: var(--radius); padding: 14px 16px; margin: 14px 0; }
.banner-error { background: var(--bad-bg); color: var(--danger); }
[data-theme="dark"] .banner-error { color: #fecaca; }
.banner-warn { background: var(--warn-bg); color: var(--warn-text); }
.banner-info { background: var(--accent-soft); }
.note { font-size: 14px; color: var(--muted); }
.confirm-box {
  border: 2px solid var(--danger); border-radius: var(--radius);
  padding: 16px 18px; margin: 16px 0; background: var(--surface);
}
.confirm-box h3 { margin-top: 0; color: var(--danger); }
.footer-line { margin-top: 32px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; }

/* ── Loading skeleton (UX round) ────────────────────────────────────────── */
.skeleton { margin: 14px 0; }
.skel { border-radius: 10px; background: var(--surface-2); position: relative; overflow: hidden; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(148,163,184,.20), transparent);
  animation: skel-sweep 1.3s infinite;
}
@keyframes skel-sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.skel-title { height: 27px; width: 230px; margin-bottom: 18px; }
.skel-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; margin-bottom: 18px; }
.skel-card { height: 98px; }
.skel-row { height: 58px; margin-bottom: 12px; }
@media (prefers-reduced-motion: reduce) { .skel::after { animation: none; } }

/* ── Bottom nav + More sheet (phones) ───────────────────────────────────── */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: none; background: var(--surface); border-top: 1px solid var(--border);
  padding: 4px 2px calc(4px + env(safe-area-inset-bottom, 0px));
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 52px; justify-content: center; color: var(--muted);
  text-decoration: none; font-size: 11px; border-radius: 8px; padding: 4px 2px;
}
.bottom-nav a.active { color: var(--accent); font-weight: 650; }
.bottom-nav .nav-icon { line-height: 1; }
.bottom-nav .nav-icon svg { width: 21px; height: 21px; }
.more-sheet {
  position: fixed; inset: 0; z-index: 40; background: rgba(2, 6, 23, .5);
  display: flex; align-items: flex-end; justify-content: center;
}
.more-sheet-card {
  background: var(--surface); border-radius: 16px 16px 0 0;
  width: 100%; max-width: 560px; max-height: 75vh; overflow-y: auto; padding: 12px 16px 24px;
}
.more-sheet-head { display: flex; justify-content: space-between; align-items: center; }
.more-sheet-nav a {
  display: flex; align-items: center; gap: 12px; min-height: 52px;
  padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 16px;
}
.more-sheet-nav a:hover { background: var(--surface-2); }
.more-sheet-nav .nav-icon svg { width: 21px; height: 21px; }

/* ── Tablet: icons-only sidebar ─────────────────────────────────────────── */
@media (max-width: 820px) {
  .sidebar { width: 60px; flex-basis: 60px; padding: 12px 6px; }
  .sidebar a { justify-content: center; padding: 8px 4px; }
  .sidebar a .nav-label { display: none; }
  .content { padding: 18px 18px 100px; }
  .kv { grid-template-columns: 140px 1fr; }
}

/* ── Phone: bottom nav, tables become cards ─────────────────────────────── */
@media (max-width: 600px) {
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .content { padding: 14px 14px 110px; }
  .tenant-label { display: none; }
  h1 { font-size: 18px; }
  h2 { font-size: 21px; }
  .btn-primary, .btn-row .btn { width: 100%; }
  .btn-row .btn-sm { width: auto; }
  .cards { grid-template-columns: 1fr 1fr; }
  .table-wrap { border: none; background: transparent; overflow: visible; box-shadow: none; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tbody tr {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 10px; padding: 6px 0;
    box-shadow: var(--shadow);
  }
  .table-wrap td {
    border-bottom: none; padding: 5px 14px;
    display: grid; grid-template-columns: 112px 1fr; gap: 10px; align-items: baseline;
  }
  .table-wrap td::before {
    content: attr(data-label);
    font-size: 11.5px; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .04em; padding-top: 2px;
  }
  .table-wrap td.no-label { grid-template-columns: 1fr; }
  .table-wrap td.no-label::before { content: none; }
  .table-wrap td.num { text-align: left; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dd { margin-bottom: 8px; }
}

/* Job 1 (Nov 16): explainability — screen intros, Guide steps, glossary. */
.page-intro { font-size: 15px; line-height: 1.55; color: var(--text); background: var(--surface-2); border-left: 3.5px solid var(--accent); border-radius: 0 10px 10px 0; padding: 12px 16px; margin: 0 0 18px; max-width: 76ch; }
ol.steps { margin: 8px 0 16px; padding-left: 22px; line-height: 1.55; }
ol.steps li { margin: 6px 0; }
dl.glossary { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; margin: 8px 0; }
dl.glossary dt { font-weight: 600; }
dl.glossary dd { margin: 0; line-height: 1.5; }
@media (max-width: 560px) { dl.glossary { grid-template-columns: 1fr; } dl.glossary dt { margin-top: 8px; } }
