:root {
  --bg: #0e0f13;
  --panel: #16181f;
  --panel-2: #1d2029;
  --border: #262a35;
  --text: #e6e8ee;
  --muted: #8b90a0;
  --accent: #d97757;
  --accent-2: #c4633f;
  --user: #23324a;
  --tool: #1a2620;
  --err: #f0806b;
  --warn: #e0b34a;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--err); min-height: 1.2em; font-size: 13px; margin-top: 8px; }
button { cursor: pointer; font-family: inherit; }
.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0; }

/* ---- Login ---- */
.login {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; padding: 20px;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px; width: 320px;
  display: flex; flex-direction: column; gap: 10px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 12px; }
.login-card input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px; border-radius: 8px; font-size: 15px;
}
.login-card button {
  background: var(--accent); color: #1a0f0a; border: none;
  padding: 12px; border-radius: 8px; font-weight: 600; font-size: 15px;
}

/* ---- App shell ---- */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px; gap: 12px; min-height: 0;
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.new-chat {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 10px; border-radius: 8px; font-weight: 600;
}
.new-chat:hover { border-color: var(--accent); }
.tabs { display: flex; gap: 6px; }
.tab {
  flex: 1; background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 8px; border-radius: 8px; font-size: 13px;
}
.tab.active { color: var(--text); background: var(--panel-2); border-color: var(--accent); }
.badge {
  background: var(--accent); color: #1a0f0a; border-radius: 10px;
  padding: 0 6px; font-size: 11px; font-weight: 700;
}
.session-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.session-item {
  padding: 9px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.session-item:hover { background: var(--panel-2); }
.session-item.active { background: var(--panel-2); border-color: var(--accent); }
.session-item .title { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .sub { font-size: 11px; color: var(--muted); display: flex; gap: 6px; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 10px; }

/* ---- Main ---- */
.main { min-width: 0; display: flex; flex-direction: column; height: 100vh; }
.view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.view-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }

/* Bubbles */
.msg { max-width: 780px; width: 100%; margin: 0 auto; }
.msg .role { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.bubble { border-radius: var(--radius); padding: 12px 14px; white-space: normal; word-wrap: break-word; }
.msg.user .bubble { background: var(--user); }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--border); }
.bubble pre { background: #0b0c10; padding: 12px; border-radius: 8px; overflow-x: auto; font-family: var(--mono); font-size: 13px; }
.bubble code { font-family: var(--mono); font-size: 13px; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }

/* Thinking */
.thinking { max-width: 780px; width: 100%; margin: 0 auto; }
.thinking details { background: var(--panel); border: 1px dashed var(--border); border-radius: 8px; }
.thinking summary { cursor: pointer; padding: 8px 12px; color: var(--muted); font-size: 13px; }
.thinking .body { padding: 0 12px 12px; color: var(--muted); font-size: 13px; white-space: pre-wrap; }

/* Tool cards */
.tool { max-width: 780px; width: 100%; margin: 0 auto; }
.tool details { background: var(--tool); border: 1px solid var(--border); border-radius: 8px; }
.tool.err details { border-color: var(--err); }
.tool summary { cursor: pointer; padding: 9px 12px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.tool .name { font-family: var(--mono); color: var(--accent); }
.tool .spin { width: 12px; height: 12px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tool pre { margin: 0; padding: 10px 12px; font-family: var(--mono); font-size: 12px; overflow-x: auto; white-space: pre-wrap; }
.tool .stderr { color: var(--err); }

/* Composer */
.composer { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px; font-family: inherit; font-size: 15px;
  max-height: 200px;
}
.composer button {
  background: var(--accent); color: #1a0f0a; border: none; padding: 12px 18px;
  border-radius: 10px; font-weight: 600;
}
.composer #stop { background: var(--panel-2); color: var(--text); border: 1px solid var(--err); }
.turn-meta { padding: 0 20px 10px; font-size: 12px; color: var(--muted); text-align: center; min-height: 1.4em; }

/* Inbox */
.inbox-list { overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.inbox-item {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; cursor: pointer;
}
.inbox-item.unread { border-left: 3px solid var(--accent); }
.inbox-item .head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.inbox-item .title { font-weight: 600; }
.inbox-item.unread .title { color: #fff; }
.inbox-item .src { font-size: 11px; color: var(--muted); }
.inbox-item .sev-warn { color: var(--warn); }
.inbox-item .sev-alert { color: var(--err); }
.inbox-item .body { margin-top: 8px; color: var(--muted); font-size: 14px; }
.inbox-item .body.collapsed { display: none; }

.empty { color: var(--muted); text-align: center; padding: 40px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 5; width: 280px; height: 100vh; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
}
