:root {
  color-scheme: light;
  --bg: #f6f7f9; --surface: #ffffff; --border: #e3e6ea;
  --text: #191919; --text-2: #666666;
  --accent: #257de0; --accent-ink: #ffffff;
  --pos: #0b7a1f; --neg: #c63a3b;
  --series-1: #257de0; --series-2: #f47230; --grid: #ececec;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111213; --surface: #191919; --border: #2c2e31;
    --text: #efefef; --text-2: #9c9c9c;
    --accent: #338ced; --pos: #3ec457; --neg: #eb6263;
    --series-1: #338ced; --series-2: #e76624; --grid: #2a2a2a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .4rem 0; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--text-2); font-weight: 600; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .8rem; overflow-x: auto; }
.container { max-width: 1180px; margin: 0 auto; padding: 0 1rem; }
main.container { padding-bottom: 3rem; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); margin-bottom: 1.2rem; }
.topbar .container { height: 56px; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.logo { color: var(--accent); }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.gap { gap: .6rem; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: .7rem; }
.mt { margin-top: 1rem; }
.right { text-align: right; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }
.big { font-size: 1.1rem; margin: 0; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.narrow { max-width: 440px; margin: 3rem auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.error { border-color: var(--neg); }
.card.ai { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.callout { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); border-radius: 8px; padding: .7rem .9rem; }
.callout.neg { background: color-mix(in srgb, var(--neg) 12%, var(--surface)); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 + section { margin-top: 1rem; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; margin-top: 1rem; }
@media (max-width: 860px) { .grid-main { grid-template-columns: 1fr; } }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--text-2); }
label.row { flex-direction: row; color: var(--text); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem; width: 100%; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
button, .button { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: .5rem .9rem; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.small { padding: .2rem .55rem; font-size: .85rem; }
button.link { background: none; border: none; padding: 0; color: var(--accent); }
button.link.muted { color: var(--text-2); }
button[disabled] { opacity: .6; cursor: progress; }
.list { list-style: none; padding: 0; margin: 0; }
.list > li { padding: .55rem 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: none; }
.list > li > a { color: var(--text); }
.list > li.me { font-weight: 600; }
.activity .date { color: var(--text-2); font-size: .8rem; width: 5.5rem; flex-shrink: 0; }
.chip { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--text-2); font-weight: 500; }
.chip.ai { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.conf-low { color: var(--neg); } .conf-medium { color: #b97800; } .conf-high { color: var(--pos); }
.file { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); cursor: pointer; }
.file input { width: auto; border: none; padding: 0; }
details summary { cursor: pointer; color: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tile, .fact { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.tile-label { font-size: .8rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.tile-value { font-size: 1.7rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.fact-value { font-size: 1.15rem; font-weight: 600; text-transform: capitalize; }
.chart { position: relative; height: 260px; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: .5rem .4rem; border-bottom: 1px solid var(--border); text-align: left; }
.table th { font-size: .8rem; color: var(--text-2); font-weight: 600; }
.table .right { text-align: right; }
.draft { border: 1px solid var(--border); }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .7rem; margin: .7rem 0; }
.span2 { grid-column: span 2; }
@media (max-width: 520px) { .span2 { grid-column: auto; } }
.parts { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .7rem; padding: .6rem; border: 1px dashed var(--border); border-radius: 8px; }
.part { flex-direction: row; align-items: center; gap: .6rem; color: var(--text); }
.part .val { width: 7rem; }
.answer { border-top: 1px solid var(--border); padding-top: .7rem; margin-top: .7rem; }
.answer .q { font-weight: 600; margin-bottom: .3rem; }
.answer .a { white-space: pre-wrap; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.answer .li { white-space: normal; padding-left: .2rem; }
.name-input { width: 8rem; flex: none; }

/* ---------- mobile ---------- */
html { -webkit-text-size-adjust: 100%; }
.hide-sm { display: inline; } .show-sm { display: none; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.grid-main { grid-template-columns: minmax(0, 1fr) 360px; }
.grid-main > * { min-width: 0; }
.act { display: flex; align-items: center; gap: .6rem; }
.act .what { flex: 1; min-width: 0; }
.act .what b { overflow-wrap: anywhere; }
.act .amt { white-space: nowrap; }
.act .del button { padding: .4rem .5rem; }
.grid2 { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.container { padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }

@media (max-width: 860px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .col-main, .col-side { display: contents; }
  .o1 { order: 1; } .o2 { order: 2; } .o3 { order: 3; } .o4 { order: 4; } .o5 { order: 5; }
  .grid-main > .col-main > .card, .grid-main > .col-side > .card { margin-bottom: 0; }
  .grid-main { gap: 1rem; }
}

@media (max-width: 600px) {
  body { font-size: 16px; }
  h1 { font-size: 1.4rem; }
  .hide-sm { display: none; } .show-sm { display: inline; }
  .topbar .container { height: 52px; }
  .nav { gap: 1rem; }
  .card { padding: .9rem 1rem; border-radius: 10px; }
  /* prevent iOS focus-zoom, bigger tap targets */
  input, select, textarea { font-size: 16px; padding: .65rem .7rem; }
  input[type=checkbox] { width: 1.25rem; height: 1.25rem; }
  button, .button { padding: .65rem 1rem; min-height: 44px; }
  button.small { padding: .45rem .8rem; min-height: 40px; }
  button.link { min-height: 0; padding: .3rem .5rem; }
  .actions { width: 100%; }
  .actions .button { flex: 1; text-align: center; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
  .tile, .fact { padding: .8rem .9rem; }
  .tile-value { font-size: 1.35rem; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
  .fact-value { font-size: 1.05rem; }
  .chart { height: 240px; }
  /* activity: date on its own line */
  .act { flex-wrap: wrap; row-gap: .1rem; }
  .act .date { width: 100%; }
  .act .what { flex: 1 1 0; }
  .list > li { padding: .7rem 0; }
  /* editor */
  .grid-form { grid-template-columns: 1fr 1fr; }
  .span2 { grid-column: 1 / -1; }
  .part .val { width: 6rem; }
  .row.between.wrap > .file { width: 100%; }
  .table { font-size: .9rem; }
  .narrow { margin: 1.5rem auto; }
}
@media (max-width: 600px) {
  .tiles .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .file { flex-wrap: wrap; max-width: 100%; }
  .file input { max-width: 100%; }
}
