/* Second Thought pilot — readable chat + foldable per-turn Debug sidebar. */
:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #1c2430; --muted: #66707d;
  --line: #d9dee5; --accent: #2b5fd9; --accent-ink: #ffffff;
  --user-bubble: #2b5fd9; --agent-bubble: #ffffff;
  --danger: #b3261e; --ok: #1b7f4d; --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --panel: #1b2129; --ink: #e6eaf0; --muted: #9aa4b0;
    --line: #2c3440; --accent: #6d97ee; --user-bubble: #34599e; --agent-bubble: #1e252e;
    --danger: #e5857d; --ok: #67c393;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 -apple-system, "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
}
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); font-size: 20px; }
.brand h1 { font-size: 16px; margin: 0; font-weight: 600; }
.status-bar { color: var(--muted); font-size: 12.5px; margin-left: 8px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 7px 14px; font-size: 14px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:disabled { opacity: 0.5; cursor: default; }
.btn.ghost[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.gate {
  max-width: 460px; margin: 10vh auto 0; padding: 0 16px; text-align: center;
}
.gate-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px 24px; text-align: left;
}
.gate-card h2 { margin: 0 0 8px; font-size: 18px; }
.gate-card input {
  width: 100%; padding: 9px 12px; margin: 12px 0; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); color: var(--ink); font-size: 14px;
}
.gate-error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }
.gate-notice { color: var(--muted); font-size: 12.5px; margin-top: 14px; }

.app { display: flex; height: calc(100vh - 57px); }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.messages { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; background: var(--agent-bubble); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.error-banner {
  margin: 0 16px; padding: 10px 14px; border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 12%, var(--panel));
  border: 1px solid var(--danger); color: var(--ink); font-size: 14px;
}
.error-banner .btn { margin-left: 10px; }
.waiting { padding: 8px 18px; color: var(--muted); font-size: 14px; }
.waiting::after { content: "…"; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 100% { content: "…"; } }
.composer { display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea {
  flex: 1; resize: vertical; min-height: 64px; max-height: 200px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: var(--bg); color: var(--ink); font: inherit;
}
.composer .btn { align-self: flex-end; }

.sidebar {
  width: min(520px, 45vw); border-left: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted);
}
.sidebar-head select { font-size: 13px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; }
.debug-body { flex: 1; overflow-y: auto; padding: 12px 14px; font-size: 13.5px; }
.debug-empty { color: var(--muted); }
.debug-body h3 { font-size: 13px; color: var(--muted); margin: 16px 0 6px; text-transform: none; }
.debug-body details { border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; background: var(--bg); }
.debug-body summary {
  cursor: pointer; padding: 7px 10px; list-style: revert;
  display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
}
.debug-body summary .tag { font-size: 11.5px; color: var(--muted); }
.debug-body .detail-content { padding: 4px 12px 10px; }
.debug-body pre {
  margin: 6px 0; padding: 10px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; overflow: auto; max-height: 320px; font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; word-break: break-word;
}
.tl { list-style: none; margin: 6px 0; padding: 0; }
.tl li { padding: 3px 0; color: var(--ink); }
.tl button {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font: inherit; padding: 2px 4px; text-align: left;
}
.tl .tl-err { color: var(--danger); }
.badge { font-size: 11px; border-radius: 6px; padding: 1px 7px; border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.fail { color: var(--danger); border-color: var(--danger); }
@media (max-width: 900px) {
  .app { flex-direction: column-reverse; }
  .sidebar { width: 100%; max-height: 45vh; border-left: none; border-top: 1px solid var(--line); }
}
