:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #1d1f21;
  --muted: #62666b;
  --line: #e2e1dc;
  --accent: #1f5f8b;
  --accent-text: #ffffff;
  --ready: #1f6f43;
  --ready-bg: #e5f3ea;
  --context: #8a4b00;
  --context-bg: #fdf0dc;
  --verify: #a3341b;
  --verify-bg: #fde8e2;
  --done: #4b5563;
  --done-bg: #eceef1;
  --fix-bg: #e3eefb;
  --fix-line: #3d7cc9;
  --quote-bg: #f3f0e2;
  --user-fix: #7c3aed;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 4%);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

h1, h2, h3 { margin: 0; line-height: 1.25; }

q { quotes: "“" "”"; }

.muted { color: var(--muted); }
.error { color: var(--verify); }
.pad { padding: 16px; }
.hint { color: var(--muted); font-size: 13px; }

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; letter-spacing: 0.01em; }

.day-nav { display: flex; align-items: center; gap: 8px; }
.day-label { text-align: center; min-width: 200px; }
.day-label h1 { font-size: 18px; }

.account { justify-self: end; display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 14px; }

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon-button:disabled { opacity: 0.35; cursor: default; }

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
}
.link-button:hover { text-decoration: underline; }

/* Layout: list and detail side by side on wide screens */

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  height: calc(100vh - 57px);
}

.list, .detail { overflow-y: auto; }
.list { border-right: 1px solid var(--line); padding: 12px 14px 40px; }
.detail { background: var(--surface); padding: 0 28px; }

.list-summary { margin: 4px 4px 10px; color: var(--muted); font-size: 14px; }

.earlier {
  display: block;
  width: 100%;
  margin-bottom: 12px;
  padding: 8px 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--accent);
  text-align: left;
  cursor: pointer;
}

.group h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 4px 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.count {
  display: inline-block;
  min-width: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--done-bg);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  text-transform: none;
  letter-spacing: 0;
}

.cards, .plain, .facts { list-style: none; margin: 0; padding: 0; }
.cards li + li { margin-top: 8px; }

.card {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
}
.card:hover { border-color: #c9c7bf; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgb(31 95 139 / 18%); }
.card.done { opacity: 0.7; box-shadow: none; }

.card-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.card-title { margin-top: 4px; font-weight: 650; }
.card-summary { margin-top: 2px; color: #3a3d40; font-size: 14px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.card-meta .missing { color: var(--context); }
.card-facts { margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; }
.card-facts li { margin-top: 3px; }

.badges { display: inline-flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--done-bg);
  color: var(--done);
}
.badge.ready_for_review, .badge.in_review { background: var(--ready-bg); color: var(--ready); }
.badge.needs_context { background: var(--context-bg); color: var(--context); }
.badge.needs_verification { background: var(--verify-bg); color: var(--verify); }
.badge.confirmed { background: var(--ready-bg); color: var(--ready); }

.kind {
  display: inline-block;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--done-bg);
  color: var(--done);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kind.request { background: #e6eefb; color: #1e4f8f; }
.kind.commitment { background: #ece6fb; color: #5b2f9e; }
.kind.deadline { background: var(--verify-bg); color: var(--verify); }
.kind.decision { background: var(--ready-bg); color: var(--ready); }

/* Detail */

.empty { display: grid; place-items: center; height: 60vh; color: var(--muted); }

.detail-head {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 18px 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.detail-head .back { display: none; margin-bottom: 8px; }
.detail-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.detail-title h2 { font-size: 21px; }
.detail-head p { margin: 6px 0 0; font-size: 14px; }

.notice {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--done-bg);
  font-size: 14px;
}
.notice.needs_context { background: var(--context-bg); color: #5c3200; }

.form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbf9;
}

.field { display: grid; gap: 4px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.subform { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-left: 12px; border-left: 3px solid var(--line); }

select, input, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cfcdc6;
  border-radius: 8px;
  background: var(--surface);
}
select:focus, input:focus, textarea:focus { outline: 2px solid rgb(31 95 139 / 35%); border-color: var(--accent); }
textarea { resize: vertical; }

.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
}
.chip button { border: 0; background: none; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; padding: 0 4px; }
.chips .add-related { width: auto; max-width: 100%; padding: 4px 8px; font-size: 14px; color: var(--accent); }
.check input { width: auto; margin-top: 4px; }

.block { margin-top: 24px; }
.block h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 15px; }
.block > p { margin: 0; }

.flags { padding: 14px 16px; border-radius: var(--radius); background: var(--verify-bg); }
.flags > .hint { margin: -4px 0 10px; }
.flag { padding: 10px 12px; border-radius: 8px; background: var(--surface); }
.flag + .flag { margin-top: 8px; }
.flag-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.heard { font-size: 17px; font-weight: 650; }
.used-in { margin-top: 6px; font-size: 13px; }
.used-in q { display: block; color: var(--muted); }

.verdict { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-top: 8px; font-size: 14px; }
.verdict label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.verdict input[type="radio"] { width: auto; }
.verdict-value { flex: 1 1 200px; }

.play {
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.play.small { padding: 0 6px; font-size: 12px; }

.fact { padding: 10px 0; border-top: 1px solid var(--line); }
.fact:first-child { border-top: 0; }
.fact.flagged { padding-left: 10px; border-left: 3px solid var(--verify); }
.fact-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.fact-head .link-button { margin-left: auto; font-size: 13px; }
blockquote { margin: 6px 0 0; padding-left: 10px; border-left: 3px solid var(--quote-bg); color: var(--muted); font-size: 13px; }

.readonly { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 18px 0 0; }
.readonly dt { color: var(--muted); font-size: 13px; font-weight: 600; }
.readonly dd { margin: 0; }

/* Transcript */

#recording { width: 100%; margin-bottom: 8px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 0 0 8px; font-size: 12px; }
.legend span { padding: 0 4px; }

.transcript {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fcfcfa;
  font-size: 15px;
  line-height: 1.7;
}
.segment { display: grid; grid-template-columns: 48px 1fr; gap: 8px; align-items: baseline; }
.segment .time { color: var(--muted); font-size: 12px; }
.raw-text { white-space: pre-wrap; color: #3a3d40; }

.mark-quote { background: var(--quote-bg); }
.mark-fix { background: var(--fix-bg); box-shadow: inset 0 -2px var(--fix-line); cursor: pointer; }
.mark-flag { background: var(--verify-bg); box-shadow: inset 0 -2px var(--verify); cursor: pointer; }
.mark-user { text-decoration: line-through wavy var(--user-fix); }
.legend .mark-fix, .legend .mark-flag { cursor: default; }

.panel {
  position: relative;
  margin-top: 10px;
  padding: 12px 36px 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.panel p { margin: 0 0 6px; }
.panel .close { position: absolute; top: 6px; right: 8px; border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.inline { display: flex; gap: 8px; }

.user-fixes { margin-top: 10px; font-size: 14px; }
.user-fix-item { display: inline-flex; gap: 4px; margin-right: 12px; }

details.raw { margin-top: 14px; }
details.raw summary { cursor: pointer; color: var(--accent); font-size: 14px; margin-bottom: 8px; }

/* Actions */

.actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin: 28px -28px 0;
  padding: 12px 28px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.actions .muted { margin-right: auto; font-size: 14px; }
.actions.dismiss input { flex: 1; }

.primary, .secondary, .danger {
  padding: 9px 18px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.primary { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); }
.secondary { border: 1px solid #cfcdc6; background: var(--surface); }
.danger { border: 1px solid var(--verify); background: var(--verify); color: #fff; }
button:disabled { opacity: 0.6; cursor: default; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 8px;
  background: #222;
  color: #fff;
  font-size: 14px;
  transform: translateX(-50%);
  box-shadow: var(--shadow);
}
.toast.error { background: var(--verify); }

/* Phones: one column; the detail replaces the list */

@media (max-width: 860px) {
  .topbar { grid-template-columns: 1fr auto; padding: 8px 16px; }
  .brand { display: none; }
  .day-nav { justify-self: start; }
  .day-label { min-width: 0; text-align: left; }
  .layout { display: block; height: auto; }
  .list, .detail { overflow: visible; }
  .list { border-right: 0; padding: 10px 16px 40px; }
  .detail { display: none; padding: 0 16px; }
  .layout.showing-detail .list { display: none; }
  .layout.showing-detail .detail { display: block; }
  .detail-head { position: static; }
  .detail-head .back { display: inline-block; }
  .subform { grid-template-columns: 1fr; }
  .actions { margin: 24px -16px 0; padding: 10px 16px; }
}
