:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1c2330;
  --muted: #5b6573;
  --line: #dde2e8;
  --accent: #2563eb;
  --danger: #dc2626;
  --warn-bg: #fff7e6;
  --warn-ink: #8a5a00;
  --err-bg: #fdecec;
  --err-ink: #8f1d1d;
  --ok-bg: #e9f8ee;
  --ok-ink: #166534;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 6px; padding: 5px 10px; }
button:hover { border-color: #b9c2cf; background: #f3f5f8; }
button.danger { color: var(--danger); }
button.danger:hover { background: #fdecec; border-color: #f1b3b3; }
button.icon { padding: 2px 6px; border: none; background: transparent; color: var(--muted); }
button.icon:hover { color: var(--ink); background: #eef1f5; }
select, input[type=number], input[type=text] { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
input[type=number] { width: 100px; text-align: right; }
input.invalid { border-color: var(--danger); background: #fff5f5; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #eef1f5; padding: 1px 4px; border-radius: 4px; }

.topbar { display: flex; align-items: center; justify-content: flex-start; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand .sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-left: auto; }
.status { color: var(--muted); font-size: 12px; margin-left: 8px; }

/* Interface language, same segmented look as the mode toggle but header-sized */
.lang-toggle { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-left: 4px; }
.lang-toggle .lang-btn { border: none; border-radius: 0; background: #fff; color: var(--muted); padding: 5px 9px; font-size: 12px; font-weight: 600; letter-spacing: 0.02em; }
.lang-toggle .lang-btn + .lang-btn { border-left: 1px solid var(--line); }
.lang-toggle .lang-btn.on { background: var(--accent); color: #fff; }

.banner { margin: 10px 16px 0; padding: 8px 12px; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid #f3d9a4; border-radius: var(--radius); }
.selftest { margin: 10px 16px 0; padding: 10px 12px; background: #111827; color: #d1fae5; border-radius: var(--radius); font-size: 12px; max-height: 320px; overflow: auto; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 12px 16px 40px; align-items: start; }
.sidebar, .inputs, .results { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
/* Entries drawer (off-canvas, toggled by the hamburger) */
.sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 320px; max-width: 90vw; z-index: 30; border-radius: 0; border-width: 0 1px 0 0;
  box-shadow: 0 0 24px rgba(0,0,0,0.12); overflow: auto; transform: translateX(-105%); transition: transform 0.16s ease-out; padding: 12px 14px; }
body.sidebar-open .sidebar { transform: none; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.28); z-index: 29; }
.backdrop[hidden] { display: none; }
.hamburger { position: relative; font-size: 18px; line-height: 1; padding: 4px 9px; margin-right: 4px; }
.menu-badge { position: absolute; top: -6px; right: -6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 10px; line-height: 16px; text-align: center; font-weight: 600; }
.menu-badge:empty { display: none; }
.current-entry { display: flex; align-items: center; gap: 8px; max-width: 320px; text-align: left; margin: 0; padding: 6px 10px; background: #f3f5f8; border: 1px dashed var(--line); }
.current-entry:hover { background: #eef1f5; }
.current-entry .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.current-entry .lbl { color: var(--muted); font-size: 12px; }
.current-entry .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.current-entry .tag { font-size: 10px; padding: 1px 5px; border-radius: 8px; background: #e5e7eb; color: var(--muted); text-transform: uppercase; margin-left: 4px; white-space: nowrap; }
.current-entry .tag.rev { background: #ede9fe; color: #5b21b6; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.entry-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.entry { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; border: 1px solid transparent; cursor: pointer; min-width: 0; }
.entry:hover { background: #f3f5f8; }
.entry.selected { border-color: var(--accent); background: #eef3ff; }
.entry input[type=color] { width: 20px; height: 20px; padding: 0; border: none; background: none; cursor: pointer; }
.entry .name { overflow: hidden; overflow-wrap: anywhere; line-height: 1.25; font-size: 13px; }
.entry .name.hidden-entry { color: var(--muted); text-decoration: line-through; }
.entry .tools { display: flex; align-items: center; gap: 2px; }
.entry .vis { cursor: pointer; font-size: 13px; }
.entry .vis input { display: none; }
.entry .vis span { opacity: 0.35; }
.entry .vis input:checked + span { opacity: 1; }
.entry .tag { font-size: 10px; padding: 1px 5px; border-radius: 8px; background: #eef1f5; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.entry .tag.rev { background: #ede9fe; color: #5b21b6; }

.mode-toggle { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin: 0; }
.mode-toggle .seg { flex: 1; border: none; border-radius: 0; background: #fff; padding: 6px 10px; color: var(--muted); white-space: nowrap; }
.mode-toggle .seg + .seg { border-left: 1px solid var(--line); }
.mode-toggle .seg.active { background: var(--accent); color: #fff; }
.summary { font-size: 12px; color: var(--muted); background: #f3f5f8; border-radius: 6px; padding: 6px 8px; margin: 10px 0 0; min-height: 28px; line-height: 1.4; }
.summary .bad { color: var(--danger); }

.inputs-top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
#inputForm { display: contents; }
.main-fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 14px; flex: 1 1 420px; }
.field { display: flex; flex-direction: column; gap: 2px; }
.field .label { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.field .ctl { display: flex; align-items: center; gap: 4px; }
.field .unit { font-size: 11px; color: var(--muted); white-space: nowrap; }
.field input[type=number] { width: 88px; }
.field select { max-width: 230px; }
.field[hidden] { display: none; }
.adv-tabs { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.adv-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.adv-tab { font-size: 12.5px; padding: 3px 10px; border-radius: 14px; color: var(--muted); }
.adv-tab::after { content: " ▸"; font-size: 10px; }
.adv-tab.on { background: #eef3ff; border-color: var(--accent); color: var(--accent); }
.adv-tab.on::after { content: " ▾"; }
.adv-panel { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 14px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #f8f9fb; }
.adv-panel[hidden] { display: none; }

.warnings { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.warnings:empty { display: none; }
.warnings .flag { padding: 6px 10px; border-radius: 6px; font-size: 13px; line-height: 1.4; }
.warnings .flag .range { display: inline-block; min-width: 84px; font-variant-numeric: tabular-nums; font-weight: 600; margin-right: 6px; }
.warnings .flag.error { background: var(--err-bg); color: var(--err-ink); }
.warnings .flag.warn { background: var(--warn-bg); color: var(--warn-ink); }
.warnings .ok { background: var(--ok-bg); color: var(--ok-ink); padding: 6px 10px; border-radius: 6px; font-size: 13px; }
.warnings .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin: 4px 0 8px; align-items: center; }
.legend .sw { display: inline-block; width: 22px; height: 3px; vertical-align: middle; margin-right: 6px; border-radius: 2px; }
.legend .item { white-space: nowrap; }
.legend .key { color: var(--muted); }
.legend .key.note { flex-basis: 100%; color: var(--warn-ink); background: var(--warn-bg); border-radius: 6px; padding: 4px 8px; line-height: 1.4; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.chart-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px 6px; background: #fff; min-width: 0; }
.chart-card[hidden] { display: none; }
.chart-card h3 { font-size: 13px; }
.chart-sub { font-size: 11px; color: var(--muted); margin: 2px 0 4px; }
.chart-readout { min-height: 46px; font-size: 12px; line-height: 1.45; color: var(--muted); background: #f3f5f8; border-radius: 6px; padding: 5px 8px; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.chart-readout.active { color: var(--ink); }
.chart-readout .ro-x { font-weight: 600; padding-bottom: 3px; margin-bottom: 3px; border-bottom: 1px solid var(--line); }
.chart-readout .ro-entry { display: grid; grid-template-columns: 11px minmax(0, 1fr) auto; align-items: baseline; gap: 0 6px; padding: 1px 0; }
.chart-readout .ro-entry + .ro-entry { border-top: 1px dotted var(--line); }
.chart-readout .ro-dot { width: 9px; height: 9px; border-radius: 50%; align-self: center; }
.chart-readout .ro-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-readout .ro-vals { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0 10px; white-space: nowrap; }
.chart-readout .ro-val + .ro-val { position: relative; }
.chart-readout .ro-val + .ro-val::before { content: "·"; color: var(--muted); position: absolute; left: -6px; }
.chart-wrap { position: relative; height: 250px; }

.table-wrap { margin-top: 4px; margin-bottom: 14px; }
.table-wrap.details { margin-top: 16px; }
.table-wrap.details > summary { cursor: pointer; list-style: none; }
.table-wrap.details > summary::-webkit-details-marker { display: none; }
.table-wrap.details > summary h2 { display: inline-flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.table-wrap.details > summary h2::before { content: "▸"; color: var(--muted); margin-right: 2px; }
.table-wrap.details[open] > summary h2::before { content: "▾"; }
.table-wrap.details > summary .hint { font-weight: 400; margin: 0; }
.table-head h2 .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 5px 0 2px; vertical-align: middle; }
.length-scroll { overflow-x: auto; }
.results-table.length-table thead th { position: static; }
.length-table th .unit { display: block; font-weight: 400; font-size: 10.5px; color: var(--muted); }
.results-table.length-table td:first-child, .results-table.length-table th:first-child { font-weight: 600; position: static; }
.length-table tr.infeasible td { color: #9aa3af; background: #fafbfc; }
.length-table td.notes { text-align: left; }
.length-table td.notes .badge { white-space: nowrap; }
.length-table tbody td { padding: 5px 8px; }
.table-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 6px; flex-wrap: wrap; }
.table-head select { padding: 2px 6px; }
.results-table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.results-table th, .results-table td { border-bottom: 1px solid var(--line); padding: 4px 8px; text-align: right; white-space: nowrap; }
.results-table th:first-child, .results-table td:first-child { text-align: left; position: sticky; left: 0; background: #fff; }
.results-table thead th { position: sticky; top: 58px; background: #fff; z-index: 1; }
.results-table thead th .mode { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.results-table thead th .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.results-table tr.section td { background: #f3f5f8; font-weight: 600; text-align: left; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; padding-top: 8px; }
.results-table td.infeasible { color: #9aa3af; background: #fafbfc; }
.results-table td .unit { color: var(--muted); font-size: 11px; margin-left: 3px; }
.badge { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 8px; margin: 1px 2px 1px 0; }
.badge.error { background: var(--err-bg); color: var(--err-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.ok { background: var(--ok-bg); color: var(--ok-ink); }

.notes { margin-top: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.notes summary { cursor: pointer; color: var(--ink); font-weight: 600; }
.notes ul { padding-left: 18px; }

.empty { color: var(--muted); font-size: 13px; padding: 8px; }

@media (max-width: 1100px) {
  .layout { gap: 10px; padding: 10px 10px 30px; }
}
.chart-card h3 select { font-size: 12.5px; padding: 1px 4px; margin: 0 2px; vertical-align: baseline; }
.length-table th.has-tip { cursor: help; }
.tip-bubble { position: absolute; z-index: 40; max-width: 300px; background: #1c2330; color: #f3f5f8; border-radius: 8px; padding: 8px 11px; font-size: 12px; line-height: 1.45; box-shadow: 0 6px 20px rgba(0,0,0,0.18); pointer-events: none; font-weight: 400; text-align: left; white-space: normal; }
.tip-bubble[hidden] { display: none; }
.tip-bubble::before { content: ""; position: absolute; top: -6px; left: var(--arrow-x, 50%); margin-left: -6px; border: 6px solid transparent; border-top: none; border-bottom-color: #1c2330; }
.tip-bubble .tip-head { font-weight: 600; margin-bottom: 3px; color: #fff; }
.tip-bubble .tip-body { color: #dde2e8; }
.length-table th .better { font-weight: 600; }
.length-table th .better.lower { color: #166534; }
.length-table th .better.higher { color: #1d4ed8; }
.dialog { position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, 0.35); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog[hidden] { display: none; }
.dialog-box { background: var(--panel); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,0.25); padding: 16px 18px; width: min(440px, 100%); }
.dialog-box h2 { font-size: 15px; margin-bottom: 6px; }
.dialog-msg { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.45; white-space: pre-line; }
.dialog-box input[type=text] { width: 100%; margin-bottom: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.dialog-actions button.primary.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.dialog-actions button.primary:hover { filter: brightness(0.95); }
.band-legend { display: flex; flex-wrap: wrap; gap: 3px 12px; font-size: 11px; color: var(--muted); margin: 0 0 5px; }
.band-legend .bl-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.band-legend .bl-item.bl-danger { color: var(--danger); font-weight: 600; }
.band-legend .bl-sw { width: 16px; height: 10px; border-radius: 3px; border: 1px solid; flex: none; }
