:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f2630;
  --line: #2d3540;
  --text: #e6edf3;
  --muted: #8b96a5;
  --accent: #3fb5d4;
  --accent-2: #2a7f95;
  --warn: #f0b429;
  --danger: #ef6b6b;
  --ok: #4cc38a;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; font-size: 14px; }
button, input, select { font: inherit; color: inherit; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 16px;
  height: 52px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); font-size: 22px; }
.name { font-weight: 700; font-size: 17px; letter-spacing: .3px; }
.badge { font-size: 11px; color: var(--warn); border: 1px solid var(--warn); border-radius: 10px; padding: 1px 8px; }
.study-meta { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session { display: flex; align-items: center; gap: 10px; }
.room code { background: var(--panel-2); padding: 2px 6px; border-radius: 4px; }
.presence { display: flex; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #0d1117;
  margin-left: -6px; border: 2px solid var(--panel);
}

/* Buttons */
.btn {
  background: var(--accent-2); border: 1px solid var(--accent); border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
.btn:hover { background: var(--accent); color: #0d1117; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 13px; }

/* Layout */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 230px 1fr 330px;
}
.panel { background: var(--panel); overflow: auto; padding: 12px; }
.worklist { border-right: 1px solid var(--line); }
.side { border-left: 1px solid var(--line); display: flex; flex-direction: column; padding: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 4px 0 10px; }
h3 { font-size: 14px; margin: 16px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

#worklist { list-style: none; padding: 0; margin: 0; }
#worklist li {
  padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; cursor: pointer;
}
#worklist li:hover { border-color: var(--accent-2); }
#worklist li.active { border-color: var(--accent); background: var(--panel-2); }
#worklist .wl-title { font-weight: 600; }
#worklist .wl-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.hint { margin-top: 16px; font-size: 12px; color: var(--muted); line-height: 1.5; border-top: 1px solid var(--line); padding-top: 12px; }

/* Viewer */
.viewer { display: flex; flex-direction: column; min-width: 0; background: #000; }
.toolbar {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 8px; background: var(--panel-2); border-bottom: 1px solid var(--line);
}
.group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tool {
  background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
.tool:hover { border-color: var(--accent-2); }
.tool.active { background: var(--accent); color: #0d1117; border-color: var(--accent); }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }

.canvas-wrap { position: relative; flex: 1; min-height: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.follow-bar {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(22, 27, 34, .9); border: 1px solid var(--line); border-radius: 16px;
  padding: 4px 12px; font-size: 12px; display: none; gap: 8px; align-items: center;
}
.follow-bar.show { display: flex; }
.follow-bar button { background: none; border: none; color: var(--accent); cursor: pointer; text-decoration: underline; }

.slicebar { display: flex; align-items: center; gap: 8px; padding: 8px; background: var(--panel-2); border-top: 1px solid var(--line); }
#slice { flex: 1; accent-color: var(--accent); }
#sliceLabel { min-width: 90px; text-align: right; color: var(--muted); }

/* Tabs */
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: none; padding: 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.count { background: var(--accent); color: #0d1117; border-radius: 8px; padding: 0 6px; font-size: 11px; }
.count:empty { display: none; }
.tabpane { display: none; padding: 12px; overflow: auto; flex: 1; }
.tabpane.active { display: flex; flex-direction: column; }

.checklist, .annlist, .people, .chat { list-style: none; padding: 0; margin: 0 0 10px; }
.checklist li { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.checklist li.done span { color: var(--muted); text-decoration: line-through; }
.checklist li.flash { animation: flash 1.4s ease 2; }
@keyframes flash { 50% { background: rgba(240, 180, 41, .25); } }
.checklist .by { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }

.annlist li { border: 1px solid var(--line); border-left: 4px solid var(--c, var(--accent)); border-radius: 6px; padding: 6px 8px; margin-bottom: 6px; }
.annlist .ann-head { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); }
.annlist .ann-head a { color: var(--accent); cursor: pointer; }
.annlist input[type=text] { width: 100%; margin-top: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; }
.annlist .ann-actions { display: flex; justify-content: space-between; margin-top: 4px; font-size: 12px; }
.annlist .del { background: none; border: none; color: var(--danger); cursor: pointer; }
.annlist .flagged { color: var(--warn); font-weight: 600; }
.empty { color: var(--muted); font-size: 12px; font-style: italic; }

.chat { flex: 1; overflow: auto; }
.chat li { margin-bottom: 8px; line-height: 1.4; }
.chat .who { font-weight: 600; }
.chat .time { color: var(--muted); font-size: 11px; margin-left: 4px; }
.chatform { display: flex; gap: 6px; }
.chatform input, .field input { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.people li { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.people .avatar { margin-left: 0; }
.people .role { margin-left: auto; font-size: 11px; color: var(--warn); }
.row { display: flex; gap: 12px; align-items: center; margin: 8px 0; }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; }

.toast {
  position: fixed; bottom: 36px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: 8px;
  padding: 10px 16px; max-width: 520px; opacity: 0; pointer-events: none; transition: all .25s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.disclaimer { text-align: center; font-size: 11px; color: var(--muted); padding: 4px; border-top: 1px solid var(--line); background: var(--panel); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr 300px; }
  .worklist { display: none; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 1fr 280px; }
  .study-meta, .room { display: none; }
}
