/* DeliverSure AI v2 — admin-native. Follows Polaris visual language:
   Inter typescale on 4px grid, tabular numbers, thin borders over shadows,
   restrained radius, dark primary actions. No gradients, no glow, no emoji. */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

:root {
  --bg: #f1f1f1;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --ink-2: #303030;
  --sub: #5d666f;
  --line: #e1e3e5;
  --line-soft: #edeef0;
  --action: #1a1a1a;
  --action-hover: #333333;
  --link: #006fbb;
  --ok: #0e7a3d;
  --ok-bg: #dcf2e2;
  --warn-tx: #7a5200;
  --warn-bg: #ffedb5;
  --bad: #c00020;
  --bad-bg: #ffdbe0;
  --accent: #008060;
  --accent-soft: rgba(0, 128, 96, 0.1);
  --chart-actual: #3f4756;
  --chart-fc: #009e73;
  --chart-actual: #3f4756;
  --chart-fc: #009e73;
  --chart-grid: #e7e9eb;
  --chart-text: #5d666f;
  --input-border: #c9cccf;
  --r-card: 8px;
  --r-ctl: 4px;
}
html[data-theme="dark"] {
  --bg: #101214;
  --surface: #1a1d20;
  --ink: #e9ebee;
  --ink-2: #c6ccd3;
  --sub: #9aa2ab;
  --line: #2c3138;
  --line-soft: #23272d;
  --action: #e9ebee;
  --action-hover: #ffffff;
  --link: #6aa8ff;
  --ok: #3fce7a;
  --ok-bg: #123626;
  --warn-tx: #f0b429;
  --warn-bg: #3a2f10;
  --bad: #ff6b7a;
  --bad-bg: #3d1620;
  --accent: #2fbf8f;
  --accent-soft: rgba(47, 191, 143, 0.14);
  --chart-actual: #aeb6c0;
  --chart-fc: #2fbf8f;
  --chart-grid: #2c3138;
  --chart-text: #9aa2ab;
  --input-border: #3a4048;
}
html[data-theme="dark"] .btn.primary { color: #101214; }
html[data-theme="dark"] .chart-tip, html[data-theme="dark"] .toast { background: #f2f4f6; color: #101214; }
html[data-theme="dark"] input[type="number"], html[data-theme="dark"] input[type="text"], html[data-theme="dark"] select { background: #23272d; color: var(--ink); }
html[data-theme="dark"] .skel { background: #262b31; }
* { box-sizing: border-box; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "tnum" 1, "cv05" 1;
  margin: 0; background: var(--bg); color: var(--ink);
  font-size: 14.5px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.015em; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0 0 8px; }

/* Top nav: flat, admin-like */
.topnav {
  display: flex; align-items: center; gap: 2px;
  padding: 0 20px; height: 56px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; margin-right: 16px; white-space: nowrap; }
.brand .mark { width: 22px; height: 22px; border-radius: 5px; background: var(--accent); display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.brand .mark svg { width: 14px; height: 14px; }
.topnav a.nav { text-decoration: none; color: var(--ink-2); font-weight: 500; font-size: 14px; padding: 7px 12px; border-radius: 6px; }
.topnav a.nav:hover { background: #f1f2f3; }
.topnav a.nav.active { background: #e9eaeb; color: var(--ink); font-weight: 600; }
.topnav .meta { margin-left: auto; font-size: 13px; color: var(--sub); white-space: nowrap; }

/* Page */
.page { max-width: 1280px; margin: 0 auto; padding: 24px 24px 56px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-head .sub { color: var(--sub); font-size: 13px; margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Cards: border first, minimal shadow */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 0 rgba(0,0,0,0.04); }
.card.flat { box-shadow: none; }

/* Stat bleeds: label above, value, caption. No giant shadow tiles. */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); margin-bottom: 12px; overflow: hidden; }
.stat { padding: 14px 16px; border-left: 1px solid var(--line-soft); }
.stat:first-child { border-left: 0; }
.stat .l { font-size: 12px; font-weight: 500; color: var(--sub); margin-bottom: 2px; }
.stat .v { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; }
.stat .c { font-size: 12px; color: var(--sub); margin-top: 2px; }

/* Badges: flat, small, text+icon */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; line-height: 1.5; white-space: nowrap; }
.badge svg { width: 12px; height: 12px; }
.badge.low { background: var(--ok-bg); color: var(--ok); }
.badge.medium { background: var(--warn-bg); color: var(--warn-tx); }
.badge.high { background: var(--bad-bg); color: var(--bad); }
.badge.neutral { background: #e9eaeb; color: var(--ink-2); }

/* Score: uniform square block, number only, color from the risk scale. */
.scorepill { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; padding: 0; border-radius: 8px; font-size: 15px; font-weight: 800; white-space: nowrap; font-feature-settings: "tnum" 1; }
table.grid td.scorecell { text-align: center; width: 70px; }
.seg { display: inline-flex; border: 1px solid var(--input-border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--ink-2); font: 600 13px "Inter", sans-serif; padding: 7px 14px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--input-border); }
.seg button.on { background: var(--action); color: var(--surface); }
html[data-theme="dark"] .seg button.on { color: #101214; }

/* Buttons: dark primary like current admin, bordered secondary */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: var(--r-ctl); padding: 7px 14px; font: 600 13px/1.4 "Inter", sans-serif; cursor: pointer; text-decoration: none; }
.btn svg { width: 14px; height: 14px; }
.btn.primary { background: var(--action); color: #fff; }
.btn.primary:hover { background: var(--action-hover); }
.btn.secondary { background: var(--surface); border-color: #c9cccf; color: var(--ink); }
.btn.secondary:hover { background: #f7f7f8; }
.btn.plain { background: none; color: var(--link); padding: 7px 8px; }
.btn.plain:hover { text-decoration: underline; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* Tables: dense index-table style */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { font-size: 12px; font-weight: 600; color: var(--sub); text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; vertical-align: middle; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover { background: #f7f7f8; }
table.grid a.rowlink { color: var(--ink); font-weight: 500; text-decoration: none; }
table.grid a.rowlink:hover { color: var(--link); text-decoration: underline; }

/* Forms */
label.f { display: block; font-size: 13px; font-weight: 500; margin: 10px 0 2px; }
input[type="number"], input[type="text"], select { border: 1px solid #c9cccf; border-radius: var(--r-ctl); padding: 7px 9px; font: 400 13.5px "Inter", sans-serif; background: #fff; max-width: 100%; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.fieldrow { display: flex; gap: 16px; flex-wrap: wrap; }

/* Skeleton: static blocks (Polaris pattern, no shimmer gimmick) */
.skel { background: #eceeef; border-radius: 4px; min-height: 14px; margin: 8px 0; }

/* Chart */
.chart-wrap { position: relative; }
.chart-tip { position: absolute; pointer-events: none; background: #1a1a1a; color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 4px; white-space: nowrap; display: none; z-index: 5; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--sub); margin-top: 8px; align-items: center; flex-wrap: wrap; }
.legend .sw { display: inline-block; width: 16px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.legend .band { width: 16px; height: 10px; border-radius: 2px; background: var(--accent-soft); border: 1px solid rgba(0,128,96,.25); display: inline-block; margin-right: 6px; vertical-align: middle; }

/* Notice banner: flat, icon + text, single accent border */
.notice { display: flex; gap: 10px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--link); border-radius: 6px; padding: 12px 14px; margin-bottom: 12px; font-size: 13.5px; }
.notice svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; color: var(--link); }
.notice.warn { border-left-color: var(--warn-tx); }
.notice.warn svg { color: var(--warn-tx); }

/* Wizard */
.wizard { max-width: 600px; margin: 32px auto; }
.steps-meta { font-size: 12px; font-weight: 600; color: var(--sub); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.progress { height: 4px; background: var(--line-soft); border-radius: 2px; margin-bottom: 16px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.2s ease; }
.wizard-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }

/* Pricing */
.pricing { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.tier { border: 1px solid var(--line); border-radius: var(--r-card); padding: 16px; background: #fff; }
.tier.current { border: 2px solid var(--ink); padding: 15px; }
.tier h3 { font-size: 14px; }
.tier .amt { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.tier ul { margin: 8px 0 12px; padding-left: 18px; font-size: 13px; color: var(--ink-2); }
.tier li { margin-bottom: 3px; }

.footnote { font-size: 12px; color: var(--sub); line-height: 1.55; }
.muted { color: var(--sub); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1a1a1a; color: #fff; padding: 9px 16px; border-radius: 6px; font-size: 13.5px; opacity: 0; transition: opacity 0.15s; z-index: 50; }
.toast.show { opacity: 1; }

@media (max-width: 640px) {
  .page { padding: 16px 12px 48px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .stat .v { font-size: 20px; }
  .topnav { padding: 0 12px; overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- v3 additions: score ring, charts, funnel, plans, disclosure ---- */
.btn { transition: background 0.12s, transform 0.06s, box-shadow 0.12s; }
.btn:active { transform: translateY(1px); }
.btn.primary { box-shadow: 0 1px 2px rgba(0,0,0,0.18); }
.btn.primary:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.2); }

.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.ring { display: inline-flex; align-items: center; gap: 12px; }
.ring svg { width: 76px; height: 76px; }
.ring .n { font-size: 19px; font-weight: 700; }
.ring .t { font-size: 12px; color: var(--sub); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; background: #f1f2f3; color: var(--ink-2); border-radius: 999px; padding: 3px 10px; }
.chip.hot { background: var(--bad-bg); color: var(--bad); }
.chip svg { width: 12px; height: 12px; }

details.disclosure { border-top: 1px solid var(--line-soft); margin-top: 10px; padding-top: 8px; }
details.disclosure summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--link); list-style: none; display: inline-flex; align-items: center; gap: 6px; }
details.disclosure summary::-webkit-details-marker { display: none; }
details.disclosure summary::before { content: ""; border: solid var(--link); border-width: 0 1.5px 1.5px 0; padding: 2.5px; transform: rotate(45deg); transition: transform 0.15s; }
details.disclosure[open] summary::before { transform: rotate(225deg); }

.bars { display: flex; align-items: flex-end; gap: 5px; height: 150px; padding-top: 8px; }
.bars .b { flex: 1; min-width: 0; border-radius: 3px 3px 0 0; background: #9db9d3; position: relative; transition: height 0.3s ease; }
.bars .b.bad { background: #d39a9d; }
.bars .b:hover::after { content: attr(data-t); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: #1a1a1a; color: #fff; font-size: 11px; padding: 3px 7px; border-radius: 4px; white-space: nowrap; }
.bars-x { display: flex; gap: 5px; font-size: 10.5px; color: var(--sub); margin-top: 4px; }
.bars-x span { flex: 1; text-align: center; overflow: hidden; }

.funnel .frow { display: flex; align-items: center; gap: 10px; margin: 7px 0; font-size: 13px; }
.funnel .fl { width: 150px; color: var(--ink-2); flex-shrink: 0; }
.funnel .ftrack { flex: 1; background: var(--line-soft); border-radius: 4px; height: 20px; overflow: hidden; }
.funnel .fbar { display: block; height: 100%; border-radius: 4px; background: var(--accent); min-width: 3px; transition: width 0.35s ease; }
.funnel .fbar.dim { background: #7fa8c9; }
.funnel .fbar.pale { background: #b9c9d8; }
.funnel .fv { width: 64px; text-align: right; font-weight: 700; flex-shrink: 0; }

.goal { margin: 8px 0; }
.goal .gl { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 4px; }
.goal .gt { height: 8px; background: var(--line-soft); border-radius: 4px; overflow: hidden; }
.goal .gf { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.4s ease; }

/* Plans: whole card is the hit target */
.tier { cursor: pointer; position: relative; transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s; }
.tier:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,0.08); }
.tier:active { transform: translateY(0); }
.tier:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.tier.pop { border: 2px solid var(--accent); padding: 15px; }
.tier .popbadge { position: absolute; top: -11px; left: 14px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 10px; border-radius: 999px; letter-spacing: 0.02em; }
.tier .check { position: absolute; top: 12px; right: 12px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: none; align-items: center; justify-content: center; animation: pop 0.25s ease; }
.tier .check svg { width: 13px; height: 13px; }
.tier.current .check { display: inline-flex; }
.tier.selecting { animation: pulse 0.35s ease; }
@keyframes pop { 0% { transform: scale(0.4); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(0,128,96,0.45); } 100% { box-shadow: 0 0 0 12px rgba(0,128,96,0); } }
.anchor { font-size: 12px; color: var(--sub); }
.breakeven { font-size: 12.5px; color: var(--ok); font-weight: 600; margin-top: 6px; }

.search { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.search input[type="text"] { min-width: 240px; }
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--ink); }
table.grid th .arr { font-size: 10px; margin-left: 3px; }

.donut-legend { font-size: 12.5px; }
.donut-legend .row { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.donut-legend .sw2 { width: 12px; height: 12px; border-radius: 3px; }

/* Range sliders (theme-matched, no raw number typing) */
.sliderow { display: flex; align-items: center; gap: 12px; margin: 10px 0; max-width: 560px; }
.sliderow label { width: 210px; flex-shrink: 0; font-size: 13.5px; font-weight: 500; }
.sliderow output { width: 64px; text-align: right; font-weight: 700; font-size: 14px; }
input[type="range"] { flex: 1; appearance: none; -webkit-appearance: none; height: 6px; border-radius: 3px; background: var(--line); outline-offset: 4px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); border: 2px solid var(--ink); cursor: pointer; }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid var(--ink); cursor: pointer; }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line); }

/* Dashboard resize handle */
.rsz { position: relative; }
.rsz-handle { position: absolute; top: 0; bottom: 0; width: 14px; margin-left: -7px; cursor: col-resize; z-index: 5; display: flex; align-items: center; justify-content: center; }
.rsz-handle::after { content: ""; width: 4px; height: 40px; border-radius: 2px; background: transparent; transition: background 0.15s; }
.rsz-handle:hover::after, .rsz-handle.on::after { background: #c9cccf; }
@media (max-width: 900px) { .rsz-handle { display: none; } }

/* Toggle switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; font-weight: 500; margin: 8px 0; }
.switch input { position: absolute; opacity: 0; }
.switch .tk { width: 36px; height: 21px; border-radius: 999px; background: #c9cccf; transition: background 0.15s; flex-shrink: 0; position: relative; }
.switch .tk::after { content: ""; position: absolute; top: 2.5px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.25); }
.switch input:checked + .tk { background: var(--accent); }
.switch input:checked + .tk::after { left: 17px; }
.switch input:focus-visible + .tk { outline: 2px solid var(--link); outline-offset: 2px; }

.calc { font-size: 13px; }
.calc .crow { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.calc .crow:last-child { border-bottom: 0; }
.calc .ck { color: var(--ink-2); }
.calc .cv { font-weight: 700; text-align: right; }
