:root {
  --bg: #0b0d14;
  --panel: #121521;
  --panel-2: #191d2c;
  --line: #262b3d;
  --text: #e8eaf2;
  --muted: #8d93a8;
  --accent: #8b7bff;
  --accent-2: #4fd1e8;
  --warn: #f2b05e;
  --danger: #ff6b7a;
  --ok: #4ade9b;
  --radius: 14px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5fa; --panel: #ffffff; --panel-2: #eef0f7; --line: #dde0ea;
    --text: #171a26; --muted: #626a80; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }

/* Barra lateral */
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 16px; gap: 8px; min-height: 0;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; margin-bottom: 14px; }
.brand-dot { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 30% 30%, var(--accent-2), var(--accent)); box-shadow: 0 0 16px var(--accent); }
.field-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.row { display: flex; gap: 6px; }
select, input, textarea {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%;
}
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.path { font-size: 12px; color: var(--muted); word-break: break-all; margin: 0 0 10px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.conversations { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.conversations li button {
  width: 100%; text-align: left; background: none; border: 0; border-radius: 10px; padding: 8px 10px;
  color: var(--text); display: flex; gap: 8px; align-items: center;
}
.conversations li button:hover { background: var(--panel-2); }
.conversations li button[aria-current="true"] { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.conversations .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversations .channel { font-size: 11px; color: var(--muted); }
.busy-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); animation: blink 1s infinite; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 6px; }
.engines-status { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); }
.engines-status span::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; background: var(--muted); }
.engines-status span.on::before { background: var(--ok); }
.spend { font-size: 12px; color: var(--muted); margin: 0; }
.icon-btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; width: 38px; flex: none; font-size: 18px; }
.link-btn { background: none; border: 0; color: var(--accent-2); padding: 0; font-size: 13px; text-decoration: none; }

/* Área principal */
.main { display: grid; grid-template-rows: auto auto 1fr auto; min-height: 0; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 22px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar h1 { font-size: 16px; font-weight: 600; margin: 0; flex: 1; min-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; }
.segmented { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.segmented button { border: 0; background: none; padding: 5px 11px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.segmented button[aria-checked="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.segmented button:disabled { opacity: .35; cursor: not-allowed; }
.segmented button[data-value="total"][aria-checked="true"] { color: var(--warn); }

.stage { display: grid; justify-items: center; padding: 14px 16px 6px; gap: 6px; transition: padding .3s; }
.orb-wrap { background: none; border: 0; padding: 0; border-radius: 50%; width: min(260px, 60vw); aspect-ratio: 1; }
.orb-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; }
#orb { width: 100%; height: 100%; display: block; }
.app.has-messages .orb-wrap { width: min(170px, 40vw); }
.status { margin: 0; color: var(--muted); min-height: 1.5em; text-align: center; }
.voice-options { display: flex; gap: 16px; font-size: 13px; color: var(--muted); flex-wrap: wrap; justify-content: center; }
.voice-settings label { display: inline-flex; align-items: center; gap: 6px; }
.voice-settings select { width: auto; padding: 3px 6px; font-size: 12px; border-radius: 8px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle input { width: auto; accent-color: var(--accent); }
.live-activity { list-style: none; margin: 4px 0 0; padding: 0; width: min(640px, 100%); font-size: 13px; color: var(--muted); display: grid; gap: 2px; }
.live-activity li { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-activity li b { color: var(--warn); font-weight: 600; margin-right: 6px; }

.transcript { overflow-y: auto; padding: 8px 22px 20px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.msg { max-width: min(760px, 92%); border-radius: var(--radius); padding: 10px 14px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.assistant.error { border-color: var(--danger); }
.msg.note { align-self: center; background: none; color: var(--muted); font-size: 13px; padding: 2px 8px; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.msg .meta button { background: none; border: 0; color: var(--accent-2); padding: 0; font-size: 12px; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin-bottom: 0; }
.msg pre { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-x: auto; font-size: 13px; }
.msg code { font-family: Consolas, "Cascadia Code", monospace; font-size: 13px; }
.msg :not(pre) > code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
.msg ul, .msg ol { margin: 0 0 8px; padding-left: 22px; }
.msg h3 { font-size: 15px; margin: 10px 0 6px; }
.msg a { color: var(--accent-2); }
details.activity { margin-top: 8px; font-size: 13px; color: var(--muted); }
details.activity summary { cursor: pointer; }
details.activity li { overflow-wrap: anywhere; }

.composer { display: flex; gap: 8px; padding: 12px 22px 18px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 180px; min-height: 44px; padding: 11px 12px; }
.mic-btn, .send-btn { width: 44px; height: 44px; flex: none; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); display: grid; place-items: center; }
.mic-btn svg, .send-btn svg { width: 20px; height: 20px; fill: currentColor; }
.send-btn { background: var(--accent); border-color: var(--accent); color: #fff; }
.mic-btn.recording { background: var(--danger); border-color: var(--danger); color: #fff; animation: blink 1.2s infinite; }
.stop-btn { height: 44px; border-radius: 12px; border: 1px solid var(--danger); background: none; color: var(--danger); padding: 0 14px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); width: min(460px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog form { display: grid; gap: 8px; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.error { font-size: 13px; color: var(--danger); margin: 0; min-height: 1em; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 14px; margin-top: 8px; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 8px 18px; }

.only-mobile { display: none; }
@keyframes blink { 50% { opacity: .45; } }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 10; transform: translateX(-100%); transition: transform .25s; }
  .app.sidebar-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.6); }
  .only-mobile { display: inline-block; }
  .topbar, .transcript, .composer { padding-left: 16px; padding-right: 16px; }
  .topbar h1 { min-width: 0; }
  .controls { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .segmented { display: flex; min-width: 0; }
  .segmented button { flex: 1; padding: 6px 4px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .composer { gap: 6px; }
  .msg { max-width: 100%; }
  .brand .icon-btn { margin-left: auto; }
}

/* Saúde do servidor */
.health { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; }
.health-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.health-uptime { margin-left: auto; color: var(--muted); font-size: 11px; }
.health-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.health-dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.health-dot.atencao { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.health-dot.critico { background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: blink 1s infinite; }
.health-verdict { margin: 0; font-size: 12px; color: var(--muted); }
.health-rows { display: grid; gap: 5px; }
.health-row { display: grid; grid-template-columns: 56px 1fr 44px; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.health-row .bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; }
.health-row .bar i { display: block; height: 100%; border-radius: 4px; background: var(--ok); transition: width .6s; }
.health-row .bar i.atencao { background: var(--warn); } .health-row .bar i.critico { background: var(--danger); }
.health-row .bar i.maya { background: var(--accent); }
.health-row b { font-weight: 600; color: var(--text); text-align: right; }
#health-chart { width: 100%; height: 42px; }
.health-legend { margin: 0; font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.health-legend span { display: inline-block; width: 10px; height: 3px; border-radius: 2px; }
.health-legend .lg-server { background: var(--accent-2); } .health-legend .lg-maya { background: var(--accent); margin-left: 8px; }
.user-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.user-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar { overflow-y: auto; }
.conversations { min-height: 80px; }
