/* ---------- Theme tokens ---------- */
:root {
  --bg: #f4f6fa;
  --bg-elev: #ffffff;
  --bg-sub: #eef1f6;
  --text: #0f172a;
  --text-muted: #55627a;
  --border: #d9dfe9;
  --accent: #15803d;
  --accent-soft: #dcfce7;
  --accent-text: #14532d;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --meter-track: #e2e8f0;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .18);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --bg-elev: #111a2c;
    --bg-sub: #182338;
    --text: #e6ebf5;
    --text-muted: #9aa8c2;
    --border: #253248;
    --accent: #22c55e;
    --accent-soft: #14311f;
    --accent-text: #bbf7d0;
    --warn: #f59e0b;
    --warn-soft: #3a2a0a;
    --danger: #f87171;
    --danger-soft: #3f1515;
    --info: #60a5fa;
    --info-soft: #14243f;
    --meter-track: #223049;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -16px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elev: #111a2c;
  --bg-sub: #182338;
  --text: #e6ebf5;
  --text-muted: #9aa8c2;
  --border: #253248;
  --accent: #22c55e;
  --accent-soft: #14311f;
  --accent-text: #bbf7d0;
  --warn: #f59e0b;
  --warn-soft: #3a2a0a;
  --danger: #f87171;
  --danger-soft: #3f1515;
  --info: #60a5fa;
  --info-soft: #14243f;
  --meter-track: #223049;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -16px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .35em; }
h1 { font-size: clamp(1.6rem, 3.5vw, 2.4rem); letter-spacing: -.01em; }
h2 { font-size: 1.25rem; }
h3.sub { font-size: 1rem; margin-top: 1.5rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
p { margin: 0 0 .6em; }
code { background: var(--bg-sub); padding: .1em .4em; border-radius: 6px; font-size: .92em; }
small { color: var(--text-muted); }
a { color: var(--info); }
.hidden { display: none !important; }
.wrap { width: min(1180px, 100% - 32px); margin-inline: auto; }
.top-gap { margin-top: 1rem; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 1rem; min-height: 56px; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; text-decoration: none; color: var(--text); }
.brand-icon {
  width: 22px; height: 14px; border-radius: 4px; background: var(--accent); position: relative; display: inline-block;
}
.brand-icon::after { content: ""; position: absolute; right: -4px; top: 4px; width: 3px; height: 6px; background: var(--accent); border-radius: 1px; }
.site-nav { display: flex; gap: .25rem; margin-left: auto; }
.site-nav a { color: var(--text-muted); text-decoration: none; padding: .35rem .6rem; border-radius: 8px; font-size: .92rem; }
.site-nav a:hover { background: var(--bg-sub); color: var(--text); }
.header-actions { display: flex; gap: .4rem; }
@media (max-width: 760px) {
  .site-nav { display: none; }
  .header-actions { margin-left: auto; }
}

/* ---------- Hero ---------- */
.hero { padding: 2.2rem 0 1.2rem; max-width: 760px; }
.hero p { color: var(--text-muted); font-size: 1.05rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem;
  margin: 1.1rem 0;
  box-shadow: var(--shadow);
}
.muted-card { box-shadow: none; background: transparent; }
.card-head { margin-bottom: 1rem; }
.card-head p { color: var(--text-muted); margin: 0; }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.row-gap { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.wrap-row { flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.spec-note a { color: var(--info); text-decoration: none; font-weight: 600; }
.spec-note a:hover { text-decoration: underline; }

fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin: 0; min-width: 0; }
legend { padding: 0 .4rem; font-weight: 600; color: var(--text-muted); font-size: .9rem; }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; min-width: 0; }
.field > span { color: var(--text-muted); font-weight: 500; }
.field.inline { flex-direction: row; align-items: center; gap: .5rem; }
.field small { font-size: .8rem; }
input[type="text"], input[type="number"], select {
  font: inherit;
  color: var(--text);
  background: var(--bg-sub);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: .5rem .65rem;
  min-width: 0;
  width: 100%;
}
.field.inline select, .field.inline input { width: auto; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input.invalid { border-color: var(--danger); }
.custom-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin-top: .75rem; padding: .75rem; border-radius: 10px; background: var(--bg-sub); }

.spec-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .5rem; margin-top: .75rem; }
.spec { background: var(--bg-sub); border-radius: 9px; padding: .45rem .6rem; }
.spec b { display: block; font-size: 1.02rem; }
.spec span { color: var(--text-muted); font-size: .78rem; }
.spec-note { grid-column: 1 / -1; font-size: .82rem; color: var(--text-muted); padding: 0 .2rem; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: .9rem;
  border-radius: 9px; padding: .5rem .9rem;
  border: 1px solid var(--border); background: var(--bg-sub); color: var(--text);
  cursor: pointer; transition: background .15s, transform .05s;
}
.btn:hover { background: color-mix(in srgb, var(--bg-sub) 70%, var(--border)); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #05240f; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.small { padding: .3rem .6rem; font-size: .8rem; }
.btn.icon { padding: .4rem .6rem; font-size: 1rem; line-height: 1; }

/* ---------- Packs ---------- */
.pack-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.pack { border: 1px solid var(--border); border-radius: 12px; background: var(--bg); overflow: hidden; }
.pack-head { display: flex; align-items: center; gap: .5rem; padding: .7rem .9rem; border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.pack-name { font-weight: 700; font-size: 1rem; background: transparent; border-color: transparent; padding: .3rem .4rem; flex: 1; }
.pack-name:hover, .pack-name:focus { border-color: var(--border); background: var(--bg-sub); }
.pack-body { padding: .9rem; display: flex; flex-direction: column; gap: .8rem; }
.pack-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.pack-stats .spec b { font-size: .98rem; }
@media (max-width: 400px) { .pack-stats { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Results ---------- */
.warnings { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.warnings:empty { display: none; }
.alert { border-radius: 10px; padding: .6rem .8rem; font-size: .9rem; border: 1px solid transparent; display: flex; gap: .55rem; align-items: flex-start; }
.alert::before { content: "●"; font-size: .7rem; margin-top: .35rem; }
.alert.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--text); }
.alert.danger::before { color: var(--danger); }
.alert.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.alert.warn::before { color: var(--warn); }
.alert.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 40%, transparent); }
.alert.info::before { color: var(--info); }
.alert.ok { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.alert.ok::before { color: var(--accent); }

.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }
.tile { background: var(--bg-sub); border-radius: 12px; padding: .8rem .9rem; border: 1px solid var(--border); }
.tile .label { color: var(--text-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.tile .value { font-size: 1.45rem; font-weight: 700; margin: .15rem 0; font-variant-numeric: tabular-nums; }
.tile .value small { font-size: .8rem; font-weight: 500; color: var(--text-muted); margin-left: .15em; }
.tile .sub { font-size: .8rem; color: var(--text-muted); }
.tile.highlight { border-color: var(--accent); background: var(--accent-soft); }
.tile.highlight .label { color: var(--accent-text); }
.tile.wide { grid-column: 1 / -1; }

.meter { height: 8px; border-radius: 99px; background: var(--meter-track); overflow: hidden; margin-top: .35rem; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.meter.warn > i { background: var(--warn); }
.meter.danger > i { background: var(--danger); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 10px; }
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 720px; }
.data-table th, .data-table td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table th { background: var(--bg-sub); font-weight: 600; color: var(--text-muted); font-size: .8rem; white-space: nowrap; }
.data-table th small { font-weight: 400; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td .muted { color: var(--text-muted); font-size: .82rem; display: block; }
.data-table td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 99px; border: 1px solid transparent; white-space: nowrap; }
.badge.ok { background: var(--accent-soft); color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.badge.info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, transparent); }

/* ---------- Recommendations ---------- */
.note { font-size: .9rem; color: var(--text-muted); margin-bottom: 1rem; }
.rec-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.rec { border: 1px solid var(--border); border-radius: 12px; padding: .9rem; background: var(--bg); display: flex; flex-direction: column; gap: .5rem; }
.rec.top { border-color: var(--accent); }
.rec-title { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.rec-title b { font-size: 1rem; }
.rec-kv { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .6rem; font-size: .85rem; }
.rec-kv span { color: var(--text-muted); }
.rec-kv b { font-variant-numeric: tabular-nums; }
.rec p { font-size: .84rem; color: var(--text-muted); margin: 0; }
.rec .why { font-size: .84rem; color: var(--text); }
.rec .actions { margin-top: auto; }
.details summary { cursor: pointer; font-weight: 600; color: var(--text-muted); padding: .4rem 0; }
.details[open] summary { margin-bottom: .6rem; }

/* ---------- BMS ---------- */
.bms-list { display: flex; flex-direction: column; gap: 1rem; }
.bms-pack { border: 1px solid var(--border); border-radius: 12px; padding: 1rem; background: var(--bg); }
.bms-pack h3 { font-size: 1rem; margin-bottom: .25rem; }
.bms-req { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0 .8rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip, .bms-req .chip { background: var(--bg-sub); border: 1px solid var(--border); border-radius: 99px; padding: .2rem .65rem; font-size: .82rem; }
.bms-req .chip b { font-variant-numeric: tabular-nums; }
.bms-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: .7rem; }

/* ---------- Notes / footer ---------- */
.notes { padding-left: 1.2rem; color: var(--text-muted); font-size: .9rem; }
.notes li { margin: .3rem 0; }
.site-footer { border-top: 1px solid var(--border); margin-top: 2rem; padding: 1.2rem 0 2rem; color: var(--text-muted); font-size: .85rem; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .card { padding: 1rem; }
  .hero { padding-top: 1.4rem; }
  .totals { grid-template-columns: repeat(2, 1fr); }
  .tile .value { font-size: 1.25rem; }
}
