:root {
  --bg: #fffaf0;
  --surface: #ffffff;
  --ink: #2b2118;
  --muted: #7a6a5c;
  --line: #eadfcd;
  --accent: #fad058;
  --accent-ink: #4a3410;
  --brown: #9e7855;
  --good: #2f7d4f;
  --good-bg: #e5f4ea;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --warn-bg: #fff3c4;
  --bubble: #e7f8dc;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1712;
    --surface: #2a221b;
    --ink: #f3ebe1;
    --muted: #b5a594;
    --line: #43382d;
    --accent-ink: #2b2118;
    --good-bg: #1f3a29;
    --bad-bg: #4a1f1b;
    --warn-bg: #4a3d12;
    --bubble: #23402c;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5; }
a { color: var(--brown); }
main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
h1 { font-size: 1.6rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 28px 0 10px; }
small { color: var(--muted); font-weight: 400; }
code { background: var(--line); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; word-break: break-all; }

.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 10px 16px;
  background: var(--accent); color: var(--accent-ink); }
.top a { color: var(--accent-ink); text-decoration: none; font-weight: 500; }
.top nav { display: flex; flex-wrap: wrap; gap: 4px 16px; flex: 1; }
.brand { font-weight: 800 !important; font-size: 1.1rem; }
.brand span, .login h1 span { font-weight: 400; }
.signout { margin: 0; }
.practice { background: var(--warn-bg); padding: 8px 16px; text-align: center; font-size: 0.9rem; }

.note { background: var(--good-bg); color: var(--good); padding: 10px 14px; border-radius: var(--radius); }
.error { background: var(--bad-bg); color: var(--bad); padding: 10px 14px; border-radius: var(--radius); }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.85rem; }
.crumbs { margin: 0 0 4px; font-size: 0.9rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin: 16px 0; }
.card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.panel { margin: 16px 0; }
.panel h2 { margin-top: 0; }
.label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.big { font-size: 1.6rem; font-weight: 700; }
.big small { font-size: 0.95rem; }

.row-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.row-head h1, .row-head h2 { margin: 0; }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td:first-child { white-space: normal; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.chip { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 0.8rem;
  background: var(--line); color: var(--ink); text-transform: lowercase; }
.chip.sending, .chip.approved, .chip.done { background: var(--good-bg); color: var(--good); }
.chip.paused, .chip.pending, .chip.draft { background: var(--warn-bg); }
.chip.cancelled, .chip.rejected, .chip.disabled { background: var(--bad-bg); color: var(--bad); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--bad);
  color: #fff; font-size: 0.75rem; text-align: center; }

form { margin: 0; }
.stack { display: grid; gap: 12px; max-width: 640px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input { flex: 1; min-width: 160px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
label { display: grid; gap: 4px; font-weight: 500; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); width: 100%; }
input[type=checkbox] { width: auto; margin-top: 4px; }
button, .button { font: inherit; font-weight: 600; padding: 9px 16px; border: 0; border-radius: 8px;
  background: var(--brown); color: #fff; cursor: pointer; text-decoration: none; display: inline-block; }
button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.link { background: none; color: var(--accent-ink); padding: 0; font-weight: 500; }

.bubble { background: var(--bubble); border-radius: 10px; padding: 12px 14px; white-space: pre-wrap;
  font-family: inherit; max-width: 520px; margin: 8px 0; }
.header-media { max-width: 320px; border-radius: 10px; display: block; }
.pick { display: block; text-decoration: none; color: var(--ink); }
.pick:hover { border-color: var(--brown); }
.template header { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.template h2 { margin: 0 8px 0 0; }

.events { list-style: none; padding: 0; margin: 0; }
.events li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.events time { color: var(--muted); margin-right: 8px; font-size: 0.9rem; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.conversations { list-style: none; padding: 0; }
.conversations a { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px;
  text-decoration: none; color: var(--ink); }
.conversations .who { font-weight: 600; }
.conversations .when { color: var(--muted); font-size: 0.85rem; }
.conversations .last { color: var(--muted); grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thread { list-style: none; padding: 0; display: grid; gap: 8px; }
.thread li { max-width: 80%; padding: 8px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.thread li.out { justify-self: end; background: var(--bubble); border-color: transparent; }
.thread pre { margin: 0; white-space: pre-wrap; font-family: inherit; }
.thread .meta { font-size: 0.75rem; color: var(--muted); }

.login { max-width: 380px; margin: 10vh auto; }

@media (max-width: 640px) {
  .top nav { order: 3; flex-basis: 100%; }
  .signout { margin-left: auto; }
  .two { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .thread li { max-width: 95%; }
}
