/* Cores JavAnd (as do CRM): ciano da marca sobre cinzas azulados. O tema vem de
   data-theme no <html>, posto por theme.js (escolha guardada ou o do sistema). */
:root {
  color-scheme: light;
  --bg: #eef3f5; --panel: #ffffff; --line: #d5e0e4; --text: #1a202c; --muted: #5a6b75;
  --brand: #46a8b3; --accent: #1d7d88; --accent-text: #ffffff; --accent-soft: rgba(70, 168, 179, .14);
  --ok: #2f855a; --warn: #b45309; --bad: #c53030; --off: #a0aec0;
  --user-bubble: #1d7d88; --user-text: #ffffff; --ai-bubble: #e3ecef; --ai-text: #1a202c;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b161a; --panel: #13232a; --line: #25393f; --text: #f1f7f8; --muted: #9bb0b6;
  --brand: #46a8b3; --accent: #5fd0d8; --accent-text: #062126; --accent-soft: rgba(70, 168, 179, .22);
  --ok: #68d391; --warn: #fbd38d; --bad: #fc8181; --off: #5c7178;
  --user-bubble: #1f8a95; --user-text: #ffffff; --ai-bubble: #1b3038; --ai-text: #f1f7f8;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: grid; grid-template-columns: 270px 1fr;
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, select, input { font: inherit; color: inherit; }

#side {
  display: flex; flex-direction: column; gap: 10px; padding: 12px; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
#new {
  padding: 9px 12px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
#convs { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv {
  display: flex; align-items: center; gap: 4px; border-radius: 6px; padding: 0 4px 0 0;
}
.conv:hover { background: var(--bg); }
.conv.active { background: var(--accent-soft); }
.conv.active { font-weight: 600; }
.conv .open {
  flex: 1; min-width: 0; text-align: left; padding: 7px 8px; border: 0; background: none; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv .del { border: 0; background: none; cursor: pointer; color: var(--muted); visibility: hidden; padding: 4px 6px; }
.conv:hover .del, .conv .del:focus { visibility: visible; }
.empty { color: var(--muted); padding: 8px; }

#models-box { border-top: 1px solid var(--line); padding-top: 8px; }
#models-box h2 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#models { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; max-height: 38vh; overflow-y: auto; }
#models li { display: grid; grid-template-columns: 10px 1fr auto; gap: 7px; align-items: baseline; }
#models .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); align-self: center; }
#models li.on .dot { background: var(--ok); }
#models li.wait .dot { background: var(--warn); }
#models .why { grid-column: 2 / -1; color: var(--muted); font-size: 12px; }
.tier { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 0 6px; }

#user-box { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--line); padding-top: 8px; }
#user-name { flex: 1 1 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
#admin-link { color: var(--text); text-decoration: none; font-size: 13px; }
#user-box { flex-wrap: wrap; }
#user-box button, dialog button, #admin-link {
  border: 1px solid var(--line); background: none; border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
#user-box button:hover, dialog button:hover { background: var(--bg); }
[hidden] { display: none !important; }

dialog {
  width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto;
  border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px;
  background: var(--panel); color: var(--text); margin: auto;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 10px; font-size: 18px; }
dialog h3 { margin: 0 0 8px; font-size: 14px; }
dialog form { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding: 14px 0; }
dialog label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 12px; }
dialog input { padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 14px; }
dialog form button[type=submit], #tfa-start { align-self: flex-start; background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; padding: 6px 12px; }
dialog .small { margin: 0; color: var(--muted); font-size: 12px; }
dialog a { color: var(--accent); font-size: 13px; }
#tfa-setup, #tfa-confirm { display: flex; flex-direction: column; gap: 8px; }
#tfa-secret { padding: 8px 10px; border: 1px dashed var(--line); border-radius: 6px; font-size: 15px; letter-spacing: 1px; word-break: break-all; user-select: all; }
#account-msg { margin: 0 0 10px; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line); font-size: 13px; }
#account-msg.err { color: var(--warn); border-color: var(--warn); }
#account-msg.ok { color: var(--ok); border-color: var(--ok); }

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100vh; height: 100dvh; }
header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 9px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
header label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); max-width: 60vw; }
#status { flex: 1 1 220px; min-width: 0; color: var(--muted); font-size: 13px; }
#status b { color: var(--text); }
#status .fb { color: var(--warn); }
#theme-toggle { border: 1px solid var(--line); background: none; border-radius: 6px; padding: 4px 10px; cursor: pointer; white-space: nowrap; }
#theme-toggle:hover { background: var(--bg); }
#side { border-top: 3px solid var(--brand); }
input[type=checkbox] { accent-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#menu { display: none; border: 1px solid var(--line); background: none; border-radius: 6px; padding: 4px 9px; cursor: pointer; }
/* Coluna de leitura centrada: em ecrãs largos as mensagens não se espalham de ponta a ponta. */
#chat-host { flex: 1; min-height: 0; display: flex; justify-content: center; }
#chat-host deep-chat { display: block; flex: 0 1 920px; min-width: 0; }

@media (max-width: 760px) {
  body { grid-template-columns: 1fr; }
  #side { position: fixed; inset: 0 20% 0 0; z-index: 10; transform: translateX(-105%); transition: transform .15s; }
  body.side-open #side { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  #menu { display: block; }
}
