:root {
  --bg: #0f1419;
  --panel: #172028;
  --card: #1e2a35;
  --text: #e7eef5;
  --muted: #8aa0b2;
  --acc: #4cc2ff;
  --ok: #3ddc97;
  --bad: #ff6b7a;
  --warn: #ffb020;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}
.top {
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 8px;
  border-bottom: 1px solid #243140;
  background: rgba(15, 20, 25, 0.92);
  position: sticky; top: 0; z-index: 5;
  backdrop-filter: blur(8px);
}
.brand-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.brand { font-weight: 700; letter-spacing: 0.4px; color: var(--acc); font-size: 18px; }
.mode-badge {
  display: inline-block; margin-left: 8px; padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.2px;
  background: var(--card); color: var(--muted); vertical-align: middle;
}
.mode-badge.observe { background: #2a3d20; color: var(--ok); }
.mode-badge.admin { background: #4a2028; color: var(--bad); }
select {
  width: 100%; margin-bottom: 12px; border: 0; border-radius: 10px;
  padding: 12px; background: var(--card); color: var(--text); font-size: 16px;
}
.ghost {
  border: 0; background: transparent; color: var(--muted);
  font-size: 20px; cursor: pointer; padding: 4px 8px;
}
.tabs { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: var(--card); color: var(--muted);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tabs button.on { background: var(--acc); color: #04222f; font-weight: 600; }
main { flex: 1; display: flex; min-height: 0; }
.panel { display: none; flex: 1; flex-direction: column; min-height: 0; padding: 12px; }
.panel.on { display: flex; }

.msgs {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
  padding-bottom: 8px;
}
.bubble {
  max-width: 85%; padding: 10px 12px; border-radius: var(--radius);
  white-space: pre-wrap; word-break: break-word;
}
.bubble.me { align-self: flex-end; background: #1a4a66; }
.bubble.bot { align-self: flex-start; background: var(--card); }
.bubble.sys { align-self: center; color: var(--muted); font-size: 12px; background: transparent; }
.bubble .tools {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid #2a3848;
  font-size: 12px; color: var(--muted);
}
.bubble .tools code {
  background: #14202b; padding: 1px 6px; border-radius: 6px; color: var(--ok);
}
.bubble.pending { opacity: 0.7; }
.bubble.pending::after {
  content: "…"; animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }

.composer {
  display: flex; gap: 8px; padding: 10px 0 calc(4px + var(--safe-b));
  border-top: 1px solid #243140;
}
.composer input {
  flex: 1; border: 0; border-radius: 999px; padding: 12px 16px;
  background: var(--card); color: var(--text); outline: none;
  font-size: 16px;
}
.send, .mic, .row button {
  border: 0; border-radius: 999px; cursor: pointer; font-size: 16px;
  background: var(--acc); color: #04222f; min-width: 48px; height: 48px;
  flex-shrink: 0;
}
.mic.rec {
  background: var(--bad); color: #fff; animation: pulse 1.1s infinite;
}
@keyframes pulse { 50% { transform: scale(1.08); } }

.row { display: flex; gap: 8px; margin-bottom: 12px; }
.row input {
  flex: 1; border: 0; border-radius: 999px; padding: 12px 16px;
  background: var(--card); color: var(--text); outline: none; font-size: 16px;
}
.list {
  list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1;
  padding-bottom: var(--safe-b);
}
.list li {
  background: var(--card); border-radius: 12px; padding: 12px; margin-bottom: 8px;
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
}
.list li .body { flex: 1; min-width: 0; }
.list li .sub {
  color: var(--muted); font-size: 12px; margin-top: 2px; word-break: break-all;
}
.list button.x {
  background: transparent; color: var(--muted); border: 0; cursor: pointer;
  font-size: 18px; min-width: 36px; height: 36px;
}
.list li.done .body { opacity: 0.5; text-decoration: line-through; }
.list .empty {
  text-align: center; color: var(--muted); padding: 24px 0; background: transparent;
}

dialog {
  border: 0; border-radius: 16px; background: var(--panel); color: var(--text);
  padding: 20px; width: min(92vw, 360px);
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog .hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
dialog input {
  width: 100%; margin-bottom: 12px; border: 0; border-radius: 10px;
  padding: 12px; background: var(--card); color: var(--text); font-size: 16px;
}
dialog button {
  border: 0; border-radius: 10px; padding: 12px;
  background: var(--acc); color: #04222f; font-weight: 600; cursor: pointer;
}
.field { display: block; margin-bottom: 10px; }
.field span {
  display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px;
}
.dlg-actions { display: flex; gap: 8px; }
.dlg-actions button { flex: 1; }
.dlg-actions .danger {
  background: transparent; color: var(--bad); border: 1px solid var(--bad);
}

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--card); color: var(--text); padding: 10px 16px;
  border-radius: 999px; font-size: 13px; z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  opacity: 0; transition: opacity .2s; pointer-events: none;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }
