:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --border: #dde3e9;
  --text: #17212b;
  --muted: #5f6d7a;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #e1f2ef;
  --danger: #c2410c;
  --danger-soft: #fff1e8;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #a16207;
  --warn-soft: #fdf6e3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418;
    --surface: #151d23;
    --surface-2: #1c262e;
    --border: #2a3640;
    --text: #e6edf2;
    --muted: #93a3b1;
    --brand: #2dd4bf;
    --brand-ink: #062b27;
    --brand-soft: #123532;
    --danger: #fb923c;
    --danger-soft: #3a2316;
    --ok: #4ade80;
    --ok-soft: #14301f;
    --warn: #facc15;
    --warn-soft: #33290d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ── Botões e campos ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-weight: 600; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--brand); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--muted); padding: 0 6px; }
.btn.link:hover { color: var(--text); }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.input, select.input {
  height: 38px; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); width: 100%;
}
.input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; background: var(--border); cursor: pointer; transition: background .15s;
}
.switch span::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; transition: transform .15s;
}
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.badge.on { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }

/* ── Login ── */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 800;
}
.auth-card h1 { margin: 6px 0 0; font-size: 20px; }
.error-box { background: var(--danger-soft); color: var(--danger); padding: 8px 12px; border-radius: 9px; font-size: 13px; }

/* ── Estrutura ── */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px; height: 58px;
  display: flex; align-items: center; gap: 16px;
}
.nav { display: flex; align-items: center; gap: 2px; overflow-x: auto; flex: 1; }
.nav button {
  border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600;
}
.nav button:hover { color: var(--text); background: var(--surface-2); }
.nav button.active { color: var(--brand); background: var(--brand-soft); }
.user-box { display: flex; align-items: center; gap: 6px; font-size: 13px; }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head p { margin: 2px 0 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.grow { flex: 1; min-width: 200px; }
.spaced { margin-top: 14px; }

/* ── Chat ── */
.chat { display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 440px; }
.chat-log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: min(720px, 88%); padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word;
  background: var(--surface-2); border: 1px solid transparent;
}
.msg.user .bubble { background: var(--brand); color: var(--brand-ink); }
.bubble.refused { border-color: var(--warn); background: var(--warn-soft); }
.bubble.error { border-color: var(--danger); background: var(--danger-soft); }
.bubble.done { border-color: var(--ok); background: var(--ok-soft); }
.bubble.confirm { border-color: var(--brand); }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.btn.mic { flex: none; width: 44px; padding: 0; font-size: 18px; }
.btn.mic.on { background: var(--danger); border-color: var(--danger); animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-pulse { 50% { box-shadow: 0 0 0 6px var(--danger-soft); } }
.voice-toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 4px 12px; cursor: pointer; font-size: 13px;
}
.chip:hover { border-color: var(--brand); }
.options { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; white-space: normal; }
.option {
  text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 12px; cursor: pointer;
}
.option:hover:not(:disabled) { border-color: var(--brand); }
.option:disabled { opacity: .6; cursor: default; }
.actions { display: flex; gap: 8px; margin-top: 10px; }
.typing { color: var(--muted); font-size: 13px; }

/* ── Tabelas ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
td.center, th.center { text-align: center; }
tr:last-child td { border-bottom: 0; }
.mini-table { margin-top: 10px; max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; white-space: normal; background: var(--surface); }
.mini-table th, .mini-table td { padding: 6px 10px; font-size: 13px; }

/* ── Modal ── */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; padding: 20px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 12px; }
.checks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.checks li { display: flex; gap: 10px; }
.dot { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; }
.dot.ok { background: var(--ok-soft); color: var(--ok); }
.dot.bad { background: var(--danger-soft); color: var(--danger); }
.dot.na { background: var(--surface-2); color: var(--muted); }

/* ── Avisos ── */
.toast-area { position: fixed; right: 16px; top: 72px; pointer-events: none; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; max-width: 360px; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); color: #fff; }
.notice { padding: 10px 14px; border-radius: 10px; background: var(--brand-soft); font-size: 13px; margin-bottom: 14px; }

@media (max-width: 720px) {
  .topbar { position: static; }
  .topbar-inner { height: auto; flex-wrap: wrap; gap: 6px 12px; padding-block: 10px; }
  .user-box { margin-left: auto; }
  .nav { order: 3; flex-basis: 100%; }
  .nav button { padding: 6px 10px; white-space: nowrap; }
  main { padding-top: 14px; }
  .chat { height: calc(100vh - 240px); min-height: 380px; }
}
