:root {
  --bg: #f4f6fa; --panel: #ffffff; --ink: #18202f; --muted: #5d6779; --line: #dde2ea;
  --accent: #1f4fd1; --accent-ink: #ffffff; --brand: #14213d; --gold: #c8a24a;
  --owner: #e7eeff; --warn: #8a5300; --warnbg: #fff3dc; --bad: #b3261e; --ok: #1b7a3a;
  --radius: 12px; --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d1424; --panel: #151e31; --ink: #e8ecf4; --muted: #9aa5ba; --line: #26314a; --accent: #7aa2ff; --accent-ink: #0d1424; --brand: #0d1424; --owner: #1f2e52; --warn: #ffc56b; --warnbg: #3a2c12; --bad: #ff8a80; --ok: #7bd88f; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--bad); }
button.listening { background: var(--bad); border-color: var(--bad); color: #fff; }
button.wide { width: 100%; }
select { max-width: 100%; }
input[type=text], input:not([type]), input[inputmode], select, textarea { padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); min-width: 0; }
label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1.2em; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: calc(8px + var(--safe-top)) 16px 8px; background: var(--brand); color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: .01em; white-space: nowrap; }
.top nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.top nav a { color: #d6def0; text-decoration: none; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.top nav a.active, .top nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.status { display: flex; align-items: center; gap: 10px; margin-left: auto; font-size: 13px; }
.who { color: #d6def0; white-space: nowrap; }
.pill { padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.14); font-size: 12px; }
.pill.online { background: #1b7a3a; }
.pill.offline { background: #8a5300; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--gold); color: #14213d; font-size: 12px; text-align: center; }
.banner { padding: 8px 16px; background: var(--warnbg); color: var(--warn); font-size: 13px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.narrow { max-width: 440px; margin: 32px auto; }
.panel h1 { margin: 0 0 6px; font-size: 22px; }
details { margin: 14px 0; }
summary { cursor: pointer; color: var(--accent); }

.workspace { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 52px); }
.agents { border-right: 1px solid var(--line); background: var(--panel); padding: 12px; position: sticky; top: 52px; align-self: start; max-height: calc(100vh - 52px); overflow-y: auto; }
.agents h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 8px 6px; }
.agent { display: block; width: 100%; text-align: left; margin: 4px 0; padding: 10px; border-radius: 10px; border: 1px solid transparent; background: none; }
.agent.active { background: var(--owner); border-color: var(--line); }
.agent .name { font-weight: 600; }
.agent .meta { font-size: 12px; color: var(--muted); }
.view { min-width: 0; padding: 16px 20px 24px; }
#view-chat { display: flex; flex-direction: column; padding-bottom: 0; }
.note { background: var(--warnbg); color: var(--warn); padding: 8px 12px; border-radius: 10px; margin-bottom: 8px; }
.chat { flex: 1; max-width: 860px; width: 100%; margin: 0 auto; padding-bottom: 120px; }
.msg { margin: 10px 0; display: flex; flex-direction: column; }
.msg.owner { align-items: flex-end; }
.bubble { max-width: 85%; padding: 9px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.owner .bubble { background: var(--owner); }
.msg.queued .bubble { opacity: .65; border-style: dashed; }
.meta { font-size: 12px; color: var(--muted); margin: 2px 4px; }
.interrupted { font-size: 12px; color: var(--warn); background: var(--warnbg); border-radius: 6px; padding: 2px 6px; margin-top: 4px; }
.card { max-width: 85%; margin-top: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.card h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.card ul { margin: 0; padding-left: 18px; }
.card .conflict { color: var(--warn); }
.composer { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); margin: 0 -20px; padding: 10px 20px calc(10px + var(--safe-bottom)); }
.bar { max-width: 860px; margin: 0 auto; display: flex; gap: 8px; }
.bar input { flex: 1; }
.hint { max-width: 860px; margin: 6px auto 0; font-size: 12px; color: var(--muted); min-height: 1.2em; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.section { margin-bottom: 16px; }
.section h2 { margin: 0 0 8px; font-size: 17px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > label { margin: 0; }
input[type=range] { width: 100%; }
table.prefs { width: 100%; border-collapse: collapse; }
table.prefs th, table.prefs td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.inbox-item { display: block; width: 100%; text-align: left; margin: 6px 0; }
.inbox-item.unread { border-left: 4px solid var(--gold); }
.inbox-detail { white-space: pre-wrap; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--owner); color: var(--muted); margin-right: 6px; }
.ok { color: var(--ok); }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 8px; }
  .top nav { order: 3; flex-basis: 100%; }
  .workspace { grid-template-columns: 1fr; }
  .agents { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); display: flex; gap: 6px; overflow-x: auto; padding: 8px; }
  .agents h2 { display: none; }
  .agent { min-width: 160px; }
  .view { padding: 12px 12px 20px; }
  .composer { margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
  .bubble, .card { max-width: 95%; }
}
.spaced { margin-top: 16px; }
