:root, [data-theme="light"] {
  --bg: #f3f6f5; --panel: #ffffff; --ink: #14201e; --muted: #56645f; --line: #d5dfdb; --soft: #e9efed;
  --accent: #0d6b62; --accent-ink: #ffffff; --accent-soft: #d9efeb; --bad: #b42318; --ok: #1d6b3f; --warn-bg: #fff4d9;
  --bar: #0d6b62; --bar-other: #9fb3ad; --shadow: 0 1px 2px rgba(15,30,28,.05), 0 6px 18px rgba(15,30,28,.05);
  --g-hot: #c2410c; --g-warm: #d97706; --g-mql: #0d6b62; --g-early: #4f7d96; --g-notq: #8a9894; --g-dq: #b42318;
}
[data-theme="dark"] {
  --bg: #0e1513; --panel: #16201d; --ink: #e4ecea; --muted: #9fb0aa; --line: #2a3733; --soft: #1f2a27;
  --accent: #5cc8b8; --accent-ink: #062521; --accent-soft: #173430; --bad: #f4978e; --ok: #82d3a4; --warn-bg: #30290f;
  --bar: #5cc8b8; --bar-other: #4d625c; --shadow: 0 1px 2px rgba(0,0,0,.4);
  --g-hot: #fb923c; --g-warm: #fbbf24; --g-mql: #5cc8b8; --g-early: #8ec1db; --g-notq: #8a9a95; --g-dq: #f4978e;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; overflow-x: hidden; }
a { color: var(--accent); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); } .small { font-size: .86rem; } .bad { color: var(--bad); } .strong { font-weight: 600; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .logo { color: var(--accent); flex: none; }
.brand strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sep { color: var(--muted); }
.topactions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.backlink { text-decoration: none; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.credits { font-size: .86rem; color: var(--muted); }
.topup { font-size: .86rem; }

button { font: inherit; cursor: pointer; border-radius: 10px; min-height: 40px; }
button:disabled { cursor: not-allowed; opacity: .55; }
.primary { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); padding: 8px 20px; font-weight: 600; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.primary.big { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; font-size: 1.05rem; min-height: 48px; }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); padding: 6px 12px; }
.ghost:hover:not(:disabled) { background: var(--soft); }
.ghost.sq { width: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.ghost.strong { font-weight: 600; border-color: var(--accent); color: var(--accent); }
.quiet { background: none; border: none; color: var(--accent); padding: 6px 4px; text-decoration: underline; text-underline-offset: 3px; }
.linkbtn { background: none; border: none; color: var(--accent); padding: 4px 0; min-height: 40px; text-align: left; font-weight: 600; }

main { max-width: 1120px; margin: 0 auto; padding: 0 16px 40px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.hero { padding: 22px 0 8px; max-width: 760px; }
h1 { font-size: clamp(1.6rem, 4.8vw, 2.3rem); line-height: 1.15; margin: 0 0 8px; letter-spacing: -.01em; }
.lede { margin: 0 0 10px; color: var(--muted); font-size: 1.04rem; }
.perks { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0 0 12px; }
.perks li { font-size: .82rem; background: var(--accent-soft); color: var(--ink); padding: 3px 10px; border-radius: 999px; }
textarea, select, input[type=text] { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.start { padding: 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; position: relative; border-style: dashed; border-width: 2px; }
.start.dragging { border-color: var(--accent); background: var(--accent-soft); }
.start > label.field { color: var(--ink); font-weight: 600; margin: 0; }
.msgarea { display: block; width: 100%; font-size: .95rem; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.45; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.startrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.startrow .primary { min-width: 170px; min-height: 46px; }
.startrow .ghost { min-height: 46px; }
.startsub { margin: 0; }
.drophint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.1rem; color: var(--accent); background: var(--accent-soft); border-radius: 12px; pointer-events: none; }
.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 0; }
.chipbtn { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: .9rem; min-height: 40px; }
.chipbtn:hover, .chipbtn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.msg { margin: 10px 0 0; padding: 8px 12px; border-radius: 10px; background: var(--soft); }
.msg.bad { background: var(--warn-bg); color: var(--ink); border-left: 3px solid var(--bad); }

.work { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; margin-top: 16px; align-items: start; scroll-margin-top: 64px; }
.viewer { padding: 14px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sourceline { margin: 0 0 4px; overflow-wrap: anywhere; }
.headline { margin: 0 0 12px; line-height: 1.5; font-size: 1.05rem; overflow-wrap: anywhere; }
.bignum { font-size: 1.6rem; color: var(--accent); margin-right: 2px; }
.h3 { font-size: 1.05rem; margin: 18px 0 6px; }
.count { color: var(--muted); font-weight: 500; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--muted); margin: 0 0 8px; }

/* the steps */
.funnel { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.funnel li { display: grid; grid-template-columns: minmax(0, 15em) minmax(60px, 1fr) 4.5em 3.5em; gap: 8px; align-items: center; font-size: .9rem; }
.flabel { color: var(--muted); }
.fbar { height: 12px; background: var(--soft); border-radius: 6px; overflow: hidden; }
.ffill { display: block; height: 100%; background: var(--bar); border-radius: 6px; opacity: .55; }
.funnel li.final .ffill { opacity: 1; }
.funnel li.final .flabel, .funnel li.final .fnum { color: var(--ink); font-weight: 700; }
.fnum { text-align: right; font-variant-numeric: tabular-nums; }
.fdelta { color: var(--bad); font-size: .82rem; font-variant-numeric: tabular-nums; }

.exportbox { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.exp-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.exp-grid .ghost { flex: 1 1 auto; }
#exportMsg { margin: 0; } #exportMsg:empty { display: none; }

/* lists of addresses */
.block { margin: 0; }
.rows { list-style: none; margin: 4px 0 0; padding: 0; font-size: .9rem; }
.rows li { padding: 5px 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 2px 10px; overflow-wrap: anywhere; }
.rows li:last-child { border-bottom: none; }
.rows .addr { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; min-width: 0; overflow-wrap: anywhere; }
.rows .why { color: var(--muted); font-size: .84rem; }
.group { border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; margin: 6px 0; background: var(--bg); }
.group summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; gap: 6px; font-weight: 600; }
.group .rows { margin-bottom: 6px; }
.domchart { display: block; width: 100%; max-width: 520px; height: auto; }
.domchart .lbl { font-size: 11px; fill: var(--muted); font-family: system-ui, -apple-system, sans-serif; }
.domchart .dname { fill: var(--ink); }
.domchart .dbar { fill: var(--bar); }
.domchart .dbar.other { fill: var(--bar-other); }
.notchecked { margin: 14px 0 0; padding: 8px 10px; background: var(--soft); border-radius: 8px; }
.more { margin-top: 14px; }
.more summary { cursor: pointer; color: var(--accent); padding: 8px 0; min-height: 40px; font-weight: 600; }
.optlist { display: grid; gap: 2px; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; padding: 8px 0; min-height: 40px; cursor: pointer; }
label.check input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }

/* AI */
.ai { padding: 12px 14px; }
.ai summary { cursor: pointer; font-weight: 600; padding: 4px 0; min-height: 40px; }
.sum-t { font-weight: 600; }
.badge { font-size: .74rem; font-weight: 500; background: var(--soft); color: var(--muted); border-radius: 999px; padding: 2px 8px; margin-left: 4px; }
.hint { font-size: .88rem; color: var(--muted); margin: 8px 0; }
.hint.strong { color: var(--ink); }
.hint.bad { color: var(--bad); }
.hint:empty { display: none; }
.warn-soft { background: var(--warn-bg); color: var(--ink); padding: 8px 10px; border-radius: 8px; }
.ai-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.progress { margin-top: 10px; padding: 10px; background: var(--soft); border-radius: 10px; }
.progresshead { display: flex; justify-content: space-between; }
.steps { margin: 6px 0 0; padding-left: 20px; font-size: .9rem; color: var(--muted); }
.steps li.on { color: var(--ink); font-weight: 600; }
.steps li.done { color: var(--ok); }
.report { margin-top: 10px; font-size: .9rem; }
.report p { margin: 6px 0; }
.report h3 { font-size: .95rem; margin: 14px 0 4px; }
.report .flags { background: var(--warn-bg); border-radius: 8px; padding: 6px 10px 6px 26px; margin: 4px 0 8px; }
.report .flags li { color: var(--bad); }
.report #aiUse { margin-top: 8px; }

.history { margin-top: 16px; padding: 14px; }
.historylist { list-style: none; padding: 0; margin: 8px 0 0; }
.historylist li { padding: 2px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }

.about { margin-top: 32px; max-width: 760px; }
.about h2 { font-size: 1.2rem; margin: 22px 0 8px; }
.howlist { padding-left: 20px; } .howlist li { margin: 6px 0; }
.faq dt { font-weight: 600; margin-top: 12px; } .faq dd { margin: 4px 0 0; color: var(--muted); }
.foot { border-top: 1px solid var(--line); padding: 18px 16px 30px; text-align: center; color: var(--muted); font-size: .88rem; }
.foot p { margin: 4px 0; }

/* docs pages */
.doc { max-width: 900px; padding-top: 18px; }
.doc h1 { font-size: 1.8rem; } .doc h2 { margin-top: 28px; }
.doc table { border-collapse: collapse; width: 100%; font-size: .9rem; display: block; overflow-x: auto; }
.doc th, .doc td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.doc pre { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow-x: auto; font-size: .84rem; line-height: 1.45; margin: 0; }
.codegroup { margin: 10px 0 18px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tab { background: var(--panel); border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 4px 10px; min-height: 34px; font-size: .84rem; }
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.statebox { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: var(--panel); }
.statebox p { margin: 4px 0; }
.tokenrow { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.tokenbox { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; word-break: break-all; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); width: 100%; }
.mini { background: var(--panel); border: 1px solid var(--line); color: var(--ink); padding: 6px 12px; border-radius: 10px; }

/* grades */
.grades li { grid-template-columns: minmax(0, 11em) minmax(60px, 1fr) 3em minmax(0, 14em); }
.faction { color: var(--muted); font-size: .82rem; }
.grades .ffill { opacity: 1; }
.g-hot .ffill { background: var(--g-hot); } .g-warm .ffill { background: var(--g-warm); } .g-mql .ffill { background: var(--g-mql); }
.g-early .ffill { background: var(--g-early); } .g-notq .ffill { background: var(--g-notq); } .g-dq .ffill { background: var(--g-dq); }
.notes { margin: 12px 0 0; padding: 8px 10px 8px 28px; background: var(--warn-bg); border-radius: 8px; font-size: .9rem; }
.notes li { margin: 3px 0; }
.listhead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-top: 12px; }
.listhead .h3 { margin: 6px 0; }
label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
label.inline select, .maprow select { min-height: 40px; padding: 4px 8px; max-width: 100%; }
.leads { list-style: none; margin: 4px 0 8px; padding: 0; }
.leads > li { border-bottom: 1px solid var(--line); }
.leads > li.empty { padding: 8px 0; border: none; }
.lead summary { display: grid; grid-template-columns: 2.6em 3em minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; cursor: pointer; padding: 8px 0; min-height: 44px; list-style: none; }
.lead summary::-webkit-details-marker { display: none; }
.lead .rank { color: var(--muted); font-size: .84rem; font-variant-numeric: tabular-nums; }
.pill { display: inline-flex; justify-content: center; border-radius: 999px; font-weight: 700; font-size: .9rem; padding: 2px 0; color: #fff; font-variant-numeric: tabular-nums; }
[data-theme="dark"] .pill { color: #0e1513; }
.pill.g-hot { background: var(--g-hot); } .pill.g-warm { background: var(--g-warm); } .pill.g-mql { background: var(--g-mql); }
.pill.g-early { background: var(--g-early); } .pill.g-notq { background: var(--g-notq); } .pill.g-dq { background: var(--g-dq); }
.who { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; line-height: 1.3; }
.glabel { font-size: .8rem; color: var(--muted); text-align: right; }
.breakdown { padding: 0 0 10px 3.2em; font-size: .9rem; }
.breakdown p { margin: 6px 0 2px; }
.breakdown .rows li { flex-wrap: nowrap; }
.pts { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3em; }
.pts.pos { color: var(--ok); } .pts.neg { color: var(--bad); }
.tablewrap { overflow-x: auto; }
.srctable, .gradetable { border-collapse: collapse; width: 100%; font-size: .9rem; }
.srctable th, .srctable td, .gradetable th, .gradetable td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.icpgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 10px; }
.icpgrid .wide { grid-column: 1 / -1; }
.icpgrid input { min-height: 40px; padding: 6px 10px; width: 100%; }
.maplist { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.maprow .mapcol { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .84rem; overflow-wrap: anywhere; }
.asof { border: none; padding: 0; margin: 8px 0 0; }
.asof legend { color: var(--muted); padding: 0; }
.scorecard { padding: 12px 14px; }
.scorecard .h3 { margin-top: 0; }
.parts { padding-left: 18px; margin: 0; font-size: .9rem; color: var(--muted); }
.parts li { margin: 4px 0; } .parts b { color: var(--ink); }
.aibiz { font-family: inherit; min-height: 90px; }
.settings li { flex-direction: column; }
.settings li.chg .addr { color: var(--accent); font-weight: 600; }
.settings .basis { font-size: .8rem; color: var(--muted); font-style: italic; }
.settings .basis.bad { color: var(--bad); font-style: normal; }

@media (max-width: 880px) {
  .work { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .topbar { padding: 8px 12px; }
  .hero { padding-top: 14px; }
  .lede { font-size: .98rem; }
  .msgarea { min-height: 84px; }
  .startrow .primary { flex: 1 1 auto; }
  .funnel li { grid-template-columns: minmax(0, 1fr) 3.5em 3em; }
  .funnel .fbar { grid-column: 1 / -1; grid-row: 2; }
  .grades li { grid-template-columns: minmax(0, 1fr) 3em; }
  .grades .faction { display: none; }
  .icpgrid, .maplist { grid-template-columns: minmax(0, 1fr); }
  .lead summary { grid-template-columns: 2.2em 2.8em minmax(0, 1fr); }
  .lead .glabel { grid-column: 3; text-align: left; }
  .breakdown { padding-left: 0; }
}

/* CRM Data Cleanup */
.issue summary, .lead.issue summary { grid-template-columns: 5.8em minmax(0, 1fr); }
.pill.sev-critical { background: var(--g-dq); font-size: .78rem; padding: 3px 0; }
.pill.sev-warning { background: var(--g-warm); font-size: .78rem; padding: 3px 0; }
.issue .breakdown { padding-left: 6.4em; }
.issue .breakdown .rows li, .dups .rows li { flex-wrap: wrap; }
.s-critical .ffill { background: var(--g-dq); } .s-warn .ffill { background: var(--g-warm); } .s-clean .ffill { background: var(--ok); }
.dupset { padding: 6px 0; border-bottom: 1px solid var(--line); }
.dupset p { margin: 4px 0; }
.bignum.band-poor { color: var(--bad); } .bignum.band-needs-work { color: var(--g-hot); } .bignum.band-fair { color: var(--g-warm); } .bignum.band-good { color: var(--ok); }
#prevLine { margin: -6px 0 10px; }
.maplist .h3 { grid-column: 1 / -1; }
@media (max-width: 560px) {
  .lead.issue summary { grid-template-columns: 5.4em minmax(0, 1fr); }
  .issue .breakdown { padding-left: 0; }
}
