:root {
  --bg: #101418;
  --panel: #171d24;
  --panel2: #1d252f;
  --ink: #e8edf2;
  --dim: #93a1b0;
  --line: #2a3440;
  --accent: #e8b33d;
  --good: #3fa46a;
  --bad: #c14b4b;
  --tutor: #233146;
  --resident: #26332a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-system, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
header {
  display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
h1 { font-size: 22px; margin: 0; letter-spacing: 0.2px; }
.tag { margin: 2px 0 0; color: var(--dim); }
.keybox { min-width: 320px; max-width: 560px; flex: 1; }
.keybox label { font-size: 13px; color: var(--dim); display: block; margin-bottom: 6px; }
.keyrow { display: flex; gap: 8px; flex-wrap: wrap; }
.keyrow input { flex: 1; min-width: 180px; }
input, select, textarea {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; font: inherit; font-size: 15px;
}
textarea { width: 100%; resize: vertical; }
button {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 12px; font: inherit; font-size: 15px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #161006; border-color: var(--accent); font-weight: 600; }
button.good { border-color: var(--good); }
button.bad { border-color: var(--bad); }
button:disabled { opacity: 0.55; cursor: wait; }
.status { font-size: 13px; color: var(--dim); margin: 6px 0 0; }
.status.ok { color: var(--good); }
.status.err { color: #e07a7a; }
.dim { color: var(--dim); }

main {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px;
  padding: 16px 20px; align-items: start;
}
.thread {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; min-height: 320px; max-height: 56vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
}
.msg { border-radius: 10px; padding: 10px 12px; max-width: 92%; white-space: pre-wrap; }
.msg .who { display: block; font-size: 12px; color: var(--dim); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.6px; }
.msg.resident { background: var(--resident); align-self: flex-end; }
.msg.tutor { background: var(--tutor); align-self: flex-start; }
.msg.note { background: transparent; border: 1px dashed var(--line); color: var(--dim); align-self: center; font-size: 14px; }
.msg.error { background: #3a1f22; border: 1px solid var(--bad); align-self: stretch; max-width: 100%; }
.interim { color: var(--dim); min-height: 20px; margin: 6px 2px 0; font-style: italic; }
.composer { margin-top: 10px; }
.composer-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.check { font-size: 14px; color: var(--dim); display: inline-flex; gap: 6px; align-items: center; }
.casebar {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.casebar-label { color: var(--dim); font-size: 14px; }

.side { display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.panel h2 { font-size: 15px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--dim); }
.panel video { width: 100%; border-radius: 8px; background: #000; display: none; }
.panel video.on { display: block; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
button.snap-btn {
  width: 100%; margin: 4px 0; padding: 13px; font-size: 17px; font-weight: 700;
  background: var(--accent); color: #161006; border-color: var(--accent); border-radius: 10px;
}
button.snap-btn:hover { filter: brightness(1.08); }
.snap-key { font-weight: 400; font-size: 13px; opacity: 0.75; }
.snap-thumb { width: 100%; border-radius: 8px; border: 1px solid var(--line); margin-top: 8px; display: block; }
.snap-thumb[hidden] { display: none; }
.question-view { font-size: 14px; background: var(--panel2); border-radius: 8px; padding: 10px; max-height: 300px; overflow-y: auto; white-space: pre-wrap; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--dim); font-size: 14px; }
.map-entry { border-bottom: 1px solid var(--line); padding: 8px 0; }
.map-entry:last-child { border-bottom: none; }
.map-entry .topic { font-weight: 700; }
.map-entry .meta { font-size: 12px; color: var(--dim); }
.hist-entry { border-bottom: 1px solid var(--line); padding: 8px 0; font-size: 14px; }
.hist-entry:last-child { border-bottom: none; }
.hist-entry .meta { font-size: 12px; color: var(--dim); }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  .thread { max-height: none; }
}
