:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --muted: #98a0ad;
  --accent: #5b8cff;
  --accent-2: #3f6fe0;
  --edit: #f0a93b;
  --comment: #46c08d;
  --danger: #e0566a;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.hidden { display: none !important; }
.spacer { flex: 1; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.85rem; line-height: 1.4; }

/* Top bar */
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
#topbar .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.icon-btn {
  background: transparent; color: var(--text); border: none;
  font-size: 1.2rem; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--panel-2); }
.badge { font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.badge.human { background: rgba(91,140,255,.18); color: var(--accent); }
.badge.claude { background: rgba(240,169,59,.18); color: var(--edit); }
.badge.done { background: rgba(70,192,141,.18); color: var(--comment); }
#versionSelect { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; }

/* Buttons */
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 0.9rem; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: 0.82rem; }
.btn.danger { color: var(--danger); border-color: var(--danger); }

/* Drawer */
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(86vw, 340px);
  background: var(--panel); border-right: 1px solid var(--border);
  z-index: 30; display: flex; flex-direction: column;
  padding-top: max(0px, env(safe-area-inset-top));
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-bottom: 1px solid var(--border); }
.drawer-head > div { display: flex; gap: 6px; }
.filter { margin: 10px 12px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); }
.session-list { overflow-y: auto; flex: 1; padding: 0 8px 12px; }
.session-item { padding: 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.session-item:hover { background: var(--panel-2); }
.session-item.active { border-color: var(--accent); background: var(--panel-2); }
.session-item .si-title { font-weight: 600; font-size: 0.92rem; }
.session-item .si-meta { font-size: 0.76rem; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }

/* Main */
#main { flex: 1; min-height: 0; display: flex; }
.empty { margin: auto; max-width: 460px; text-align: center; padding: 24px; }
.empty h1 { font-weight: 700; }
.workspace { flex: 1; display: flex; min-height: 0; width: 100%; }
.editor-pane { flex: 1.6; display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--border); }
.annotations-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; max-width: 380px; }

.pane-toolbar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toggle { font-size: 0.82rem; color: var(--muted); display: flex; align-items: center; gap: 5px; margin-left: auto; }
#bodyEditor {
  flex: 1; width: 100%; resize: none; border: none; outline: none;
  background: var(--bg); color: var(--text); padding: 18px 22px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem; line-height: 1.6;
}
.preview { flex: 1; overflow-y: auto; padding: 18px 22px; line-height: 1.6; }
.preview h1,.preview h2,.preview h3 { line-height: 1.25; }
.pane-footer { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }

.pane-head { display: flex; align-items: baseline; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.annotation-list { overflow-y: auto; flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.ann {
  border: 1px solid var(--border); border-left-width: 3px; border-radius: 8px;
  padding: 9px 10px; background: var(--panel); cursor: pointer;
}
.ann:hover { background: var(--panel-2); }
.ann.edit { border-left-color: var(--edit); }
.ann.comment { border-left-color: var(--comment); }
.ann.addressed { opacity: .55; }
.ann.detached { border-style: dashed; }
.ann .ann-type { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.ann.edit .ann-type { color: var(--edit); }
.ann.comment .ann-type { color: var(--comment); }
.ann .ann-quote { font-size: 0.8rem; color: var(--muted); margin: 4px 0; border-left: 2px solid var(--border); padding-left: 8px; max-height: 3.2em; overflow: hidden; }
.ann .ann-note { font-size: 0.88rem; white-space: pre-wrap; }
.ann .ann-flags { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; }
.modal-card h2 { margin-top: 0; }
.modal-card label { display: block; font-size: 0.85rem; color: var(--muted); margin-top: 12px; }
.modal-card input, .modal-card select, .modal-card textarea {
  width: 100%; margin-top: 5px; padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font-size: 0.95rem; font-family: inherit;
}
.modal-card .row { display: flex; gap: 10px; }
.modal-card .row label { flex: 1; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
.quote { background: var(--panel-2); border-left: 3px solid var(--accent); margin: 8px 0; padding: 8px 12px; border-radius: 6px; font-size: 0.88rem; white-space: pre-wrap; max-height: 8em; overflow-y: auto; }
.status { font-size: 0.85rem; margin-top: 10px; min-height: 1.1em; }
.status.ok { color: var(--comment); }
.status.err { color: var(--danger); }

/* Toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.toast.err { border-color: var(--danger); }

/* Mobile */
@media (max-width: 760px) {
  #topbar .title { max-width: 32vw; }
  .workspace { flex-direction: column; }
  .editor-pane { flex: none; height: 58%; border-right: none; border-bottom: 1px solid var(--border); }
  .annotations-pane { flex: 1; max-width: none; }
}
