:root {
  --bg: #00303a;
  --panel: #04404c;
  --panel-2: #0a4c59;
  --line: #1c6270;
  --text: #e8f4f2;
  --muted: #8fb7b5;
  --accent: #7ee0c3;
  --accent-ink: #00303a;
  --them: #ffc979;
  --danger: #ff8f8f;
  color-scheme: dark;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); display: flex; flex-direction: column; }

button, select, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.small { padding: 3px 10px; font-size: 13px; }
button.danger { color: var(--danger); }
button.recording { background: var(--danger); border-color: var(--danger); color: #3a0000; }
select, input, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pill { background: var(--bg); border-radius: 99px; padding: 0 7px; font-size: 12px; margin-left: 4px; }

header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 17px; }
.brand em, h1 em { color: var(--accent); font-style: normal; font-weight: 400; }
.logo { color: var(--accent); font-size: 22px; }
.rec { display: flex; align-items: center; gap: 8px; }
#timer { font-variant-numeric: tabular-nums; min-width: 44px; }
.meter { width: 6px; height: 22px; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; position: relative; overflow: hidden; }
.meter i { position: absolute; bottom: 0; left: 0; right: 0; height: 0; background: var(--accent); transition: height 80ms; }
.meter.them i { background: var(--them); }
.status { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; font-size: 12px; }
.chip { border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; color: var(--muted); white-space: nowrap; }
.chip.ready { color: var(--accent); border-color: var(--accent); }
.chip.error { color: var(--danger); border-color: var(--danger); }
.menu { position: relative; display: flex; gap: 8px; }
.popover {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 260px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 30px #0008;
}
.popover[hidden] { display: none; }
.popover label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

main {
  flex: 1; min-height: 0; display: grid; gap: 12px; padding: 12px 16px 16px;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr);
}
.pane {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.pane h2 { margin: 0; padding: 10px 14px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border-bottom: 1px solid var(--line); }
.scroll { flex: 1; overflow-y: auto; padding: 10px 14px; }
.empty { color: var(--muted); font-size: 14px; }

.tabs { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tabs [role="tab"] { background: none; border: none; border-radius: 6px; color: var(--muted); }
.tabs [role="tab"][aria-selected="true"] { color: var(--text); background: var(--panel-2); }
#enhanceBtn { margin-left: auto; }
#notes { flex: 1; resize: none; border: none; border-radius: 0; background: transparent; padding: 14px; line-height: 1.7; outline: none; }
.enhanced { flex: 1; overflow-y: auto; padding: 8px 16px 16px; }
.enhanced[hidden] { display: none; }
.enhanced .item { margin: 10px 0; }
.enhanced .mine { font-weight: 600; }
.enhanced .ai { color: var(--muted); margin-top: 2px; }
.enhanced .ai.done { color: var(--text); }
.enhanced h3 { font-size: 14px; color: var(--accent); margin: 18px 0 6px; }
.enhanced ul { margin: 4px 0; padding-left: 20px; }
.enhanced ul.quotes { list-style: none; padding-left: 10px; border-left: 2px solid var(--line); color: var(--muted); font-size: 14px; }
.enhanced ul.quotes li { margin: 2px 0; }
.enhanced time { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--muted); }
.enhanced a { text-decoration: none; }
.enhanced .who { font-size: 12px; font-weight: 600; color: var(--accent); }
.enhanced .who.Them { color: var(--them); }
.enhanced .due { font-size: 12px; color: var(--them); border: 1px solid var(--line); border-radius: 99px; padding: 0 6px; }

.seg { margin: 0 0 8px; }
.seg .who { font-size: 12px; font-weight: 600; color: var(--accent); margin-right: 6px; }
.seg.Them .who { color: var(--them); }
.seg time { font-size: 11px; color: var(--muted); margin-right: 6px; font-variant-numeric: tabular-nums; }
.seg.pending { color: var(--muted); font-style: italic; }
.seg.flash { background: var(--panel-2); border-radius: 6px; transition: background 0.3s; }
.seg mark { background: none; color: inherit; border-bottom: 2px solid var(--them); }

.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.card .q { font-weight: 600; margin-bottom: 6px; }
.card .q::before { content: "? "; color: var(--them); }
.card.ask .q::before { content: "› "; color: var(--accent); }
.card .a { white-space: pre-wrap; }
.card .a.none { color: var(--muted); font-style: italic; }
.card .src { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.card .src details { font-size: 12px; background: var(--bg); border-radius: 6px; padding: 2px 8px; max-width: 100%; }
.card .src summary { cursor: pointer; color: var(--accent); }
.card .src p { margin: 4px 0; color: var(--muted); white-space: pre-wrap; }
.card .kind { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 2px; }
.card.context { border-style: dashed; }
.card.context .q { font-weight: 400; color: var(--muted); font-style: italic; }
.card.context .q::before { content: "“"; }
.card .a + .extract { margin-top: 8px; }
.extract { margin: 0; padding: 6px 10px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 6px 6px 0; }
.extract b { font-weight: 600; color: var(--text); }
.extract .ctx { color: var(--muted); }
.extract cite { display: block; margin-top: 4px; font-size: 12px; font-style: normal; color: var(--accent); }
.ask-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.ask-form input { flex: 1; min-width: 0; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 100vw); z-index: 30;
  background: var(--panel); border-left: 1px solid var(--line); padding: 14px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px; box-shadow: -10px 0 30px #0008;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer-head h2 { margin: 0; font-size: 16px; }
.drop { display: block; border: 1.5px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--panel-2); }
#pasteForm { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#kbList { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
#kbList li { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 8px; padding: 6px 10px; }
#kbList .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#kbList button { padding: 0 8px; }

.overlay { position: fixed; inset: 0; background: #001d24e6; z-index: 40; display: grid; place-items: center; padding: 16px; }
.overlay[hidden] { display: none; }
.dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; max-width: 480px; display: flex; flex-direction: column; gap: 10px; }
.dialog h1 { margin: 0; font-size: 24px; }
.dialog p, .dialog ul { margin: 0; }
.dialog ul { padding-left: 20px; }
.dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; grid-auto-rows: minmax(320px, auto); overflow-y: auto; }
  .status { margin-left: 0; width: 100%; }
}
