/* ── IA Dev — "bancada de operação" ───────────────────────────────────── */
/* Identidade: console industrial em carbono quente, âmbar de sinalização como
 * marca e tipografia técnica (Chakra Petch para display, IBM Plex Sans/Mono
 * para corpo e dados). Todos os nomes de classe/variável anteriores foram
 * preservados — as views dependem deles inline. */

:root {
  /* Superfícies em camadas (carbono quente, do fundo para a elevação) */
  --bg:         #0c0b09;
  --bg-card:    #14120e;
  --bg-input:   #1b1913;
  --bg-hover:   #242018;
  --bg-elev:    #211e17;
  --border:     #2e2a20;
  --border-soft:#211e17;

  /* Texto (branco quente — papel sob luz de bancada) */
  --text:       #ece7db;
  --text-dim:   #a49c89;
  /* ≥4.5:1 sobre --bg/--bg-card (AA em texto pequeno). */
  --text-muted: #877f6c;

  /* Marca: âmbar de sinalização + pólo cobre */
  --accent:      #ffb454;
  --accent-dim:  #e09a38;
  --accent-soft: rgba(255,180,84,0.12);
  --accent-grad: linear-gradient(135deg, #ffb454 0%, #f26d3d 100%);

  /* Estados */
  --green:  #7ed787;
  --red:    #f07862;
  --yellow: #e8c547;
  --orange: #fb923c;
  /* 2º polo do gradiente de marca, exposto como token para que os
   * gráficos (Chart.js) derivem a paleta das CSS vars em vez de hex avulso. */
  --purple: #f26d3d;

  /* Tipografia */
  --font:    'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --display: 'Chakra Petch', 'IBM Plex Sans', sans-serif;
  --mono:    'IBM Plex Mono', 'JetBrains Mono', monospace;

  /* Raios (cantos mais retos — ferramenta, não brinquedo) */
  --radius:    6px;
  --radius-sm: 4px;
  --radius-lg: 10px;

  /* Sombras / elevação */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow:    0 4px 16px -4px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3);
  --shadow-lg: 0 16px 48px -12px rgba(0,0,0,0.6);
  --glow:      0 0 0 1px rgba(255,180,84,0.18), 0 6px 20px -6px rgba(255,180,84,0.4);

  /* Movimento */
  --ease:     cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --t-fast:   0.14s var(--ease);
  --t:        0.22s var(--ease);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  /* Atmosfera de bancada: grade técnica sutil (blueprint) + luz âmbar vinda do
   * canto da mesa. A grade dá textura sem competir com dados. */
  background-image:
    radial-gradient(900px 600px at 10% -10%, rgba(255,180,84,0.07), transparent 60%),
    radial-gradient(800px 600px at 100% 0%, rgba(242,109,61,0.045), transparent 55%),
    linear-gradient(rgba(236,231,219,0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(236,231,219,0.022) 1px, transparent 1px);
  background-size: auto, auto, 28px 28px, 28px 28px;
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; transition: color var(--t-fast); }
a:hover { text-decoration: underline; }

/* ── Hierarquia de heading ───────────────────────────────────
 * Tamanhos padronizados via CSS — as views NÃO devem usar font-size inline em
 * headings. Regras mais específicas (.page-header h1, .chart-container h3,
 * .code-block h*) continuam prevalecendo onde já existem.
 * h1/h2 usam a display técnica (Chakra Petch); h3– seguem no corpo, para
 * títulos de card não competirem com dados. */
h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: 1.3; letter-spacing: -0.2px; }
h1, h2 { font-family: var(--display); letter-spacing: 0.2px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
h4 { font-size: 13px; }
h5 { font-size: 12px; }
h6 { font-size: 11px; }

/* ── Skip-to-content ─────────────────────────────────────────
 * Link invisível até receber foco — primeiro tabulável da página, leva direto
 * ao <main id="main-content"> pulando a sidebar inteira. */
.skip-link {
  position: fixed;
  top: -120px;
  left: 12px;
  z-index: 2000;
  background: var(--accent-grad);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: top var(--t-fast);
}
.skip-link:focus {
  top: 12px;
  outline: 2px solid #fff;
  outline-offset: 2px;
  text-decoration: none;
}

/* Scrollbars discretas (WebKit) */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

::selection { background: rgba(255,180,84,0.32); color: #fff; }

/* ── Layout ────────────────────────────────────────────────────────────── */

.sidebar {
  width: 240px;
  background: rgba(20,18,14,0.78);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
  border-right: 1px solid var(--border-soft);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

/* Wordmark técnico: Chakra Petch caps + cursor de terminal pulsando —
 * a marca é "um agente trabalhando". */
.sidebar-logo {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.sidebar-logo span {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar-logo::after {
  content: '▌';
  margin-left: 4px;
  color: var(--accent);
  font-size: 15px;
  animation: caret-blink 1.15s steps(1) infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }

/* Entrada da nav: revelação escalonada, uma vez por carga de página. */
@keyframes nav-in { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: none; } }
.sidebar-nav a { animation: nav-in 0.35s var(--ease-out) backwards; }
.sidebar-nav a:nth-of-type(1)  { animation-delay: 20ms; }
.sidebar-nav a:nth-of-type(2)  { animation-delay: 40ms; }
.sidebar-nav a:nth-of-type(3)  { animation-delay: 60ms; }
.sidebar-nav a:nth-of-type(4)  { animation-delay: 80ms; }
.sidebar-nav a:nth-of-type(5)  { animation-delay: 100ms; }
.sidebar-nav a:nth-of-type(6)  { animation-delay: 120ms; }
.sidebar-nav a:nth-of-type(7)  { animation-delay: 140ms; }
.sidebar-nav a:nth-of-type(8)  { animation-delay: 160ms; }
.sidebar-nav a:nth-of-type(9)  { animation-delay: 180ms; }
.sidebar-nav a:nth-of-type(10) { animation-delay: 200ms; }
.sidebar-nav a:nth-of-type(n+11) { animation-delay: 220ms; }
@media (prefers-reduced-motion: reduce) {
  .sidebar-nav a { animation: none; }
  .sidebar-logo::after { animation: none; }
}

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.sidebar-nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-dim);
  font-size: 14px;
  border-radius: 0 8px 8px 0;
  margin-right: 10px;
  transition: color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.sidebar-nav a:hover { color: var(--text); background: var(--bg-hover); text-decoration: none; }
.sidebar-nav a.active { color: var(--accent); background: var(--accent-soft); }
.sidebar-nav a.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 60%;
  border-radius: 0 3px 3px 0;
  background: var(--accent-grad);
}

/* ── Ícones SVG ───────────────────────────────────────────────
 * .nav-icon (nav + topbar mobile) e os ícones do FAB referenciam o sprite via
 * <use>. stroke/fill são propriedades herdadas em SVG: defini-las aqui faz os
 * símbolos herdarem o traço e o currentColor do <a>/<button> hospedeiro,
 * acompanhando os estados ativo/hover sem CSS por ícone. */
.nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Rótulo de seção com "régua técnica": traço curto em âmbar antes do texto —
 * agrupa por contexto de uso (Operação / Panorama / Diagnóstico...). */
.sidebar-nav .section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 20px 6px;
  font-family: var(--display);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  color: var(--text-muted);
}
.sidebar-nav .section-label::before {
  content: '';
  width: 10px;
  height: 1px;
  background: var(--accent-dim);
  opacity: 0.7;
  flex-shrink: 0;
}

.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid var(--border-soft);
  font-size: 13px;
}
.sidebar-user .name { color: var(--text); font-weight: 500; }
.sidebar-user .role { color: var(--text-muted); font-size: 11px; text-transform: uppercase; }
/* Estilos do worker-status/seletor de idioma migrados de inline. */
.sidebar-worker {
  padding: 8px 12px; font-size: 11px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--border);
}
.worker-dot { width: 8px; height: 8px; border-radius: 50%; background: #777; display: inline-block; }

/* Barra de topo com versão/data/hora da UI e do worker. Alinhada à direita e
   discreta: é dado de diagnóstico permanente, não conteúdo — precisa estar
   sempre visível sem competir com a página. Cobre só a largura do conteúdo
   (left = largura da sidebar) para não passar por cima do logo. */
.app-topbar {
  position: fixed;
  top: 0; left: 240px; right: 0;
  height: 30px;
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 0 32px;
  font-size: 10px; color: var(--text-muted);
  background: rgba(20,23,31,0.8);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--border-soft);
  /* Abaixo da sidebar (100) e dos modais; acima do conteúdo. */
  z-index: 140;
}
.app-topbar .build-item { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.app-topbar .build-who { opacity: 0.7; }
.app-topbar .build-sep { opacity: 0.35; }
.app-topbar .build-val {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Consolas, monospace);
}
/* Commits diferentes entre UI e worker: deploy pela metade. Cor + title, sem
   badge nem modal — o aviso mora onde o dado já está. */
.app-topbar .build-val.build-drift { color: var(--yellow, #e8c547); }
.locale-select {
  margin-top: 6px; background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 4px;
}
.sidebar-logout { color: var(--text-muted); margin-top: 4px; display: inline-block; }

.main {
  margin-left: 240px;
  flex: 1;
  /* 28 do respiro original + 30 da .app-topbar fixa. */
  padding: 58px 32px 28px;
  min-height: 100vh;
  animation: page-in 0.4s var(--ease-out) both;
}

/* Uma animação de transform com fill `both` mantém o elemento como containing
 * block de descendentes position:fixed PARA SEMPRE (a animação fica "aplicada"
 * mesmo terminada — Chromium retém matrix identidade). Por isso páginas COM
 * painel contextual trocam para page-in-fade (só opacidade) via body:has() —
 * ver camada Shell v2. */
@keyframes page-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes page-in-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.4px; }

/* ── Cards ─────────────────────────────────────────────────────────────── */

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--t), box-shadow var(--t), border-color var(--t);
}
/* realce superior sutil — dá sensação de superfície iluminada */
.card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
}
.cards-grid .card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--border);
}
/* entrada escalonada dos cards de métrica */
.cards-grid .card { animation: card-in 0.45s var(--ease-out) both; }
.cards-grid .card:nth-child(1) { animation-delay: 0.02s; }
.cards-grid .card:nth-child(2) { animation-delay: 0.06s; }
.cards-grid .card:nth-child(3) { animation-delay: 0.10s; }
.cards-grid .card:nth-child(4) { animation-delay: 0.14s; }
.cards-grid .card:nth-child(5) { animation-delay: 0.18s; }
.cards-grid .card:nth-child(6) { animation-delay: 0.22s; }
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.card-value { font-size: 28px; font-weight: 700; margin-top: 4px; letter-spacing: -0.5px; }
.card-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.card-value.green  { color: var(--green); }
.card-value.red    { color: var(--red); }
.card-value.yellow { color: var(--yellow); }
.card-value.accent {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ── Tables ────────────────────────────────────────────────────────────── */

.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--bg-input); }
th { text-align: left; padding: 11px 14px; font-weight: 600; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
td { padding: 11px 14px; border-top: 1px solid var(--border-soft); }
tbody tr { transition: background var(--t-fast); }
tr:hover td { background: var(--bg-hover); }

/* ── Badges ────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border: 1px solid transparent;
}
.badge-success  { background: rgba(74,222,128,0.13); color: var(--green);   border-color: rgba(74,222,128,0.25); }
.badge-error    { background: rgba(248,113,113,0.13); color: var(--red);    border-color: rgba(248,113,113,0.25); }
.badge-warning  { background: rgba(250,204,21,0.13);  color: var(--yellow); border-color: rgba(250,204,21,0.25); }
.badge-info     { background: rgba(255,180,84,0.13); color: var(--accent); border-color: rgba(255,180,84,0.25); }
.badge-neutral  { background: rgba(139,143,163,0.13); color: var(--text-dim); border-color: rgba(139,143,163,0.22); }

/* ── Forms ─────────────────────────────────────────────────────────────── */

.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: end;
}

select, input[type="text"], input[type="number"], input[type="date"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
select:hover, input[type="text"]:hover, input[type="number"]:hover, input[type="date"]:hover { border-color: var(--bg-hover); }
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  font-family: var(--font);
}
.btn:hover { background: var(--bg-hover); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn-primary { background: var(--accent-grad); border-color: transparent; color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { box-shadow: var(--glow); filter: brightness(1.06); }
.btn-danger { background: rgba(248,113,113,0.14); border-color: rgba(248,113,113,0.5); color: var(--red); }
.btn-danger:hover { background: rgba(248,113,113,0.22); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; filter: none; }

label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }

textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  min-height: 150px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

/* ── Chip input (tags editaveis com enter pra adicionar, x pra remover) ── */

.chip-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  min-height: 36px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.chip-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.chip-input input {
  flex: 1;
  min-width: 120px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  padding: 2px 0;
}
/* Lista de tags (chip-input usado como seletor, não input) e campo de tag custom (inline → classe). */
.chip-input--list { cursor: default; min-height: 38px; align-content: flex-start; }
.nt-tag-custom { width: 100%; margin-top: 6px; font-size: 13px; }
.nt-tag-empty { font-size: 12px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-hover);
  color: var(--text);
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  transition: border-color var(--t-fast);
}
.chip-x {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
  border-radius: 50%;
  transition: background var(--t-fast), color var(--t-fast);
}
.chip-x:hover {
  background: var(--red);
  color: #fff;
}

/* Chip clicavel — multi-selecao de tags na criacao de tarefa */
.chip-toggle {
  cursor: pointer;
  padding: 3px 10px;
  background: transparent;
  color: var(--text-dim);
  user-select: none;
}
.chip-toggle:hover { border-color: var(--accent); }
.chip-toggle.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

/* ── Áreas do repo: tabela compacta + edição inline ─────────────────── */

.area-table {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.area-row {
  display: grid;
  grid-template-columns: 1.2fr 1.6fr auto 1.4fr auto;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  border-top: 1px solid var(--border);
}
.area-row:first-child { border-top: none; }
.area-row > div {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.area-row--head {
  background: var(--bg-input);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
  font-size: 11px;
}
.area-row:not(.area-row--head) { cursor: pointer; }
.area-row:not(.area-row--head):hover { background: var(--bg-hover); }
.area-row:not(.area-row--head):hover .area-edit-hint { opacity: 1; }
.area-edit-hint {
  opacity: 0;
  font-size: 11px;
  color: var(--accent);
  transition: opacity var(--t-fast);
}
.area-actions { text-align: right; white-space: nowrap; overflow: visible; }
.area-edit {
  padding: 12px;
  background: var(--bg-input);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}

/* ── Seções colapsáveis na config (details/summary) ─────────────────── */
.config-section {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.config-section::-webkit-details-marker { display: none; }
.config-section:hover { background: var(--bg-hover); border-color: var(--accent-dim); }
details[open] > .config-section {
  border-color: var(--accent-dim);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
.config-section__chev {
  color: var(--accent);
  font-size: 12px;
  line-height: 1;
  transition: transform var(--t-fast);
}
details[open] > .config-section .config-section__chev { transform: rotate(90deg); }
.config-section__title { font-size: 13px; font-weight: 600; color: var(--text); }
.config-section__hint {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  color: var(--text-dim);
}
.config-section__body {
  border: 1px solid var(--accent-dim);
  border-top: none;
  border-bottom-left-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  padding: 12px;
}

/* ── Master-detail (sidebar list + main content) ────────────────────── */

.master-detail {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
}
.master-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
}
.master-list-item {
  display: block;
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.master-list-item:hover {
  background: var(--bg-hover);
  transform: translateX(2px);
}
.master-list-item.active {
  background: var(--bg-input);
  border-left-color: var(--accent);
}
.master-list-item .name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}
.master-list-item .meta {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  gap: 4px;
  margin-top: 2px;
  flex-wrap: wrap;
}
.master-list-empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--text-dim);
  font-size: 13px;
}
.master-detail-content {
  min-width: 0;
}

/* ── Tabs ───────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab {
  position: relative;
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: color var(--t-fast);
}
.tab::after {
  content: '';
  position: absolute;
  left: 14px; right: 14px; bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent-grad);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform var(--t);
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  color: var(--accent);
  font-weight: 600;
}
.tab.active::after { transform: scaleX(1); }

/* ── Detail panels ─────────────────────────────────────────────────────── */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.detail-item { }
.detail-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; }
.detail-value { font-size: 14px; color: var(--text); margin-top: 2px; }

.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: ''; position: absolute; left: 7px; top: 8px; bottom: 8px;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; padding: 12px 0; }
.timeline-item::before {
  content: ''; position: absolute; left: -20px; top: 18px;
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 3px rgba(255,180,84,0.18);
}
.timeline-item.success::before { background: var(--green); box-shadow: 0 0 0 3px rgba(74,222,128,0.18); }
.timeline-item.error::before   { background: var(--red); box-shadow: 0 0 0 3px rgba(248,113,113,0.18); }

/* Painéis do gate da decomposição. Classes em vez de style= inline
   porque a contagem de inline tem teto — e porque os quatro
   painéis são a mesma coisa com severidades diferentes.
   Começam ocultos pela classe; o JS mostra com style.display = 'block'. */
.gate-card { display: none; }
.gate-card h4 { font-size: 14px; margin-bottom: 4px; }
.gate-card > p { margin-bottom: 8px; }
/* Contradição é DEFEITO no texto, não pendência a decidir — daí a cor diferente
   dos painéis de risco/decisão, que são amarelos. */
.gate-card--defeito { border-color: var(--red, #f07862); }
.gate-item { padding: 10px; margin-bottom: 8px; }
.gate-sub { margin-top: 4px; }
.gate-hint { margin-top: 6px; }

.code-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  word-break: break-word;
  max-height: 500px;
  overflow-y: auto;
}

/* JSON syntax highlight (window.formatJsonHtml) */
.json-block {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
  tab-size: 2;
}
.json-key  { color: #9ecbff; }      /* azul claro — chaves */
.json-str  { color: #c3e88d; }      /* verde — strings */
.json-num  { color: #f78c6c; }      /* laranja — numeros */
.json-bool { color: #c792ea; }      /* roxo — true/false */
.json-null { color: #ff5370; }      /* vermelho — null */
.code-block pre { background: var(--bg); padding: 12px; border-radius: 6px; overflow-x: auto; font-family: var(--mono); font-size: 12px; }
.code-block code { font-family: var(--mono); font-size: 12px; }
.code-block p code { background: var(--bg); padding: 1px 5px; border-radius: 3px; }
.code-block h1, .code-block h2, .code-block h3, .code-block h4 { margin: 16px 0 8px; }
.code-block h1 { font-size: 18px; }
.code-block h2 { font-size: 16px; color: var(--accent); }
.code-block h3 { font-size: 14px; }
.code-block h4 { font-size: 13px; color: var(--text-dim); }
.code-block table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 12px; }
.code-block th, .code-block td { padding: 6px 10px; border: 1px solid var(--border); text-align: left; }
.code-block th { background: var(--bg); font-weight: 600; }
.code-block ul, .code-block ol { padding-left: 20px; margin: 8px 0; }
.code-block li { margin: 4px 0; }
.code-block strong { color: var(--text); }
.code-block hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.code-block blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-dim); margin: 12px 0; }

/* ── Diff ──────────────────────────────────────────────────────────────── */

.diff-block { font-family: var(--mono); font-size: 12px; line-height: 1.7; }
.diff-block .add { color: var(--green); background: rgba(74,222,128,0.08); }
.diff-block .del { color: var(--red); background: rgba(248,113,113,0.08); }
.diff-block .hdr { color: var(--accent); }

/* ── Charts ────────────────────────────────────────────────────────────── */

.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--t), border-color var(--t);
}
.chart-container:hover { box-shadow: var(--shadow); }
.chart-container h3 { font-size: 14px; margin-bottom: 12px; color: var(--text-dim); }

/* ── Pagination ────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 16px;
}
.pagination a, .pagination span {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background var(--t-fast), color var(--t-fast);
}
.pagination a { background: var(--bg-input); color: var(--text-dim); }
.pagination a:hover { background: var(--bg-hover); text-decoration: none; }
.pagination .current { background: var(--accent-grad); color: #fff; }

/* ── Toast / Alerts ────────────────────────────────────────────────────── */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.alert-success { background: rgba(74,222,128,0.12); border: 1px solid rgba(74,222,128,0.3); color: var(--green); }
.alert-error { background: rgba(248,113,113,0.12); border: 1px solid rgba(248,113,113,0.3); color: var(--red); }
.alert-info { background: rgba(255,180,84,0.12); border: 1px solid rgba(255,180,84,0.3); color: var(--accent); }
/* Advertência — a ação DEU CERTO, mas há uma condição que o usuário
   precisa saber (ex.: enfileirado sem worker no ar). Distinta de error, que
   significa "não aconteceu". */
.alert-warn { background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.35); color: #f59e0b; }

/* Banner flutuante de advertência (window.notifyWarnings) — empilha no topo,
   acima do conteúdo, sem deslocar o layout. */
#warnStack {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 9999; width: min(680px, calc(100vw - 24px));
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
#warnStack .alert { pointer-events: auto; margin-bottom: 0; display: flex; gap: 10px; align-items: flex-start; }
#warnStack .alert button {
  margin-left: auto; background: none; border: none; color: inherit;
  cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; opacity: .7;
}
#warnStack .alert button:hover { opacity: 1; }

/* ── Misc ──────────────────────────────────────────────────────────────── */

.flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.text-dim { color: var(--text-dim); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.mono { font-family: var(--mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
/* Utilitários de consolidação (substituem style= inline comuns). */
.w-full { width: 100%; }
.min-w-0 { min-width: 0; }
.self-end { align-self: flex-end; }
.text-error { color: var(--error, #f07862); }
.text-center { text-align: center; }
.flex-1 { flex: 1; }
.cursor-pointer { cursor: pointer; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--green); }
.text-danger { color: var(--red); }
.text-warn { color: var(--yellow); }
.fw-600 { font-weight: 600; }
/* `.hidden` é estático: NÃO usar onde o JS alterna `el.style.display` — nesses
   casos prefira x-show/:class. Serve para esconder no estado inicial via classe. */
.hidden { display: none; }

/* ── Login page ────────────────────────────────────────────────────────── */

.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; width: 100%;
}
.login-box {
  position: relative;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 40px; text-align: center; max-width: 400px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: page-in 0.5s var(--ease-out) both;
}
.login-box::before {
  content: '';
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--accent-grad);
}
.login-box h1 { font-size: 24px; margin-bottom: 8px; letter-spacing: -0.5px; }
.login-box p { color: var(--text-dim); margin-bottom: 24px; }

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

[x-cloak] { display: none !important; }

.chat-fab {
  position: fixed;
  bottom: 24px; right: 24px;
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 22px -4px rgba(255,180,84,0.55), 0 4px 12px rgba(0,0,0,0.4);
  z-index: 300;
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--t), box-shadow var(--t), background var(--t);
}
.chat-fab:hover { transform: scale(1.08) translateY(-2px); box-shadow: 0 10px 30px -4px rgba(255,180,84,0.7); }
.chat-fab:active { transform: scale(1.02); }
.chat-fab-active { background: var(--bg-input); color: var(--text); box-shadow: var(--shadow); }

.chat-panel {
  position: fixed;
  bottom: 88px; right: 24px;
  width: 440px;
  max-height: 600px;
  background: rgba(20,23,31,0.85);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  max-height: 400px;
  min-height: 200px;
}

/* Contexto (seletor de projeto) e citações do chat do cliente. */
.chat-context {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.chat-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.chat-source-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
}

.chat-msg {
  margin-bottom: 12px;
  max-width: 95%;
  animation: msg-in 0.3s var(--ease-out) both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-msg.user { margin-left: auto; }
.chat-msg.assistant { margin-right: auto; }

.chat-msg-role {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.chat-msg.user .chat-msg-role { text-align: right; color: var(--accent); }

.chat-msg-body {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.user .chat-msg-body { background: rgba(255,180,84,0.12); border-color: rgba(255,180,84,0.25); }
.chat-msg-body code {
  background: var(--bg); padding: 1px 5px; border-radius: 3px;
  font-family: var(--mono); font-size: 12px;
}
.chat-msg-body pre {
  background: var(--bg); padding: 10px; border-radius: 6px;
  margin: 8px 0; overflow-x: auto; font-family: var(--mono); font-size: 12px;
}

.chat-msg-time { margin-top: 2px; }
.chat-msg.user .chat-msg-time { text-align: right; }

.chat-input {
  padding: 12px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 8px;
}
.chat-input textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  resize: none;
}

/* ── Thread da tarefa interna ───────────────────────────── */

.thread {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: min(72vh, 900px);
  overflow-y: auto;
  padding: 4px;
}
.thread-msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  animation: msg-in 0.3s var(--ease-out) both;
}
.thread-msg.user {
  align-self: flex-end;
  background: rgba(108, 138, 255, 0.12);
  border-color: rgba(108, 138, 255, 0.35);
}
/* Mensagem do agente é DOCUMENTO (análise, plano, perguntas), não balão de
 * chat — largura cheia; o balão estreito fica pras mensagens do usuário. */
.thread-msg.agent {
  align-self: flex-start;
  background: var(--bg-input);
  max-width: 100%;
}
/* Resumo-âncora (full-width, em destaque) + colapso do histórico
 * anterior ao resumo. */
.thread-msg.summary {
  align-self: stretch;
  max-width: 100%;
  background: var(--accent-soft);
  border-color: var(--accent-dim);
  border-left: 3px solid var(--accent);
}
.thread-collapsed {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.thread-collapsed > summary { user-select: none; }
.thread-msg .thread-meta { margin-bottom: 8px; font-size: 12px; }
.thread-msg .thread-meta strong { font-weight: 600; color: var(--text); }
/* Corpo legível das mensagens/respostas (markdown renderizado). As análises
 * do agente são longas e densas — a hierarquia precisa ser visível: títulos
 * claramente maiores que o corpo, respiro entre blocos, hr como divisor. */
.thread-msg .thread-body { font-size: 15px; line-height: 1.65; overflow-wrap: break-word; }
.thread-msg .thread-body p { margin: 10px 0; }
.thread-msg .thread-body p:first-child { margin-top: 0; }
.thread-msg .thread-body p:last-child { margin-bottom: 0; }
.thread-msg .thread-body ul,
.thread-msg .thread-body ol { margin: 10px 0; padding-left: 24px; }
.thread-msg .thread-body li { margin: 5px 0; }
.thread-msg .thread-body li > p { margin: 4px 0; }
.thread-msg .thread-body h1,
.thread-msg .thread-body h2,
.thread-msg .thread-body h3,
.thread-msg .thread-body h4 { margin: 20px 0 8px; line-height: 1.35; font-weight: 650; }
.thread-msg .thread-body h1:first-child,
.thread-msg .thread-body h2:first-child,
.thread-msg .thread-body h3:first-child,
.thread-msg .thread-body h4:first-child { margin-top: 0; }
.thread-msg .thread-body h1 { font-size: 20px; }
.thread-msg .thread-body h2 { font-size: 18px; }
.thread-msg .thread-body h3 {
  font-size: 16.5px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.thread-msg .thread-body h4 { font-size: 15px; }
.thread-msg .thread-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}
.thread-msg .thread-body code {
  font-size: 13.5px;
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 4px;
  overflow-wrap: anywhere; /* paths longos (src/pages/.../index.tsx) quebram em vez de estourar */
}
.thread-msg .thread-body pre {
  overflow-x: auto;
  background: rgba(0, 0, 0, 0.3);
  padding: 10px;
  border-radius: 6px;
  margin: 10px 0;
}
.thread-msg .thread-body pre code { background: none; padding: 0; overflow-wrap: normal; }
.thread-msg .thread-body table { display: block; overflow-x: auto; margin: 10px 0; }
.thread-msg .thread-body blockquote {
  margin: 10px 0;
  padding-left: 12px;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}

/* Perguntas abertas do agente (formulário de resposta): texto cheio e legível,
 * com o rótulo [PERGUNTA N] em destaque — antes herdava fonte pequena. */
.answer-item label {
  display: block;
  font-size: 14.5px;
  line-height: 1.55;
  margin-bottom: 6px;
}
.answer-item label strong { color: var(--accent); }

/* ── Responsive ────────────────────────────────────────────────────────── */

/* Topbar mobile + off-canvas: em telas estreitas a sidebar
 * desliza por cima do conteudo (toggle .sidebar-open no body via hamburguer)
 * em vez de simplesmente sumir — sem isso o PWA mobile ficava sem menu. */
.mobile-topbar { display: none; }
.mobile-topbar .sidebar-logo { margin: 0; font-size: 18px; }
.sidebar-backdrop { display: none; }

@media (max-width: 768px) {
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    padding: 0 12px;
    background: rgba(20,23,31,0.8);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border-bottom: 1px solid var(--border-soft);
    z-index: 150;
  }
  .mobile-menu-btn {
    background: none;
    border: none;
    color: var(--text);
    min-width: 44px;
    min-height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  /* Hambúrguer como SVG (i-menu), maior que o ícone da nav. */
  .mobile-menu-btn .nav-icon { width: 24px; height: 24px; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s var(--ease-out);
    z-index: 250;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    animation: fade-in 0.2s var(--ease) both;
  }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
  /* Em mobile a .app-topbar não é uma barra própria: ocupa só a sobra à direita
     DENTRO da mobile-topbar (que já tem hambúrguer e logo à esquerda). Duas
     barras empilhadas comeriam 82px de uma tela de 640. */
  .app-topbar {
    left: auto; height: 52px; padding: 0 12px; gap: 0;
    flex-direction: column; align-items: flex-end; justify-content: center;
    background: transparent; border-bottom: 0;
    backdrop-filter: none; -webkit-backdrop-filter: none;
    z-index: 160;  /* acima da mobile-topbar (150), que é o fundo desta faixa */
    font-size: 9px;
  }
  .app-topbar .build-sep { display: none; }
  .main { margin-left: 0; padding: 68px 16px 16px; }
  .cards-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .chat-panel { width: calc(100vw - 32px); right: 16px; }
}

/* Viewport <=480px: coluna unica, alvos de toque >=44px,
 * tabelas com scroll horizontal, thread ocupando a largura toda. */
@media (max-width: 480px) {
  .btn, button, select, input[type="text"], input[type="number"], textarea {
    min-height: 44px;
  }
  .btn-sm { min-height: 38px; }
  .page-header { flex-wrap: wrap; gap: 8px; }
  .cards-grid { grid-template-columns: 1fr; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .thread { max-height: none; }
  .thread-msg { max-width: 100%; }
  #taskModal { padding: 12px !important; }
  .modal-overlay { padding: 12px; }
}

/* ── Modal overlay ─────────────────────────────────────────────────────── */
/* Substitui confirm() nativo do browser, que sobrepunha botoes do header
 * em telas com altura curta. Renderiza centralizado independente da posicao
 * do trigger. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fade-in 0.18s var(--ease) both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
/* `.hidden` sozinho perde para o display:flex acima (mesma especificidade,
 * ordem posterior) — o #taskModal alterna `.hidden` via JS e ficava sempre
 * visível. Duas classes garantem a vitória independente da ordem. */
.modal-overlay.hidden { display: none; }
.modal-overlay .card {
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.26s var(--ease-out) both;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Ingestão de conteúdo ───────────────────────────── */
/* Botão "falar" e dropzone de documento — usados no thread interno e no
 * modal "Nova tarefa". */
.voice-btn.recording {
  background: #7f1d1d;
  border-color: #f07862;
  color: #fecaca;
  animation: voice-pulse 1.2s ease-in-out infinite;
}
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(248, 113, 113, 0); }
}
.dropzone {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(108, 138, 255, 0.08);
  color: var(--text);
}
.dropzone-preview {
  text-align: left;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 160px;
  overflow-y: auto;
  background: var(--bg-input);
  border-radius: 6px;
  padding: 8px;
  margin-top: 8px;
}

/* ── Acessibilidade: respeita quem prefere menos movimento ─────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Estilos consolidados (migrados de blocos <style> das views
   para o sistema de tokens). Origem: assistant-chat.ejs, logs.ejs. Mantêm o comportamento visual anterior, agora cacheável/versionado
   e compatível com CSP por nonce (sem <style> inline nas views).
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Conversa do analista (origem: views/assistant-chat.ejs) ─────────────── */
/* Thread + painel lateral de escopo; empilha em mobile (390px ok) */
.assistant-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .assistant-grid { grid-template-columns: 1fr; } }
.scope-panel h4 { margin: 12px 0 4px; }
.scope-panel ul { margin: 4px 0 0 18px; padding: 0; }
.scope-panel li { margin-bottom: 4px; }
.spec-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 12px; background: var(--bg-input); }
.spec-card input[type="text"], .spec-card textarea { width: 100%; }
.thread-msg.system .thread-body { font-size: 13px; }
.typing { font-style: italic; color: var(--text-muted); }

/* ── Logs: realce de linha por nível (origem: views/logs.ejs) ────────────── */
.row-error { background: rgba(248,113,113,0.08); }
.row-warn  { background: rgba(250,204,21,0.06); }

/* ── Widget de chat: estados migrados de inline (origem: partials/footer.ejs) */
/* Ícones do FAB agora são SVG do sprite (currentColor herdado). */
.chat-fab-icon, .chat-fab-icon-close {
  width: 24px; height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chat-empty { text-align: center; padding: 40px 16px; color: var(--text-muted); font-size: 13px; }
.diff-block { max-height: 250px; overflow-y: auto; font-size: 11px; margin-bottom: 8px; }
.chat-created-files { font-size: 12px; color: var(--green); margin-bottom: 8px; }

/* ── Consumo por projeto ──────────────────────────────────── */
/* Duas colunas em telas largas, uma coluna no celular — as tabelas de modelo e
   etapa são comparadas lado a lado, mas nenhuma delas precisa de largura. */
.consumption-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 900px) {
  .consumption-grid { grid-template-columns: 1fr; }
}

/* Série diária em barras de CSS puro: a única pergunta desta série é "está
   subindo?", e isso não justifica carregar biblioteca de gráfico. */
.spark-row {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 90px;
  margin-top: 12px;
  padding: 0 2px;
}
.spark-bar {
  flex: 1 1 0;
  min-width: 3px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  opacity: 0.75;
  transition: opacity 0.15s var(--ease-out);
}
.spark-bar:hover { opacity: 1; }
/* Cabeçalho de bloco do dashboard — era style= inline repetido em cada card. */
.card-section-title { margin-bottom: 12px; color: var(--text-dim); }

/* ── Hub do projeto: abas ─────────────────────────────────── */
/* Abas são links (rotas), não estado de cliente — o sublinhado marca a atual.
   Rolagem horizontal no celular em vez de quebrar em duas linhas. */
.project-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.project-tab {
  flex: 0 0 auto;
  padding: 10px 16px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s var(--ease-out), border-color 0.15s var(--ease-out);
  white-space: nowrap;
}
.project-tab:hover { color: var(--text); }
.project-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 500;
}

/* Utilitários usados pelo hub do projeto. */
.clickable { cursor: pointer; }
.text-warning { color: var(--yellow); }
.btn.disabled { opacity: 0.45; pointer-events: none; }
/* Card do índice de projetos: é um link inteiro, então precisa perder a cara
   de link e ganhar a de cartão clicável. */
.project-card { text-decoration: none; color: inherit; display: block; }
.project-card:hover { border-color: var(--accent); }

/* ── tasks.ejs após a extração do JS ──────────────────────── */
/* Classes que substituem style= inline montado em string de JavaScript. */
.btn-group { display: flex; gap: 0; }
.btn-group .btn:first-child { border-radius: 6px 0 0 6px; }
.btn-group .btn:last-child  { border-radius: 0 6px 6px 0; }
.filter-select { font-size: 13px; }
.empty-state { text-align: center; padding: 40px; color: var(--text-muted); }
/* Caixa do modal de tarefas — o overlay já existe (.modal-overlay). */
.modal-box {
  max-width: 800px;
  margin: 40px auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.form-stack { display: grid; gap: 12px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .form-grid-2 { grid-template-columns: 1fr; } }
.modal-steps { font-size: 13px; color: var(--text-dim); padding-left: 20px; margin-top: 8px; }

/* ═══════════════════════════════════════════════════════════════════════════
   Shell v2 — sidebar colapsível, painel contextual à direita e componentes
   de seção. Camada ADITIVA: nenhuma classe anterior foi removida.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Sidebar colapsível ─────────────────────────────────────────────────── */
.sidebar { transition: width var(--t); }
/* min-width:0 — .main é flex item (body é flex) e o default min-width:auto o
 * impede de encolher abaixo do min-content: com a margem do painel contextual
 * a página transbordava na horizontal e o conteúdo deslizava por baixo do
 * painel fixo. */
.main    { transition: margin-left var(--t), margin-right var(--t); min-width: 0; }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.sidebar-head .sidebar-logo { border-bottom: none; padding-bottom: 0; flex: 1; min-width: 0; }
.nav-collapse-btn {
  background: none; border: 1px solid transparent; color: var(--text-muted);
  width: 30px; height: 30px; margin-right: 12px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast);
}
.nav-collapse-btn:hover { color: var(--accent); background: var(--bg-hover); }
.nav-collapse-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.sidebar-sep { border-bottom: 1px solid var(--border-soft); margin: 14px 0 0; }

html.nav-collapsed .sidebar { width: 68px; }
html.nav-collapsed .main    { margin-left: 68px; }
html.nav-collapsed .sidebar-logo { display: none; }
html.nav-collapsed .sidebar-head { justify-content: center; }
html.nav-collapsed .nav-collapse-btn { margin: 0; }
html.nav-collapsed .nav-collapse-btn svg { transform: rotate(180deg); }
html.nav-collapsed .sidebar-nav a {
  justify-content: center; padding: 11px 0; margin: 0 8px; border-radius: var(--radius);
}
html.nav-collapsed .sidebar-nav a .nav-label { display: none; }
html.nav-collapsed .sidebar-nav a.active::before { display: none; }
html.nav-collapsed .sidebar .section-label {
  height: 10px; padding: 0; margin: 4px 12px; overflow: hidden; text-indent: -999px;
  border-top: 1px solid var(--border-soft);
}
html.nav-collapsed .sidebar-user { display: none; }
html.nav-collapsed .sidebar-worker { justify-content: center; }
html.nav-collapsed .sidebar-worker #worker-label { display: none; }

/* ── Painel contextual (direita) ────────────────────────────────────────── */
/* Página com painel contextual: .main anima só opacidade — a animação de
 * transform (mesmo terminada, fill both) faria o .main de containing block e
 * o painel fixo ancoraria nele em vez do viewport. */
body:has(.context-panel) .main { animation-name: page-in-fade; }

.context-panel {
  position: fixed; top: 30px; right: 0; bottom: 0; width: 340px; z-index: 90;
  background: rgba(20,18,14,0.82);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
  border-left: 1px solid var(--border-soft);
  display: flex; flex-direction: column;
  transition: width var(--t);
}
body:has(.context-panel) .main { margin-right: 340px; }
.context-panel.ctx-collapsed { width: 46px; }
body:has(.context-panel.ctx-collapsed) .main { margin-right: 46px; }

.ctx-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft); min-height: 47px;
}
.ctx-head h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-dim); white-space: nowrap; overflow: hidden;
}
.ctx-icon { width: 16px; height: 16px; stroke: var(--accent); fill: none; stroke-width: 2; flex-shrink: 0; }
.ctx-toggle {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  width: 26px; height: 26px; margin-left: auto; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: color var(--t-fast), background var(--t-fast);
}
.ctx-toggle:hover { color: var(--accent); background: var(--bg-hover); }
.ctx-toggle svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; }
.ctx-body { flex: 1; overflow-y: auto; padding: 14px; }
.ctx-collapsed .ctx-body, .ctx-collapsed .ctx-head h2, .ctx-collapsed .ctx-head .ctx-icon { display: none; }
.ctx-collapsed .ctx-head { justify-content: center; padding: 12px 0; border-bottom: none; }
.ctx-collapsed .ctx-toggle { margin: 0; }
.ctx-collapsed .ctx-toggle svg { transform: rotate(180deg); }
.ctx-rail-label {
  display: none; writing-mode: vertical-rl; text-orientation: mixed;
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--text-muted); margin: 14px auto 0; user-select: none;
}
.ctx-collapsed .ctx-rail-label { display: block; }

/* Grupos dentro do painel contextual */
.ctx-group { margin-bottom: 18px; }
.ctx-group-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted); font-weight: 600; margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.ctx-group-title svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; }
.ctx-field { margin-bottom: 10px; }
.ctx-field label { font-size: 11px; color: var(--text-muted); display: block; margin-bottom: 3px; }
.ctx-field input, .ctx-field select, .ctx-field textarea {
  width: 100%; padding: 7px 9px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text); font-family: inherit;
}
.ctx-kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 12px; border-bottom: 1px dashed var(--border-soft); }
.ctx-kv:last-child { border-bottom: none; }
.ctx-kv .k { color: var(--text-muted); flex-shrink: 0; }
.ctx-kv .v { text-align: right; word-break: break-word; }

/* Telas estreitas: painel expandido vira overlay sobre o conteúdo */
@media (max-width: 1100px) {
  body:has(.context-panel) .main { margin-right: 46px; }
  .context-panel:not(.ctx-collapsed) { box-shadow: var(--shadow-lg); }
}
@media (max-width: 768px) {
  html.nav-collapsed .sidebar { width: 240px; }
  html.nav-collapsed .main { margin-left: 0; }
  .context-panel { top: 0; }
  body:has(.context-panel) .main { margin-right: 0; padding-right: 56px; }
}

/* ── Seções (panel) ─────────────────────────────────────────────────────── */
.panel {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); margin-bottom: 20px;
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(255,180,84,0.035), transparent);
}
.panel-head .panel-icon { width: 16px; height: 16px; stroke: var(--accent); fill: none; stroke-width: 2; flex-shrink: 0; }
.panel-head h2, .panel-head h3 {
  font-family: var(--display); font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim);
}
.panel-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.panel-body { padding: 16px; }
.panel-body.flush { padding: 0; }
.panel-body.flush .table-wrap { border: none; border-radius: 0; margin: 0; }
.panel-foot { padding: 10px 16px; border-top: 1px solid var(--border-soft); display: flex; align-items: center; gap: 8px; }

/* ── Stats (KPIs) ───────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat {
  background: var(--bg-input); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 12px 14px; min-width: 0;
}
.stat-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-muted); margin-bottom: 4px; display: flex; align-items: center; gap: 5px;
}
.stat-label svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; }
.stat-value { font-family: var(--mono); font-size: 22px; font-weight: 600; line-height: 1.2; }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.stat.ok .stat-value { color: var(--green); }
.stat.warn .stat-value { color: var(--yellow); }
.stat.err .stat-value { color: var(--red); }
.stat.info .stat-value { color: var(--accent); }

/* ── Cabeçalho de página modernizado ────────────────────────────────────── */
.page-header { border-bottom: 1px solid var(--border-soft); padding-bottom: 14px; }
.page-head-icon {
  width: 34px; height: 34px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid rgba(255,180,84,0.25);
  display: inline-flex; align-items: center; justify-content: center;
  margin-right: 12px; flex-shrink: 0;
}
.page-head-icon svg { width: 18px; height: 18px; stroke: var(--accent); fill: none; stroke-width: 2; }
.page-title-wrap { display: flex; align-items: center; min-width: 0; }
.page-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

/* Botões com ícone */
.btn svg.btn-icon { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; vertical-align: -2px; margin-right: 5px; }
.btn.btn-icon-only { padding: 6px 8px; }
.btn.btn-icon-only svg.btn-icon { margin-right: 0; }

@media (prefers-reduced-motion: reduce) {
  .sidebar, .main, .context-panel { transition: none; }
}

/* Topbar acompanha o colapso da sidebar */
html.nav-collapsed .app-topbar { left: 68px; }
