/* =========================================================
   OptiRoute — design system
   ========================================================= */

:root{
  --bg:#f5f6f8;
  --bg-soft:#eceef2;
  --surface:#ffffff;
  --border:#e2e5eb;
  --border-strong:#ccd1db;
  --text:#151920;
  --text-soft:#5a6270;
  --text-faint:#8991a0;
  --accent-1:#e2660f;
  --accent-1-hover:#c2560c;
  --accent-2:#0d7d6c;
  --accent-grad:linear-gradient(120deg,#e2660f 0%,#dc7b1f 50%,#0d7d6c 130%);
  --accent-soft:rgba(226,102,15,0.11);
  --accent-2-soft:rgba(13,125,108,0.12);
  --success:#1f8a5c;
  --success-soft:rgba(31,138,92,0.12);
  --danger:#c43f30;
  --danger-soft:rgba(196,63,48,0.12);
  --warning:#b5790a;
  --warning-soft:rgba(197,145,10,0.14);
  --shadow-sm:0 1px 2px rgba(15,20,30,0.06);
  --shadow-md:0 6px 18px -6px rgba(15,20,30,0.12);
  --shadow-lg:0 20px 48px -16px rgba(15,20,30,0.20);
  --radius:14px;
  --radius-sm:9px;
  --font-head:'Sora',ui-sans-serif,system-ui,sans-serif;
  --font-body:'Inter',ui-sans-serif,system-ui,sans-serif;
  --font-mono:'JetBrains Mono',ui-monospace,monospace;
  --topbar-h:60px;
  --footer-h:30px;
  color-scheme: light;
}

:root[data-theme="dark"]{
  --bg:#10131a;
  --bg-soft:#161a22;
  --surface:#191d26;
  --border:rgba(233,238,247,0.09);
  --border-strong:rgba(233,238,247,0.17);
  --text:#eef1f6;
  --text-soft:#a5adbb;
  --text-faint:#727b8c;
  --accent-soft:rgba(232,128,45,0.16);
  --accent-2-soft:rgba(22,163,143,0.16);
  --shadow-sm:0 1px 2px rgba(0,0,0,0.35);
  --shadow-md:0 10px 26px -10px rgba(0,0,0,0.55);
  --shadow-lg:0 26px 60px -18px rgba(0,0,0,0.6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#10131a;
    --bg-soft:#161a22;
    --surface:#191d26;
    --border:rgba(233,238,247,0.09);
    --border-strong:rgba(233,238,247,0.17);
    --text:#eef1f6;
    --text-soft:#a5adbb;
    --text-faint:#727b8c;
    --accent-soft:rgba(232,128,45,0.16);
    --accent-2-soft:rgba(22,163,143,0.16);
    --shadow-sm:0 1px 2px rgba(0,0,0,0.35);
    --shadow-md:0 10px 26px -10px rgba(0,0,0,0.55);
    --shadow-lg:0 26px 60px -18px rgba(0,0,0,0.6);
    color-scheme: dark;
  }
}

*,*::before,*::after{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:var(--font-body);
  -webkit-font-smoothing:antialiased;
  transition:background .3s ease,color .3s ease;
  overflow:hidden;
  /* Header/main/footer as flex rows so <main> always gets exactly the space
     left over and the footer sits flush at the viewport bottom — without
     this, <main> has no defined height (percentage heights inside it don't
     resolve), so on lighter-content screens like the upload page the footer
     ends up floating mid-page instead of pinned to the bottom edge. */
  display:flex;
  flex-direction:column;
}
#mainRoot{ flex:1; min-height:0; display:flex; flex-direction:column; overflow:hidden; }
h1,h2,h3,h4{ font-family:var(--font-head); margin:0; letter-spacing:-0.01em; }
p{ margin:0; }
button{ font-family:inherit; }
svg{ display:block; }
::selection{ background:var(--accent-1); color:#fff; }

/* The `hidden` attribute and a class-based `display` rule (e.g. `.foo{display:flex}`)
   have equal CSS specificity, so without this the later rule wins and the element
   stays visible/clickable despite `hidden` being set. Used throughout the app
   (busy overlay, app shell, tabbar, status pill, etc.), so make `hidden` always win. */
[hidden]{ display:none !important; }

.grad-text{
  background:var(--accent-grad);
  -webkit-background-clip:text; background-clip:text; color:transparent;
}
/* Gradient text-clip looks blotchy once a span wraps onto a second line
   (each line reads a different slice of the same gradient box), so longer
   headline highlights use a flat accent color instead. */
.accent-text{ color:var(--accent-1); }

.icon{ flex-shrink:0; }

/* ---------- page skeleton (fixed viewport, no page scroll) ---------- */
.topbar{
  height:var(--topbar-h);
  display:flex; align-items:center; justify-content:space-between; gap:20px;
  padding:0 22px;
  background:var(--surface);
  border-bottom:1px solid var(--border);
  flex-shrink:0;
}
.topbar-left{ display:flex; align-items:center; gap:12px; min-width:0; }
.brand{ display:flex; align-items:center; gap:9px; font-family:var(--font-head); font-weight:700; font-size:18px; }
.brand-mark{ display:flex; align-items:center; justify-content:center; width:30px; height:30px; border-radius:9px; background:var(--accent-grad); color:#fff; }
.brand-tag{ font-size:12px; color:var(--text-faint); border-left:1px solid var(--border); padding-left:12px; white-space:nowrap; }

.tabbar{ position:relative; display:flex; gap:4px; background:var(--bg-soft); padding:4px; border-radius:11px; border:1px solid var(--border); }
.tab-btn{ position:relative; z-index:1; display:flex; align-items:center; gap:7px; border:none; background:transparent; color:var(--text-soft); font-weight:600; font-size:13.5px; padding:8px 16px; border-radius:8px; cursor:pointer; transition:color .2s ease; }
.tab-btn.is-active{ color:#fff; }
.tab-btn svg{ opacity:.85; }
.tab-indicator{ position:absolute; top:4px; left:4px; height:calc(100% - 8px); width:100px; border-radius:8px; background:var(--accent-1); transition:transform .28s cubic-bezier(.65,0,.35,1), width .28s cubic-bezier(.65,0,.35,1); z-index:0; }

.topbar-right{ display:flex; align-items:center; gap:10px; }
.status-pill{ display:flex; align-items:center; gap:7px; background:var(--success-soft); color:var(--success); font-size:12.5px; font-weight:600; padding:6px 12px; border-radius:999px; }
.status-pill .dot{ width:6px; height:6px; border-radius:50%; background:var(--success); box-shadow:0 0 0 3px var(--success-soft); }
.icon-btn{ display:flex; align-items:center; justify-content:center; width:34px; height:34px; border-radius:9px; border:1px solid var(--border); background:var(--surface); color:var(--text-soft); cursor:pointer; transition:all .15s ease; }
.icon-btn:hover{ color:var(--accent-1); border-color:var(--accent-1); }

.theme-toggle{ border:none; background:none; padding:0; cursor:pointer; }
.theme-toggle-track{ display:flex; align-items:center; width:50px; height:27px; border-radius:999px; background:var(--bg-soft); border:1px solid var(--border); padding:2px; }
.theme-toggle-thumb{ display:flex; align-items:center; justify-content:center; width:21px; height:21px; border-radius:50%; background:var(--accent-1); color:#fff; transform:translateX(0); transition:transform .25s cubic-bezier(.65,0,.35,1); }
:root[data-theme="dark"] .theme-toggle-thumb{ transform:translateX(23px); background:var(--accent-2); }
.icon-sun{ display:block; } .icon-moon{ display:none; }
:root[data-theme="dark"] .icon-sun{ display:none; } :root[data-theme="dark"] .icon-moon{ display:block; }

.app-footer{ height:var(--footer-h); flex-shrink:0; display:flex; align-items:center; justify-content:center; padding:0 18px; color:var(--text-faint); font-size:11px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; border-top:1px solid var(--border); background:var(--surface); }
.app-footer a{ color:var(--text-soft); text-decoration:none; font-weight:600; }
.app-footer a:hover{ color:var(--accent-1); text-decoration:underline; }

/* ---------- buttons / inputs ---------- */
.btn{ display:inline-flex; align-items:center; gap:8px; justify-content:center; border:1px solid var(--border-strong); border-radius:10px; padding:9px 16px; font-weight:600; font-size:13.5px; cursor:pointer; transition:transform .12s ease, box-shadow .15s ease, border-color .15s ease, background .15s ease, color .15s ease; white-space:nowrap; background:var(--surface); color:var(--text); background-clip:padding-box; }
.btn:active{ transform:translateY(1px); }
.btn:disabled{ opacity:.45; cursor:not-allowed; }
.btn-primary{ background:var(--accent-1); border-color:var(--accent-1); color:#fff; }
.btn-primary:not(:disabled):hover{ background:var(--accent-1-hover); border-color:var(--accent-1-hover); box-shadow:var(--shadow-md); }
.btn-secondary{ background:var(--surface); color:var(--text); border-color:var(--border-strong); }
.btn-secondary:not(:disabled):hover{ border-color:var(--accent-1); color:var(--accent-1); }
.btn-ghost{ background:transparent; color:var(--text-soft); border-color:var(--border); }
.btn-ghost:hover{ color:var(--text); border-color:var(--border-strong); }
.btn-lg{ padding:12px 22px; font-size:14px; border-radius:11px; }
.btn-block{ width:100%; margin-top:8px; }
.btn-row{ display:flex; gap:10px; flex-wrap:wrap; margin-top:14px; flex-shrink:0; }
.btn-row-even{ flex-wrap:nowrap; }
.btn-row-even .btn{ flex:1 1 0; min-width:0; padding-left:10px; padding-right:10px; }

.input{ width:100%; background:var(--surface); border:1px solid var(--border); color:var(--text); border-radius:9px; padding:8px 11px; font-size:13.5px; font-family:inherit; transition:border-color .15s ease, box-shadow .15s ease; background-clip:padding-box; }
.input:focus{ outline:none; border-color:var(--accent-1); box-shadow:0 0 0 3px var(--accent-soft); }
.input-sm{ padding:6px 10px; width:200px; }
select.input{ appearance:none; background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23928a7c' stroke-width='1.6' fill='none'/%3E%3C/svg%3E"); background-repeat:no-repeat; background-position:right 12px center; padding-right:30px; }

.link-btn{ background:none; border:none; color:var(--accent-1); font-size:12px; font-weight:600; cursor:pointer; padding:0; }
.link-btn:hover{ text-decoration:underline; }

.slider{ -webkit-appearance:none; width:100%; height:5px; border-radius:999px; background:var(--bg-soft); outline:none; margin:6px 0 4px; }
.slider::-webkit-slider-thumb{ -webkit-appearance:none; width:15px; height:15px; border-radius:50%; background:var(--accent-1); cursor:pointer; border:2px solid var(--surface); box-shadow:0 0 0 1px var(--border-strong); }
.slider::-moz-range-thumb{ width:15px; height:15px; border-radius:50%; background:var(--accent-1); cursor:pointer; border:2px solid var(--surface); }

.switch-row{ display:flex; align-items:center; justify-content:space-between; gap:10px; font-size:13.5px; color:var(--text); padding:7px 0; cursor:pointer; }
.switch-row-label{ display:flex; align-items:center; gap:6px; }
.switch{ position:relative; display:inline-block; flex-shrink:0; }
.switch input{ position:absolute; opacity:0; width:0; height:0; }
.switch-track{ display:block; width:36px; height:21px; border-radius:999px; background:var(--bg-soft); border:1px solid var(--border-strong); transition:background .2s ease; }
.switch-thumb{ position:absolute; top:2px; left:2px; width:15px; height:15px; border-radius:50%; background:#fff; box-shadow:var(--shadow-sm); transition:transform .2s cubic-bezier(.65,0,.35,1); }
.switch input:checked + .switch-track{ background:var(--accent-1); border-color:var(--accent-1); }
.switch input:checked + .switch-track .switch-thumb{ transform:translateX(15px); }

/* ---------- tooltips ("glassy popups") ---------- */
.tip{ position:relative; display:inline-flex; align-items:center; justify-content:center; width:16px; height:16px; border-radius:50%; color:var(--text-faint); cursor:help; border:none; background:none; padding:0; }
.tip:hover, .tip:focus-visible{ color:var(--accent-1); }
.tip::after{
  content:attr(data-tip);
  position:absolute; z-index:50; left:50%; bottom:calc(100% + 9px); transform:translateX(-50%) translateY(4px);
  width:max-content; max-width:230px;
  background:color-mix(in srgb, var(--surface) 72%, transparent);
  -webkit-backdrop-filter:blur(14px) saturate(160%); backdrop-filter:blur(14px) saturate(160%);
  border:1px solid var(--border-strong); color:var(--text);
  font-size:11.5px; font-weight:500; line-height:1.5; text-align:left;
  padding:9px 11px; border-radius:9px; box-shadow:var(--shadow-lg);
  opacity:0; visibility:hidden; pointer-events:none;
  transition:opacity .15s ease, transform .15s ease;
}
.tip:hover::after, .tip:focus-visible::after{ opacity:1; visibility:visible; transform:translateX(-50%) translateY(0); }
.tip::before{
  content:''; position:absolute; z-index:50; left:50%; bottom:calc(100% + 5px); transform:translateX(-50%);
  border:5px solid transparent; border-top-color:var(--border-strong);
  opacity:0; visibility:hidden; transition:opacity .15s ease;
}
.tip:hover::before, .tip:focus-visible::before{ opacity:1; visibility:visible; }

/* ---------- upload screen ---------- */
/* The scroll container spans the full width so its scrollbar (or reserved
   track, on non-overlay scrollbar systems) sits at the true window edge.
   The centered 920px content lives in .upload-inner instead — putting
   overflow + max-width on the same element makes the scrollbar hug the
   edge of that narrow box, leaving a bare, panel-shaped gap next to it on
   wide viewports. */
.upload-screen{ flex:1; min-height:0; width:100%; overflow-y:auto; }
.upload-inner{ min-height:100%; max-width:920px; margin:0 auto; padding:48px 24px 60px; display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; }
.eyebrow{ font-size:12px; font-weight:700; letter-spacing:.07em; text-transform:uppercase; color:var(--accent-1); background:var(--accent-soft); padding:5px 13px; border-radius:999px; }
.upload-hero h1{ font-size:clamp(26px,4vw,40px); line-height:1.15; margin:18px 0 12px; font-weight:700; }
.hero-sub{ color:var(--text-soft); font-size:15px; line-height:1.6; max-width:660px; }
.upload-grid{ display:grid; grid-template-columns:1fr 1fr; gap:18px; width:100%; margin:32px 0 24px; }
@media (max-width:720px){ .upload-grid{ grid-template-columns:1fr; } }

.dropzone{ background:var(--surface); border:1.5px dashed var(--border-strong); border-radius:var(--radius); padding:24px 20px; cursor:pointer; transition:all .18s ease; text-align:left; }
.dropzone:hover{ border-color:var(--accent-1); box-shadow:var(--shadow-md); }
.dropzone.is-active{ border-color:var(--accent-2); background:var(--accent-2-soft); }
.dropzone.is-done{ border-style:solid; border-color:var(--success); }
.dz-icon{ display:flex; align-items:center; justify-content:center; width:36px; height:36px; border-radius:9px; background:var(--accent-soft); color:var(--accent-1); }
.dz-title{ font-family:var(--font-head); font-weight:700; font-size:15px; margin-top:10px; }
.dz-sub{ color:var(--text-faint); font-size:12px; margin-top:5px; line-height:1.5; }
.dz-file{ margin-top:12px; font-size:12px; font-weight:600; color:var(--accent-1); background:var(--bg-soft); border-radius:7px; padding:7px 9px; font-family:var(--font-mono); word-break:break-all; }
.dropzone.is-done .dz-file{ color:var(--success); }

.upload-progress{ width:100%; max-width:420px; margin-top:20px; }
.progress-bar{ height:7px; border-radius:999px; background:var(--bg-soft); overflow:hidden; }
.progress-fill{ height:100%; width:0%; border-radius:999px; background:var(--accent-1); transition:width .3s ease; }
.progress-label{ margin-top:8px; font-size:12px; color:var(--text-faint); }

.upload-messages{ width:100%; max-width:640px; display:flex; flex-direction:column; gap:8px; margin-top:16px; }
.msg{ font-size:12.5px; text-align:left; padding:10px 14px; border-radius:9px; line-height:1.5; }
.msg-info{ background:var(--accent-2-soft); color:var(--text); }
.msg-warn{ background:var(--warning-soft); color:#7a5209; }
:root[data-theme="dark"] .msg-warn{ color:#f0b95c; }
.msg-error{ background:var(--danger-soft); color:#8a2e20; }
:root[data-theme="dark"] .msg-error{ color:#ff9a87; }

.template-help{ margin-top:30px; max-width:640px; }
.template-help-title{ font-weight:700; font-size:14px; color:var(--text); }
.template-help-sub{ margin-top:4px; font-size:12.5px; color:var(--text-faint); line-height:1.5; }
.template-btn-row{ display:flex; gap:10px; flex-wrap:wrap; justify-content:center; margin-top:14px; }
.format-help{ margin-top:20px; color:var(--text-soft); font-size:13px; }
.format-help summary{ cursor:pointer; font-weight:600; color:var(--accent-1); }
.format-help-body{ text-align:left; margin-top:10px; line-height:1.6; }

/* ---------- app shell ---------- */
.app-shell{ display:flex; flex:1; min-height:0; overflow:hidden; }
.sidebar{ width:296px; flex-shrink:0; border-right:1px solid var(--border); background:var(--surface); transition:width .22s ease; overflow:hidden; }
.app-shell.sidebar-collapsed .sidebar{ width:0; border-right-color:transparent; }
.sidebar-scroll{ width:296px; padding:18px 18px 24px; overflow-y:auto; height:100%; }
.sidebar-collapse{ position:relative; align-self:center; width:20px; height:44px; margin-left:-1px; z-index:10; border-radius:0 9px 9px 0; border:1px solid var(--border); border-left:none; background:var(--surface); color:var(--text-soft); display:flex; align-items:center; justify-content:center; cursor:pointer; flex-shrink:0; }
.app-shell.sidebar-collapsed .sidebar-collapse svg{ transform:rotate(180deg); }

.side-section{ padding:15px 0; border-bottom:1px solid var(--border); }
.side-section:first-child{ padding-top:0; }
.side-section:last-child{ border-bottom:none; }
.side-title{ display:flex; align-items:center; gap:6px; font-size:11px; font-weight:700; letter-spacing:.06em; text-transform:uppercase; color:var(--text-faint); margin-bottom:11px; }
.field-label{ display:flex; align-items:center; gap:6px; font-size:12.5px; font-weight:600; color:var(--text-soft); margin:11px 0 6px; }
.field-label:first-of-type{ margin-top:0; }
.field-label-val{ margin-left:auto; }
.field-value{ font-family:var(--font-mono); color:var(--accent-1); font-weight:600; font-size:11.5px; }

.multiselect{ margin-top:6px; }
.multiselect-actions{ display:flex; align-items:center; gap:10px; margin:8px 0; }
.ms-count{ margin-left:auto; font-size:11px; color:var(--text-faint); }
.multiselect-list{ max-height:180px; overflow-y:auto; border:1px solid var(--border); border-radius:9px; padding:5px; background:var(--surface); }
.ms-item{ display:flex; align-items:center; gap:8px; padding:6px 8px; border-radius:6px; font-size:13px; cursor:pointer; }
.ms-item:hover{ background:var(--bg-soft); }
.ms-item input{ accent-color:var(--accent-1); }

/* ---------- content / tabs (fit-to-viewport) ---------- */
.content{ flex:1; min-width:0; padding:18px 24px; display:flex; flex-direction:column; overflow:hidden; }
.tab-panel{ display:none; flex-direction:column; height:100%; min-height:0; }
.tab-panel.is-active{ display:flex; }
.panel-head{ margin-bottom:14px; flex-shrink:0; display:flex; align-items:baseline; justify-content:space-between; gap:16px; flex-wrap:wrap; }
.panel-head h2{ font-size:19px; font-weight:700; }
.panel-sub{ color:var(--text-faint); font-size:12.5px; margin-top:3px; }

/* ---------- stat cards ---------- */
.stat-grid{ display:grid; grid-template-columns:repeat(6,1fr); gap:12px; margin-bottom:14px; flex-shrink:0; }
@media (max-width:1200px){ .stat-grid{ grid-template-columns:repeat(3,1fr); } }
@media (max-width:640px){ .stat-grid{ grid-template-columns:repeat(2,1fr); } }
.stat-card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:14px 16px; transition:border-color .15s ease, box-shadow .15s ease; }
.stat-card:hover{ border-color:var(--border-strong); box-shadow:var(--shadow-sm); }
.stat-icon{ display:flex; align-items:center; justify-content:center; width:28px; height:28px; border-radius:8px; background:var(--accent-soft); color:var(--accent-1); }
.stat-value{ font-family:var(--font-head); font-size:22px; font-weight:700; margin-top:9px; }
.stat-label{ font-size:11.5px; color:var(--text-faint); margin-top:1px; font-weight:500; }

/* ---------- cards / tables ---------- */
.card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:16px; box-shadow:var(--shadow-sm); }
.card-flex{ flex:1; min-height:0; display:flex; flex-direction:column; margin-bottom:0; }
.card-head{ display:flex; align-items:center; justify-content:space-between; gap:14px; margin-bottom:12px; flex-wrap:wrap; flex-shrink:0; }
.card-head-actions{ display:flex; align-items:center; gap:10px; }
.side-hint{ font-size:11px; color:var(--text-faint); margin-top:8px; line-height:1.5; }
.card-head h3{ font-size:14px; font-weight:700; }

.table-scroll{ overflow:auto; flex:1; min-height:0; border-radius:9px; border:1px solid var(--border); }
table.data-table{ border-collapse:collapse; width:100%; font-size:12.5px; }
table.data-table thead th{ position:sticky; top:0; background:var(--bg-soft); color:var(--text-soft); text-align:left; font-weight:700; padding:9px 12px; border-bottom:1px solid var(--border); white-space:nowrap; z-index:1; }
table.data-table tbody td{ padding:8px 12px; border-bottom:1px solid var(--border); white-space:nowrap; color:var(--text); }
table.data-table tbody tr:hover{ background:var(--bg-soft); }
table.data-table tbody tr:last-child td{ border-bottom:none; }
.badge{ display:inline-block; padding:2px 8px; border-radius:999px; font-size:11px; font-weight:700; }
.badge-warn{ background:var(--warning-soft); color:#7a5209; }
:root[data-theme="dark"] .badge-warn{ color:#f0b95c; }
.badge-ok{ background:var(--success-soft); color:var(--success); }

.table-pager{ display:flex; align-items:center; justify-content:center; gap:12px; margin-top:10px; font-size:12.5px; color:var(--text-soft); flex-shrink:0; }
.table-pager button{ display:flex; align-items:center; gap:4px; border:1px solid var(--border-strong); background:var(--surface); color:var(--text); border-radius:8px; padding:5px 12px; cursor:pointer; }
.table-pager button:disabled{ opacity:.4; cursor:not-allowed; }

/* ---------- map ---------- */
.map-dual-grid{ display:grid; grid-template-columns:1fr 1fr; gap:14px; flex:1; min-height:0; }
@media (max-width:960px){ .map-dual-grid{ grid-template-columns:1fr; } }
.map-card{ padding:0; overflow:hidden; display:flex; flex-direction:column; min-height:0; }
.map-pane-head{ display:flex; align-items:center; justify-content:space-between; padding:10px 14px; border-bottom:1px solid var(--border); flex-shrink:0; }
.map-pane-title{ font-family:var(--font-head); font-weight:700; font-size:13px; color:var(--text); }
.map-pane-toggle{ padding:0; gap:8px; }
.map-pane-toggle .switch-row-label{ font-size:12px; color:var(--text-soft); font-weight:600; }
#mapOriginal, #mapOptimized{ width:100%; flex:1; min-height:0; }
.leaflet-container{ background:var(--bg-soft); font-family:var(--font-body); }
.leaflet-popup-content-wrapper{ border-radius:10px; }
.legend-row{ display:flex; gap:18px; margin-top:10px; flex-wrap:wrap; flex-shrink:0; font-size:12px; }
.legend-item{ display:flex; align-items:center; gap:7px; color:var(--text-soft); }
.legend-dot{ width:9px; height:9px; border-radius:50%; display:inline-block; }
.legend-line{ width:16px; height:3px; border-radius:2px; display:inline-block; }
.legend-line-orig{ background:#8a8378; }
.legend-line-opt{ background:var(--accent-1); }
.legend-dot-point{ background:var(--accent-1); }

/* ---------- optimize tab ---------- */
.compare-grid{ display:grid; grid-template-columns:repeat(3,1fr); gap:14px; margin-bottom:14px; flex-shrink:0; }
@media (max-width:900px){ .compare-grid{ grid-template-columns:1fr; } }
.compare-card h4{ font-size:12.5px; color:var(--text-soft); margin-bottom:12px; font-weight:700; }
.compare-bars{ display:flex; flex-direction:column; gap:9px; }
.cbar-row{ display:flex; align-items:center; gap:10px; }
.cbar-label{ width:60px; font-size:11px; color:var(--text-faint); font-weight:600; flex-shrink:0; }
.cbar-track{ flex:1; height:12px; border-radius:999px; background:var(--bg-soft); overflow:hidden; }
.cbar-fill{ height:100%; border-radius:999px; width:0%; transition:width .8s cubic-bezier(.22,1,.36,1); }
.cbar-fill.orig{ background:#a9a196; }
.cbar-fill.opt{ background:var(--accent-1); }
.cbar-num{ width:82px; text-align:right; font-family:var(--font-mono); font-size:11.5px; font-weight:600; flex-shrink:0; }

.tables-row{ display:grid; grid-template-columns:1fr 1fr; gap:14px; flex:1; min-height:0; }
@media (max-width:1000px){ .tables-row{ grid-template-columns:1fr; } }

/* ---------- report ---------- */
#tab-reports .content{ overflow:hidden; }
.report-preview-card{ flex:1; min-height:0; padding:20px; display:flex; justify-content:center; background:var(--bg-soft); border-radius:var(--radius); overflow-y:auto; }
.report-doc{ width:100%; max-width:760px; background:var(--surface); color:var(--text); border-radius:6px; box-shadow:var(--shadow-lg); padding:44px 48px; height:fit-content; }
.report-empty{ color:var(--text-faint); text-align:center; padding:60px 0; font-size:14px; }
.report-doc h1{ font-family:var(--font-head); font-size:22px; margin-bottom:2px; }
.report-doc .report-date{ color:var(--text-faint); font-size:12px; margin-bottom:22px; }
.report-doc h2{ font-size:13.5px; margin:22px 0 10px; padding-bottom:7px; border-bottom:2px solid var(--accent-1); }
.report-doc table{ width:100%; border-collapse:collapse; font-size:11.5px; margin-bottom:10px; }
.report-doc th{ text-align:left; background:var(--bg-soft); padding:6px 9px; font-weight:700; }
.report-doc td{ padding:6px 9px; border-bottom:1px solid var(--border); }
.report-kpis{ display:grid; grid-template-columns:repeat(4,1fr); gap:10px; margin:12px 0 4px; }
.report-kpi{ border:1px solid var(--border); border-radius:8px; padding:9px 11px; }
.report-kpi .k-label{ font-size:10px; color:var(--text-faint); text-transform:uppercase; letter-spacing:.04em; }
.report-kpi .k-value{ font-family:var(--font-head); font-size:17px; font-weight:700; margin-top:2px; }
.report-footer{ margin-top:28px; padding-top:12px; border-top:1px solid var(--border); font-size:10.5px; color:var(--text-faint); }
.report-footer a{ color:var(--text-soft); }
.report-muted{ color:var(--text-faint); font-size:12.5px; }

@media print{
  /* The report must print as a plain white document even when the app is
     in dark mode — dark-theme values are set on :root via [data-theme],
     which is unaffected by print media on its own, so force the light
     values here regardless of which theme is currently active on screen. */
  :root{
    --surface:#ffffff !important; --bg-soft:#eceef2 !important;
    --text:#151920 !important; --text-soft:#5a6270 !important; --text-faint:#8991a0 !important;
    --border:#e2e5eb !important; --accent-1:#e2660f !important;
  }
  body{ background:#ffffff !important; }
  body *{ visibility:hidden; }
  .report-doc, .report-doc *{ visibility:visible; }
  .report-doc{ position:absolute; inset:0; box-shadow:none; max-width:none; margin:0; border-radius:0; height:auto; background:#ffffff !important; }
  .topbar, .sidebar, .sidebar-collapse, .app-footer, .toast-stack, .busy-overlay, .report-preview-card{ display:none !important; }
  .report-preview-card{ display:block !important; overflow:visible; background:#ffffff !important; }
}

/* ---------- toasts / busy ---------- */
.toast-stack{ position:fixed; bottom:20px; right:20px; z-index:200; display:flex; flex-direction:column; gap:10px; }
.toast{ background:var(--surface); border:1px solid var(--border); box-shadow:var(--shadow-lg); border-radius:11px; padding:11px 15px; font-size:13px; max-width:340px; animation:toastIn .25s cubic-bezier(.22,1,.36,1) both; }
.toast.warn{ border-left:3px solid var(--warning); }
.toast.error{ border-left:3px solid var(--danger); }
.toast.success{ border-left:3px solid var(--success); }
@keyframes toastIn{ from{ opacity:0; transform:translateX(30px);} to{ opacity:1; transform:translateX(0);} }

.busy-overlay{ position:fixed; inset:0; background:rgba(23,20,16,0.4); z-index:300; display:flex; align-items:center; justify-content:center; }
.busy-card{ background:var(--surface); border-radius:14px; padding:24px 32px; display:flex; flex-direction:column; align-items:center; gap:13px; box-shadow:var(--shadow-lg); font-size:13.5px; font-weight:600; color:var(--text-soft); border:1px solid var(--border); }
.spinner{ width:30px; height:30px; border-radius:50%; border:3px solid var(--bg-soft); border-top-color:var(--accent-1); animation:spin .8s linear infinite; }
@keyframes spin{ to{ transform:rotate(360deg); } }

/* scrollbars */
::-webkit-scrollbar{ width:9px; height:9px; }
::-webkit-scrollbar-track{ background:transparent; }
::-webkit-scrollbar-thumb{ background:var(--border-strong); border-radius:999px; }
::-webkit-scrollbar-thumb:hover{ background:var(--text-faint); }
