:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede5;
  --ink: #1c2321;
  --ink-2: #5b6461;
  --ink-3: #8a918e;
  --line: #e3dfd5;
  --brand: #0f3d3e;
  --brand-ink: #f3c969;
  --accent: #b5651d;
  --high: #b3261e;
  --high-bg: #fbe9e7;
  --med: #9a5b00;
  --med-bg: #fdf1dc;
  --low: #3b6b8f;
  --low-bg: #e8f0f7;
  --ok: #2e7d4f;
  --ok-bg: #e5f3ea;
  --bar: #00918b;
  --bar-hi: #006f6a;
  --bubble-me: #0f3d3e;
  --bubble-me-ink: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 28, .06), 0 2px 10px rgba(20, 30, 28, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615;
    --surface: #1a201f;
    --surface-2: #222a28;
    --ink: #e9edeb;
    --ink-2: #aab3b0;
    --ink-3: #7d8784;
    --line: #2c3533;
    --brand: #173f40;
    --brand-ink: #f3c969;
    --accent: #e0a060;
    --high: #ff8a80;
    --high-bg: #3a1d1b;
    --med: #f0b95a;
    --med-bg: #36291a;
    --low: #8cb8dc;
    --low-bg: #1b2a36;
    --ok: #7fd1a1;
    --ok-bg: #16301f;
    --bar: #1aa8a0;
    --bar-hi: #4cc9c0;
    --bubble-me: #2a5e5f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--brand); color: #fff;
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  display: grid; place-items: center; background: var(--brand-ink); color: var(--brand);
  font: 700 20px/1 Georgia, serif;
}
.name { font-weight: 650; line-height: 1.15; }
.biz { font-size: 13px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 58vw; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.badge { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; padding: 3px 8px; border-radius: 99px; background: rgba(243, 201, 105, .2); color: var(--brand-ink); }
.icon-btn { background: rgba(255,255,255,.12); border: 0; color: #fff; width: 36px; height: 36px; border-radius: 10px; font-size: 20px; }

/* Layout */
main { max-width: 720px; margin: 0 auto; padding: 14px 16px calc(96px + var(--safe-b)); outline: none; }
h2 { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); margin: 22px 2px 8px; font-weight: 650; }
h2:first-child { margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card { margin-top: 10px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.empty { color: var(--ink-3); text-align: center; padding: 28px 8px; }

/* Brief card */
.brief { background: linear-gradient(160deg, var(--brand), #0b2e2f); color: #fff; border: 0; }
.brief .subject { font-size: 13px; opacity: .8; margin-bottom: 6px; }
.brief .opening { font-size: 17px; line-height: 1.45; }
.brief .row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; }
.brief .btn { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; }
.brief .btn.primary { background: var(--brand-ink); color: var(--brand); }
.btn:disabled { opacity: .55; cursor: default; }

/* Scoreboard */
.score { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--ink-2); }
.stat.good b { color: var(--ok); }

/* Slips */
.slip { display: flex; gap: 12px; align-items: flex-start; }
.sev { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; }
.sev.high { background: var(--high); } .sev.medium { background: var(--med); } .sev.low { background: var(--low); }
.slip .t { font-weight: 620; }
.slip .d { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.slip .acts { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 11px; font-weight: 650; letter-spacing: .03em; text-transform: uppercase; padding: 2px 7px; border-radius: 6px; }
.tag.high { background: var(--high-bg); color: var(--high); } .tag.medium { background: var(--med-bg); color: var(--med); } .tag.low { background: var(--low-bg); color: var(--low); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; padding-top: 0; }
.list li:last-child { padding-bottom: 0; }
.ord { display: flex; justify-content: space-between; gap: 10px; }
.ord .n { font-weight: 650; font-variant-numeric: tabular-nums; }

/* Drafts */
.draft .hd { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.draft .to { font-weight: 650; }
.draft .subj { font-size: 14px; color: var(--ink-2); }
.draft details { margin: 10px 0; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.draft summary { cursor: pointer; color: var(--ink-2); }
.draft .msg { white-space: pre-wrap; margin-top: 8px; }
.checks { margin: 10px 0; padding: 10px 12px; background: var(--med-bg); color: var(--med); border-radius: 10px; font-size: 14px; }
.checks div + div { margin-top: 4px; }
.draft textarea { width: 100%; min-height: 170px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface); resize: vertical; line-height: 1.45; }
.draft .acts { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.by { font-size: 12px; color: var(--ink-3); }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 88%; padding: 10px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.owner { align-self: flex-end; background: var(--bubble-me); color: var(--bubble-me-ink); border-bottom-right-radius: 5px; }
.bubble.derek { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; box-shadow: var(--shadow); white-space: normal; }
.bubble.derek p { margin: 0 0 8px; } .bubble.derek p:last-child { margin-bottom: 0; }
.bubble.derek ul, .bubble.derek ol { margin: 4px 0 8px; padding-left: 20px; }
.lookups { align-self: flex-start; font-size: 12px; color: var(--ink-3); margin: -4px 0 0 4px; }
.lookups summary { cursor: pointer; }
.typing { align-self: flex-start; color: var(--ink-3); font-size: 14px; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(62px + var(--safe-b)); z-index: 4;
  background: var(--bg); border-top: 1px solid var(--line); padding: 8px 12px;
}
.composer form { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px; background: var(--surface); max-height: 120px; }
.composer .btn { border-radius: 20px; }
.chat-pad { height: 70px; }
.suggest { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 8px; }
.suggest button { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-size: 14px; }

/* Brain */
.file { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; background: none; border: 0; padding: 10px 0; border-top: 1px solid var(--line); }
.file:first-child { border-top: 0; padding-top: 0; }
.file code { font-size: 14px; }
.md { font-size: 15px; }
.md h1 { font-size: 20px; margin: 0 0 10px; } .md h2 { text-transform: none; letter-spacing: 0; font-size: 16px; color: var(--ink); margin: 18px 0 6px; }
.md blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--line); color: var(--ink-2); }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; display: block; overflow-x: auto; }
.md td, .md th { border: 1px solid var(--line); padding: 5px 8px; text-align: left; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.commit { font-size: 14px; }
.commit .sha { font-family: ui-monospace, Consolas, monospace; color: var(--accent); font-size: 12px; }

/* Activity */
.ev { display: flex; gap: 10px; }
.ev .ic { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); font-size: 14px; }
.ev .when { font-size: 12px; color: var(--ink-3); }
.saved { font-size: 12px; color: var(--ok); white-space: nowrap; }

/* Usage chart: one series, one hue (validated: #00918b vs #fff 3.9:1; #1aa8a0 vs dark 5.6:1) */
.chart { position: relative; }
.chart-title { font-size: 14px; font-weight: 620; margin-bottom: 10px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 120px; border-bottom: 1px solid var(--line); }
.bar-col { position: relative; flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; cursor: default; outline: none; padding: 0 1px; }
.bar { background: var(--bar); border-radius: 4px 4px 0 0; min-height: 0; }
.bar-col.on .bar, .bar-col:focus-visible .bar { background: var(--bar-hi); }
.bar-val { position: absolute; bottom: calc(100% + 2px); left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bars .bar-col:has(.bar-val) { justify-content: flex-end; }
.bar-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); margin-top: 4px; }
.chart-tip { position: absolute; top: 34px; max-width: 260px; background: var(--ink); color: var(--bg); font-size: 12px; padding: 6px 9px; border-radius: 8px; pointer-events: none; z-index: 2; }
.usage-table { border-collapse: collapse; width: 100%; margin-top: 6px; font-variant-numeric: tabular-nums; }
.usage-table th, .usage-table td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.usage-table th:first-child, .usage-table td:first-child { text-align: left; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs button { position: relative; background: none; border: 0; padding: 8px 0 9px; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; color: var(--ink-3); min-height: 62px; }
.tabs .ti { font-size: 20px; line-height: 1.2; }
.tabs button.on { color: var(--brand); font-weight: 650; }
@media (prefers-color-scheme: dark) { .tabs button.on { color: var(--brand-ink); } }
.pill { position: absolute; top: 5px; left: 50%; margin-left: 8px; background: var(--high); color: #fff; font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; border-radius: 9px; padding: 0 5px; }

/* Sheet + toast */
dialog { border: 0; border-radius: 18px 18px 0 0; padding: 0; width: 100%; max-width: 720px; margin: auto auto 0; max-height: 88dvh; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 20, 18, .45); }
.sheet-body { padding: 16px 16px calc(20px + var(--safe-b)); overflow: auto; max-height: 88dvh; }
.sheet-body .close { float: right; }
.sheet-body iframe { width: 100%; height: 70dvh; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.menu button { display: block; width: 100%; text-align: left; margin-top: 8px; }
#toast { position: fixed; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); z-index: 9; }
#toast.show { opacity: 1; }

@media (min-width: 760px) {
  main { padding-top: 22px; }
  .tabs { max-width: 720px; left: 50%; transform: translateX(-50%); border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}
