/* SignalPoint portal, shared stylesheet (redesign, September 2026).
   Tokens and every shared component. Page-specific rules live in their own
   file, linked through {% block head %}. Rules: flat surfaces, hairline
   borders, blue only for "current" and "do this", status colours only for
   status, radius 6px on cards and dialogs, 4px on controls, nothing larger. */

/* ---- Tokens ------------------------------------------------------------- */
:root {
  --blue: #375B95;
  --blue-deep: #2C4A78;
  --blue-wash: #E7EEF7;
  --blue-light: #B9C8E0;
  --ink: #1B1C1E;
  --ink-2: #4B4E55;
  --mute: #737478;
  --line: #E1E4E9;
  --ground: #F0F2F4;
  --paper: #FFFFFF;
  --well: #F6F7F9;
  --good: #0B6A4A;
  --warn: #B9781A;
  /* Text shade of --warn: #B9781A is 3.2:1 on paper, so 13px status text uses
     this darker step, which clears 4.5:1 on paper (5.9:1) and well (5.5:1). */
  --warn-ink: #8A5A0F;
  --bad: #C0392B;
  --radius: 6px;
  --radius-sm: 4px;
  --font: "Poppins", "Segoe UI", Arial, sans-serif;
  --scrim: rgba(27, 28, 30, 0.4);
  --topbar-h: 52px;
  /* Carrier colours: used by the carrier tag only (rule 3 exception). */
  --vz: #B4262A;
  --vz-wash: #FDECEC;
  --att: #0B6C9E;
  --att-wash: #E6F4FB;
}

/* ---- Reset -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; margin: 0; }
button { cursor: pointer; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
[hidden] { display: none !important; }

/* Every focusable control shows the same ring. */
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Skip link: the first tab stop on every page. Hidden until it has focus,
   then shown as a button over the top bar. */
.skip-link {
  position: absolute; top: 4px; left: 8px; z-index: 40;
  display: inline-flex; align-items: center; height: 44px; padding: 0 14px;
  font-size: 13.5px; font-weight: 500; color: var(--blue); text-decoration: none;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.skip-link:not(:focus) {
  width: 1px; height: 1px; padding: 0; margin: -1px; border: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}
/* The skip target takes focus programmatically only; it is not a control, so
   it draws no ring (rule 10 covers controls). */
main[tabindex="-1"]:focus { outline: none; }

/* ---- Type scale --------------------------------------------------------- */
h1, .h1 { font-size: 24px; font-weight: 600; line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h2, .h2 { font-size: 15px; font-weight: 600; line-height: 1.3; margin: 0; }
h3, .h3 { font-size: 13.5px; font-weight: 600; line-height: 1.3; margin: 0; }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }
.muted { color: var(--mute); }
.small { font-size: 13px; }
.label, .kpi-label, .table th {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--mute);
}
.figure, .kpi-figure { font-size: 22px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Layout ------------------------------------------------------------- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 24px 72px; }
.wrap.wide { max-width: max(1500px, 80vw); }

/* ---- Preview "Viewing as" switch (only rendered when sign-in is off) ----- */
.view-as { display: flex; align-items: center; gap: 8px; margin: 0; }
.view-as-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--mute); white-space: nowrap; }
.view-as-select { height: 36px; width: auto; max-width: 260px; padding: 0 34px 0 10px; font-size: 13px; }
.view-as-sheet { padding: 12px 16px 4px; }
.view-as-sheet .view-as { flex-direction: column; align-items: stretch; gap: 6px; }
.view-as-sheet .view-as-select { height: 44px; max-width: none; width: 100%; }

/* ---- Top bar ------------------------------------------------------------ */
/* The bar's background and bottom border span the viewport. Its contents sit
   in .topbar-inner, which takes the same max-width and side padding as the
   page's .wrap (and .wrap.wide), so the logo and the user area line up with
   the content edges at any screen width. */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex; align-items: center; gap: 20px;
  height: 100%;
  max-width: 1120px; margin: 0 auto; padding: 0 24px;
}
.topbar-inner.wide { max-width: max(1500px, 80vw); }
/* The logo is the way home; the link spans at least 44px of the bar (rule 11)
   while the image itself stays 30px (28px on phones). */
.brand { display: inline-flex; align-items: center; flex: none; min-height: 44px; }
.brand img { height: 30px; width: auto; }
.nav { display: flex; align-items: center; gap: 4px; min-width: 0; }
.nav a {
  display: inline-flex; align-items: center;
  height: 32px; padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; line-height: 1;
  color: var(--ink-2); white-space: nowrap; text-decoration: none;
}
.nav a:hover { color: var(--ink); background: var(--well); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--blue); background: var(--blue-wash); font-weight: 600; }
/* Styled by id as well as class: the id survives anything a script does to
   the class list. Clerk mounts its user button into the inner #user-button
   span and replaces that span's className, so the span is styled by id only. */
.user-area, #user-area { margin-left: auto; display: flex; align-items: center; gap: 10px; min-height: 32px; }
#user-button { display: flex; align-items: center; gap: 10px; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--well); border: 1px solid var(--line); color: var(--ink-2);
  font-size: 11.5px; font-weight: 600; line-height: 1; text-transform: uppercase;
}
.user-role { font-size: 13px; color: var(--ink-2); text-transform: capitalize; }

/* Phone menu button: three bars drawn with backgrounds. Hidden above 640px. */
.menu-btn {
  display: none; margin-left: auto; flex: none;
  width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink);
  flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.menu-btn:hover { background: var(--well); }
.menu-btn .bar { display: block; width: 18px; height: 2px; background: currentColor; }

/* ---- Page header -------------------------------------------------------- */
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 12px 16px; margin: 0 0 20px;
}
.page-head-main { min-width: 0; flex: 1 1 320px; }
.page-title { font-size: 24px; font-weight: 600; line-height: 1.25; margin: 0; overflow-wrap: anywhere; }
.page-sub { margin: 4px 0 0; font-size: 13.5px; color: var(--ink-2); max-width: 72ch; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.page-actions:empty { display: none; }

/* Back link with a CSS chevron. */
.back {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0 0 8px; min-height: 24px;
  font-size: 13px; font-weight: 500; color: var(--blue); text-decoration: none;
}
.back::before {
  content: ""; display: inline-block; width: 7px; height: 7px; flex: none;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(135deg); margin-right: 2px;
}
.back:hover { text-decoration: underline; }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  font-family: var(--font); font-size: 13.5px; font-weight: 500; line-height: 1;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
.btn:hover { background: var(--well); text-decoration: none; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-deep); border-color: var(--blue-deep); color: #fff; }
/* Quiet: a borderless neutral button (the top-bar Sign in). Not blue: blue is
   reserved for the current nav item and the primary action (rule 1). */
.btn-quiet { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--well); color: var(--ink); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { background: var(--bad); border-color: var(--bad); color: #fff; filter: brightness(.92); }
.btn-sm { height: 36px; padding: 0 12px; font-size: 13px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: default; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex: none; }

/* ---- Forms -------------------------------------------------------------- */
.field { margin: 0 0 16px; }
.label { display: block; margin: 0 0 6px; }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--mute); }
.row { display: flex; gap: 16px; }
.row > * { flex: 1 1 0; min-width: 0; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="url"], input[type="tel"], input[type="date"],
input[type="month"], select, textarea, .input {
  display: block; width: 100%; height: 40px; padding: 0 12px;
  font-family: var(--font); font-size: 13.5px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .12s ease;
}
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--mute); opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: var(--mute); }
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
input[disabled], select[disabled], textarea[disabled] { background: var(--well); color: var(--mute); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; margin: 0 6px 0 0; accent-color: var(--blue); vertical-align: -3px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 24px; font-size: 13.5px; cursor: pointer; }

/* Selects: strip the OS chrome and draw one chevron. */
select {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 34px;
  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 d='M1 1.5 6 6.5l5-5' fill='none' stroke='%234B4E55' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
select[multiple] { height: auto; padding: 6px 8px; background-image: none; }

input[type="file"] {
  display: block; width: 100%; min-height: 40px; padding: 5px 12px 5px 5px;
  font-family: var(--font); font-size: 13.5px; color: var(--ink-2);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  height: 28px; padding: 0 12px; margin-right: 10px;
  font-family: var(--font); font-size: 13px; font-weight: 500; color: var(--ink);
  background: var(--well); border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover { border-color: var(--mute); }

/* ---- Card --------------------------------------------------------------- */
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 20px; margin: 0 0 16px;
}
.card:last-child { margin-bottom: 0; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 0 0 14px; padding: 0 0 12px; border-bottom: 1px solid var(--line);
}
.card-head h2, .card-head .card-title { font-size: 15px; font-weight: 600; margin: 0; min-width: 0; }
.card-head .card-action { display: flex; align-items: center; gap: 8px; flex: none; }
.card-section { padding: 14px 0; border-top: 1px solid var(--line); }
.card-section:first-child { border-top-width: 0; padding-top: 0; }
.card-section:last-child { padding-bottom: 0; }
.card > .tablewrap { margin: 0 -20px; border-width: 1px 0; border-radius: 0; }
.card > .tablewrap:last-child { margin-bottom: -16px; border-bottom-width: 0; }
.card > .card-head + .tablewrap { margin-top: -14px; }

/* ---- Tables ------------------------------------------------------------- */
.tablewrap {
  overflow: auto; -webkit-overflow-scrolling: touch;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
/* Header labels sit on --well, where --mute is 4.36:1; --ink-2 clears 4.5:1. */
.table th { background: var(--well); white-space: nowrap; color: var(--ink-2); }
.table td { color: var(--ink); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num, .table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover td { background: var(--well); }
.table tr.rowlink { cursor: pointer; }
.table.zebra tbody tr:nth-child(even) td { background: var(--well); }
.table .cell-actions { text-align: right; white-space: nowrap; }
.table .cell-actions form { display: inline; }
/* Sub-lines sit on --well when the row is hovered or zebra-striped, where
   --mute is 4.36:1; --ink-2 clears 4.5:1 on both paper and well. */
.table .sub { display: block; font-size: 11.5px; color: var(--ink-2); }

/* ---- KPI tiles ---------------------------------------------------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 0 0 20px; }
.kpi {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; min-width: 0;
}
.kpi-label { display: block; }
/* A figure never breaks inside its digits. It stays on the 22px scale (rule 9);
   only a figure marked .long (12 or more characters, the seven-digit dollar
   case) scales down on phones. The kpi macro and app.js add the class. */
.kpi-figure { margin-top: 6px; white-space: nowrap; }
.kpi-sub { margin-top: 4px; font-size: 13px; color: var(--mute); }

/* ---- Tag and status ----------------------------------------------------- */
.tag {
  display: inline-block; padding: 0 8px; line-height: 20px;
  font-size: 11.5px; font-weight: 500; color: var(--ink-2); white-space: nowrap;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
/* The carrier tag is the one coloured category label (rule 3 exception). */
.tag.carrier-verizon_vz { color: var(--vz); background: var(--vz-wash); border-color: transparent; }
.tag.carrier-att { color: var(--att); background: var(--att-wash); border-color: transparent; }
/* Status is a coloured text label (rule 2), never a dot or band (rule 3). */
.status { display: inline-block; font-size: 13px; font-weight: 500; color: var(--mute); white-space: nowrap; }
.status-good { color: var(--good); }
.status-warn { color: var(--warn-ink); }
.status-off { color: var(--mute); }

/* ---- Tap list (phone) --------------------------------------------------- */
.list { margin: 0; padding: 0; list-style: none; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.list-item {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 10px 14px;
  color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--well); text-decoration: none; }
.list-main { flex: 1 1 auto; min-width: 0; }
/* Titles wrap to two lines before clamping, so a client name is not cut short
   next to the amount and the row's buttons on a phone. */
.list-title {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  overflow: hidden; overflow-wrap: anywhere;
  font-size: 13.5px; font-weight: 500; line-height: 1.35;
}
.list-sub { display: block; font-size: 13px; color: var(--ink-2); } /* --ink-2: see .table .sub */
.list-amount { flex: none; font-size: 13.5px; font-weight: 500; font-variant-numeric: tabular-nums; }
.list-item::after {
  content: ""; display: inline-block; flex: none; width: 7px; height: 7px;
  border-right: 1.5px solid var(--mute); border-bottom: 1.5px solid var(--mute);
  transform: rotate(-45deg); margin-left: 2px;
}

/* ---- Flash -------------------------------------------------------------- */
.flash {
  display: flex; align-items: center; gap: 12px;
  margin: 0 0 16px; padding: 10px 10px 10px 14px;
  font-size: 13.5px; font-weight: 500; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}
.flash-msg { flex: 1 1 auto; min-width: 0; }
.flash-success .flash-msg { color: var(--good); }
.flash-error .flash-msg { color: var(--bad); }
.flash-info .flash-msg { color: var(--ink); }
.flash-link { flex: none; font-weight: 500; color: var(--blue); white-space: nowrap; }
.flash-close {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--mute); cursor: pointer;
}
.flash-close:hover { background: var(--well); color: var(--ink); }
.flash-close svg { width: 16px; height: 16px; }

/* ---- Dialog and bottom sheet (native <dialog>, restyled) ---------------- */
.dialog, .sheet { color: var(--ink); background: var(--paper); }
.dialog::backdrop, .sheet::backdrop { background: var(--scrim); }
.dialog {
  width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 0; margin: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.dialog.wide { width: min(720px, calc(100vw - 32px)); }
.dialog-head, .sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.dialog-head h2, .dialog-head h3, .sheet-head h2, .sheet-head h3 { font-size: 15px; font-weight: 600; margin: 0; }
.dialog-body { padding: 20px 20px 8px; }
.dialog-body h3 { font-size: 15px; font-weight: 600; margin: 0 0 6px; }
.dialog-body p { font-size: 13.5px; color: var(--ink-2); margin: 0; }
.dialog-body .hint { font-size: 13px; color: var(--mute); }
.dialog-subject { display: inline-block; margin: 0 0 10px; padding: 0 8px; line-height: 22px; font-size: 13px; font-weight: 500; color: var(--ink-2); background: var(--well); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.dialog-icon { width: 22px; height: 22px; margin: 0 0 12px; color: var(--bad); }
.dialog-icon.info { color: var(--ink-2); }
.dialog-icon svg { width: 22px; height: 22px; }
.dialog-actions, .sheet-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 20px; }
.dialog-head + .dialog-body { padding-top: 16px; }

.sheet {
  position: fixed; inset: auto 0 0 0;
  width: 100%; max-width: none; max-height: 85vh; margin: 0; padding: 0;
  border: 0; border-top: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0;
  overflow: auto;
}
.sheet-body { padding: 8px 16px 16px; }
.sheet-nav { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.sheet-nav a, .sheet-nav button {
  display: flex; align-items: center; width: 100%; min-height: 44px; padding: 0 12px;
  font-family: var(--font); font-size: 15px; font-weight: 500; text-align: left;
  color: var(--ink); background: transparent; border: 0; border-radius: var(--radius-sm);
  text-decoration: none; cursor: pointer;
}
.sheet-nav a:hover, .sheet-nav button:hover { background: var(--well); text-decoration: none; }
.sheet-nav a[aria-current="page"] { color: var(--blue); background: var(--blue-wash); font-weight: 600; }
.sheet-nav .sheet-divider { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.dialog-close {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 36px; height: 36px; padding: 0; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--mute); cursor: pointer;
}
.dialog-close:hover { background: var(--well); color: var(--ink); }
.dialog-close svg { width: 16px; height: 16px; }

/* ---- Empty state -------------------------------------------------------- */
.empty {
  padding: 32px 16px; text-align: center; color: var(--mute);
  background: var(--paper); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty-title { font-size: 15px; font-weight: 600; color: var(--ink); margin: 0; }
.empty-detail { font-size: 13.5px; margin: 4px 0 0; }
.empty .btn { margin-top: 14px; }

/* ---- Utilities ---------------------------------------------------------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.grow { flex: 1 1 auto; min-width: 0; }
.right { text-align: right; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-16 { margin-top: 16px; } .mb-16 { margin-bottom: 16px; }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 1024px) {
  /* Tablets and phones are touch layouts: every control reaches the 44px
     minimum (rule 11). The type scale itself does not change. */
  .nav a { height: 44px; padding: 0 12px; }
  .back { min-height: 44px; margin-bottom: 0; }
  .check { min-height: 44px; }
  .btn, .btn-sm { min-height: 44px; }
  input[type="text"], input[type="email"], input[type="password"], input[type="number"],
  input[type="search"], input[type="url"], input[type="tel"], input[type="date"],
  input[type="month"], select, .input { height: 44px; }
  input[type="file"] { min-height: 44px; }
  .flash-close, .dialog-close { width: 44px; height: 44px; }
  .kpi-grid:not(.client-cards) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row { flex-direction: column; gap: 0; }
}

@media (max-width: 640px) {
  :root { --topbar-h: 48px; }
  .wrap { padding: 16px 16px 56px; }
  /* 3px on the right: the menu button is 44px wide around 18px bars, so the
     bars end 13px inside it, on the same 16px edge as the page content. */
  .topbar-inner { padding: 0 3px 0 16px; gap: 8px; }
  .brand img { height: 28px; }
  .nav, .goto { display: none; }
  .menu-btn { display: none; }
  .view-as-label { display: none; }
  .view-as-select { max-width: 150px; height: 36px; }
  .page-head { margin-bottom: 16px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .card { padding: 14px 16px; }
  .card > .tablewrap { margin: 0 -16px; }
  .kpi-grid { gap: 10px; }
  .kpi { padding: 12px 14px; }
  /* Two tiles across leave about 137px for the figure. Up to 11 characters
     ("$123,456.78", 121px at 22px/600) fit; a seven-digit dollar amount needs
     148px, so only a .long figure scales with the viewport. */
  .kpi-figure.long { font-size: clamp(16px, 5.2vw, 22px); }
  /* Data grids pin the first column and scroll inside their own box. */
  .tablewrap .table th:first-child, .tablewrap .table td:first-child { position: sticky; left: 0; z-index: 1; background: var(--paper); }
  .tablewrap .table th:first-child { background: var(--well); }
  .tablewrap .table tbody tr:hover td:first-child { background: var(--well); }
  .table th, .table td { padding: 10px 12px; }
  /* max-width: none beats the user-agent dialog:modal cap (100% - 6px - 2em),
     which would otherwise hold the dialog at 342px on a 375px phone. */
  .dialog, .dialog.wide { width: calc(100vw - 24px); max-width: none; }
  .flash { font-size: 13px; padding: 4px 4px 4px 14px; }
  .dialog-head, .sheet-head { padding: 8px 8px 8px 20px; }
}

/* ---- Print -------------------------------------------------------------- */
@media print {
  body { background: #fff; }
  .topbar, .menu-btn, .page-actions, .flash, .flash-close, .sheet, .dialog, .back { display: none !important; }
  .wrap, .wrap.wide { max-width: none; padding: 0; }
  .card, .tablewrap, .kpi { border-color: #999; }
}

/* ---- Motion ------------------------------------------------------------- */
/* ---- Charts (shared by the viewer, the client home and the admin pages) --- */
.chart-tools { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin: 0 0 10px; }
.range-switch { display: inline-flex; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.range-switch button { height: 32px; padding: 0 12px; border: 0; background: transparent; font-family: var(--font); font-size: 13px; font-weight: 500; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.range-switch button + button { border-left: 1px solid var(--line); }
.range-switch button:hover { background: var(--well); color: var(--ink); }
.range-switch button[aria-pressed="true"] { background: var(--blue-wash); color: var(--blue); font-weight: 600; }
.range-switch button:focus-visible { outline-offset: -2px; }
.chart-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 10px; }
.chart-section-head .chart-tools { margin: 0; }
.chart-section-title { font-size: 15px; font-weight: 600; margin: 0; }
.chart-later { margin: 0 0 16px; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0 0 16px; }
.chart-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chart-card { min-width: 0; padding: 14px 16px 12px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.chart-card.span-2 { grid-column: span 2; }
.chart-grid.month-cards { grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); align-items: start; }
.chart-grid.month-cards .chart-card.full { grid-column: 1 / -1; }
.chart-grid.trend-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chart-grid.trend-grid .chart-card.full { grid-column: 1 / -1; }
.chart-grid.trend-grid .chart-card.full .chart-body { height: 300px; }
/* Worth a Look: four short lists */
.look-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.look-card { min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); }
.look-card h4 { display: flex; justify-content: space-between; gap: 8px; margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--ink); }
.look-card h4 span { color: var(--mute); font-weight: 400; font-size: 12px; white-space: nowrap; }
.look-card ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.look-card li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: baseline; font-size: 12.5px; color: var(--ink); }
.look-card li.muted { color: var(--mute); }
.look-card li a { color: inherit; text-decoration: none; min-width: 0; }
.look-card li a:hover b { text-decoration: underline; text-underline-offset: 3px; }
.look-card li b { display: block; font-weight: 500; overflow-wrap: anywhere; }
.look-card li small { display: block; color: var(--mute); font-size: 11.5px; }
.look-card .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.look-card .amt small { font-weight: 400; text-align: right; }
.look-card .foot { margin-top: 8px; font-size: 12px; }
.look-card .foot a { color: var(--blue); text-decoration: none; }
.look-card .foot a:hover { text-decoration: underline; text-underline-offset: 3px; }
.chart-card.full .rank { columns: 2; column-gap: 32px; }
.chart-card.full .rank li { break-inside: avoid; }
.chart-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px; margin: 0 0 8px; }
.chart-head h3 { font-size: 13.5px; font-weight: 600; margin: 0; color: var(--ink); }
.chart-sub { font-size: 13px; color: var(--mute); }
.chart-body { position: relative; height: 220px; }
.chart-body.tall { height: 260px; }
.chart-body canvas { width: 100%; height: 100%; }
.chart-note { margin: 12px 0 0; font-size: 13px; color: var(--ink-2); }
/* Ranked bars: name, bar to scale, figure with its share. */
.rank { list-style: none; margin: 0; padding: 0; }
.rank li + li { border-top: 1px solid var(--line); }
.rank-row { display: grid; grid-template-columns: minmax(110px, 1.1fr) minmax(80px, 2fr) auto; align-items: center; gap: 12px; min-height: 40px; padding: 6px 0; color: var(--ink); text-decoration: none; }
a.rank-row:hover { background: var(--well); text-decoration: none; }
.rank-name { font-size: 13px; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.rank-sub { display: block; font-size: 11.5px; font-weight: 400; color: var(--mute); }
.rank-track { height: 10px; background: var(--well); border-radius: 2px; overflow: hidden; }
.rank-fill { display: block; height: 100%; background: var(--blue); }
.rank-value { font-size: 13px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rank-share { display: block; font-size: 11.5px; font-weight: 400; color: var(--mute); }
.chart-more { margin: 8px 0 0; }
.spark { display: block; }
@media (max-width: 1024px) {
  .chart-grid, .chart-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .chart-card.span-2 { grid-column: auto; }
  .chart-grid.month-cards { grid-template-columns: minmax(0, 1fr); }
  .chart-grid.trend-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Three lines under a full-width chart: the one left over takes the row. */
  .chart-grid.trend-grid .chart-card:last-child:nth-child(even) { grid-column: 1 / -1; }
  .chart-grid.trend-grid .chart-card.full .chart-body { height: 260px; }
  .chart-card.full .rank { columns: 1; }
  .range-switch button { height: 44px; }
  .rank-row { min-height: 44px; }
}
@media (max-width: 640px) {
  .chart-grid.trend-grid { grid-template-columns: minmax(0, 1fr); }
  .chart-grid.trend-grid .chart-card.full .chart-body { height: 220px; }
  .chart-tools { justify-content: stretch; }
  .range-switch { display: flex; width: 100%; }
  .range-switch button { flex: 1 1 0; padding: 0 6px; }
  .chart-body { height: 200px; }
  .chart-body.tall { height: 250px; }
  .rank-row { grid-template-columns: minmax(0, 1fr) auto; }
  .rank-track { grid-column: 1 / -1; order: 3; }
}
@media print { .chart-tools { display: none !important; } .chart-card { break-inside: avoid; } }

/* ---- Go to client (admin top bar) ------------------------------------------ */
.goto { margin: 0 0 0 auto; flex: 0 1 260px; min-width: 140px; }
.goto input { height: 34px; font-size: 13px; background: var(--well); }
.goto + .user-area, .goto + #user-area { margin-left: 0; }

/* ---- "Viewing as the client" strip ------------------------------------------ */
.asbar { background: var(--blue-deep); color: #fff; font-size: 13px; }
.asbar-inner { max-width: 1120px; margin: 0 auto; padding: 8px 24px; display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; }
.asbar-inner.wide { max-width: max(1500px, 80vw); }
.asbar-msg { flex: 1 1 260px; }
.asbar-form { display: flex; align-items: center; gap: 8px; margin: 0; }
.asbar-form label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.asbar-form select { height: 32px; width: auto; max-width: 260px; font-size: 13px; padding: 0 30px 0 10px; }
.asbar .btn { height: 32px; }

/* ---- Client workspace header -------------------------------------------------- */
.cbar { background: var(--paper); border-bottom: 1px solid var(--line); }
.cbar-inner { max-width: max(1500px, 80vw); margin: 0 auto; padding: 12px 24px 0; }
.cbar-top { display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap; }
.cbar-top .back { margin: 0; flex: 0 0 100%; }
.cbar-name { font-size: 22px; font-weight: 600; line-height: 1.25; margin: 0; }
.cbar-sum { font-size: 13px; color: var(--mute); }
.cbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.cbar-actions .inline-form { display: inline-flex; margin: 0; }
.cbar-tabs { display: flex; gap: 2px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.cbar-tabs::-webkit-scrollbar { display: none; }
.cbar-tabs a { flex: none; display: inline-flex; align-items: center; height: 40px; padding: 0 14px; font-size: 13.5px; font-weight: 500; color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; }
.cbar-tabs a:hover { color: var(--ink); text-decoration: none; }
.cbar-tabs a[aria-current="page"] { color: var(--blue); font-weight: 600; border-bottom-color: var(--blue); }

/* ---- Filters (admin Reports) --------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; }
.filters input[type="search"] { flex: 1 1 200px; max-width: 280px; height: 36px; font-size: 13px; }
.filters select { width: auto; height: 36px; font-size: 13px; padding: 0 30px 0 10px; }
.filters select.is-set, .filters input.is-set { border-color: var(--blue); background-color: var(--blue-wash); color: var(--blue); font-weight: 600; }
.filters .filters-count { margin-left: auto; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.table th a.sort { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
.table th a.sort:hover { color: var(--ink); }
.table th a.sort[aria-current]::after { content: ""; border: 4px solid transparent; border-top: 5px solid currentColor; margin-top: 4px; }
.table th a.sort[aria-current="asc"]::after { border-top: 0; border-bottom: 5px solid currentColor; margin-top: 0; }

/* ---- Bottom tab bar (phones): the destinations, always in view ---------------- */
.tabbar { display: none; }
.tabbar-ic { display: block; width: 18px; height: 18px; border: 1.5px solid currentColor; border-radius: 4px; position: relative; }
.ic-list::before { content: ""; position: absolute; left: 3px; right: 3px; top: 4px; height: 1.5px; background: currentColor; box-shadow: none; }
.ic-list::after { content: ""; position: absolute; left: 3px; right: 3px; top: 9px; height: 1.5px; background: currentColor; }
.ic-user { border-radius: 50%; }
/* Users: a head over shoulders, inside the same 18px frame. */
.ic-people { border-radius: 50%; }
.ic-people::before { content: ""; position: absolute; left: 50%; top: 2.5px; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: currentColor; }
.ic-people::after { content: ""; position: absolute; left: 50%; bottom: 2px; width: 9px; height: 4px; margin-left: -4.5px; border-radius: 4px 4px 0 0; background: currentColor; }
.ic-up::before { content: ""; position: absolute; left: 50%; top: 4px; width: 6px; height: 6px; margin-left: -4px; border-left: 1.5px solid currentColor; border-top: 1.5px solid currentColor; transform: rotate(45deg); }
.ic-dash::before { content: ""; position: absolute; left: 3px; bottom: 3px; width: 3px; height: 6px; background: currentColor; }
.ic-dash::after { content: ""; position: absolute; right: 3px; bottom: 3px; width: 3px; height: 10px; background: currentColor; }
@media (max-width: 640px) {
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
            min-height: 58px; padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--paper); border-top: 1px solid var(--line); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 58px;
              font-size: 11.5px; font-weight: 500; color: var(--mute); text-decoration: none; }
  .tabbar a[aria-current="page"] { color: var(--blue); font-weight: 600; }
  .tabbar a[aria-current="page"] .tabbar-ic { background: var(--blue-wash); }
  body:has(.tabbar) { padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px)); }
  .cbar-inner { padding: 10px 16px 0; }
  .cbar-name { font-size: 20px; }
  .cbar-sum { flex: 0 0 100%; }
  .cbar-actions { margin-left: 0; flex: 0 0 100%; }
  .cbar-actions .btn, .cbar-actions .inline-form { flex: 1 1 0; }
  .cbar-actions .inline-form .btn { width: 100%; }
  .cbar-tabs a { height: 44px; }
  .asbar-inner { padding: 8px 16px; }
  .filters input[type="search"], .filters select { flex: 1 1 100%; max-width: none; height: 44px; }
  .filters .filters-count { margin-left: 0; flex: 1 1 100%; }
}
@media (max-width: 1024px) { .cbar-tabs a { height: 44px; } .goto input { height: 44px; } .filters select, .filters input[type="search"] { height: 44px; } }
@media print { .tabbar, .asbar, .cbar-actions, .cbar-tabs, .goto, .filters { display: none !important; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* --- Demo client and Demo mode --- */
.demobar { background: var(--ink); }
.demo-on { margin: 0 0 0 8px; }
.goto + .demo-on { margin-left: 8px; }
.demo-on + .user-area, .demo-on + #user-area { margin-left: 0; }
.sheet-form { margin: 0; }
.demo-note { margin: 0 0 12px; }
.demo-controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px 24px; padding: 4px 0 2px; }
.demo-carriers { display: flex; flex-direction: column; gap: 6px; margin: 0; }
.demo-label { font-size: 12px; font-weight: 500; color: var(--mute); }
.demo-reset { margin: 0 0 0 auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--paper); }
.seg button { border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 500; color: var(--ink); padding: 0 14px; height: 36px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--blue); color: #fff; }
.savings { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 32px; background: var(--blue-wash); border: 1px solid var(--line); border-radius: 6px; padding: 18px 20px; margin: 0 0 16px; }
.savings-main { display: flex; flex-direction: column; gap: 2px; }
.savings-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--mute); }
.savings-figure { font-size: 30px; font-weight: 600; color: var(--good); line-height: 1.15; }
.savings-facts { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0; }
.savings-facts div { display: flex; flex-direction: column; }
.savings-facts dt { font-size: 12px; color: var(--mute); }
.savings-facts dd { margin: 0; font-size: 16px; font-weight: 600; color: var(--ink); }
@media (max-width: 900px) { .topbar .demo-on { display: none; } }
@media (max-width: 1024px) { .seg button { height: 44px; } }
@media (max-width: 640px) { .demo-reset { margin-left: 0; } .savings-figure { font-size: 26px; } }
@media print { .demobar, .demo-card, .demo-on { display: none !important; } }

/* Five admin links: between a phone and a wide screen the bar gives up the
   Go to client box and the preview label before anything can overlap. */
.nav { flex: none; }
.nav a { white-space: nowrap; }
@media (max-width: 1180px) { .goto, .view-as-label { display: none; } }
@media (max-width: 860px) { .topbar .demo-on { display: none; } .nav a { padding-left: 8px; padding-right: 8px; } }

/* The client cards: five or six across on a wide screen, three, then two,
   then one as the screen narrows. Nothing wraps inside a card. */
.client-cards { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.client-cards .kpi { min-width: 0; }
.client-cards .kpi-figure, .client-cards .kpi-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-cards .kpi-sub { overflow-wrap: anywhere; }
.kpi-good .kpi-figure { color: var(--good); }
.kpi-bad .kpi-figure { color: var(--bad); }
@media (max-width: 1024px) { .client-cards, .kpi-grid.client-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) { .client-cards, .kpi-grid.client-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 400px) { .client-cards, .kpi-grid.client-cards { grid-template-columns: minmax(0, 1fr); } }
