:root {
  --bg: #f5f3ee; --panel: #ffffff; --ink: #1d2320; --muted: #5d6a64; --line: #e2ddd2;
  --brand: #0f5c4d; --brand-2: #0b4a3e; --brand-soft: #e3efe9; --accent: #c98a12; --accent-soft: #fbf1dc;
  --danger: #b3261e; --danger-soft: #fbe9e7; --ok: #1f7a44; --ok-soft: #e4f3ea; --warn: #9a6200; --warn-soft: #fff4d9;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  --radius: 12px; --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111614; --panel: #1a211e; --ink: #e8ece9; --muted: #9aa8a1; --line: #2c3632;
    --brand: #3fae90; --brand-2: #58c3a5; --brand-soft: #1b2e28; --accent: #e3a73a; --accent-soft: #2d2616;
    --danger: #ff8a80; --danger-soft: #3a1f1d; --ok: #6fd39a; --ok-soft: #1a2e22; --warn: #f0b64a; --warn-soft: #33290f;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #111614; --panel: #1a211e; --ink: #e8ece9; --muted: #9aa8a1; --line: #2c3632;
  --brand: #3fae90; --brand-2: #58c3a5; --brand-soft: #1b2e28; --accent: #e3a73a; --accent-soft: #2d2616;
  --danger: #ff8a80; --danger-soft: #3a1f1d; --ok: #6fd39a; --ok-soft: #1a2e22; --warn: #f0b64a; --warn-soft: #33290f;
  --shadow: none;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 'IBM Plex Sans', system-ui, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 1.55rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }
.mono, code { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* header */
.top { background: var(--brand-2); color: #fff; display: flex; align-items: center; gap: 16px; padding: 10px 20px; position: sticky; top: 0; z-index: 10; }
.brand { display: flex; gap: 10px; align-items: center; color: #fff; text-decoration: none; font-weight: 700; }
.brand small { display: block; font-weight: 400; font-size: .72rem; opacity: .75; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: #f4d58d; color: var(--brand-2); display: grid; place-items: center; font-weight: 800; }
.top nav { display: flex; gap: 4px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.top nav a { color: #d7e9e2; text-decoration: none; padding: 7px 11px; border-radius: 8px; font-size: .92rem; }
.top nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.top nav a.on { background: rgba(255,255,255,.15); color: #fff; }
.logout button { background: none; border: 1px solid rgba(255,255,255,.25); color: #d7e9e2; border-radius: 8px; padding: 6px 10px; cursor: pointer; font: inherit; font-size: .85rem; }
.menu-btn { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.4rem; }
@media (max-width: 860px) {
  .menu-btn { display: block; }
  .top { flex-wrap: wrap; }
  .top nav { display: none; width: 100%; flex-direction: column; align-items: stretch; }
  body.nav-open .top nav { display: flex; }
}

/* cards & grid */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
.kpi .l { color: var(--muted); font-size: .82rem; }
.kpi .s { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }

/* forms */
label { display: block; font-size: .83rem; font-weight: 600; color: var(--muted); margin: 0 0 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 12px; }
.hint { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--brand); color: #fff; border: 0; border-radius: 9px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--brand-2); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.sm { padding: 6px 10px; font-size: .85rem; }
.btn.danger { background: var(--danger); }
.btn.accent { background: var(--accent); }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.best td { background: var(--ok-soft); }
tr.total td { font-weight: 700; border-top: 2px solid var(--ink); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--brand-soft); }

/* badges & notices */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.muted { background: var(--line); color: var(--muted); }
.flash, .notice { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid transparent; }
.flash.ok, .notice.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err, .notice.err { background: var(--danger-soft); color: var(--danger); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--brand-soft); color: var(--ink); }
.pill-code { font-family: var(--mono); font-weight: 600; font-size: 1.05rem; background: var(--accent-soft); color: var(--ink); padding: 3px 9px; border-radius: 7px; border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }

/* progress */
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .4s; }
.steps { list-style: none; padding: 0; margin: 0; }
.steps li { padding: 6px 0 6px 26px; position: relative; color: var(--muted); }
.steps li::before { content: ''; position: absolute; left: 4px; top: 11px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.steps li.on { color: var(--ink); font-weight: 600; }
.steps li.on::before { background: var(--accent); animation: pulse 1s infinite alternate; }
.steps li.done::before { background: var(--brand); }
@keyframes pulse { to { opacity: .35; } }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* estimate page */
.wizard-step { display: flex; gap: 12px; align-items: flex-start; }
.wizard-step .n { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.choice { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 8px; cursor: pointer; display: block; }
.choice:hover { border-color: var(--brand); }
.choice input { width: auto; margin-right: 8px; }
.choice.sel { border-color: var(--brand); background: var(--brand-soft); }
.search-results { max-height: 340px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; margin-top: 8px; }
.search-results div { padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: .88rem; }
.search-results div:hover { background: var(--brand-soft); }
details summary { cursor: pointer; font-weight: 600; }
.reasoning { white-space: pre-wrap; font-size: .9rem; background: var(--bg); border-radius: 10px; padding: 12px; border: 1px solid var(--line); }
.big { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }
.doc { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.doc:last-child { border-bottom: 0; }
.doc .ic { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.doc .ic.adil { background: var(--danger-soft); color: var(--danger); }
.doc .ic.mcinet { background: var(--warn-soft); color: var(--warn); }
.doc .ic.base { background: var(--brand-soft); color: var(--brand); }

/* login */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), var(--bg)); }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { color: var(--ink); margin-bottom: 18px; }

@media print {
  .top, .no-print, .btn { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
