:root {
  --bg: #0b0f14;
  --bg-soft: #111823;
  --bg-card: #141c28;
  --line: #22303f;
  --text: #e6edf6;
  --muted: #8b9bb0;
  --accent: #5b9dff;
  --accent-soft: #1c2c45;
  --ok: #3ecf8e;
  --warn: #f2b544;
  --error: #ff6b6b;
  --live: #5b9dff;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.note { margin: 10px 0 0; font-size: 13px; }
.link { font-size: 13px; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 20, 0.9);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; letter-spacing: 0.2px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), #8b6bff);
  display: inline-block;
}
.brand-text { font-size: 16px; }

.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.nav-link {
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.nav-link:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--accent-soft); color: var(--text); }
.nav-badge {
  min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--line); color: var(--text);
  font-size: 11px; line-height: 18px; text-align: center;
}
.nav-badge.is-urgent { background: var(--warn); color: #201708; font-weight: 700; }
.nav-logout { margin-left: 6px; }

/* Layout */
.page { max-width: 1080px; margin: 0 auto; padding: 22px 20px 60px; display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card-warn { border-color: #4a3a16; background: #1b1710; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 620; letter-spacing: 0.2px; }
.card-head .link { color: var(--accent); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 820px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 2px;
}
.stat-label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.6px; }
.stat-value { font-size: 24px; font-weight: 640; letter-spacing: -0.4px; }
.stat-sub { color: var(--muted); font-size: 12.5px; }

/* Meter */
.meter-row { margin: 14px 0; }
.meter-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.meter-label { font-size: 13.5px; color: var(--text); }
.meter-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.meter-value.is-limited { color: var(--error); }
.meter-foot { display: flex; justify-content: space-between; font-size: 12px; margin-top: 5px; }
progress.meter {
  appearance: none; -webkit-appearance: none;
  width: 100%; height: 8px; border: 0; border-radius: 6px;
  background: #1d2836; overflow: hidden; display: block;
}
progress.meter::-webkit-progress-bar { background: #1d2836; border-radius: 6px; }
progress.meter::-webkit-progress-value { background: linear-gradient(90deg, var(--accent), #8b6bff); border-radius: 6px; }
progress.meter::-moz-progress-bar { background: linear-gradient(90deg, var(--accent), #8b6bff); border-radius: 6px; }
progress.meter.is-limited::-webkit-progress-value { background: var(--error); }
progress.meter.is-limited::-moz-progress-bar { background: var(--error); }

/* Banner & flash */
.banner { display: flex; flex-direction: column; gap: 2px; border-radius: var(--radius); padding: 12px 16px; font-size: 14px; }
.banner-error { background: #2a1516; border: 1px solid #5b2626; color: #ffc9c9; }
.banner-warn { background: #241d10; border: 1px solid #52411b; color: #ffe1a8; }
.flash { border-radius: 10px; padding: 10px 14px; font-size: 14px; margin-bottom: 12px; }
.flash-error { background: #2a1516; border: 1px solid #5b2626; color: #ffc9c9; }
.flash-ok { background: #10241b; border: 1px solid #1f5340; color: #b6f0d6; }
.flash-warn { background: #241d10; border: 1px solid #52411b; color: #ffe1a8; }

/* Inbox */
.inbox { display: flex; flex-direction: column; gap: 8px; }
.inbox-item {
  display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--text);
}
.inbox-item:hover { text-decoration: none; border-color: #33465c; }
.inbox-priority {
  width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; background: var(--line); color: var(--muted);
}
.inbox-item.tone-warn .inbox-priority { background: #4a3a16; color: var(--warn); }
.inbox-item.tone-error .inbox-priority { background: #3a1a1c; color: var(--error); }
.inbox-item.tone-ok .inbox-priority { background: #12301f; color: var(--ok); }
.inbox-item.tone-live .inbox-priority { background: var(--accent-soft); color: var(--accent); }
.inbox-main { display: flex; flex-direction: column; min-width: 0; }
.inbox-title { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-detail { color: var(--muted); font-size: 12.5px; }
.inbox-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 12px; text-align: right; }

/* List & rows */
.list { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: center;
  padding: 11px 4px; border-bottom: 1px solid var(--line); color: var(--text);
}
.row:last-child { border-bottom: 0; }
.row:hover { text-decoration: none; background: rgba(255, 255, 255, 0.02); }
.row-state { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.row-state.is-live { background: var(--live); box-shadow: 0 0 0 4px rgba(91, 157, 255, 0.15); }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-title { font-weight: 540; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { display: flex; align-items: center; gap: 10px; font-size: 12.5px; white-space: nowrap; }
@media (max-width: 640px) {
  .row { grid-template-columns: 10px 1fr; }
  .row-meta { grid-column: 2; justify-content: flex-start; flex-wrap: wrap; }
}

.chip {
  display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11.5px;
  background: var(--line); color: var(--muted); margin-left: 4px;
}
.chip-running { background: var(--accent-soft); color: var(--accent); }
.chip-warn { background: #4a3a16; color: var(--warn); }
.chip-succeeded, .chip-completed, .chip-ok { background: #12301f; color: var(--ok); }
.chip-failed, .chip-error { background: #3a1a1c; color: var(--error); }
.chip-running-state { background: var(--accent-soft); color: var(--accent); }

/* Meta */
.meta-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 18px; margin: 0; }
@media (max-width: 760px) { .meta-grid { grid-template-columns: 1fr 1fr; } }
.meta-grid > div { display: flex; flex-direction: column; gap: 2px; }
.meta-grid dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.meta-grid dd { margin: 0; font-size: 13.5px; }

.pending { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #3a2f18; font-size: 14px; flex-wrap: wrap; }
.pending:last-child { border-bottom: 0; }

/* Transcript */
.transcript { display: flex; flex-direction: column; gap: 14px; max-height: 70vh; overflow: auto; padding-right: 4px; }
.msg { border-left: 2px solid var(--line); padding: 2px 0 2px 14px; }
.msg-user { border-left-color: var(--accent); }
.msg-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; margin-bottom: 6px; }
.msg-role { font-weight: 650; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.6px; }
.msg-assistant .msg-role { color: var(--accent); }
.msg-user .msg-role { color: var(--ok); }
.msg-body { display: flex; flex-direction: column; gap: 8px; }
.part-text {
  margin: 0; font: inherit; font-size: 14px; white-space: pre-wrap; word-break: break-word;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  max-height: 420px; overflow: auto;
}
.part-reasoning, .part-tool { border: 1px solid var(--line); border-radius: 8px; background: #101722; }
.part-reasoning > summary, .part-tool > summary {
  cursor: pointer; padding: 8px 12px; font-size: 12.5px; color: var(--muted);
  display: flex; align-items: center; gap: 8px; list-style: none;
}
.part-reasoning > summary::-webkit-details-marker, .part-tool > summary::-webkit-details-marker { display: none; }
.part-reasoning pre, .part-tool pre {
  margin: 0; padding: 10px 12px; border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word;
  max-height: 320px; overflow: auto; color: #c7d3e2;
}
.tool-name { color: var(--text); font-family: var(--mono); font-size: 12px; }
.tool-label { color: var(--muted); font-size: 11px !important; text-transform: uppercase; letter-spacing: 0.6px; }
.live-buffer {
  margin-top: 12px; border: 1px dashed #33507a; border-radius: 8px; padding: 10px 12px;
  background: #0f1a29; white-space: pre-wrap; font-size: 13.5px; max-height: 240px; overflow: auto;
}
.live-buffer.is-idle { opacity: 0.5; }

/* Chart */
.chart { width: 100%; height: 90px; display: block; overflow: visible; }
.bar { fill: #2c4260; }
.bar.bar-cost { fill: #5b9dff; }
.bar.bar-token { fill: #8b6bff; }
.bar-label { fill: var(--muted); font-size: 7px; }

/* Forms */
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input[type="search"] { flex: 1; min-width: 180px; }
input, select, textarea, button { font: inherit; color: var(--text); }
input, select, textarea {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
select { width: auto; }
textarea { resize: vertical; font-family: var(--mono); font-size: 13px; }
.form { display: flex; flex-direction: column; gap: 12px; max-width: 460px; }
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row label { font-size: 13px; color: var(--muted); }
.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--text); cursor: pointer; font-size: 14px; text-align: center;
}
.btn:hover { border-color: #3a4d63; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #08111f; font-weight: 620; }
.btn-primary:hover { background: #74adff; border-color: #74adff; }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: 0.6; cursor: default; }
.install-btn { padding: 4px 10px; font-size: 12.5px; }

/* Auth */
.auth-card {
  max-width: 380px; margin: 8vh auto; background: var(--bg-card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 26px 26px 22px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-card .form { max-width: none; }

/* Misc */
.empty { color: var(--muted); font-size: 13.5px; margin: 6px 0; }
.footer {
  max-width: 1080px; margin: 0 auto; padding: 18px 20px 40px;
  display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line);
}
@media (max-width: 640px) {
  .footer { flex-direction: column; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .nav { margin-left: 0; width: 100%; }
}
