:root {
  --bg: #0b1020;
  --bg-soft: #121a30;
  --panel: #161f38;
  --panel-2: #1c2745;
  --line: #26324f;
  --text: #e8edf7;
  --muted: #94a3c4;
  --accent: #4f8cff;
  --accent-2: #22d3a6;
  --warn: #f7b955;
  --bad: #ff6b6b;
  --good: #22d3a6;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 15% -10%, #1a2547 0%, transparent 60%),
              radial-gradient(900px 500px at 100% 0%, #16323f 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  font: 15px/1.55 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

/* Animated geometric backdrop. Sits behind everything, ignores the pointer, and
   drifts with the scroll position — see the canvas painter in app.js. */
/* Full strength here — the per-shape alpha in the painter is what keeps it from
   competing with the cards, and dimming twice made it invisible. */
#bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

/* The cards sit on the animation, so they need to be opaque enough to read. */
.card { backdrop-filter: blur(3px); }
header, main, .savebar { position: relative; z-index: 1; }

@media (prefers-reduced-motion: reduce) { #bg { display: none; } }

a { color: var(--accent); }

/* ── layout ───────────────────────────────────────────────────────────── */

header {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(14px);
  background: rgba(11, 16, 32, .82);
  border-bottom: 1px solid var(--line);
}

.bar {
  max-width: 1360px; margin: 0 auto; padding: 14px 22px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 11px; font-weight: 700; font-size: 17px; }
.brand .dot {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #08122a; font-size: 15px; font-weight: 800;
}
.brand small { display: block; font-weight: 500; font-size: 11.5px; color: var(--muted); letter-spacing: .3px; }

.spacer { flex: 1; }

.langs { display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
.langs button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 5px 11px; border-radius: 7px; font: inherit; font-size: 13px; font-weight: 600;
}
.langs button.on { background: var(--accent); color: #06102a; }

.pill {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); white-space: nowrap;
}
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: block; }
.pill.ok i { background: var(--good); box-shadow: 0 0 9px var(--good); }
.pill.ok { color: var(--good); }
.pill.off i { background: var(--bad); }
.pill.off { color: var(--bad); }

nav.tabs {
  max-width: 1360px; margin: 0 auto; padding: 0 22px 0;
  display: flex; gap: 3px; overflow-x: auto;
}
nav.tabs button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 11px 16px; font: inherit; font-weight: 600; font-size: 14px;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
nav.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
nav.tabs button:hover { color: var(--text); }

main { max-width: 1360px; margin: 0 auto; padding: 26px 22px 90px; }

/* align-items:start keeps a short card short instead of stretching it to match
   the tallest one in its row. */
.grid {
  display: grid; gap: 18px; align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
}

/* ── cards ────────────────────────────────────────────────────────────── */

.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card h3 {
  margin: 0 0 4px; font-size: 15px; letter-spacing: .2px;
  display: flex; align-items: center; gap: 9px;
}
.card h3 .ico { font-size: 17px; }
.card .hint { margin: 0 0 16px; color: var(--muted); font-size: 12.8px; line-height: 1.5; }
.card.wide { grid-column: 1 / -1; }

/* ── forms ────────────────────────────────────────────────────────────── */

.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field .sub { font-weight: 400; color: #6f7fa6; }

input[type=text], input[type=number], input[type=url], select, textarea {
  width: 100%; background: #0e1730; color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
  font: inherit; font-size: 14px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 74px; font-size: 13px; line-height: 1.5; }

/* Side-by-side fields: a label that wraps to two lines must not push its own
   input below the neighbouring one, so the inputs align on the bottom edge. */
.row2, .row3 { display: grid; gap: 11px; align-items: end; }
.row2 { grid-template-columns: 1fr 1fr; }
.row3 { grid-template-columns: repeat(3, 1fr); }
.row2 > .field, .row3 > .field { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }

.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  background: #0e1730; border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 12px; font-size: 13px; user-select: none;
}
.check input { accent-color: var(--accent); }
.check.on { border-color: var(--accent); background: #13234a; }

button.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  font: inherit; font-weight: 650; font-size: 13.5px;
  background: var(--accent); color: #06102a;
}
button.btn:hover { filter: brightness(1.08); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
button.btn.ghost { background: #1b2647; color: var(--text); border: 1px solid var(--line); }
button.btn.good { background: var(--accent-2); }
button.btn.warn { background: var(--warn); color: #2a1c00; }
.btns { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 14px; }

/* ── save bar ─────────────────────────────────────────────────────────── */

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(12, 18, 36, .95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); transform: translateY(110%);
  transition: transform .22s ease;
}
.savebar.show { transform: translateY(0); }
.savebar .inner {
  max-width: 1360px; margin: 0 auto; padding: 13px 22px;
  display: flex; align-items: center; gap: 14px;
}
.savebar .msg { color: var(--warn); font-size: 13.5px; font-weight: 600; }

/* ── log / output ─────────────────────────────────────────────────────── */

pre.log {
  background: #060c1c; border: 1px solid var(--line); border-radius: 10px;
  padding: 13px 15px; margin: 13px 0 0; max-height: 340px; overflow: auto;
  font: 12.3px/1.6 "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  color: #b9c7e6; white-space: pre-wrap; word-break: break-word;
}
pre.log:empty { display: none; }
.log .ok { color: var(--good); }

/* ── tables ───────────────────────────────────────────────────────────── */

/* The right edge fades while there is more table to scroll to, so a cut-off
   column reads as "scroll me" instead of "broken layout". */
.tablewrap {
  overflow-x: auto; border: 1px solid var(--line); border-radius: 11px;
  background:
    linear-gradient(to right, var(--panel) 30%, rgba(22, 31, 56, 0)) left / 40px 100% no-repeat,
    linear-gradient(to left, var(--panel) 30%, rgba(22, 31, 56, 0)) right / 40px 100% no-repeat,
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .5), transparent) left / 16px 100% no-repeat,
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .5), transparent) right / 16px 100% no-repeat;
  background-attachment: local, local, scroll, scroll;
}
table { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 1120px; }
th, td { padding: 9px 11px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #101a33; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; position: sticky; top: 0; }
tbody tr:hover { background: #14203c; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.tag.alerted { background: rgba(34, 211, 166, .16); color: var(--good); }
.tag.rejected { background: rgba(148, 163, 196, .14); color: var(--muted); }
.tag.below { background: rgba(247, 185, 85, .15); color: var(--warn); }
.tag.error { background: rgba(255, 107, 107, .15); color: var(--bad); }
.tag.noref { background: rgba(79, 140, 255, .15); color: var(--accent); }

/* analysis table: a second line under a cell carries the "why" */
td .sub {
  display: block; font-size: 11px; color: #7186ad; margin-top: 3px;
  white-space: normal; max-width: 260px; line-height: 1.4;
}
td .sub.warnt { color: var(--warn); }
td .sub.badt { color: var(--bad); }
td .car { font-weight: 650; }

/* Cells default to nowrap so numbers never break, but a car name like
   "CUPRA Formentor 1.5 TSI LED+NAV+PARKLENK+FULL LINK+ACC" then stretches the
   column past 450px and pushes the last columns off screen. This one wraps. */
td.carcell { white-space: normal; max-width: 300px; }
td.carcell .car { display: block; overflow-wrap: anywhere; }
td.carcell .sub { max-width: none; }
td .muted { color: var(--muted); }
table td { vertical-align: top; }

a.veri {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .3px;
  padding: 3px 8px; border: 1px solid var(--line); border-radius: 7px;
  color: var(--accent); text-decoration: none;
}
a.veri:hover { background: rgba(79, 140, 255, .14); border-color: var(--accent); }

/* pulse on the status dot while a cycle is actually running */
.pill i.beat { animation: beat 1.1s ease-in-out infinite; }
@keyframes beat { 0%, 100% { opacity: 1; transform: scale(1); }
                  50% { opacity: .35; transform: scale(.75); } }

/* ── stats ────────────────────────────────────────────────────────────── */

.stats { display: grid; gap: 13px; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); }
.stat {
  background: #101a33; border: 1px solid var(--line); border-radius: 12px; padding: 15px 17px;
}
.stat .v { font-size: 26px; font-weight: 750; letter-spacing: -.5px; }
.stat .k { color: var(--muted); font-size: 12px; margin-top: 3px; }
.stat.good .v { color: var(--good); }
.stat.warn .v { color: var(--warn); }
.stat.bad .v { color: var(--bad); }

.note {
  border-left: 3px solid var(--accent); background: rgba(79, 140, 255, .08);
  padding: 11px 14px; border-radius: 0 9px 9px 0; font-size: 13px; color: #c3d2ef;
  margin: 0 0 16px;
}
.note.warn { border-color: var(--warn); background: rgba(247, 185, 85, .08); }

.trimrow { display: grid; grid-template-columns: 130px 1fr; gap: 9px; margin-bottom: 8px; align-items: center; }
.trimrow span { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: capitalize; }
.trimrow input { font-size: 13px; }

.scenario { display: grid; grid-template-columns: 1fr 150px; gap: 9px; margin-bottom: 9px; align-items: center; }
.scenario-block { border: 1px solid var(--line, #2a2f3a); border-radius: 10px; padding: 10px; margin-bottom: 11px; }
.scenario-block .sc-label { width: 100%; font-weight: 600; margin-bottom: 8px; }
.gasto-row { display: grid; grid-template-columns: 1fr 130px 34px; gap: 8px; margin-bottom: 6px; align-items: center; }
.gasto-row .gd-del { background: transparent; border: 1px solid var(--line, #2a2f3a); border-radius: 8px; color: #e66; cursor: pointer; height: 34px; font-size: 16px; }
.gasto-total { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.gasto-total .gd-add { background: transparent; border: 1px dashed var(--line, #3a4150); border-radius: 8px; color: var(--fg, #cdd3df); cursor: pointer; padding: 5px 10px; }
.gasto-total b { margin-left: auto; }
@media (max-width: 640px) { .gasto-row { grid-template-columns: 1fr 90px 30px; } }

@media (max-width: 640px) {
  .row2, .row3, .scenario, .trimrow { grid-template-columns: 1fr; }
  main { padding: 18px 14px 90px; }
  .bar { padding: 12px 14px; }
  nav.tabs { padding: 0 14px; }
}

/* section band between config card groups */
.sect {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 10px;
  margin: 14px 0 -4px; padding: 0 2px;
  font-size: 12.5px; font-weight: 700; letter-spacing: .6px;
  text-transform: uppercase; color: var(--muted);
}
.sect::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, var(--line), transparent);
}
.sect .ico { font-size: 15px; }
.sect:first-child { margin-top: 0; }

/* when/id column: the timestamp reads first, the short id sits under it as the
   handle you quote when reporting a bug */
td.whencell { white-space: nowrap; }
td.whencell .clock { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12.5px; }
td.whencell .idcode {
  font-family: "JetBrains Mono", Consolas, monospace; font-size: 10.5px;
  letter-spacing: .4px; color: #64789f; cursor: help; max-width: none;
}

/* ── Review tab (manual reference queue) ─────────────────────────────── */
button.btn.small { padding: 7px 14px; font-size: 13px; }
button.btn.tiny { padding: 4px 9px; font-size: 12px; }
.kv { display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
      padding: 5px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv > .sub { flex: 0 0 auto; }
.kv > b { text-align: right; }
.revcard { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  margin: 10px 0; background: rgba(20, 30, 58, .5); transition: border-color .2s; }
.revcard.done { border-color: rgba(34, 211, 166, .5); background: rgba(20, 40, 42, .4); }
.revtop { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.revtitle { font-weight: 700; font-size: 15px; color: var(--text); }
.revlinks { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.revbtn { display: inline-block; padding: 6px 12px; border-radius: 8px; font-size: 13px;
  text-decoration: none; background: #1b2647; color: var(--text); border: 1px solid var(--line); }
.revbtn:hover { filter: brightness(1.15); }
.revsave { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.revinput { flex: 1; min-width: 260px; padding: 9px 12px; border-radius: 8px;
  background: #0f1830; border: 1px solid var(--line); color: var(--text); font-size: 13px; }
.revinput:focus { outline: none; border-color: var(--accent); }
.okt { color: var(--good); }
