/* Console de operação do AQIO — CSS externo (ADR-0022 §3.1).
   Extraído do <style> inline original; Navy removido (decisão do fundador,
   2026-08-27 — ver docs/design-cockpit.md §7): a distinção "console vs. app
   de campo" agora vem da estrutura (zonas/widgets), não de paleta própria.
   Zero dependência nova — vanilla CSS, mesmos tokens do design system AQIO. */

:root {
  /* Superfícies — tokens canônicos do AQIO (lib/theme.ts) */
  --base: #0F1315; --surface: #171C1F; --surface2: #212729; --line: #2E3539;
  --ink: #F3F0EA; --muted: #8A9296; --faint: #6B7377;

  /* Ember: território exclusivo de "ação que o operador pede". */
  --ember: #F04E37; --ember-bright: #FF6B54; --ember-deep: #C33A28;
  --ember-dim: rgba(240,78,55,.12); --ember-line: rgba(240,78,55,.32);

  /* Semânticos — separados do acento, nunca decorativos */
  --ok: #3FB984; --ok-dim: rgba(63,185,132,.12); --ok-line: rgba(63,185,132,.32);
  --warn: #E5A73F; --warn-dim: rgba(229,167,63,.12);
  --err: #E8674A;

  --display: 'Archivo', system-ui, sans-serif;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --top: env(safe-area-inset-top); --bot: env(safe-area-inset-bottom);
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { overscroll-behavior-y: none; }
body {
  margin: 0;
  /* Compromisso deliberado com um só tema: instrumento de operação, sempre
     escuro. Fundo pintado explicitamente — nunca herdar o ground do host. */
  background: var(--base); color: var(--ink);
  font-family: var(--sans); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--bot) + 8px);
}
button, input, textarea, select { font-family: inherit; }
:focus-visible { outline: 2px solid var(--ember-bright); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ── Cabeçalho — banda neutra, sem paleta própria ───────────────────────── */
header {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--top) + 13px) 18px 13px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(170%) blur(16px);
  -webkit-backdrop-filter: saturate(170%) blur(16px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.lock { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.lock .wm { font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: -.01em; line-height: 1; }
.lock .slash { color: var(--line); font-size: 15px; line-height: 1; }
.lock .kind { font-family: var(--mono); font-weight: 500; font-size: 11.5px; letter-spacing: .14em; color: var(--ember); line-height: 1; }
.who { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 3px; display: block; }
.hdr-actions { display: flex; gap: 8px; flex: none; }
.ib {
  height: 34px; min-width: 34px; padding: 0 10px; border-radius: var(--r-md);
  background: rgba(255,255,255,.05); border: 1px solid var(--line); color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px; justify-content: center; cursor: pointer;
  font-size: 12.5px; font-family: var(--sans);
}
.ib:hover { background: rgba(255,255,255,.09); color: var(--ink); }
.ib:active { transform: scale(.97); }
.ib svg { width: 15px; height: 15px; flex: none; }
.ib.spinning svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding: 16px 18px 28px; max-width: 1180px; margin: 0 auto; }

/* ── Zonas e widgets — o cockpit (design-cockpit.md) ─────────────────────── */
.zona { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px; margin-bottom: 24px; }
.zona > h2 { grid-column: 1 / -1; }
/* A zona de risco reaproveita a classe .zona só pro espaçamento entre zonas —
   o grid de verdade fica em .zona-risco-corpo (o gate button vem antes, fora
   do grid). Sem isto, gate e corpo viram itens lado a lado no grid de 12
   colunas herdado de .zona (achado real ao testar — ver console-smoke). */
.zona.zona-risco { display: block; }

.widget { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.widget-fixo { background: transparent; border: none; border-radius: 0; overflow: visible; }
.widget-full { grid-column: 1 / -1; }
.widget-lg { grid-column: span 6; }
.widget-md { grid-column: span 4; }
@media (max-width: 899px) { .widget-lg, .widget-md { grid-column: 1 / -1; } }

.widget-header {
  all: unset; box-sizing: border-box; cursor: pointer; width: 100%;
  display: flex; align-items: center; gap: 10px; padding: 13px 16px;
}
.widget-header:hover { background: rgba(255,255,255,.02); }
.widget-titulo { font-family: var(--display); font-weight: 600; font-size: 14px; color: var(--ink); flex: none; }
.widget-resumo { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; text-align: right; margin-right: 4px; }
.widget-chevron { width: 16px; height: 16px; flex: none; color: var(--faint); transition: transform .15s; }
.widget-header[aria-expanded="true"] .widget-chevron { transform: rotate(180deg); }
.widget-corpo { padding: 0 16px 16px; }
.widget-fixo .widget-corpo { padding: 0; margin-bottom: 18px; }

/* Zona de risco — deliberadamente "fora do tom" do resto (design-cockpit.md §8) */
.zona-risco {
  grid-column: 1 / -1; border: 1.5px dashed var(--ember-line); border-radius: var(--r-md);
  padding: 14px 16px; margin-bottom: 24px; background: rgba(232,103,74,.03);
}
.zona-risco-gate {
  all: unset; box-sizing: border-box; cursor: pointer; width: 100%;
  display: flex; align-items: center; gap: 10px;
  font-family: var(--display); font-weight: 600; font-size: 14px; color: var(--err);
  text-transform: uppercase; letter-spacing: .06em;
}
.zona-risco-gate svg { width: 18px; height: 18px; flex: none; }
.zona-risco-toggle { margin-left: auto; font-size: 11.5px; font-weight: 400; text-transform: none; letter-spacing: 0; font-family: var(--sans); }
.zona-risco-corpo {
  display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px;
  margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--ember-line);
}
.zona-risco .widget { border-color: var(--ember-line); }

/* ── Estado da plataforma — Pulso ─────────────────────────────────────────── */
.pulse {
  border-radius: var(--r-lg); border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface2), var(--surface));
  overflow: hidden;
}
.pulse.calm { border-color: var(--ok-line); }
.pulse.needs { border-color: var(--ember-line); }
.pulse-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.calm .dot { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-dim); }
.needs .dot { background: var(--ember); box-shadow: 0 0 0 4px var(--ember-dim); }
.pulse-head .txt { font-family: var(--display); font-weight: 600; font-size: 15px; }
.calm .pulse-head .txt { color: var(--ok); }
.needs .pulse-head .txt { color: var(--ember-bright); }
.pulse-head .sub { font-size: 12.5px; color: var(--muted); margin-left: auto; text-align: right; }
.pulse-items { border-top: 1px solid var(--line); display: flex; flex-direction: column; }
.pitem {
  all: unset; box-sizing: border-box; cursor: pointer; width: 100%;
  display: flex; gap: 11px; padding: 12px 16px; border-bottom: 1px solid var(--line); align-items: flex-start;
}
.pitem:hover { background: rgba(255,255,255,.02); }
.pitem:last-child { border-bottom: none; }
.pitem .tag {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .1em; padding: 3px 7px; border-radius: 999px;
  flex: none; margin-top: 1px; border: 1px solid;
}
.tag.override { color: var(--warn); border-color: rgba(229,167,63,.35); background: var(--warn-dim); }
.tag.gap { color: var(--ember); border-color: var(--ember-line); background: var(--ember-dim); }
.tag.idle { color: var(--faint); border-color: var(--line); background: var(--surface2); }
.pitem .body { min-width: 0; text-align: left; }
.pitem .h { font-size: 13.5px; font-weight: 500; }
.pitem .d { font-size: 12.5px; color: var(--muted); margin-top: 2px; line-height: 1.45; }

/* ── Números ─────────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
@media (min-width: 480px) { .stats { grid-template-columns: repeat(5, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 13px 14px; }
.stat .l { font-family: var(--mono); font-size: 9.5px; letter-spacing: .13em; color: var(--faint); text-transform: uppercase; }
.stat .n { font-size: 25px; font-weight: 700; margin-top: 5px; line-height: 1.05; }
.stat.span2 { grid-column: span 2; }
@media (min-width: 480px) { .stat.span2 { grid-column: auto; } }

/* ── Seções ──────────────────────────────────────────────────────────────── */
h2 {
  font-family: var(--mono); font-size: 10px; letter-spacing: .16em; color: var(--faint);
  margin: 0 0 9px; font-weight: 500; text-transform: uppercase;
  display: flex; align-items: center; gap: 9px;
}
h2::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.split { display: grid; gap: 18px; }
@media (min-width: 640px) { .split { grid-template-columns: 1fr 1fr; } }

/* ── Linhas (mobile) ─────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 13px 14px; display: flex; align-items: center; gap: 12px;
}
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; font-size: 14.5px; }
.row .s { color: var(--muted); font-size: 12.5px; margin-top: 4px; display: flex; flex-wrap: wrap; align-items: center; gap: 0 5px; }
.row .s .bit { white-space: nowrap; }
.row .s .sep { color: var(--faint); }

/* ── Tabela (desktop) ────────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 560px; }
thead th {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--faint); font-weight: 500; text-align: left; padding: 11px 14px;
  border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface2);
}
thead th.r, tbody td.r { text-align: right; }
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.02); }
.only-wide { display: none; } .only-narrow { display: block; }
@media (min-width: 760px) { .only-wide { display: block; } .only-narrow { display: none; } }

/* ── Interruptor ─────────────────────────────────────────────────────────── */
.sw {
  flex: none; display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--surface2); border: 1px solid var(--line); color: var(--faint);
  border-radius: 999px; padding: 6px 12px 6px 8px; font-size: 12px; font-weight: 500; font-family: var(--sans);
  transition: background .15s, border-color .15s, color .15s;
}
.sw .led { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; transition: background .15s, box-shadow .15s; }
.sw[aria-pressed="true"] { background: var(--ok-dim); border-color: var(--ok-line); color: var(--ok); }
.sw[aria-pressed="true"] .led { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-dim); }
.sw:active { transform: scale(.97); }
.sw:disabled { opacity: .45; cursor: default; }
.chip {
  font-family: var(--mono); font-size: 9px; letter-spacing: .1em; padding: 2px 6px; border-radius: 999px;
  color: var(--warn); border: 1px solid rgba(229,167,63,.35); background: var(--warn-dim);
  margin-left: 7px; vertical-align: middle; white-space: nowrap;
}

/* ── Eventos ─────────────────────────────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 2px 14px; }
.evt { display: flex; gap: 12px; align-items: flex-start; padding: 11px 0; border-bottom: 1px solid var(--line); }
.evt:last-child { border-bottom: none; }
.evt .when { font-family: var(--mono); font-size: 11px; color: var(--faint); flex: none; width: 40px; padding-top: 1px; font-variant-numeric: tabular-nums; }
.evt .grow { min-width: 0; flex: 1; }
.evt .what { font-size: 13.5px; }
.evt .what b { font-weight: 600; }
.evt .meta { font-family: var(--mono); font-size: 11px; color: var(--faint); margin-top: 3px; word-break: break-word; }
.vazio { color: var(--faint); font-size: 13px; text-align: center; padding: 26px 14px; line-height: 1.65; }
.vazio b { display: block; color: var(--muted); font-weight: 500; margin-bottom: 3px; }

/* ── Login ───────────────────────────────────────────────────────────────── */
.login {
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
  padding: calc(var(--top) + 24px) 24px calc(var(--bot) + 24px); max-width: 360px; margin: 0 auto;
}
.login .lock { margin-bottom: 22px; }
.login .lock .wm { font-size: 27px; } .login .lock .kind { font-size: 13px; }
.login h1 { font-family: var(--display); font-size: 19px; margin: 0 0 5px; font-weight: 600; }
.login p { color: var(--muted); margin: 0 0 22px; font-size: 13px; line-height: 1.55; }
input, textarea, select {
  width: 100%; font-size: 16px; /* 16px evita o zoom automático do iOS */
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: var(--r-md); padding: 13px 14px; margin-bottom: 9px;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--ember); }
.btn {
  width: 100%; padding: 14px; border-radius: var(--r-md); border: none; cursor: pointer;
  background: var(--ember); color: #fff; font-size: 15px; font-weight: 600; font-family: var(--sans);
  display: flex; align-items: center; justify-content: center; gap: 9px;
}
.btn:hover { background: var(--ember-bright); } .btn:active { background: var(--ember-deep); }
.btn:disabled { opacity: .55; cursor: default; }
.spin { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.err { color: var(--err); font-size: 13px; margin-top: 11px; min-height: 18px; line-height: 1.45; }

/* ── Confirmação destrutiva (ADR-0022 §3.3, design-cockpit.md §8) ─────────── */
dialog.confirm-dialog, dialog.lightbox-dialog {
  border: none; border-radius: var(--r-lg); background: var(--surface); color: var(--ink);
  padding: 0; max-width: 440px; width: calc(100vw - 40px);
}
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(2px); }
.confirm-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.confirm-h { font-family: var(--display); font-weight: 700; font-size: 16px; }
.confirm-msg { font-size: 13.5px; color: var(--muted); line-height: 1.5; margin: 0; }
.confirm-msg b { color: var(--ink); }
.confirm-label { font-size: 12.5px; color: var(--muted); }
.confirm-input { margin-top: 6px; margin-bottom: 0; background: var(--surface2); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.btn-ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: var(--r-md);
  padding: 10px 16px; font-size: 13.5px; font-family: var(--sans); cursor: pointer;
}
.btn-ghost:hover { color: var(--ink); border-color: var(--faint); }
.btn-perigo { width: auto; background: var(--err); }
.btn-perigo:hover { background: var(--ember-bright); }
.btn-perigo:disabled { opacity: .4; cursor: default; }
.confirm-preview { font-size: 13px; color: var(--muted); max-height: 50vh; overflow-y: auto; }
.confirm-preview p { margin: 0 0 10px; color: var(--ink); }

.lightbox-dialog { padding: 16px; text-align: center; max-width: min(90vw, 720px); }
.lightbox-dialog img { max-width: 100%; border-radius: var(--r-md); display: block; margin-bottom: 12px; }

details summary { user-select: none; }
details summary::-webkit-details-marker { color: var(--faint); }

/* ── Aviso (substitui alert) ─────────────────────────────────────────────── */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(120%);
  bottom: calc(var(--bot) + 18px); z-index: 60; max-width: calc(100vw - 36px);
  background: var(--surface2); border: 1px solid var(--ember-line); color: var(--ink);
  border-radius: var(--r-md); padding: 12px 16px; font-size: 13.5px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5); transition: transform .22s ease, opacity .22s ease; opacity: 0;
}
#toast.up { transform: translateX(-50%) translateY(0); opacity: 1; }
