:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #d9dee6;
  --primary: #1f5f8b;
  --primary-text: #ffffff;
  --accent: #e8a33d;
  --ok: #1e7f4f;
  --warn: #a35f00;
  --bad: #b3261e;
  --user-bubble: #1f5f8b;
  --user-text: #ffffff;
  --agent-bubble: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --surface-2: #232b35;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --border: #2e3844;
    --agent-bubble: #1b2129;
    --ok: #4cc38a;
    --warn: #e0a24a;
    --bad: #f2827a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
@media (prefers-color-scheme: dark) { a { color: #7fb6e0; } }
h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.2; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

button, .button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.primary, .button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.danger { color: var(--bad); }
button:disabled { opacity: 0.5; cursor: default; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  max-width: 100%;
}
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.6rem 0 0.2rem; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 650; }
.topbar .brand .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-right: 0.4rem; }
.topbar .spacer { flex: 1; }
.topbar form { margin: 0; }
.nav a { margin-right: 0.8rem; text-decoration: none; }
.nav a.active { font-weight: 650; text-decoration: underline; }

/* login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); }
.login-card { width: 100%; max-width: 380px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 1rem; }
.error { color: var(--bad); margin: 0.5rem 0; }
.notice { background: var(--surface-2); border-radius: 8px; padding: 0.5rem 0.7rem; font-size: 0.85rem; color: var(--muted); }

/* demo layout */
.demo { display: grid; grid-template-columns: minmax(0, 1fr) 360px; height: calc(100% - 57px); }
@media (max-width: 860px) {
  .demo { grid-template-columns: 1fr; height: auto; }
  .panel { border-left: none; border-top: 1px solid var(--border); max-height: none; }
  .chat { height: 70vh; }
}
.chat { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.msg { max-width: 78%; padding: 0.55rem 0.8rem; border-radius: 14px; box-shadow: var(--shadow); white-space: normal; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: var(--user-text); border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; background: var(--agent-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: transparent; box-shadow: none; color: var(--muted); font-size: 0.85rem; text-align: center; }
.msg p { margin: 0 0 0.4rem; }
.msg p:last-child { margin-bottom: 0; }
.msg ol, .msg ul { margin: 0.2rem 0 0.4rem 1.2rem; padding: 0; }
.msg .meta { display: block; margin-top: 0.3rem; font-size: 0.75rem; color: var(--muted); }
.msg.user .meta { color: rgba(255, 255, 255, 0.75); }
.typing { color: var(--muted); font-style: italic; }
.composer { display: flex; gap: 0.5rem; padding: 0.75rem 1rem; border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea { flex: 1; resize: none; height: 2.6rem; }
.voicebar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; padding: 0.5rem 1rem; border-top: 1px solid var(--border); background: var(--surface-2); }
.voicebar .level { width: 90px; height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.voicebar .level span { display: block; height: 100%; width: 0; background: var(--ok); transition: width 80ms linear; }
.voicebar select { max-width: 260px; }
.msg.caption { opacity: 0.65; font-style: italic; }
.start { margin: auto; text-align: center; max-width: 460px; padding: 16px; }
.start select { margin: 0.5rem 0 1rem; }

/* side panel */
.panel { border-left: 1px solid var(--border); background: var(--surface); overflow-y: auto; padding: 0.9rem; display: flex; flex-direction: column; gap: 0.8rem; }
.pcard { border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.7rem; background: var(--surface); }
.pcard h3 { display: flex; align-items: center; gap: 0.4rem; }
.badge { display: inline-block; font-size: 0.72rem; padding: 0.1rem 0.45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--bad); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.15rem 0.6rem; font-size: 0.85rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.events { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.82rem; }
.event { border-left: 3px solid var(--border); padding: 0.2rem 0.5rem; }
.event.ok { border-left-color: var(--ok); }
.event.bad { border-left-color: var(--bad); }
.event.flag { border-left-color: var(--warn); }
.event summary { cursor: pointer; }
.event pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.75rem; background: var(--surface-2); padding: 0.4rem; border-radius: 6px; margin: 0.3rem 0 0; }

/* rating dialog */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: 420px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.stars { display: flex; gap: 0.3rem; margin: 0.5rem 0; }
.stars button { font-size: 1.3rem; padding: 0.2rem 0.55rem; }
.stars button.on { background: var(--accent); border-color: var(--accent); color: #1c2430; }
dialog textarea { width: 100%; height: 4rem; }

/* admin */
.admin { padding: 1rem; max-width: 1200px; margin: 0 auto; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: var(--surface); font-size: 0.88rem; }
th, td { border-bottom: 1px solid var(--border); padding: 0.4rem 0.5rem; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 1.2rem; }
.checks label { display: flex; align-items: center; gap: 0.4rem; color: var(--text); font-size: 0.9rem; margin: 0.25rem 0; }
.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }
.timeline .ev { border-left: 3px solid var(--border); padding: 0.35rem 0.7rem; margin: 0.3rem 0; background: var(--surface); }
.timeline .ev.user_message { border-left-color: var(--primary); }
.timeline .ev.assistant_message { border-left-color: var(--accent); }
.timeline .ev.panel { border-left-color: var(--ok); }
.timeline .ev.error { border-left-color: var(--bad); }
.timeline pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.78rem; margin: 0.3rem 0 0; }
