/* ATLAS — interface minimalista estilo "modo de voz" (referência: ChatGPT Voice).
   Fundo preto absoluto, acento amarelo Caterpillar, sem cards/paineis fixos. */

:root {
  --bg: #000000;
  --fg: #f5f5f0;
  --muted: #8a8a86;
  --yellow: #FFCD11;
  --yellow-dim: #b89a13;
  --danger: #ff6e5a;
  --surface: #141414;
  --surface-2: #1d1d1d;
  --border: #2a2a2a;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.icon-btn {
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  border-radius: 999px; color: var(--fg); flex: none;
}
.icon-btn:active { background: rgba(255,255,255,0.08); }

/* ---------- topo ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 6px 8px;
  flex: none;
}
.brand {
  margin: 0; text-align: center; flex: 1;
  font-family: Georgia, "Times New Roman", "Noto Serif", serif;
  font-weight: 400; letter-spacing: 0.14em;
  font-size: 20px; color: var(--fg);
}

/* ---------- centro: núcleo + rótulo ---------- */
.stage {
  position: relative; flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
}
.core-wrap {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
#atlas-canvas { width: min(78vw, 78vh); height: min(78vw, 78vh); display: block; touch-action: manipulation; }

.state-label {
  position: relative; z-index: 1;
  font-size: 12px; letter-spacing: 0.08em; color: var(--muted);
  text-transform: uppercase; margin-bottom: 6px; min-height: 16px;
  text-align: center;
}

/* ---------- conversa (bolhas, só aparece quando há conteúdo) ---------- */
.conversation {
  position: relative; z-index: 1; width: 100%;
  max-height: 46vh; overflow-y: auto;
  padding: 0 14px 10px;
  display: flex; flex-direction: column; gap: 8px;
  scroll-behavior: smooth;
}
.conversation:empty { display: none; }

.bubble { max-width: 88%; padding: 10px 14px; border-radius: var(--radius); font-size: 15px; line-height: 1.4; }
.bubble.user { align-self: flex-end; background: var(--yellow); color: #1a1400; border-bottom-right-radius: 4px; }
.bubble.atlas { align-self: flex-start; background: var(--surface); color: var(--fg); border-bottom-left-radius: 4px; }
.bubble.interim { opacity: 0.55; }
.bubble .detail-toggle { display: block; margin-top: 8px; font-size: 12px; color: var(--yellow); text-decoration: underline; text-underline-offset: 2px; }
.bubble .detail { display: none; margin-top: 8px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 8px; }
.bubble .detail.open { display: block; }
.bubble .detail .hyp { margin: 4px 0; }
.bubble .detail .chip { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; margin-right: 6px; background: var(--surface-2); }

.bubble.evidence { align-self: flex-start; background: var(--surface); display: flex; gap: 10px; align-items: center; }
.bubble.evidence .thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; }
.bubble.evidence .ev-meta { font-size: 12px; color: var(--muted); }
.bubble.evidence .ev-meta b { color: var(--fg); font-weight: 500; }
.bubble.evidence audio { max-width: 160px; height: 32px; }
.sync-dot { display: inline-block; width: 6px; height: 6px; border-radius: 999px; margin-right: 5px; }
.sync-dot.ok { background: #4fca6b; } .sync-dot.pend { background: var(--muted); } .sync-dot.err { background: var(--danger); }

/* ---------- rodapé: barra de conversa ---------- */
.dock { flex: none; padding: 8px 10px calc(10px + var(--safe-bottom)); }
.text-bar {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 26px; padding: 6px;
}
.text-bar input {
  flex: 1; min-width: 0; background: none; border: 0; outline: none;
  padding: 8px 6px; font-size: 16px; color: var(--fg);
}
.text-bar input::placeholder { color: var(--muted); }
.mic {
  width: 44px; height: 44px; border-radius: 999px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--yellow); color: #1a1400;
  transition: background 0.15s, transform 0.15s;
}
.mic[aria-pressed="true"] { background: var(--danger); color: #fff; transform: scale(1.06); }
#app[data-state="processing"] .mic { opacity: 0.55; }

/* ---------- estado visual do app conforme data-state ---------- */
#app[data-state="offline"] .brand { color: var(--muted); }
#app[data-state="error"] .mic,
#app[data-state="mic_permission_denied"] .mic { background: var(--danger); color: #fff; }

/* ---------- drawers (esquerda / direita) ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 40;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; bottom: 0; width: min(86vw, 340px);
  background: var(--surface); z-index: 41;
  display: flex; flex-direction: column;
  padding: calc(10px + var(--safe-top)) 14px calc(10px + var(--safe-bottom));
  transition: transform 0.22s ease;
}
.drawer.left { left: 0; transform: translateX(-105%); border-right: 1px solid var(--border); }
.drawer.right { right: 0; transform: translateX(105%); border-left: 1px solid var(--border); }
.drawer.open { transform: translateX(0); }

.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.drawer-head h2 { margin: 0; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.drawer .pane { overflow-y: auto; flex: 1; margin-top: 8px; }

.case-item { width: 100%; text-align: left; padding: 12px 10px; border-radius: 10px; border-bottom: 1px solid var(--border); }
.case-item:active { background: var(--surface-2); }
.case-item.active { background: rgba(255,205,17,0.10); }
.case-item .row-title { display: block; font-size: 15px; }
.case-item .row-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

.row-btn, .row-static {
  width: 100%; text-align: left; padding: 12px 10px; border-radius: 10px;
  display: flex; flex-direction: column; border-bottom: 1px solid var(--border);
}
.row-btn:active { background: var(--surface-2); }
.row-title { font-size: 15px; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row-sub.conn.on { color: #4fca6b; }
.row-sub.conn.off { color: var(--danger); }

.btn { padding: 10px 16px; border-radius: 12px; background: var(--surface-2); color: var(--fg); font-size: 14px; }
.btn.primary { background: var(--yellow); color: #1a1400; font-weight: 600; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; text-align: center; }

/* ---------- notice / toast ---------- */
.notice {
  position: absolute; left: 12px; right: 12px; top: calc(58px + var(--safe-top));
  z-index: 30; padding: 0; max-height: 0; overflow: hidden; opacity: 0;
  transition: all 0.2s; border-radius: 12px; font-size: 13px;
}
.notice.show { max-height: 120px; opacity: 1; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.notice.error { border-color: var(--danger); }
.notice.warn { border-color: var(--yellow-dim); }
.notice-actions { flex: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%) translateY(10px);
  background: var(--surface); border: 1px solid var(--border); color: var(--fg);
  padding: 9px 16px; border-radius: 999px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: all 0.2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: #4fca6b; }
.toast.error { border-color: var(--danger); }

/* ---------- sheet (folha inferior: captura de evidência, formulários) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 60;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 10px 18px calc(18px + var(--safe-bottom));
  transform: translateY(110%); transition: transform 0.22s ease;
  max-height: 82vh; overflow-y: auto;
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 999px; margin: 6px auto 10px; }
.sheet-title { margin: 0 0 12px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.sheet-body .lbl { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.sheet-body .field {
  width: 100%; padding: 11px 12px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--fg); font-size: 15px;
}
.sheet-body .field.big { font-size: 20px; }
.sheet-body textarea.field { resize: vertical; font-family: inherit; }
.sheet-body .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-body .hidden { display: none; }
.sheet-body .preview, .sheet-body video.preview { width: 100%; border-radius: 12px; margin-bottom: 6px; }
.sheet-body .preview-audio { width: 100%; }
.sheet-body .muted { color: var(--muted); }
.sheet-body .small { font-size: 12px; }
.sheet-body .err { color: var(--danger); }
.sheet-body .form-err { color: var(--danger); font-size: 13px; min-height: 16px; margin-top: 6px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; text-align: center; }
.rec-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.rec-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }
.meter { height: 6px; border-radius: 999px; background: var(--surface-2); margin: 10px 0; overflow: hidden; }
.meter div { height: 100%; background: var(--yellow); width: 0; transition: width 0.08s linear; }

.hidden { display: none !important; }

/* ---------- v0.7.0: modo conversa por voz ---------- */
.mic.convo { background: var(--yellow); color: #000; box-shadow: 0 0 0 0 rgba(255, 205, 17, 0.55); animation: convo-ring 1.8s ease-out infinite; }
.mic.convo[aria-pressed="true"] { background: var(--danger); color: #fff; }
#app[data-convo="on"] .state-label { color: var(--yellow); }
@keyframes convo-ring {
  0% { box-shadow: 0 0 0 0 rgba(255, 205, 17, 0.55); }
  70% { box-shadow: 0 0 0 12px rgba(255, 205, 17, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 205, 17, 0); }
}
@media (prefers-reduced-motion: reduce) { .mic.convo { animation: none; } }

/* ---------- v0.8.0: motor de IA ---------- */
.prov-tag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 10px;
  letter-spacing: 0.04em; border: 1px solid var(--yellow-dim); color: var(--yellow-dim); vertical-align: middle; }
#engine-state.warn { color: var(--yellow); }
