/* Dimensional Weight Calculator */

:root {
    --bg: #eef4fb;
    --surface: #ffffff;
    --surface-2: #f5f8fc;
    --text: #15202d;
    --muted: #5a6677;
    --border: #dbe4ef;
    --brand: #1b4b78;
    --brand-2: #2a6aa0;
    --accent: #1e8a3a;          /* action green, AA on white */
    --accent-hover: #17732f;
    --danger: #c23b4b;
    --focus: #2a78d6;

    --dim-l: #2a78d6;
    --dim-w: #d06a1f;
    --dim-h: #2f9e6b;
    --box-stroke: #6b4a26;
    --tape: rgba(240, 222, 190, .85);
    --bar: #9fb3c8;
    --bar-dim: #e07b39;
    --actual: #15202d;

    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
    --maxw: 1180px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e1520;
        --surface: #16202d;
        --surface-2: #1c2836;
        --text: #e6edf5;
        --muted: #9aa8b8;
        --border: #2a3849;
        --accent: #2fae52;
        --accent-hover: #3cc461;
        --focus: #6aa8f0;
        --dim-l: #6aa8f0;
        --dim-w: #f0a060;
        --dim-h: #5cc79a;
        --box-stroke: #3d2a14;
        --bar: #4c6178;
        --bar-dim: #f0904f;
        --actual: #e6edf5;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    }
}
:root[data-theme="dark"] {
    --bg: #0e1520; --surface: #16202d; --surface-2: #1c2836; --text: #e6edf5; --muted: #9aa8b8;
    --border: #2a3849; --accent: #2fae52; --accent-hover: #3cc461; --focus: #6aa8f0;
    --dim-l: #6aa8f0; --dim-w: #f0a060; --dim-h: #5cc79a; --box-stroke: #3d2a14;
    --bar: #4c6178; --bar-dim: #f0904f; --actual: #e6edf5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: "Source Sans 3", "Source Sans Pro", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--brand-2); }
img { vertical-align: middle; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.unit { color: var(--muted); font-weight: 400; font-size: .85em; }

/* ── Header / footer ───────────────────────────────── */
.site-header {
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-2) 100%);
    color: #fff;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 14px; padding-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.25rem; }
.brand-mark { width: 32px; height: 32px; flex: none; }
.header-links, .footer-links { display: flex; gap: 8px; flex-wrap: wrap; }
.header-links a, .footer-links a, .footer-links button {
    display: inline-flex; align-items: center; gap: 6px;
    color: #fff; text-decoration: none; font-size: .9rem;
    padding: 5px 10px; border: 1px solid rgba(255, 255, 255, .35); border-radius: 999px;
    background: transparent; cursor: pointer;
}
.header-links a:hover, .footer-links a:hover, .footer-links button:hover { background: rgba(255, 255, 255, .14); }
.header-links img, .footer-links img { height: 16px; width: auto; }

.site-footer { background: linear-gradient(180deg, var(--brand) 0%, var(--brand-2) 100%); color: #fff; margin-top: 32px; }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 18px; padding-bottom: 18px; }
.footer-inner p { margin: 0; font-weight: 600; }

/* ── Cards / panels ────────────────────────────────── */
main { padding-top: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 18px; margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 1.25rem; }
h3.sub { font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; }
h3.sub:first-child { margin-top: 0; }

.top-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 20px; align-items: start; }
.top-grid .panel { margin-bottom: 0; }
.top-grid + * { margin-top: 20px; }

/* ── Forms ─────────────────────────────────────────── */
.field-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 600; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }
.field-wide { grid-column: 1 / -1; }
.field input, .field textarea {
    width: 100%; min-width: 0;
    padding: 9px 10px; border: 1px solid var(--border); border-radius: 9px;
    background: var(--surface-2); font-size: 1.05rem; font-weight: 600;
}
.field input::placeholder { color: var(--muted); font-weight: 400; font-size: .95rem; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.form-error { min-height: 1.3em; margin: 6px 0 0; color: var(--danger); font-size: .9rem; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 3px; background: var(--surface-2); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 4px 12px; border-radius: 999px; font-size: .9rem; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg input:checked + span { background: var(--brand-2); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
    font-weight: 700; cursor: pointer; background: none;
}
.btn-sm { padding: 6px 12px; font-size: .9rem; }
.btn-primary { background: var(--accent); color: #fff; flex: 1 1 auto; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-outline { border-color: var(--accent); color: var(--accent); }
.btn-outline:hover:not(:disabled) { background: var(--accent); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; margin-left: auto; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ── Live preview ──────────────────────────────────── */
.preview { margin-top: 6px; border: 1px dashed var(--border); border-radius: 12px; background: var(--surface-2); }
.preview .box-svg { cursor: grab; touch-action: none; height: 240px; }
.preview .box-svg:active { cursor: grabbing; }
.preview.is-empty .box-svg { height: 120px; }
.preview-meta { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 0; padding: 0 12px 10px; font-size: .9rem; }
.preview-meta .hint { color: var(--muted); }
.preview.is-empty .hint { display: none; }

/* ── Box drawing (SVG) ─────────────────────────────── */
.box-svg { display: block; width: 100%; height: auto; overflow: visible; }
.box-face { stroke: var(--box-stroke); stroke-width: 1.2; stroke-linejoin: round; }
.box-tape { fill-opacity: .92; stroke: rgba(70, 40, 10, .35); stroke-width: .6; stroke-linejoin: round; }
.box-tape-gloss { stroke: rgba(255, 240, 215, .45); stroke-width: 1; }
.box-shadow { fill: rgba(0, 0, 0, .12); filter: blur(3px); }
.dim-edge { stroke-width: 3; stroke-linecap: round; }
.dim-edge.dim-l { stroke: var(--dim-l); }
.dim-edge.dim-w { stroke: var(--dim-w); }
.dim-edge.dim-h { stroke: var(--dim-h); }
.dim-label { font-size: 14px; font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.preview .dim-label { stroke: var(--surface-2); }
.dim-label.dim-l { fill: var(--dim-l); }
.dim-label.dim-w { fill: var(--dim-w); }
.dim-label.dim-h { fill: var(--dim-h); }
.pieces-badge { font-size: 20px; font-weight: 800; fill: var(--muted); }

/* ── Results table ─────────────────────────────────── */
.stats { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; margin-bottom: 12px; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 1.7rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-value.small-value { font-size: 1.15rem; padding-top: .35rem; }
.stat-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.table-wrap { overflow-x: auto; }
table.results { width: 100%; border-collapse: collapse; font-size: .95rem; }
.results th, .results td { padding: 8px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.results thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; border-bottom-width: 2px; }
.results thead th .muted { text-transform: none; letter-spacing: 0; font-weight: 400; display: block; }
.results tbody th { font-weight: 600; white-space: nowrap; }
.results .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.results td.strong { font-weight: 800; font-size: 1.05rem; }
.results tbody tr td:nth-child(4), .results thead tr:last-child th:nth-child(3) { border-left: 1px solid var(--border); }
.results tbody tr:nth-child(odd) { background: var(--surface-2); }

/* ── Your boxes ────────────────────────────────────── */
.empty { color: var(--muted); margin: 0; padding: 24px; text-align: center; border: 1px dashed var(--border); border-radius: 12px; }
.lineup-scroll { overflow-x: auto; border-radius: 12px; background: var(--surface-2); }
.lineup-svg { display: block; width: 100%; height: auto; }
.lineup-svg .ground { stroke: var(--border); stroke-width: 2; }
.lineup-num { fill: #fff; font-size: 11px; font-weight: 800; }
.lineup-label { fill: var(--text); font-size: 13px; font-weight: 700; }
.lineup-dims { fill: var(--muted); font-size: 12px; }
.scale-bar { stroke: var(--text); stroke-width: 2; }
.scale-label { fill: var(--muted); font-size: 12px; }
.lineup-item { cursor: default; }

.share-bar { display: flex; height: 28px; border-radius: 8px; overflow: hidden; gap: 2px; background: var(--surface-2); }
.share-seg { display: flex; align-items: center; justify-content: center; color: #fff; font-size: .8rem; font-weight: 800; min-width: 2px; }
.share-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; padding: 0; margin: 8px 0 0; font-size: .9rem; }
.swatch, .key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.item-card { padding: 14px; border-top: 4px solid var(--item); box-shadow: none; transition: box-shadow .3s; }
.item-card.flash { box-shadow: 0 0 0 3px var(--item); }
.item-head { display: flex; align-items: flex-start; gap: 10px; }
.item-num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--item); color: #fff; display: grid; place-items: center; font-weight: 800; }
.item-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.item-title strong { overflow-wrap: anywhere; }
.item-title .muted { font-size: .85rem; }
.item-actions { display: flex; gap: 2px; flex: none; }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--muted); font-size: 1.4rem; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.item-card .box-svg { margin: 4px 0; }

.class-chip { display: inline-block; font-size: .85rem; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 8px; }

.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 9.5em minmax(0, 1fr) 4.5em; align-items: center; gap: 8px; font-size: .85rem; }
.bar-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { position: relative; height: 12px; background: var(--surface-2); border-radius: 4px; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: var(--bar); border-radius: 4px; }
.bar-fill.is-dim { background: var(--bar-dim); }
.bar-actual { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--actual); }
.bar-value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-legend { margin: 2px 0 0; font-size: .8rem; color: var(--muted); }
.key-actual { width: 2px; height: 12px; background: var(--actual); border-radius: 0; }
.key-dim { background: var(--bar-dim); margin-left: 14px; }

.mini-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 12px 0 0; }
.mini-grid div { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; }
.mini-grid dt { font-size: .75rem; color: var(--muted); }
.mini-grid dd { margin: 0; font-weight: 800; font-variant-numeric: tabular-nums; }

.lists { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.entry-list { margin: 0; padding: 8px 8px 8px 2.2em; background: var(--surface-2); border-radius: 10px; font-variant-numeric: tabular-nums; min-height: 2.5em; }

/* ── Truck class finder ────────────────────────────── */
.class-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 24px; align-items: start; }
.class-grid .field-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.class-grid .small { margin-top: 0; }
.class-result { display: flex; gap: 26px; flex-wrap: wrap; }
.class-viz #classSvg { max-width: 360px; margin: 0 auto; }
.class-viz.is-empty #classSvg { height: 40px; }
.density-scale { position: relative; margin-top: 8px; padding-bottom: 4px; }
.bands { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 2px; }
.band {
    --t: calc(var(--i) / 12);
    font-size: .72rem; font-weight: 700; text-align: center; padding: 8px 0;
    background: color-mix(in srgb, var(--brand-2) calc(18% + var(--t) * 70%), var(--surface));
    color: var(--text); border-radius: 4px; overflow: hidden;
}
.band:nth-child(n+8) { color: #fff; }
.band.is-on { outline: 3px solid var(--accent); outline-offset: 1px; position: relative; z-index: 1; }
.marker { position: absolute; top: -8px; width: 0; height: 0; margin-left: -7px; border: 7px solid transparent; border-top-color: var(--text); }
.scale-ends { display: flex; justify-content: space-between; font-size: .78rem; color: var(--muted); margin-top: 4px; }

.wiki-link { text-align: center; }
.wiki-link a { display: inline-flex; gap: 6px; align-items: center; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); text-decoration: none; color: var(--text); }

/* ── Guide article ─────────────────────────────────── */
.guide { padding: 8px 28px 20px; line-height: 1.65; }
.guide h1 { font-size: 1.6rem; line-height: 1.25; }
.guide h2 { font-size: 1.25rem; margin-top: 1.8em; }
.guide nav { background: var(--surface-2); border-radius: 10px; padding: 6px 16px; }
.guide li { margin: 4px 0; }

/* ── Dialog ────────────────────────────────────────── */
dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; width: min(460px, calc(100% - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 18, 30, .5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dialog-head h2 { margin: 0; font-size: 1.2rem; }
#contactForm { display: flex; flex-direction: column; gap: 10px; }
#contactForm input, #contactForm textarea { font-weight: 400; }
.dialog-foot { justify-content: flex-end; }
.dialog-foot .btn-primary { flex: 0 0 auto; }
.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 10px; font-size: .95rem; }
.alert-success { background: #e3f5e8; color: #135c26; }
.alert-warning { background: #fff4d6; color: #6b4e00; }
.alert-danger { background: #fde4e7; color: #8a1f2c; }

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 900px) {
    .top-grid, .class-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
    .panel { padding: 14px; }
    .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .field-grid .field:first-child { grid-column: 1 / -1; }
    .class-grid .field-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .class-grid .field-grid .field:first-child { grid-column: 1 / -1; }
    .brand { font-size: 1.05rem; }
    .cards { grid-template-columns: minmax(0, 1fr); }
    .lists { grid-template-columns: minmax(0, 1fr); }
    .guide { padding: 4px 16px 16px; }
    .band { font-size: .6rem; padding: 6px 0; }
    .toggle { margin-left: 0; }
    .bar-row { grid-template-columns: 8em minmax(0, 1fr) 4em; }
}

/* ── Print: body[data-print] picks the section ─────── */
@media print {
    :root { --bg: #fff; --surface: #fff; --surface-2: #f4f4f4; --text: #000; --muted: #444; --border: #bbb; --shadow: none; }
    body { background: #fff; }
    .site-header, .site-footer, .guide, .wiki-link, .btn, .btn-row, .item-actions, .toggle, .seg, .preview, dialog { display: none !important; }
    .card { box-shadow: none; }
    .panel { break-inside: avoid; }
    .item-card { break-inside: avoid; }
    .top-grid { display: block; }

    body[data-print="dims"] #dimPanel,
    body[data-print="dims"] .class-panel { display: none; }

    body[data-print="class"] .top-grid,
    body[data-print="class"] .boxes-panel { display: none; }
    body[data-print="class"] .class-grid form .field-grid { pointer-events: none; }
}
