:root {
  --bg: #0d1117;
  --bg2: #131a23;
  --panel: #171f2a;
  --line: #232e3c;
  --text: #dbe4ee;
  --muted: #8494a7;
  --accent: #4f8ff7;
  --accent2: #22c55e;
  --pm: #1c2a3d;
  --danger: #ef4444;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
button {
  font: inherit;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
button.ghost:hover { color: var(--text); border-color: var(--muted); }
button.danger { color: var(--danger); border-color: var(--danger); }
input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
a { color: var(--accent); text-decoration: none; }

/* ---- auth ---- */
body.auth { display: grid; place-items: center; padding: 16px; }
.card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  display: grid;
  gap: 14px;
}
.card h1 { margin: 0; font-size: 22px; }
.card h1 span, .brand span { color: var(--accent); }
.card .sub { margin: -6px 0 4px; color: var(--muted); font-size: 13px; }
.card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.err { color: var(--danger); font-size: 13px; margin: 0; }

/* ---- app frame ---- */
body.app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg2);
}
.brand { font-weight: 700; font-size: 16px; }
.topbar nav { display: flex; align-items: center; gap: 12px; }
.who { color: var(--muted); font-size: 13px; }
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: 0; }
.side {
  border-right: 1px solid var(--line);
  background: var(--bg2);
  overflow-y: auto;
  padding: 14px;
}
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.side-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.plist li {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
}
.plist li:hover { background: var(--panel); }
.plist li.on { background: var(--panel); border-color: var(--line); }
.plist .pn { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.plist .st { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.busy { background: var(--accent2); box-shadow: 0 0 8px var(--accent2); }

/* ---- main ---- */
.main { display: grid; min-height: 0; }
.empty { place-self: center; text-align: center; color: var(--muted); max-width: 420px; padding: 24px; }
.empty h2 { color: var(--text); }
#workspace { display: grid; grid-template-rows: auto auto 1fr; min-height: 0; }
.phead { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px 6px; }
.phead h2 { margin: 0; font-size: 19px; }
.phead .status { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.phead-right { display: flex; align-items: center; gap: 12px; }
.busy { color: var(--accent2); font-size: 13px; display: inline-flex; align-items: center; gap: 8px; }
.dot-pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--accent2); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
.tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.tabs button {
  background: none;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 12px;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tabpane { display: none; min-height: 0; }
.tabpane.on { display: grid; grid-template-rows: 1fr auto; }
.tabpane.doc.on { display: block; overflow-y: auto; padding: 18px 22px; }
.doc pre { white-space: pre-wrap; font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); margin: 0; }
.doc .none { color: var(--muted); }
.commit { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.commit .h { color: var(--accent); font-family: ui-monospace, Menlo, monospace; }
.commit .d { color: var(--muted); flex: none; }

/* ---- feed ---- */
.feed { overflow-y: auto; padding: 16px 20px; display: grid; gap: 10px; align-content: start; }
.row { max-width: 78ch; }
.row .meta { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.row .meta b { color: var(--text); font-weight: 600; }
.row .body {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.row.pm .body { background: var(--pm); border-color: #2a3f5e; }
.row.pm .meta b { color: var(--accent); }
.row.user .meta b { color: var(--accent2); }
.row.system { justify-self: center; color: var(--muted); font-size: 12.5px; }
.row.system .body { background: none; border: 0; padding: 2px; text-align: center; }
.row.file .body a { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.row img.thumb { max-width: 320px; max-height: 220px; border-radius: 8px; border: 1px solid var(--line); display: block; margin-top: 6px; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.composer textarea { resize: none; min-height: 44px; }
.composer button { align-self: flex-end; height: 44px; }
.composer .tool {
  width: 44px;
  padding: 0;
  flex: none;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  gap: 2px;
  font-size: 17px;
}
.composer .tool small { font-size: 9px; color: var(--muted); }
.composer .tool.rec { border-color: var(--danger); color: var(--danger); animation: pulse 1.2s infinite; }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  width: min(380px, 90vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.wide { width: min(560px, 92vw); }
dialog h4 { margin: 14px 0 2px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
select { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; width: 100%; }
.mlist { display: grid; gap: 8px; max-height: 40vh; overflow-y: auto; }
.mrow { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.mrow .mi { flex: 1; min-width: 0; }
.mrow .mi b { display: block; }
.mrow .mi span { color: var(--muted); font-size: 12.5px; }
.mrow .chip { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); color: var(--accent); white-space: nowrap; }
.mrow.off { opacity: 0.5; }
.mrow button { padding: 5px 10px; font-size: 12.5px; }
.act { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; align-items: baseline; }
.act .t { color: var(--muted); flex: none; font-size: 12px; width: 86px; }
.act .r { color: var(--accent); flex: none; width: 84px; }
.act .k { flex: none; width: 110px; color: var(--accent2); }
dialog h3 { margin: 0 0 12px; }
dialog form { display: grid; gap: 10px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); max-height: 30vh; }
  .row { max-width: 100%; }
}
