:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #dde2ea;
  --text: #111827;
  --muted: #5b6474;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --accent-soft: #e6edff;
  --warn-bg: #fff6e0;
  --warn-text: #7a4b00;
  --ok: #0f7b4d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131b;
    --surface: #161d28;
    --surface-2: #1d2634;
    --border: #2b3647;
    --text: #e8edf5;
    --muted: #9aa6b8;
    --accent: #7aa2ff;
    --accent-ink: #0b1220;
    --accent-soft: #1c2a4a;
    --warn-bg: #3a2c0c;
    --warn-text: #ffd98a;
    --ok: #4ade80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
a { color: var(--accent); }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -.01em; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 4px 16px; min-height: 60px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px; }
.brand svg { flex: none; }
.nav { display: flex; gap: 18px; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--text); }

/* Hero */
.hero { padding-top: 28px; padding-bottom: 18px; }
.hero h1 { font-size: clamp(26px, 3.4vw, 36px); margin: 0 0 8px; }
.hero p { margin: 0; color: var(--muted); max-width: 760px; font-size: 16px; }

/* Layout */
.app { display: grid; grid-template-columns: minmax(0, 470px) minmax(0, 1fr); gap: 20px; align-items: start; padding-bottom: 32px; }
@media (max-width: 980px) { .app { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-body { padding: 16px; }

/* Form controls */
label.field { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
select, input[type="number"], input[type="text"], input[type="email"], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 10px; margin-top: 4px; min-width: 0;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; background: var(--surface); color: var(--muted); border: 0; padding: 6px 12px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.btn { font: inherit; font-weight: 600; font-size: 14px; border-radius: 8px; padding: 9px 14px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-sm { padding: 5px 10px; font-size: 13px; font-weight: 500; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }

/* Cargo items */
.items { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.item { border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px 12px; background: var(--surface-2); }
.item-top { display: flex; gap: 8px; align-items: center; }
.swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; border: 1px solid rgba(0,0,0,.15); }
.item-top input[type="text"] { margin: 0; font-weight: 600; background: transparent; border-color: transparent; padding: 4px 6px; }
.item-top input[type="text"]:hover { border-color: var(--border); }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 18px; line-height: 1; }
.icon-btn:hover { background: var(--surface); color: var(--text); }
.item-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 6px; }
.item-grid label { font-size: 12px; }
.item-opts { display: flex; gap: 14px; align-items: center; margin-top: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.item-opts select { width: auto; margin: 0 0 0 6px; padding: 4px 8px; font-size: 13px; }
.item-opts label { display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 520px) { .item-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* Viewer */
.viewer-wrap { position: relative; }
.viewer { height: 440px; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; background: var(--surface-2); }
.viewer canvas { display: block; width: 100% !important; height: 100% !important; touch-action: none; }
@media (max-width: 600px) { .viewer { height: 320px; } }
.view-tools { position: absolute; left: 12px; top: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.view-tools .btn { background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(4px); }
.legend-door { position: absolute; right: 12px; bottom: 10px; font-size: 12px; color: var(--muted); }
.steps { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.steps input[type="range"] { flex: 1; accent-color: var(--accent); }
.steps output { font-size: 13px; color: var(--muted); min-width: 110px; text-align: right; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px 0; scrollbar-width: thin; }
.tabs button { font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--text); border-color: var(--accent); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
.kpi { background: var(--surface); padding: 14px 16px; }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .s { font-size: 12px; color: var(--muted); }
@media (max-width: 700px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.panel.results > .kpis:first-child .kpi:first-child { border-top-left-radius: var(--radius); }

.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 520px) { .meters { grid-template-columns: 1fr; } }
.meter .lbl { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.meter .lbl b { color: var(--text); font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; border: 1px solid var(--border); }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
tr.best td { background: var(--accent-soft); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); margin-left: 6px; vertical-align: 1px; }
.notice { background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin: 0 0 12px; }
.hint { font-size: 13px; color: var(--muted); }
.stack-gap > * + * { margin-top: 16px; }
.results-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* Content */
.content { padding-top: 12px; padding-bottom: 48px; }
.content .prose { max-width: 820px; }
.prose h2 { font-size: 24px; margin: 36px 0 10px; }
.prose h3 { font-size: 17px; margin: 22px 0 6px; }
.prose p, .prose li { color: var(--text); }
.prose .lead { color: var(--muted); font-size: 16px; }
details { border-bottom: 1px solid var(--border); padding: 12px 0; }
summary { cursor: pointer; font-weight: 600; }
details p { margin: 8px 0 0; color: var(--muted); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--text); }
.card b { display: block; margin-bottom: 4px; }
.card span { color: var(--muted); font-size: 14px; }

.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding-top: 22px; padding-bottom: 22px; font-size: 13px; color: var(--muted); }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.site-footer a { color: var(--muted); margin-right: 14px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

@media print {
  .site-header, .site-footer, .content, .view-tools, .steps, .tabs, #cargo-panel .btn, .no-print { display: none !important; }
  body { background: #fff; }
  .app { grid-template-columns: 1fr; }
  .viewer { height: 360px; }
}
.nav { gap: 6px 18px; }
@media (max-width: 600px) {
  table { font-size: 13px; }
  th, td { padding: 7px 6px; }
}
