:root {
  --bg: #f3f2ef;
  --panel: #ffffff;
  --text: #191919;
  --muted: #666;
  --line: #e3e1dc;
  --accent: #0a66c2;
  --accent-soft: #e8f1fb;
  --good: #057642;
  --warn: #b7791f;
  --bad: #c0392b;
  --track: #ebe9e5;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215;
    --panel: #1a1f24;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --line: #2a3138;
    --accent: #4b9eea;
    --accent-soft: #1b2c3d;
    --good: #3fb37f;
    --warn: #e0a743;
    --bad: #ec6b5e;
    --track: #2a3138;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.muted { color: var(--muted); }
.hidden { display: none !important; }

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  max-width: 1180px; margin: 0 auto; padding: 22px 16px 8px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { font-size: 20px; margin: 0; }
.brand p { margin: 0; font-size: 13px; }
.logo {
  width: 40px; height: 40px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 20px; font-family: Arial, sans-serif;
}
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status.ok .dot { background: var(--good); }
.status.err .dot { background: var(--bad); }

main { max-width: 1180px; margin: 0 auto; padding: 8px 16px 24px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px;
}
.panel h2 { font-size: 15px; margin: 0 0 12px; }

/* input sources: PDF, link and text all on screen; the active one is analysed */
.sources { display: grid; gap: 4px; }
.src { border-radius: 12px; padding: 2px; transition: box-shadow .15s; }
.src.active { box-shadow: 0 0 0 2px var(--accent); }
.src.active .drop, .src.active input, .src.active textarea { border-color: transparent; }
.src-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 2px 2px 4px; }
.src.active .src-label { color: var(--accent); }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 4px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
input[type="text"], textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.controls { display: flex; gap: 10px; align-items: end; margin-top: 12px; flex-wrap: wrap; }
button.primary, button.ghost {
  font: inherit; font-weight: 600; border-radius: 999px; padding: 9px 22px; cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; border: 0; }
button.primary:disabled { opacity: .55; cursor: progress; }
button.ghost { background: none; color: var(--text); border: 1px solid var(--line); }
.error { color: var(--bad); margin: 12px 0 0; }

/* results */
.results { display: grid; grid-template-columns: 300px 1fr; gap: 16px; margin-top: 16px; align-items: start; }
.analysis { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.wide { grid-column: 1 / -1; }

/* profile card */
.profile { padding: 0; overflow: hidden; position: sticky; top: 12px; }
.profile .cover { height: 64px; background: linear-gradient(120deg, var(--accent), #7a5af5); }
.profile .body { padding: 0 18px 18px; }
.avatar {
  width: 84px; height: 84px; border-radius: 50%; border: 3px solid var(--panel); margin-top: -42px;
  background: var(--track) center/cover; display: grid; place-items: center; font-size: 30px; font-weight: 700;
  color: var(--muted);
}
.profile h2 { margin: 8px 0 2px; font-size: 19px; }
.profile .headline { margin: 0 0 6px; }
.profile .meta { font-size: 13px; color: var(--muted); }
.profile h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }
.profile .about { font-size: 13.5px; max-height: 9.5em; overflow: auto; }
.profile ul { list-style: none; padding: 0; margin: 0; }
.profile li { padding: 6px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.profile li:first-child { border-top: 0; }
.profile li small { display: block; color: var(--muted); }
.profile a { color: var(--accent); }

/* summary */
.summary { display: flex; gap: 22px; align-items: center; }
.ring-wrap { position: relative; width: 120px; height: 120px; flex: none; }
.ring { width: 120px; height: 120px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--track); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .6s ease, stroke .3s; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label strong { font-size: 30px; line-height: 1; }
.ring-label span { font-size: 11px; color: var(--muted); }
.summary-text { flex: 1; min-width: 0; }
.progress { height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; }

/* question rows */
.q { padding: 8px 0; border-top: 1px solid var(--line); }
.q:first-child { border-top: 0; padding-top: 0; }
.q .row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.q .label { font-weight: 600; }
.q .val { font-weight: 700; }
.q .conf { font-size: 12px; color: var(--muted); }
.q.pending { opacity: .45; }
.bars { margin-top: 6px; display: grid; gap: 3px; }
.bar { display: grid; grid-template-columns: minmax(110px, 44%) 1fr 42px; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { display: block; height: 6px; background: var(--track); border-radius: 99px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.lead .name, .bar.lead .pct { color: var(--text); font-weight: 600; }
.bar .pct { text-align: right; font-variant-numeric: tabular-nums; }
.scale { display: flex; gap: 3px; margin-top: 6px; }
.scale span { flex: 1; height: 8px; border-radius: 3px; background: var(--track); }
.scale-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 3px; }

.signals { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 22px; }
.signals .q { border-top: 0; padding: 8px 0; }
.meter { position: relative; height: 8px; background: var(--track); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.meter .fill { display: block; position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; }

.raw summary { cursor: pointer; font-weight: 600; }
.raw h3 { font-size: 13px; color: var(--muted); }
.raw pre { background: var(--bg); padding: 12px; border-radius: 8px; overflow: auto; max-height: 340px; font-size: 12px; white-space: pre-wrap; }

footer { text-align: center; font-size: 12px; padding: 0 16px 28px; }

@media (max-width: 860px) {
  .results { grid-template-columns: 1fr; }
  .profile { position: static; }
  .grid { grid-template-columns: 1fr; }
  .summary { flex-direction: column; text-align: center; }
  .bar { grid-template-columns: 90px 1fr 38px; }
}

/* optimize */
.opt-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 4px; }
.opt-head h2 { margin: 0; }
button.small { padding: 5px 14px; font-size: 13px; }
.recs { list-style: none; margin: 8px 0 0; padding: 0; counter-reset: rec; }
.rec { display: grid; grid-template-columns: 28px 1fr; gap: 4px 10px; padding: 12px 0; border-top: 1px solid var(--line); counter-increment: rec; }
.rec:first-child { border-top: 0; }
.rec::before {
  content: counter(rec); width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; background: var(--accent-soft); color: var(--accent); grid-row: span 3;
}
.rec .tags { display: flex; gap: 6px; align-items: center; font-size: 12px; }
.rec .fix { font-weight: 600; }
.rec .evidence { font-size: 12.5px; color: var(--muted); }
.prio { border-radius: 4px; padding: 1px 7px; font-weight: 700; text-transform: uppercase; font-size: 10.5px; letter-spacing: .04em; }
.prio.high { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.prio.medium { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.prio.low { background: var(--track); color: var(--muted); }
.area { color: var(--muted); font-weight: 600; }
.opt-more { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.opt-more summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.opt-more .signals { margin-top: 10px; }
.passed { margin-top: 8px; font-size: 13px; color: var(--muted); }
.passed span { display: inline-block; margin: 2px 10px 2px 0; }
.passed span::before { content: "✓ "; color: var(--good); font-weight: 700; }
.eta-hint { margin: 8px 0 0; font-size: 12.5px; min-height: 1em; }
optgroup { font-weight: 600; }

/* model manager */
.models-head { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; font-size: 12px; color: var(--muted); font-weight: 600; flex-wrap: wrap; }
.models-head #storage { font-weight: 400; }
.models { display: grid; gap: 6px; margin-top: 6px; }
.model-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; background: var(--bg);
}
.model-row.sel { border-color: var(--accent); background: var(--accent-soft); }
.model-row input { accent-color: var(--accent); margin: 0; }
.minfo { display: flex; flex-direction: column; min-width: 0; }
.minfo small { font-size: 12px; }
.quant { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--track); color: var(--muted); }
.mside { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.mstate { font-size: 12px; color: var(--muted); white-space: nowrap; }
.mstate.ok { color: var(--good); font-weight: 600; }
.mstate.part { color: var(--warn); }
.mstate.busy { color: var(--accent); font-variant-numeric: tabular-nums; }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
@media (max-width: 600px) {
  .model-row { grid-template-columns: auto 1fr; }
  .mside { grid-column: 2; justify-content: flex-start; }
}

/* modal (never use native alert/confirm) */
.modal {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; width: min(420px, calc(100vw - 32px));
  background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.modal::backdrop { background: rgba(0, 0, 0, .45); backdrop-filter: blur(2px); }
.modal h2 { margin: 0 0 8px; font-size: 17px; }
.modal p { margin: 0 0 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
button.primary.danger-solid { background: var(--bad); }

/* PDF drop zone */
.drop {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 110px; padding: 16px;
  border: 2px dashed var(--line); border-radius: 10px; cursor: pointer; background: var(--bg); font-size: 14px;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.ready { border-style: solid; border-color: var(--good); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* page-wide PDF drop target */
.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--accent) 16%, rgba(0, 0, 0, .55)); backdrop-filter: blur(3px);
}
.drop-overlay > div {
  display: flex; flex-direction: column; gap: 6px; align-items: center; padding: 34px 48px;
  border: 3px dashed #fff; border-radius: 18px; color: #fff; font-size: 20px; text-align: center;
}
.drop-overlay span { font-size: 14px; opacity: .85; }

/* confidence: a small line under the question name, so the answer keeps the right side */
.labelwrap { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.q .row { align-items: flex-start; }
.q .row .val { text-align: right; }
.conf-line { font-size: 11.5px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.conf-line::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.conf-line.hi { color: var(--good); }
.conf-line.mid { color: var(--warn); }
.conf-line.lo { color: var(--muted); }

/* full-width sections with questions in columns, so no column runs much longer than another */
.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 0 28px; align-items: start; }
.qgrid .q { border-top: 0; border-bottom: 1px solid var(--line); padding: 12px 0; }
.qgrid .q:first-child { padding-top: 12px; }
