:root {
  --bg: #f7f6f2;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --card: #ffffff;
  --border: #e5e3dc;
  --accent: #6b46c1;
  --accent-soft: #ede9fe;
  --danger: #b91c1c;
  --ok: #15803d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17161c;
    --fg: #ecebe6;
    --muted: #8f8b82;
    --card: #201f26;
    --border: #2f2d36;
    --accent: #a78bfa;
    --accent-soft: #2a2540;
  }
}
:root[data-theme="dark"] {
  --bg: #17161c;
  --fg: #ecebe6;
  --muted: #8f8b82;
  --card: #201f26;
  --border: #2f2d36;
  --accent: #a78bfa;
  --accent-soft: #2a2540;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--bg);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-mark { color: var(--accent); font-size: 18px; }
.user { color: var(--muted); font-size: 13px; }
nav {
  display: flex;
  overflow-x: auto;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
nav button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 13px;
  cursor: pointer;
}
nav button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
main { padding: 16px; padding-bottom: 40px; }
section { display: none; }
section.active { display: block; }
section h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.placeholder {
  padding: 32px 20px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
}
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.tile .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 28px; font-weight: 600; margin-top: 2px; color: var(--accent); }

.article-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.article-card h3 { margin: 0 0 6px; font-size: 16px; }
.article-card .meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; word-break: break-all; }
.article-card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.article-card button {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.article-card button.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}
.status-line { margin-top: 8px; font-size: 12px; color: var(--muted); }
.status-line .ok { color: var(--ok); }
.status-line .err { color: var(--danger); }

.agent-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
}
.agent-card h3 { margin: 0 0 4px; font-size: 16px; }
.agent-card .meta { color: var(--muted); font-size: 13px; }

#agent-chat.hidden { display: none; }
.chat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.chat-head button { background: transparent; border: 0; font-size: 20px; color: var(--fg); cursor: pointer; }
.chat-log {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  min-height: 240px;
  max-height: 55vh;
  overflow-y: auto;
  background: var(--card);
  margin-bottom: 10px;
}
.chat-msg { padding: 8px 12px; margin: 6px 0; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; }
.chat-msg.user { background: var(--accent-soft); color: var(--fg); text-align: right; margin-left: 20%; }
.chat-msg.assistant { background: var(--card); border: 1px solid var(--border); margin-right: 20%; }
.chat-input { display: flex; gap: 8px; align-items: end; }
.chat-input textarea {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  color: var(--fg);
  font: inherit;
  resize: vertical;
}
.chat-input button {
  background: var(--accent); color: white; border: 0; border-radius: 10px;
  padding: 10px 16px; cursor: pointer; font: inherit;
}
code {
  background: var(--accent-soft);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}
