:root {
  --bg: #f4f6f9; --card: #fff; --text: #1b2430; --muted: #66717f; --line: #e3e7ed;
  --accent: #1d3557; --accent-2: #2f6fb3; --warn: #b5541c; --danger: #b3261e; --ok: #2e7d32;
  --radius: 14px; --tab-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151b; --card: #1a2029; --text: #e6eaf0; --muted: #9aa5b3; --line: #2a323d; --accent: #8db6ea; --accent-2: #8db6ea; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, "Segoe UI", "Rubik", "Assistant", Arial, sans-serif; font-size: 16px; line-height: 1.5;
  background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: .55em 1em; cursor: pointer; min-height: 44px;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { button.primary { color: #11151b; } }
button.danger { color: var(--danger); border-color: var(--danger); }
input, select, textarea {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: .6em .75em; width: 100%; min-height: 44px;
}
:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.5em; }
.stack { display: grid; gap: .6rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row > select { flex: 1 1 8rem; width: auto; }
.check { display: flex; gap: .4rem; align-items: center; }
.check input { width: auto; min-height: auto; }

.login { min-height: 100%; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(360px, 100%); display: grid; gap: .75rem; }
.login-card h1 { margin: 0 0 .5rem; text-align: center; }

#app { display: flex; flex-direction: column; min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + .6rem) 1rem .6rem; background: var(--accent); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #1a2029; color: var(--text); } }
.topbar h1 { margin: 0; font-size: 1.2rem; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: #c0392b; }
.conn.on { background: #4caf50; }
main { flex: 1; width: min(900px, 100%); margin: 0 auto; padding: 1rem 1rem calc(var(--tab-h) + env(safe-area-inset-bottom) + 1rem); }
.view { display: grid; gap: 1rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.card h2 { margin: 0 0 .5rem; font-size: 1.05rem; }
details.card summary { cursor: pointer; font-weight: 600; min-height: 32px; }
details.card form { margin-top: .75rem; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { display: grid; gap: .1rem; text-align: start; padding: .9rem 1rem; border-radius: var(--radius); }
.stat b { font-size: 1.8rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .9rem; }
.stat.warn b { color: var(--warn); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.list > li { padding: .6rem .2rem; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list.tasks > li, #approval-list > li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.task { display: flex; gap: .75rem; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.task-main { flex: 1 1 14rem; }
.task-actions { display: flex; gap: .5rem; align-items: center; }
.task-actions select { width: auto; }
.task.p-urgent { border-inline-start: 4px solid var(--danger) !important; }
.task.p-high { border-inline-start: 4px solid var(--warn) !important; }
.notes { white-space: pre-wrap; margin-top: .25rem; }
.small-btn { min-height: 36px; padding: .3em .8em; font-size: .9rem; }
#agent-list li { display: grid; grid-template-columns: 1fr auto; gap: .1rem .75rem; align-items: center; }
#agent-list li .muted { grid-column: 1; }
#agent-list li button { grid-row: 1 / span 2; grid-column: 2; }

.chips { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: none; }
.chip { white-space: nowrap; border-radius: 999px; padding: .35em .9em; min-height: 38px; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .chip.active { color: #11151b; } }

#view-chat { grid-template-rows: auto 1fr auto; height: calc(100dvh - 9.5rem - env(safe-area-inset-bottom)); }
.messages { overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; padding: .25rem; }
.msg { max-width: 85%; padding: .6rem .85rem; border-radius: 16px; background: var(--card); border: 1px solid var(--line); }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.msg time { display: block; font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.msg.user { align-self: flex-start; background: var(--accent); color: #fff; border-color: var(--accent); }
.msg.user time { color: #dfe7f1; }
@media (prefers-color-scheme: dark) { .msg.user { color: #11151b; } .msg.user time { color: #2a323d; } }
.msg.assistant { align-self: flex-end; }
.msg.live .text::after { content: " ▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .msg.live .text::after { animation: none; } }
.composer { display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; }

pre { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .6rem; overflow-x: auto; white-space: pre-wrap; font-size: .85rem; text-align: left; }
.approval { display: grid; gap: .5rem; }

.bars { display: flex; align-items: flex-end; gap: 2px; height: 80px; margin-top: .75rem; direction: ltr; }
.bars i { flex: 1; background: var(--accent-2); border-radius: 2px 2px 0 0; min-height: 1px; }

.tabbar {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tab-h) + env(safe-area-inset-bottom));
}
.tabbar button { border: 0; border-radius: 0; background: none; display: grid; place-items: center; gap: 0; font-size: .78rem; color: var(--muted); position: relative; }
.tabbar button span { font-size: 1.3rem; line-height: 1; }
.tabbar button.active { color: var(--accent-2); font-weight: 600; }
.badge { position: absolute; top: 6px; inset-inline-end: calc(50% - 22px); background: var(--danger); color: #fff; font-style: normal; font-size: .7rem; border-radius: 999px; padding: 0 .4em; min-width: 1.4em; }

.toast {
  position: fixed; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 1rem); inset-inline: 1rem; margin: auto; width: fit-content; max-width: calc(100% - 2rem);
  background: #222b36; color: #fff; padding: .6rem 1rem; border-radius: 10px; z-index: 20; box-shadow: 0 4px 16px rgb(0 0 0 / .2);
}
