/* ============================================================================
   Where's My Package? — editorial-premium design system
   Warm neutrals + system serif display, system sans for UI/data.
   The status/data-viz palette is validated colorblind-safe — do not retune it.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Warm paper neutrals */
  --bg: #f4f2ec;
  --surface: #fffdf8;
  --surface-2: #f6f3ec;
  --surface-3: #ece7dd;
  --text: #1a1613;
  --text-2: #5c564d;
  --muted: #948d80;
  --border: rgba(26, 22, 19, 0.085);
  --border-strong: rgba(26, 22, 19, 0.14);
  --grid: #e6e0d4;

  /* Soft, layered elevation */
  --shadow: 0 1px 2px rgba(40, 33, 24, .04), 0 4px 12px rgba(40, 33, 24, .05), 0 14px 28px -14px rgba(40, 33, 24, .07);
  --shadow-lg: 0 8px 24px -6px rgba(40, 33, 24, .14), 0 20px 48px -12px rgba(40, 33, 24, .18);

  /* Brand */
  --accent: #2a78d6;
  --accent-2: #4a3aa7;
  --accent-warm: #c06a34;      /* editorial warm — decorative brand moments only */

  /* Status / data-viz (validated — keep) */
  --st-delivered: #0ca30c;
  --st-transit:   #2a78d6;
  --st-ofd:       #4a3aa7;
  --st-pending:   #898781;
  --st-exception: #d03b3b;
  --st-returned:  #fab219;
  --st-notfound:  #ec835a;
  --st-unknown:   #b8b6ad;
  --warn:         #e08a00;

  /* Shape */
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --topbar-h: 62px;
  --tap: 44px;                 /* minimum touch target */

  /* Spacing scale */
  --sp-1: .25rem; --sp-2: .5rem; --sp-3: .75rem; --sp-4: 1rem;
  --sp-5: 1.5rem; --sp-6: 2rem; --sp-7: 3rem;

  /* Type */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: ui-serif, "New York", Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Safe-area shorthands (notched phones, with viewport-fit=cover) */
  --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);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #100e0b; --surface: #1c1a16; --surface-2: #232019; --surface-3: #2c2820;
    --text: #faf7f1; --text-2: #c6bfb1; --muted: #928b7d;
    --border: rgba(255, 251, 244, 0.09); --border-strong: rgba(255, 251, 244, 0.17);
    --grid: #302b22;
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 6px 20px rgba(0,0,0,.4); --shadow-lg: 0 14px 40px rgba(0,0,0,.55);
    --accent: #3987e5; --accent-2: #9085e9; --accent-warm: #dd8a4f;
    --st-transit: #3987e5; --st-ofd: #9085e9; --st-unknown: #6b6a64; --warn: #fab219;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #100e0b; --surface: #1c1a16; --surface-2: #232019; --surface-3: #2c2820;
  --text: #faf7f1; --text-2: #c6bfb1; --muted: #928b7d;
  --border: rgba(255, 251, 244, 0.09); --border-strong: rgba(255, 251, 244, 0.17);
  --grid: #302b22;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 6px 20px rgba(0,0,0,.4); --shadow-lg: 0 14px 40px rgba(0,0,0,.55);
  --accent: #3987e5; --accent-2: #9085e9; --accent-warm: #dd8a4f;
  --st-transit: #3987e5; --st-ofd: #9085e9; --st-unknown: #6b6a64; --warn: #fab219;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  line-height: 1.5; font-size: 16px;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  font-synthesis-weight: none;
  accent-color: var(--accent);   /* brand-tinted native checkboxes / radios / range */
}

/* Refined, unobtrusive scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }
h1, h2 { margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: -0.012em; text-wrap: balance; }
h1 { font-size: 1.15rem; }
p { text-wrap: pretty; }
.muted { color: var(--text-2); }
.small { font-size: 0.8rem; }
[hidden] { display: none !important; }
.ic { display: inline-flex; width: 1em; height: 1em; vertical-align: -0.13em; }
.ic svg { width: 100%; height: 100%; }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

a { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ===== Buttons ===== */
.btn {
  font: inherit; font-weight: 550; font-size: 0.86rem;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: 0.52rem 0.9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; transition: background .15s, border-color .15s, transform .04s, box-shadow .15s, opacity .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { padding: .4rem .66rem; font-size: .8rem; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; box-shadow: 0 2px 12px -2px rgba(42,120,214,.4); }
.btn.primary:hover { filter: brightness(1.06); border-color: transparent; box-shadow: 0 4px 18px -3px rgba(42,120,214,.5); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--st-exception); border-color: color-mix(in srgb, var(--st-exception) 40%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--st-exception) 12%, var(--surface)); }
.btn.block { width: 100%; justify-content: center; }
.icon-btn { width: 2.3rem; height: 2.3rem; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; font-size: 1.05rem; transition: background .15s, color .15s, border-color .15s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

input, textarea, button, select { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ===== Login ===== */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: max(1.5rem, var(--safe-t)) 1.5rem;
  background: radial-gradient(1100px 560px at 18% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
              radial-gradient(900px 520px at 100% 110%, color-mix(in srgb, var(--accent-warm) 16%, transparent), transparent 55%), var(--bg); }
.login-card { width: min(390px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 2.4rem 2rem; text-align: center; }
.login-logo { font-size: 2.8rem; }
.login-card h1 { font-size: 1.5rem; margin: .6rem 0 .15rem; }
.login-card input { width: 100%; margin: 1.1rem 0 .8rem; text-align: center; letter-spacing: .04em; padding: .7rem .75rem; min-height: var(--tap); background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
.err { color: var(--st-exception); font-size: .84rem; min-height: 1.1em; margin: .4rem 0 0; }

/* ===== Top bar ===== */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.65rem clamp(1rem, 4vw, 2rem); padding-top: max(0.65rem, var(--safe-t)); padding-left: max(clamp(1rem,4vw,2rem), var(--safe-l)); padding-right: max(clamp(1rem,4vw,2rem), var(--safe-r));
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: .7rem; cursor: pointer; border-radius: var(--radius-sm); min-width: 0; }
.brand:hover .brand-txt h1 { color: var(--accent); }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.brand-logo { font-size: 1.6rem; flex: none; }
.brand-txt { min-width: 0; }
.brand-txt h1 { font-size: 1.12rem; transition: color .15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-txt p { margin: 0; }
.top-actions { display: flex; align-items: center; gap: .5rem; flex: none; }

main { max-width: 1200px; margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); padding-left: max(clamp(1rem,3vw,2rem), var(--safe-l)); padding-right: max(clamp(1rem,3vw,2rem), var(--safe-r)); display: flex; flex-direction: column; gap: 1.25rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.3rem 1.4rem; }
.card-title { font-size: .82rem; font-weight: 640; letter-spacing: .005em; color: var(--text); display: block; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; }

/* ===== KPI cards ===== */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1rem; }
@media (max-width: 940px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, 1fr); gap: .7rem; } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.05rem; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--kc, var(--accent)); }
.kpi.clickable { cursor: pointer; transition: transform .12s ease, border-color .15s ease, box-shadow .15s ease; }
.kpi.clickable:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--kc, var(--accent)) 45%, var(--border-strong)); box-shadow: var(--shadow-lg); }
.kpi.clickable:focus-visible { outline: 2px solid var(--kc, var(--accent)); outline-offset: 2px; }
.kpi.clickable:active { transform: translateY(0); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; color: var(--text-2); }
.kpi-icon { width: 1.8rem; height: 1.8rem; border-radius: 9px; display: grid; place-items: center; font-size: .95rem; color: var(--kc, var(--accent)); background: color-mix(in srgb, var(--kc, var(--accent)) 14%, var(--surface)); }
.kpi .n { font-size: 1.85rem; font-weight: 680; letter-spacing: -.03em; font-variant-numeric: tabular-nums; margin-top: .3rem; line-height: 1.1; }
.kpi .l { font-size: .68rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; font-weight: 560; margin-top: .1rem; }
.kpi .sub { font-size: .7rem; color: var(--muted); text-transform: none; letter-spacing: 0; }

/* ===== Add card ===== */
.add-grid { display: grid; grid-template-columns: 1fr 220px; gap: 1.1rem; align-items: start; }
@media (max-width: 720px) { .add-grid { grid-template-columns: 1fr; } }
.add-input textarea { width: 100%; margin-top: .55rem; min-height: 84px; resize: vertical; background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: .65rem .75rem; font-family: var(--mono); font-size: .82rem; line-height: 1.5; }
.add-side { display: flex; flex-direction: column; gap: .6rem; padding-top: 1.7rem; }
.add-msg { min-height: 1em; }
.progress { display: flex; flex-direction: column; gap: .35rem; }
.progress-track { height: 7px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s ease; }

/* ===== Charts ===== */
.charts-grid { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 1.25rem; }
@media (max-width: 820px) { .charts-grid { grid-template-columns: 1fr; } }
.chart-box { position: relative; width: 100%; height: 250px; margin-top: .7rem; }   /* fixes the runaway-canvas bug */
.donut-area { display: flex; align-items: center; gap: 1.3rem; flex-wrap: wrap; margin-top: .5rem; }
.donut-box { width: 190px; height: 190px; flex: none; margin-top: 0; }
.donut-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; pointer-events: none; }
.donut-center .big { font-family: var(--font-display); font-size: 2.05rem; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.donut-center .lbl { font-size: .7rem; color: var(--text-2); }
.legend { display: flex; flex-direction: column; gap: .35rem; flex: 1; min-width: 150px; }
.legend .li { display: flex; align-items: center; gap: .5rem; font-size: .82rem; }
.legend .sw { width: .7rem; height: .7rem; border-radius: 3px; flex: none; }
.legend .li .c { margin-left: auto; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ===== Toolbar ===== */
.table-card { padding-top: 1.1rem; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap; margin-bottom: .8rem; }
.toolbar-left { display: flex; align-items: center; gap: .5rem; }
.toolbar-right { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.count-pill { font-size: .72rem; color: var(--text-2); background: var(--surface-3); border-radius: 99px; padding: .12rem .55rem; font-variant-numeric: tabular-nums; }
.search-wrap { position: relative; display: flex; align-items: center; }
.search-ic { position: absolute; left: .65rem; color: var(--muted); font-size: .9rem; pointer-events: none; }
.search-wrap input { width: min(250px, 52vw); padding: .5rem .7rem .5rem 2rem; font-size: .84rem; background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { font: inherit; font-size: .78rem; padding: .42rem .62rem; border: none; background: var(--surface); color: var(--text-2); cursor: pointer; }
.seg button.active { background: var(--surface-3); color: var(--text); font-weight: 550; }
.seg button + button { border-left: 1px solid var(--border); }

/* ===== Status filter chips ===== */
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .7rem; }
.chip { font: inherit; font-size: .76rem; padding: .34rem .66rem; border-radius: 99px; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); transition: background .15s, color .15s, border-color .15s; }
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .cdot { width: .5rem; height: .5rem; border-radius: 50%; }
.chip .cn { font-variant-numeric: tabular-nums; opacity: .8; }

/* ===== Bulk bar ===== */
.bulk-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .55rem .75rem; margin-bottom: .7rem; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.bulk-count { font-size: .82rem; font-weight: 550; display: flex; align-items: center; gap: .5rem; }
.linkbtn { font: inherit; font-size: .8rem; font-weight: 550; background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }
.bulk-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ===== Table ===== */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th { position: sticky; top: 0; z-index: 2; background: var(--surface);
  text-align: left; font-weight: 600; color: var(--text-2); font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  padding: .55rem .55rem; border-bottom: 1px solid var(--border-strong); white-space: nowrap; cursor: pointer; user-select: none; }
thead th.num { text-align: right; }
thead th.col-check, thead th.col-progress, thead th.col-exp { cursor: default; }
thead th[data-sort]:hover { color: var(--text); }
thead th.sorted { color: var(--text); }
thead th.sorted::after { content: " ▾"; }
thead th.sorted.asc::after { content: " ▴"; }
tbody tr.row { border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; }
tbody tr.row:hover { background: var(--surface-2); }
tbody tr.exception-row { background: color-mix(in srgb, var(--st-exception) 5%, var(--surface)); }
tbody td { padding: .65rem .55rem; vertical-align: middle; }
.density-compact tbody td { padding: .34rem .55rem; }
.density-compact thead th { padding: .42rem .55rem; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: .83rem; }
.col-check { width: 34px; }
.col-exp { width: 30px; text-align: right; }
.chev { color: var(--muted); transition: transform .18s; display: inline-flex; }
tr.expanded .chev { transform: rotate(180deg); }
.tracklink { display: inline-flex; align-items: center; gap: .35rem; color: var(--text); text-decoration: none; }
.tracklink:hover { color: var(--accent); }
.copy-btn { border: none; background: none; cursor: pointer; color: var(--muted); font-size: .82rem; padding: 0 .1rem; display: inline-flex; }
.copy-btn:hover { color: var(--accent); }
.cell-sub { color: var(--muted); font-size: .76rem; }
a.note-link { color: var(--accent); text-decoration: none; }
a.note-link:hover { text-decoration: underline; }
/* Order links (custom order URL + ShipStation) — one row, dot-separated, wraps if tight. */
.order-links { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem .5rem; }
.order-links a + a::before { content: '·'; color: var(--muted); margin-right: .5rem; }
.cell-strong { font-weight: 500; }

/* status badge */
.badge { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; padding: .2rem .52rem; border-radius: 99px; font-size: .76rem; font-weight: 550;
  border: 1px solid color-mix(in srgb, var(--bc) 38%, transparent); background: color-mix(in srgb, var(--bc) 13%, var(--surface)); color: color-mix(in srgb, var(--bc) 74%, var(--text)); }
.badge .dot { width: .48rem; height: .48rem; border-radius: 50%; background: var(--bc); flex: none; }
.pill-delay { display: inline-flex; align-items: center; gap: .25rem; margin-left: .3rem; font-size: .68rem; font-weight: 600; padding: .1rem .4rem; border-radius: 99px;
  color: color-mix(in srgb, var(--warn) 80%, var(--text)); background: color-mix(in srgb, var(--warn) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); }

/* mini stepper (in-row) */
.ministep { display: inline-flex; gap: 3px; }
.ministep .s { width: 16px; height: 5px; border-radius: 3px; background: var(--grid); }
.ministep .s.done { background: var(--sc, var(--accent)); }
.ministep .s.exc { background: var(--st-exception); }

/* expanded detail */
tr.detail-row > td { padding: 0; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.detail { padding: 1.2rem 1.1rem 1.3rem; display: grid; grid-template-columns: 1fr; gap: 1.1rem; }
.detail-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* priority pill + attention reason */
.prio-pill { display: inline-block; margin-left: .4rem; font-size: .66rem; font-weight: 700; padding: .08rem .38rem; border-radius: 99px; vertical-align: middle; }
.prio-vip { color: #fff; background: var(--st-ofd); }
.prio-high { color: color-mix(in srgb, var(--warn) 85%, var(--text)); background: color-mix(in srgb, var(--warn) 18%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); }
.return-pill { color: color-mix(in srgb, var(--st-returned) 88%, var(--text)); background: color-mix(in srgb, var(--st-returned) 18%, var(--surface)); border: 1px solid color-mix(in srgb, var(--st-returned) 45%, transparent); }
/* Carrier badge on non-UPS rows. Foreground mixes the brand hue with --text so it stays legible in both themes. */
.carrier-badge { display: inline-block; margin-left: .4rem; font-size: .6rem; font-weight: 700; letter-spacing: .04em; padding: .05rem .34rem; border-radius: 4px; vertical-align: middle; color: var(--text-2); background: color-mix(in srgb, var(--text) 6%, var(--surface)); border: 1px solid color-mix(in srgb, var(--text) 16%, transparent); }
.carrier-fedex { color: color-mix(in srgb, #7d3ac1 66%, var(--text)); border-color: color-mix(in srgb, #7d3ac1 50%, transparent); }
.carrier-usps { color: color-mix(in srgb, #2f6bb0 66%, var(--text)); border-color: color-mix(in srgb, #2f6bb0 50%, transparent); }
.carrier-dhl { color: color-mix(in srgb, #c98a00 72%, var(--text)); border-color: color-mix(in srgb, #d40511 45%, transparent); }
/* Carrier credentials block in Settings → Integrations. */
.carrier-creds { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.settings-subhead { margin: 0 0 .25rem; font-size: .92rem; }
.carrier-block { margin: .7rem 0; padding: .65rem .75rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.carrier-head { display: flex; align-items: center; gap: .4rem; margin-bottom: .45rem; }
.carrier-status { margin-left: auto; font-size: .7rem; font-weight: 600; color: color-mix(in srgb, var(--ok, #3aa76d) 80%, var(--text)); }
.reason-pill { margin-top: .15rem; font-size: .74rem; color: color-mix(in srgb, var(--warn) 82%, var(--text)); }

/* detail: editable ops fields */
.detail-ops { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .65rem; }
.dfield { display: flex; flex-direction: column; gap: .25rem; }
.dfield > label { font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dfield input, .dfield select { font: inherit; font-size: .84rem; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: .42rem .55rem; }
.detail-block { display: flex; flex-direction: column; gap: .4rem; }
.detail-triage { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .55rem .75rem; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.triage-reason { font-size: .84rem; margin-right: auto; }
.ev-label { font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.evidence { display: flex; flex-wrap: wrap; gap: .5rem 1rem; }
.ev-item { display: flex; align-items: center; gap: .4rem; font-size: .82rem; cursor: pointer; min-height: 1.9rem; }
.ev-item input { width: 1.05rem; height: 1.05rem; }

/* claims summary card */
.claims-summary { margin-top: .5rem; }
.claims-big { display: flex; gap: 1.6rem; }
.claims-n { font-size: 1.6rem; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.claims-l { font-size: .72rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.claims-list { margin-top: .85rem; display: flex; flex-direction: column; gap: .25rem; }
.claims-row { display: flex; justify-content: space-between; font-size: .84rem; border-bottom: 1px solid var(--border); padding: .25rem 0; }
.claims-row .c { color: var(--text-2); font-variant-numeric: tabular-nums; }
.card-link { margin-left: auto; float: right; }
/* Claims & recovery page */
.claims-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin: .9rem 0 1rem; }
.claims-kpi { padding: .8rem .9rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.claims-kpi.good { border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.claims-kpi.paid { border-color: color-mix(in srgb, var(--st-delivered) 45%, transparent); }
.claims-kpi.urgent { border-color: color-mix(in srgb, var(--st-exception) 45%, transparent); background: color-mix(in srgb, var(--st-exception) 7%, var(--surface-2)); }
.claims-pipe { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .9rem; }
.claims-chip { font-size: .78rem; font-weight: 550; padding: .28rem .7rem; border-radius: 99px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); cursor: pointer; font-variant-numeric: tabular-nums; }
.claims-chip:hover { border-color: var(--accent); color: var(--text); }
.claims-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#claimsTable { width: 100%; border-collapse: collapse; font-size: .86rem; }
#claimsTable th { text-align: left; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: .4rem .6rem; border-bottom: 1px solid var(--border-strong); }
#claimsTable td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.claim-row { cursor: pointer; }
.claim-row:hover { background: var(--surface-2); }
.claim-row.expanded { background: var(--surface-2); }
.claim-select { font: inherit; font-size: .8rem; padding: .12rem .3rem; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); }
.claim-dot { display: inline-block; width: .5rem; height: .5rem; border-radius: 99px; margin-right: .4rem; vertical-align: middle; background: var(--muted); }
.claim-dot-candidate { background: var(--muted); }
.claim-dot-watch { background: var(--st-notfound); }
.claim-dot-eligible { background: var(--accent); }
.claim-dot-filed { background: var(--st-ofd); }
.claim-dot-approved { background: var(--st-transit); }
.claim-dot-paid { background: var(--st-delivered); }
.claim-soon { color: var(--warn); font-weight: 600; }
.claim-overdue { color: var(--st-exception); font-weight: 700; }
@media (max-width: 720px) { .claims-kpis { grid-template-columns: repeat(2, 1fr); } }
.detail-meta { display: flex; gap: 1.6rem; flex-wrap: wrap; font-size: .82rem; }
.detail-meta div span { color: var(--muted); display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; }

/* full stepper */
.stepper { display: flex; align-items: flex-start; gap: 0; }
.stepper .step { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center; position: relative; min-width: 0; }
.stepper .step .node { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; z-index: 1;
  background: var(--surface); border: 2px solid var(--grid); color: var(--muted); }
.stepper .step.done .node { background: var(--sc); border-color: var(--sc); color: #fff; }
.stepper .step.active .node { border-color: var(--sc); color: var(--sc); box-shadow: 0 0 0 4px color-mix(in srgb, var(--sc) 22%, transparent); }
.stepper .step.exc .node { background: var(--st-exception); border-color: var(--st-exception); color: #fff; }
.stepper .step .cap { font-size: .7rem; margin-top: .4rem; color: var(--text-2); }
.stepper .step.done .cap, .stepper .step.active .cap { color: var(--text); font-weight: 550; }
.stepper .step::before { content: ""; position: absolute; top: 13px; left: -50%; width: 100%; height: 2px; background: var(--grid); z-index: 0; }
.stepper .step:first-child::before { display: none; }
.stepper .step.done::before, .stepper .step.active::before { background: var(--sc); }
.stepper .step.exc::before { background: var(--st-exception); }

/* timeline */
.timeline-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .6rem; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 .9rem 1.3rem; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.timeline li:not(:last-child)::after { content: ""; position: absolute; left: 6.5px; top: 12px; bottom: 0; width: 2px; background: var(--grid); }
.timeline li.first::before { background: var(--st-delivered); }
.tl-status { font-size: .84rem; font-weight: 500; }
.tl-meta { font-size: .76rem; color: var(--muted); }
.detail-empty { font-size: .82rem; color: var(--muted); }

/* skeleton */
.skeleton { display: flex; flex-direction: column; gap: .55rem; padding: .5rem 0; }
.skeleton .sk { height: 34px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sh 1.3s ease infinite; }
@keyframes sh { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* pager + empty states */
.pager { display: flex; align-items: center; gap: .6rem; justify-content: flex-end; padding: .8rem .2rem .1rem; margin-top: .3rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pager-info { color: var(--muted); font-size: .8rem; margin-right: auto; }
.pager-cur { font-size: .82rem; color: var(--text-2); font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 2.8rem 1rem; }
.empty-emoji { font-size: 2.4rem; }
.empty-title { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; margin: .6rem 0 .25rem; }

.foot { text-align: center; padding: .3rem 0 calc(1.5rem + var(--safe-b)); }

/* import button (wraps a hidden file input) */
.import-label { cursor: pointer; }
.import-label input { display: none; }

/* detail: editable reference / note */
.detail-note { display: flex; flex-direction: column; gap: .3rem; }
.detail-note-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.note-input { max-width: 420px; padding: .45rem .6rem; font-size: .85rem; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }

/* insights / analytics */
.svc-box { height: 220px; }
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }
.analytics-grid .wide { grid-column: 1 / -1; }
@media (max-width: 700px) { .analytics-grid { grid-template-columns: 1fr; } }
.ontime-area { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; margin-top: .5rem; }
.ontime-box { width: 170px; height: 170px; flex: none; margin-top: 0; }
.dist-box { height: 220px; }

/* filters button + badge */
.filters-badge { display: inline-grid; place-items: center; min-width: 1.05rem; height: 1.05rem; padding: 0 .28rem; margin-left: .1rem;
  border-radius: 99px; background: var(--accent); color: #fff; font-size: .68rem; font-weight: 700; }

/* filters panel */
.filters-panel { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; padding: 1rem 1.1rem; margin-bottom: .8rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); }
.filter-field { display: flex; flex-direction: column; gap: .3rem; }
.filter-field > label { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.filter-field input, .filter-field select { font: inherit; font-size: .84rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: .42rem .55rem; }
.filter-field input[type="number"] { width: 74px; }
.filter-field input[type="date"] { width: 150px; }
.late-controls { display: flex; align-items: center; gap: .3rem; }
.late-controls .preset { padding: .36rem .52rem; }
.range { display: flex; align-items: center; gap: .35rem; }
.range span { color: var(--muted); }
.filter-actions { margin-left: auto; align-self: flex-end; }
.late-pill { color: color-mix(in srgb, var(--st-exception) 82%, var(--text)); background: color-mix(in srgb, var(--st-exception) 14%, var(--surface));
  border-color: color-mix(in srgb, var(--st-exception) 45%, transparent) !important; }
.mini { font: inherit; font-size: .78rem; padding: .36rem .52rem; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text-2); cursor: pointer; }
.mini:hover { background: var(--surface-2); color: var(--text); }

/* ===== Tabs ===== */
.tabs { display: flex; gap: .25rem; padding: .3rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); width: fit-content; }
.tabs button { font: inherit; font-size: .86rem; font-weight: 550; padding: .5rem 1rem; border: none; border-radius: 8px; background: transparent; color: var(--text-2); cursor: pointer; transition: background .15s, color .15s; }
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab-panel { display: flex; flex-direction: column; gap: 1.25rem; }

/* ===== Analytics time controls ===== */
.analytics-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem 1.4rem;
  padding: .7rem .9rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); position: sticky; top: calc(var(--topbar-h) + .35rem); z-index: 5; }
.ac-group { display: flex; align-items: center; gap: .5rem; }
.ac-label { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; white-space: nowrap; }
.ac-check { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.ac-check input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; margin: 0; }
/* A chart's headline stated in words, under the canvas — readable without hovering a bar. */
.chart-note { margin-top: .6rem; font-size: .76rem; line-height: 1.45; color: var(--text-2); }

/* ===== Shipping cost ===== */
.cost-kpis { display: flex; flex-wrap: wrap; gap: .5rem 2rem; margin-top: .6rem; }
.cost-kpi { min-width: 92px; }
.cost-n { font-size: 1.35rem; font-weight: 600; letter-spacing: -.02em; }
.cost-l { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* ===== Destination tile map =====
   A schematic grid, not a projection: one equal square per state so small states stay
   readable. Shading is a single hue light→dark (sequential); the abbreviation carries
   identity so the map never depends on color alone. */
.us-map { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; margin-top: .8rem; }
.us-cell { aspect-ratio: 1; border-radius: 6px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 1px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2); transition: transform .12s ease, box-shadow .12s ease; }
.us-cell[role="button"] { cursor: pointer; }
.us-cell[role="button"]:hover, .us-cell[role="button"]:focus-visible { transform: translateY(-2px); box-shadow: var(--shadow); outline: none; }
.us-blank { background: transparent; border-color: transparent; }
.us-nodata { background: var(--surface-2); color: var(--muted); }
.us-ab { font-size: .68rem; font-weight: 700; letter-spacing: .03em; }
.us-v { font-size: .6rem; opacity: .85; white-space: nowrap; }
/* Sequential ramp, five steps of one hue against the card surface. */
.us-cell[data-step="0"], .map-sw[data-step="0"] { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border-color: transparent; }
.us-cell[data-step="1"], .map-sw[data-step="1"] { background: color-mix(in srgb, var(--accent) 32%, var(--surface)); border-color: transparent; }
.us-cell[data-step="2"], .map-sw[data-step="2"] { background: color-mix(in srgb, var(--accent) 52%, var(--surface)); border-color: transparent; }
.us-cell[data-step="3"], .map-sw[data-step="3"] { background: color-mix(in srgb, var(--accent) 74%, var(--surface)); border-color: transparent; color: #fff; }
.us-cell[data-step="4"], .map-sw[data-step="4"] { background: color-mix(in srgb, var(--accent) 96%, var(--surface)); border-color: transparent; color: #fff; }
.map-legend { display: flex; align-items: center; gap: 3px; margin-top: .7rem; }
.map-sw { width: 26px; height: 10px; border-radius: 2px; }
.map-legend-l { font-size: .68rem; color: var(--muted); margin: 0 .35rem; }
.map-metric { margin-left: auto; }
@media (max-width: 640px) {
  .us-v { display: none; }
  .us-ab { font-size: .58rem; }
}
@media (max-width: 640px) {
  .analytics-controls { gap: .55rem .8rem; position: static; }
  .ac-group { flex: 1 1 100%; justify-content: space-between; }
  .ac-group .seg { flex: 1; }
  .ac-group .seg button { flex: 1; }
}

/* ===== Attention banner ===== */
.attention-banner { display: flex; align-items: center; gap: .7rem; padding: .8rem 1rem; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); font-size: .88rem; }
.attention-banner .ab-ic { font-size: 1.1rem; }
.attention-banner .ab-text strong { font-weight: 650; }
.attention-banner .ab-btn { margin-left: auto; }

/* ===== Upcoming list ===== */
.upcoming-list { display: flex; flex-direction: column; margin-top: .5rem; }
.up-group { padding: .55rem 0; border-bottom: 1px solid var(--border); }
.up-group:last-child { border-bottom: none; }
.up-when { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .4rem; }
.up-item { display: flex; align-items: center; gap: .6rem; padding: .3rem 0; font-size: .85rem; }
.up-item .mono { color: var(--text-2); }
.up-item .up-loc { margin-left: auto; color: var(--muted); font-size: .8rem; }
.up-empty { color: var(--muted); font-size: .85rem; padding: .5rem 0; }

/* ===== Recent activity log ===== */
.log-head { margin-bottom: .5rem; }
.log-list { display: flex; flex-direction: column; }
.log-row { display: flex; align-items: flex-start; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid var(--border); font-size: .84rem; }
.log-row:last-child { border-bottom: none; }
.log-dot { width: .5rem; height: .5rem; border-radius: 50%; margin-top: .45rem; flex: none; background: var(--muted); }
.log-info .log-dot { background: var(--accent); }
.log-warn .log-dot { background: var(--warn); }
.log-error .log-dot { background: var(--st-exception); }
.log-main { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex: 1; min-width: 0; }
.log-msg { color: var(--text); }
.log-warn .log-msg { color: color-mix(in srgb, var(--warn) 82%, var(--text)); }
.log-error .log-msg { color: color-mix(in srgb, var(--st-exception) 82%, var(--text)); }
.log-time { color: var(--muted); font-size: .76rem; white-space: nowrap; flex: none; }
.log-empty { color: var(--muted); font-size: .85rem; padding: .5rem 0; }

/* ===== ShipStation config ===== */
.ss-config { display: flex; flex-direction: column; gap: .75rem; padding: .3rem .1rem .1rem; }
.ss-config input[type="text"], .ss-config input[type="password"], .ss-config input[type="number"] {
  padding: .6rem .7rem; font-size: .84rem; background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); width: 100%; }
.ss-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.webhook-row { display: flex; gap: .4rem; }
.webhook-row input { flex: 1; min-width: 0; font-family: var(--mono); font-size: .76rem; }

/* settings tabs */
.settings-tabs { display: flex; gap: .25rem; padding: .28rem; margin-bottom: .3rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); position: sticky; top: 0; z-index: 1; }
.settings-tabs button { flex: 1; font: inherit; font-size: .82rem; font-weight: 550; padding: .5rem; border: none; border-radius: 7px; background: transparent; color: var(--text-2); cursor: pointer; }
.settings-tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.settings-sec { display: flex; flex-direction: column; gap: .85rem; }

/* ===== Scorecard table ===== */
.scorecard { width: 100%; border-collapse: collapse; font-size: .84rem; }
.scorecard th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .45rem .5rem; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
.scorecard th.num, .scorecard td.num { text-align: right; font-variant-numeric: tabular-nums; }
.scorecard td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.scorecard tr:last-child td { border-bottom: none; }
.scorecard-bad { color: var(--st-exception); font-weight: 600; }
.scorecard-by { float: right; }
/* Trends & anomalies */
.trends-body { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin-top: .6rem; }
.trend-item { padding: .7rem .8rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.trend-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.trend-val { font-size: 1.5rem; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: .1rem 0; }
.trend-delta { display: inline-block; font-size: .74rem; font-weight: 650; font-variant-numeric: tabular-nums; padding: .04rem .34rem; border-radius: 6px; }
.trend-delta.good { color: color-mix(in srgb, var(--st-delivered) 82%, var(--text)); background: color-mix(in srgb, var(--st-delivered) 14%, var(--surface)); }
.trend-delta.bad { color: color-mix(in srgb, var(--st-exception) 82%, var(--text)); background: color-mix(in srgb, var(--st-exception) 14%, var(--surface)); }
.trend-delta.neutral { color: var(--text-2); background: var(--surface-3); }
.trend-sub { font-size: .72rem; color: var(--text-2); margin-top: .2rem; }
@media (max-width: 720px) { .trends-body { grid-template-columns: repeat(2, 1fr); } }

/* ===== Users / roles ===== */
.user-badge { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-list { display: flex; flex-direction: column; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: none; }
.user-info { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.user-email { font-size: .84rem; }
.user-email.user-off { color: var(--muted); }
.user-role { font: inherit; font-size: .8rem; padding: .3rem .45rem; border: 1px solid var(--border-strong); border-radius: 7px; background: var(--surface); color: var(--text); }
.user-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
/* Read-only viewers: hide the prominent write affordances (server also enforces 403). */
body[data-role="viewer"] .add-card,
body[data-role="viewer"] #refreshBtn,
body[data-role="viewer"] #bulkRefresh,
body[data-role="viewer"] #bulkArchive,
body[data-role="viewer"] #bulkDelete,
body[data-role="viewer"] #archivedToggle,
body[data-role="viewer"] .detail-actions,
body[data-role="viewer"] .detail-triage { display: none !important; }
body[data-role="viewer"] .detail-ops input,
body[data-role="viewer"] .detail-ops select,
body[data-role="viewer"] .note-input,
body[data-role="viewer"] .ev-item input { pointer-events: none; opacity: .6; }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 1.5rem; background: rgba(20, 16, 10, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.modal-card { width: min(520px, 100%); max-height: min(90vh, 760px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 1.25rem; }
.modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 1.2rem 1.25rem; display: flex; flex-direction: column; gap: .85rem; }
.modal-body .field { display: flex; flex-direction: column; gap: .3rem; }
.modal-body label { font-size: .88rem; font-weight: 500; }
.modal-body input[type="url"], .modal-body .field input[type="text"], .modal-body .field input[type="password"], .modal-body .field input[type="number"] { padding: .6rem .7rem; font-size: .84rem; background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); width: 100%; }
.modal-body code { font-family: var(--mono); font-size: .78rem; background: var(--surface-2); padding: .05rem .3rem; border-radius: 4px; }
.setting-row { display: flex; align-items: center; gap: .6rem; font-size: .88rem; cursor: pointer; min-height: 2rem; }
.setting-row input { width: 1.1rem; height: 1.1rem; flex: none; }
.modal-sep { border: none; border-top: 1px solid var(--border); margin: .3rem 0; }
.modal-actions { flex: none; display: flex; align-items: center; gap: .5rem; padding: 1rem 1.25rem; padding-bottom: max(1rem, var(--safe-b)); border-top: 1px solid var(--border); background: var(--surface); }
.modal-actions .spacer { flex: 1; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(1.4rem + var(--safe-b)); transform: translateX(-50%) translateY(1rem); background: var(--text); color: var(--surface);
  padding: .65rem 1.1rem; border-radius: 99px; font-size: .85rem; font-weight: 550; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100vw - 2rem); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================================
   Mobile / touch  (≤ 768px, ≤ 560px)
   The 9-column packages table reflows into stacked package cards.
   ========================================================================== */
@media (max-width: 768px) {
  main { gap: 1rem; }
  .card { padding: 1.1rem 1.05rem; border-radius: var(--radius); }
  .tab-panel { gap: 1rem; }

  /* Generous touch targets */
  .btn { min-height: var(--tap); }
  .btn.sm { min-height: 40px; }
  .icon-btn { width: var(--tap); height: var(--tap); }
  .chip { min-height: 38px; }
  .copy-btn { min-width: 34px; min-height: 34px; align-items: center; justify-content: center; }

  /* Top bar: logo + name only, actions stay compact */
  .brand-txt p { display: none; }
  .brand-txt h1 { font-size: 1.05rem; }
  #refreshBtn .btn-lbl { display: none; }   /* icon-only refresh */
  #refreshBtn { padding-left: 0; padding-right: 0; width: var(--tap); }
  .top-actions { gap: .4rem; }

  /* Full-width segmented tabs */
  .tabs { width: 100%; }
  .tabs button { flex: 1; }

  /* Toolbar stacks; search gets its own full-width row */
  .toolbar { align-items: stretch; }
  .toolbar-right { width: 100%; }
  .search-wrap { flex: 1 1 100%; order: -1; }
  .search-wrap input { width: 100%; }
  .density { display: none; }   /* comfortable-only on touch */
  .toolbar-right .btn { flex: 1; }

  .filters-panel { gap: .9rem 1rem; }
  .filter-field { flex: 1 1 45%; }
  .filter-field input[type="number"], .filter-field input[type="date"] { width: 100%; }
  .filter-actions { margin-left: 0; flex-basis: 100%; }
  .filter-actions .btn { width: 100%; }

  /* --- Packages table → cards ---
     Every rule is prefixed with #pkgTable so it matches the ID specificity of the
     display:block reset below; source order then lets the card rules win. */
  .table-scroll { overflow-x: visible; }
  #pkgTable, #pkgTable tbody, #pkgTable tr, #pkgTable td { display: block; width: auto; }
  #pkgTable thead { display: none; }

  #pkgTable tbody tr.row {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "check status chev"
      "track track  track"
      "act   act    act"
      "prog  prog   eta";
    align-items: center;
    gap: .5rem .7rem;
    padding: .95rem 1.05rem;
    margin-bottom: .7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
  }
  #pkgTable tbody tr.row:hover { background: var(--surface); }
  #pkgTable tbody tr.exception-row { background: color-mix(in srgb, var(--st-exception) 6%, var(--surface)); border-color: color-mix(in srgb, var(--st-exception) 32%, var(--border)); }

  #pkgTable tbody tr.row > td { display: block; padding: 0; vertical-align: initial; min-width: 0; }
  #pkgTable tbody tr.row > td.col-check { grid-area: check; align-self: start; }
  #pkgTable tbody tr.row > td.col-check input { width: 1.2rem; height: 1.2rem; }
  #pkgTable tbody tr.row > td:nth-child(2) { grid-area: status; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }   /* status badge + delay */
  #pkgTable tbody tr.row > td:nth-child(3) { grid-area: track; }                /* tracking + subs */
  #pkgTable tbody tr.row > td:nth-child(4) { display: none; }                   /* service (shown in detail) */
  #pkgTable tbody tr.row > td:nth-child(5) { grid-area: act; }                  /* last activity */
  #pkgTable tbody tr.row > td:nth-child(6) { grid-area: eta; text-align: right; align-self: end; font-size: .82rem; }  /* ETA */
  #pkgTable tbody tr.row > td:nth-child(7) { display: none; }                   /* days (shown in detail) */
  #pkgTable tbody tr.row > td.col-progress { grid-area: prog; align-self: end; }
  #pkgTable tbody tr.row > td.col-exp { grid-area: chev; text-align: right; align-self: start; color: var(--muted); }

  /* Field labels on the card (only where the value isn't self-describing) */
  #pkgTable tbody tr.row > td[data-label]::before {
    content: attr(data-label);
    display: block; font-size: .62rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); margin-bottom: .12rem; font-weight: 600;
  }

  /* Detail row spans full width beneath its card */
  #pkgTable tbody tr.detail-row { margin: -.5rem 0 .7rem; }
  #pkgTable tbody tr.detail-row > td { display: block; border-radius: 0 0 var(--radius) var(--radius); }
  .detail { padding: 1rem .9rem 1.1rem; }
  .detail-meta { gap: 1rem 1.4rem; }

  /* Full stepper: tighter so 5 stages fit narrow screens */
  .stepper .step .node { width: 22px; height: 22px; font-size: .72rem; }
  .stepper .step .cap { font-size: .62rem; }
  .stepper .step::before { top: 11px; }

  /* Charts a touch shorter */
  .chart-box { height: 220px; }
  .svc-box, .dist-box { height: 200px; }

  /* Analytics + claims spacing */
  .claims-big { gap: 1.2rem; }

  /* Settings modal → bottom sheet */
  .modal { place-items: end center; padding: 0; }
  .modal-card { width: 100%; max-width: none; max-height: 92vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; border-bottom: none; animation: sheet-up .28s cubic-bezier(.32,.72,0,1); }
  @keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
  .modal-head::before { content: ""; position: absolute; top: .5rem; left: 50%; transform: translateX(-50%); width: 2.4rem; height: .28rem; border-radius: 99px; background: var(--border-strong); }
  .modal-head { position: relative; padding-top: 1.4rem; }
}

@media (max-width: 560px) {
  /* Reduce the brand to its logomark so the action cluster never crowds it */
  .brand-txt { display: none; }
  .brand-logo { font-size: 1.75rem; }
  .top-actions { gap: .35rem; }
  .user-badge { display: none; }
}

@media (max-width: 400px) {
  main { padding: .85rem; padding-left: max(.85rem, var(--safe-l)); padding-right: max(.85rem, var(--safe-r)); }
  .kpi .n { font-size: 1.6rem; }
}
