:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #16202a;
  --muted: #5b6875;
  --border: #d9e0e6;
  --primary: #0f766e;
  --primary-text: #ffffff;
  --danger: #b42318;
  --bubble-me: #d9f2ee;
  --bubble-agent: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --surface: #182028;
    --surface-2: #202a33;
    --text: #e6edf3;
    --muted: #93a1ad;
    --border: #2d3a45;
    --primary: #2dd4bf;
    --primary-text: #062a26;
    --danger: #f97066;
    --bubble-me: #134e48;
    --bubble-agent: #202a33;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --surface: #182028; --surface-2: #202a33; --text: #e6edf3; --muted: #93a1ad;
  --border: #2d3a45; --primary: #2dd4bf; --primary-text: #062a26; --danger: #f97066;
  --bubble-me: #134e48; --bubble-agent: #202a33; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Rubik", "Assistant", Arial, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: var(--primary); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 8px 14px; font: inherit; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .9em; }
.btn:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
label small { font-weight: 400; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.row > .grow { min-width: 150px; }
.stack > * + * { margin-top: 12px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); text-align: center; }
.login-card .logo { font-size: 48px; }
.login-card input, .login-card button { margin-top: 12px; width: 100%; }

/* layout */
.app { display: flex; min-height: 100%; }
.nav {
  width: 190px; background: var(--surface); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 12px 8px; gap: 2px; position: sticky; top: 0; height: 100vh;
}
.nav .brand { font-weight: 700; padding: 8px 12px 16px; font-size: 1.1rem; }
.nav button {
  display: flex; gap: 10px; align-items: center; border: 0; background: none; color: var(--text);
  padding: 9px 12px; border-radius: 10px; font: inherit; cursor: pointer; text-align: start;
}
.nav button em { font-style: normal; }
.nav button.active { background: var(--surface-2); font-weight: 600; color: var(--primary); }
.nav .logout { margin-top: auto; color: var(--muted); }
main { flex: 1; min-width: 0; padding: 20px; max-width: 1100px; }

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .nav {
    order: 2; position: fixed; bottom: 0; top: auto; left: 0; right: 0; width: 100%; height: auto;
    flex-direction: row; justify-content: space-around; padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
    border-inline-end: 0; border-top: 1px solid var(--border); z-index: 10; overflow-x: auto;
  }
  .nav .brand { display: none; }
  .nav button { flex-direction: column; gap: 0; padding: 4px 6px; font-size: 11px; min-width: 52px; align-items: center; }
  .nav button span { font-size: 20px; }
  .nav .logout { margin-top: 0; }
  main { padding: 16px 16px 90px; }
}

/* agents grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.agent-card { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.agent-card:hover { border-color: var(--primary); }
.avatar { font-size: 28px; width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.agent-card .name { font-weight: 700; }
.badge { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-inline-start: 4px; }
.badge.warn { color: var(--danger); }

/* chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 40px); }
@media (max-width: 760px) { .chat { height: calc(100vh - 110px); } }
.chat-head { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.chat-head select { width: auto; flex: 1; max-width: 320px; }
.messages { flex: 1; overflow-y: auto; padding: 16px 0; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow); }
.msg.user { align-self: flex-start; background: var(--bubble-me); border-start-start-radius: 4px; }
.msg.assistant { align-self: flex-end; background: var(--bubble-agent); border: 1px solid var(--border); border-start-end-radius: 4px; }
.msg .time { font-size: .7rem; color: var(--muted); margin-top: 2px; }
.msg.typing { color: var(--muted); font-style: italic; }
.composer { display: flex; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
.composer textarea { min-height: 44px; max-height: 160px; }

/* lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 10px; align-items: flex-start; }
.item .grow .sub { color: var(--muted); font-size: .88em; white-space: pre-wrap; }
.done .title { text-decoration: line-through; color: var(--muted); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.checks label { font-weight: 400; margin: 0; display: flex; gap: 8px; align-items: center; background: var(--surface-2); padding: 6px 10px; border-radius: 8px; }
.checks input { width: auto; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 12px; flex-wrap: wrap; }
.hint { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; color: var(--muted); font-size: .9em; }
code, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; direction: ltr; unicode-bidi: embed; }
.kv { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 8px 12px; align-items: center; }
@media (max-width: 600px) { .kv { grid-template-columns: 1fr; } }
.kv label { margin: 0; }
.status { font-size: .85em; }
.status.ok { color: var(--primary); }
.status.bad { color: var(--danger); }
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: calc(100% - 32px);
}
.activity .item { font-size: .92em; }
.activity .kind { font-size: .75rem; color: var(--muted); min-width: 70px; }
