/* ═══════════════════════════════════════════════════════════
   NYRA — dashboard
   Tema escuro. As cores de série do gráfico vêm da paleta
   validada para fundo escuro (azul #3987e5 / laranja #d95926).
   ═══════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;

  --plane:        #0a0d14;
  --surface-1:    #131822;
  --surface-2:    #191f2c;
  --border:       rgba(255, 255, 255, 0.08);
  --border-strong:rgba(255, 255, 255, 0.14);

  --text-primary:   #eef2f8;
  --text-secondary: #9aa5b8;
  --muted:          #6b7688;

  --accent:      #4fd1ff;
  --accent-deep: #2a78d6;
  --violet:      #7c5cff;

  /* séries do gráfico — paleta validada (dark) */
  --series-text:  #3987e5;
  --series-voice: #d95926;

  /* status — paleta fixa */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;

  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

/* O atributo `hidden` precisa vencer qualquer `display` vindo de classe,
   senão elementos como o modal (display:flex) aparecem mesmo escondidos. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #16203a 0%, transparent 60%),
    var(--plane);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Topbar ─────────────────────────────────────────────── */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 13, 20, 0.7);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: baseline; gap: 9px; }

.brand-mark {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  align-self: center;
  transition: background .4s, box-shadow .4s;
}
.brand-mark[data-state="thinking"] { background: var(--violet); box-shadow: 0 0 12px var(--violet); }
.brand-mark[data-state="alert"]    { background: var(--warning); box-shadow: 0 0 12px var(--warning); }
.brand-mark[data-state="blocked"]  { background: var(--critical); box-shadow: 0 0 12px var(--critical); }

.brand-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 3px;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .5px;
}

.topbar-stats {
  display: flex;
  gap: 26px;
  margin-left: auto;
}
.tstat { display: flex; flex-direction: column; gap: 1px; }
.tstat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.tstat-value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.topbar-right { display: flex; align-items: center; gap: 14px; }

.mode-badge {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 9px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
}
.mode-badge[data-mode="economy"]   { color: var(--warning); border-color: rgba(250,178,25,.4); }
.mode-badge[data-mode="text_only"] { color: var(--serious); border-color: rgba(236,131,90,.4); }
.mode-badge[data-mode="paused"]    { color: var(--critical); border-color: rgba(208,59,59,.45); }

.conn { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.conn i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
}
.conn[data-ok="true"] i  { background: var(--good); box-shadow: 0 0 8px var(--good); }
.conn[data-ok="false"] i { background: var(--critical); box-shadow: 0 0 8px var(--critical); }

/* ── Grid principal ─────────────────────────────────────── */

.grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  gap: 14px;
  padding: 14px 16px 16px;
  min-height: 0;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}
/* Colunas laterais rolam por inteiro se o conteúdo passar da altura,
   em vez de cada painel cortar o próprio conteúdo. */
.col-left, .col-right {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.col-left::-webkit-scrollbar, .col-right::-webkit-scrollbar { width: 6px; }
.col-left::-webkit-scrollbar-thumb, .col-right::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 3px;
}
.col-left > .panel, .col-right > .panel { flex: 0 0 auto; }
.col-center { min-width: 0; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  min-height: 0;
}

.panel-title {
  margin: 0 0 13px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-secondary);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.panel-hint {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: .3px;
  text-transform: none;
  color: var(--muted);
}

/* ── Orçamento ──────────────────────────────────────────── */

.hero { margin-bottom: 16px; }
.hero-value {
  font-size: 38px;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -1px;
}
.hero-value[data-status="warning"]  { color: var(--warning); }
.hero-value[data-status="critical"] { color: var(--critical); }
.hero-label {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 5px;
}

.meter { margin-bottom: 12px; }
.meter-head {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.meter-nums { font-variant-numeric: tabular-nums; }
.meter-nums b { color: var(--text-primary); font-weight: 600; }

.meter-track {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  width: 0;
  transition: width .6s cubic-bezier(.4,0,.2,1), background .4s;
}
.meter-fill--month { background: var(--accent-deep); }
.meter-fill[data-status="warning"]  { background: var(--warning); }
.meter-fill[data-status="critical"] { background: var(--critical); }

.split {
  display: flex;
  gap: 18px;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}
.split-item { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.split-label { color: var(--muted); }
.split-value { font-weight: 600; font-variant-numeric: tabular-nums; margin-left: auto; }

.dot { width: 8px; height: 8px; border-radius: 2px; flex: 0 0 auto; }
.dot-text  { background: var(--series-text); }
.dot-voice { background: var(--series-voice); }

.projection {
  margin-top: 12px;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 11.5px;
  line-height: 1.5;
  background: rgba(250, 178, 25, 0.09);
  border: 1px solid rgba(250, 178, 25, 0.25);
  color: var(--warning);
}
.projection[data-status="critical"] {
  background: rgba(208, 59, 59, 0.1);
  border-color: rgba(208, 59, 59, 0.3);
  color: var(--critical);
}

/* ── Gráfico ────────────────────────────────────────────── */

.panel--chart { display: flex; flex-direction: column; min-height: 230px; }

.legend { display: flex; gap: 14px; margin-bottom: 10px; }
.legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-secondary);
}

.chart-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
#chart { width: 100%; height: 100%; display: block; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 11.5px;
  line-height: 1.6;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  z-index: 10;
  transform: translate(-50%, -100%);
}
.tooltip b { font-variant-numeric: tabular-nums; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-date { color: var(--muted); margin-bottom: 3px; }

/* ── ORB ────────────────────────────────────────────────── */

.orb-stage {
  flex: 1 1 auto;
  position: relative;
  min-height: 200px;
  max-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#orb { width: 100%; height: 100%; display: block; position: relative; z-index: 1; }

/* Brilho difuso atrás do ORB — decaimento suave que o shader não dá sozinho. */
.orb-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(64%, 420px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
  filter: blur(28px);
  z-index: 0;
}

.orb-state {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  color: var(--muted);
  transition: color .4s;
}
.orb-state[data-state="thinking"] { color: var(--violet); }
.orb-state[data-state="alert"]    { color: var(--warning); }
.orb-state[data-state="blocked"]  { color: var(--critical); }

/* ── Chat ───────────────────────────────────────────────── */

.panel--chat {
  flex: 0 0 auto;
  height: 46%;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.chat-log::-webkit-scrollbar { width: 7px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.chat-empty {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
  margin: auto 0;
  text-align: center;
  padding: 0 24px;
}

.msg { max-width: 82%; }
.msg-user { align-self: flex-end; }
.msg-nyra { align-self: flex-start; }

.msg-body {
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-user .msg-body {
  background: var(--accent-deep);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-nyra .msg-body {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-nyra[data-blocked="true"] .msg-body {
  border-color: rgba(208, 59, 59, .35);
  background: rgba(208, 59, 59, .08);
}

.msg-meta {
  display: flex;
  gap: 10px;
  margin-top: 5px;
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.msg-user .msg-meta { justify-content: flex-end; }
.msg-tool {
  color: var(--accent);
  background: rgba(79, 209, 255, .09);
  padding: 1px 6px;
  border-radius: 4px;
}

.typing { display: flex; gap: 4px; padding: 11px 13px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25 } 30% { opacity: 1 } }

.chat-form {
  flex: 0 0 auto;
  display: flex;
  gap: 9px;
  padding: 11px 12px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, .015);
}
.chat-form input {
  flex: 1 1 auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 13px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13.5px;
  outline: none;
  transition: border-color .2s;
}
.chat-form input:focus { border-color: var(--accent); }
.chat-form button {
  flex: 0 0 auto;
  background: var(--accent);
  color: #06121c;
  border: none;
  border-radius: 9px;
  padding: 0 17px;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
}
.chat-form button:hover { opacity: .88; }
.chat-form button:disabled { opacity: .4; cursor: not-allowed; }

/* ── Skills ─────────────────────────────────────────────── */

.skills { display: flex; flex-direction: column; gap: 3px; }
.skill-group {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin: 9px 0 3px;
}
.skill-group:first-child { margin-top: 0; }

.skill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 7px;
  border-radius: 6px;
  font-size: 12.5px;
  transition: background .15s;
}
.skill:hover { background: rgba(255, 255, 255, .03); }
.skill-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  opacity: .5;
  flex: 0 0 auto;
}
.skill[data-used="true"] .skill-dot { opacity: 1; box-shadow: 0 0 6px var(--accent); }
.skill-name { flex: 1 1 auto; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11.5px; }
.skill-count {
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ── Tarefas ────────────────────────────────────────────── */

.tasks { display: flex; flex-direction: column; gap: 7px; }
.task {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border-left: 2px solid var(--accent);
}
.task[data-kind="routine"] { border-left-color: var(--violet); }
.task-title { font-size: 12.5px; line-height: 1.4; }
.task-when {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.empty { color: var(--muted); font-size: 12px; padding: 6px 2px; }

/* ── Atividade ──────────────────────────────────────────── */

.panel--activity { display: flex; flex-direction: column; }
.activity {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 11px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.activity::-webkit-scrollbar { width: 6px; }
.activity::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.act {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 5px;
  font-variant-numeric: tabular-nums;
}
.act:hover { background: rgba(255, 255, 255, .03); }
.act-time { color: var(--muted); flex: 0 0 auto; }
.act-model { color: var(--text-secondary); flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-cost { font-weight: 600; flex: 0 0 auto; }
.act-cache { color: var(--good); font-size: 9.5px; flex: 0 0 auto; }

/* ── Modal ──────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 11, .82);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 {
  margin: 0 0 8px;
  font-size: 17px;
  color: var(--critical);
}
.modal-intro {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.options { display: flex; flex-direction: column; gap: 7px; margin-bottom: 18px; }
.option {
  text-align: left;
  padding: 11px 13px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  font-family: var(--font);
  transition: border-color .15s, background .15s;
}
.option:hover { border-color: var(--border-strong); }
.option[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(79, 209, 255, .07);
}
.option-label { font-size: 13px; font-weight: 600; display: block; }
.option-desc { font-size: 11.5px; color: var(--muted); margin-top: 3px; display: block; line-height: 1.45; }

.modal-field { margin-bottom: 13px; }
.modal-field label {
  display: block;
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.modal-field .opt { color: var(--muted); }
.modal-field input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
}
.modal-field input:focus { border-color: var(--accent); }

.modal-error {
  margin: 0 0 13px;
  padding: 9px 11px;
  border-radius: 7px;
  font-size: 12px;
  background: rgba(208, 59, 59, .12);
  border: 1px solid rgba(208, 59, 59, .3);
  color: var(--critical);
}

.modal-actions { display: flex; gap: 9px; justify-content: flex-end; }
.btn {
  padding: 9px 18px;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); }
.btn-primary { background: var(--accent); color: #06121c; }
.btn-primary:hover { opacity: .88; }
.btn-primary:disabled { opacity: .35; cursor: not-allowed; }

/* ── Responsivo ─────────────────────────────────────────── */

@media (max-width: 1180px) {
  .grid { grid-template-columns: 270px minmax(0, 1fr); }
  .col-right { display: none; }
}

@media (max-width: 860px) {
  body { overflow: auto; }
  .grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 14px; }
  .topbar-stats { gap: 18px; width: 100%; order: 3; }
  .orb-stage { min-height: 240px; }
  .panel--chat { height: auto; min-height: 340px; }
}

/* ── Voz ──────────────────────────────────────────────────── */
#voiceBtn { position: relative; }
#voiceBtn[data-ativa="1"] {
  background: var(--series-voice);
  color: #fff;
  border-color: var(--series-voice);
}
/* Pulso só enquanto a sessão está viva: é dinheiro correndo, precisa ser óbvio. */
#voiceBtn[data-ativa="1"]::after {
  content: ''; position: absolute; inset: -3px; border-radius: inherit;
  border: 1px solid var(--series-voice); animation: vozPulso 1.6s ease-out infinite;
}
@keyframes vozPulso {
  0%   { opacity: .7; transform: scale(1); }
  100% { opacity: 0;  transform: scale(1.18); }
}
.voice-status {
  margin: 8px 2px 0; font-size: 12px; letter-spacing: .02em;
  color: var(--muted, #8a93a6);
}
.voice-status[data-erro="1"] { color: var(--series-voice); }

/* ── Porta de entrada ─────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 999;
  display: grid; place-items: center;
  background: var(--bg, #070b12);
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(360px, calc(100vw - 48px));
  display: flex; flex-direction: column; gap: 6px;
  padding: 32px; border-radius: 14px;
  border: 1px solid var(--line, #1b2433);
  background: var(--panel, #0c111b);
}
.gate-title {
  margin: 0; font-size: 26px; letter-spacing: .28em;
  text-align: center; color: var(--fg, #e6edf7);
}
.gate-sub {
  margin: 0 0 18px; text-align: center; font-size: 12.5px; line-height: 1.5;
  color: var(--muted, #8a93a6);
}
.gate-label {
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted, #8a93a6); margin-top: 10px;
}
.gate-input {
  padding: 11px 13px; border-radius: 8px; font-size: 14px;
  border: 1px solid var(--line, #1b2433);
  background: var(--bg, #070b12); color: var(--fg, #e6edf7);
}
.gate-input:focus { outline: none; border-color: var(--accent, #4fd1ff); }
.gate-input[readonly] { color: var(--muted, #8a93a6); }
.gate-btn {
  margin-top: 22px; padding: 12px; border-radius: 8px; cursor: pointer;
  font-size: 14px; letter-spacing: .04em;
  border: 1px solid var(--accent, #4fd1ff);
  background: var(--accent, #4fd1ff); color: #04121b;
}
.gate-btn:disabled { opacity: .5; cursor: default; }
.gate-erro {
  margin: 14px 0 0; font-size: 12.5px; text-align: center;
  color: var(--series-voice, #d95926);
}

/* Requisitos da senha, marcados ao vivo enquanto se digita. */
.gate-regras {
  list-style: none; margin: 10px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 5px;
}
.gate-regras[hidden] { display: none; }
.gate-regras li {
  font-size: 12px; display: flex; align-items: center; gap: 8px;
  color: var(--muted, #8a93a6);
  transition: color .18s ease;
}
.gate-regras li::before {
  content: '○'; font-size: 11px; width: 12px;
}
.gate-regras li[data-ok="1"] { color: var(--sage, #4bbf8a); }
.gate-regras li[data-ok="1"]::before { content: '●'; }

/* Aviso que a Nyra deu sem ser perguntada (lembrete, tarefa concluída). */
.msg[data-aviso="true"] {
  border-left: 2px solid var(--accent, #4fd1ff);
  padding-left: 10px;
}

/* Marca onde a conversa anterior terminou e a sessão atual começa. */
.chat-retomada {
  display: flex; align-items: center; gap: 10px;
  margin: 14px 2px 10px;
  font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted, #8a93a6);
}
.chat-retomada::before, .chat-retomada::after {
  content: ''; flex: 1; height: 1px; background: var(--line, #1b2433);
}
