/* Portal — guia de cores Emes.
   Preto e branco constroem a arquitetura; o amarelo aparece só onde há prioridade (ação principal, item em foco,
   marca). Cores semânticas indicam estado como marcador; o texto continua preto para manter a leitura.
   Cinzas de suporte para superfícies, bordas e texto secundário. */

@font-face {
  font-family: 'Archivo';
  src: url('/static/fonts/archivo-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

:root {
  /* Marca */
  --preto: #0a0a0a;
  --branco: #ffffff;
  --amarelo: #f8d300;
  /* Semânticas */
  --info: #1e90ff;
  --sucesso: #28a745;
  --alerta: #f5a623;
  --erro: #e63946;
  /* Neutros */
  --cinza-100: #f1f1ef;
  --cinza-200: #e2e2de;
  --cinza-400: #999994;
  --cinza-600: #52524e;

  /* Papéis — modo claro */
  --fundo: var(--branco);
  --superficie: var(--cinza-100);
  --linha: var(--cinza-200);
  --campo-borda: var(--cinza-400);
  --texto: var(--preto);
  --texto-2: var(--cinza-600);
  --texto-3: var(--cinza-400);       /* só placeholder e desabilitado */
  --codigo-fundo: var(--preto);
  --codigo-texto: var(--branco);

  --fonte: 'Archivo', 'Arial Narrow', Arial, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --raio: 4px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fundo: var(--preto);
    --superficie: #161615;
    --linha: #2e2e2c;
    --campo-borda: var(--cinza-600);
    --texto: var(--branco);
    --texto-2: var(--cinza-200);
    --texto-3: var(--cinza-400);
    --codigo-fundo: #161615;
    --codigo-texto: var(--branco);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* O atributo hidden vence qualquer display de componente. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--fundo);
  color: var(--texto);
  font: 400 16px/1.5 var(--fonte);
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-stretch: 118%; font-weight: 800; line-height: 1.1; letter-spacing: -0.01em; }
h1 { font-size: 1.875rem; margin: 0 0 8px; }
h2 { font-size: 1.25rem; margin: 0 0 16px; }
p { margin: 0 0 12px; max-width: 72ch; }
.section-head p, .hint, .muted { color: var(--texto-2); }
code, pre, .mono { font-family: var(--mono); font-size: 0.8125rem; }
.small { font-size: 0.8125rem; }
.empty { padding: 32px; text-align: center; color: var(--texto-2); }

:focus-visible {
  outline: 2px solid var(--texto);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--amarelo);
}

/* ---- Entrada ------------------------------------------------------------------------------- */

body[data-view="login"] .topbar,
body[data-view="login"] main { display: none; }

.entry { min-height: 100vh; display: grid; grid-template-columns: minmax(300px, 5fr) 6fr; }
.entry[hidden] { display: none; }
/* Marca agrupada e centrada na vertical, na mesma linha do formulário: nada preso nos cantos. */
.entry-brand {
  background: var(--preto); color: var(--branco);
  display: flex; flex-direction: column; justify-content: center; gap: 28px;
  padding: 48px clamp(32px, 5vw, 72px);
}
.entry-mark { display: block; width: 56px; height: 56px; }
.entry-name {
  font-size: clamp(3rem, 6vw, 4.75rem); font-weight: 900; font-stretch: 125%;
  line-height: 0.92; letter-spacing: -0.03em; margin: 0 0 14px;
}
.entry-lede { color: var(--cinza-200); font-size: 1.0625rem; max-width: 30ch; margin: 0; }
/* Formulário encostado no início da coluna, perto da marca, em vez de perdido no meio. */
.entry-panel {
  display: grid; align-items: center; justify-items: start;
  padding: 48px clamp(32px, 6vw, 96px);
  background: var(--fundo); border-left: 1px solid var(--linha);
}
.entry-form { width: min(380px, 100%); }
.entry-form h1 { margin-bottom: 20px; }
.entry-form input { margin-bottom: 14px; }
.entry-form .error { margin-bottom: 14px; }
.entry-submit { width: 100%; height: 46px; font-size: 1rem; }

/* ---- Faixa superior ------------------------------------------------------------------------ */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--preto); color: var(--branco);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 36px; height: 36px; display: block; }
.brand-name { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name strong { font-stretch: 125%; font-weight: 900; font-size: 1.0625rem; }
.brand-name span { font-size: 0.8125rem; color: var(--cinza-200); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar .btn.ghost { color: var(--branco); }
.session-user { color: var(--cinza-200); font-size: 0.875rem; }

.status-alert {
  background: var(--superficie); color: var(--texto);
  border-bottom: 1px solid var(--linha); box-shadow: inset 4px 0 0 var(--erro);
  padding: 12px 24px; font-weight: 600;
}
.status-alert p { margin: 0; max-width: none; }
.status-alert p + p { margin-top: 4px; }
body[data-view="login"] .status-alert { display: none; }

main { max-width: 1200px; margin: 0 auto; padding: 32px 24px 64px; }

/* ---- Controles ----------------------------------------------------------------------------- */

label, .label { display: block; font-weight: 700; font-size: 0.875rem; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=date],
input:not([type]), select {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1.5px solid var(--campo-borda); border-radius: var(--raio);
  background: var(--fundo); color: var(--texto);
  font: 400 0.9375rem var(--fonte);
}
input:hover, select:hover { border-color: var(--texto-2); }
input:focus, select:focus { border-color: var(--texto); }
input[type=password], #app-id, .field-filter { font-family: var(--mono); }
input:disabled, select:disabled { background: var(--superficie); color: var(--texto-3); cursor: not-allowed; }
::placeholder { color: var(--texto-3); opacity: 1; }
input[type=checkbox], input[type=radio] { accent-color: var(--preto); width: 16px; height: 16px; margin: 0; }
.field { margin-bottom: 16px; }
.hint { display: block; font-size: 0.8125rem; margin-top: 6px; max-width: 72ch; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check-field { display: flex; align-items: end; padding-bottom: 10px; }
.required { color: var(--erro); font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px;
  border: 1.5px solid var(--texto); border-radius: var(--raio);
  background: var(--fundo); color: var(--texto);
  font: 700 0.9375rem var(--fonte); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--superficie); }
/* Ação principal: único lugar recorrente do amarelo. */
.btn.primary { background: var(--amarelo); border-color: var(--amarelo); color: var(--preto); }
.btn.primary:hover { background: var(--preto); border-color: var(--preto); color: var(--amarelo); }
.btn.danger { background: var(--erro); border-color: var(--erro); color: var(--preto); }
.btn.danger:hover { background: var(--preto); border-color: var(--preto); color: var(--branco); }
.btn.ghost { border-color: transparent; background: transparent; text-decoration: underline; text-underline-offset: 3px; }
.btn.ghost:hover { text-decoration-thickness: 2px; background: transparent; }
.btn.small { height: 32px; padding: 0 10px; font-size: 0.8125rem; }
.btn.link-danger { text-decoration-color: var(--erro); text-decoration-thickness: 2px; }
.btn:disabled { color: var(--texto-3); border-color: var(--linha); cursor: not-allowed; background: var(--fundo); }

/* ---- Estados: cor semântica como marcador, texto em preto ----------------------------------- */

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 10px;
  border: 1px solid var(--linha); border-radius: 999px;
  background: var(--fundo); color: var(--texto);
  font-size: 0.8125rem; font-weight: 600; white-space: nowrap;
}
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--cinza-400); flex: none; }
.pill.ok::before { background: var(--sucesso); }
.pill.warn::before { background: var(--alerta); }
.pill.err { border-color: var(--erro); }
.pill.err::before { background: var(--erro); }
.pill.info::before { background: var(--info); }

.error {
  background: var(--superficie); color: var(--texto);
  border-left: 4px solid var(--erro); border-radius: var(--raio);
  padding: 12px 14px; font-weight: 500; white-space: pre-line;
}
.warning {
  background: var(--superficie); color: var(--texto);
  border-left: 4px solid var(--alerta); border-radius: var(--raio);
  padding: 12px 14px; font-weight: 500;
}

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-block; padding: 1px 8px;
  background: var(--superficie); border: 1px solid var(--linha); border-radius: var(--raio);
  font: 500 0.75rem var(--mono); white-space: nowrap;
}
.chip.sensitive { background: var(--fundo); border-color: var(--alerta); border-width: 1.5px; font-family: var(--fonte); font-weight: 600; }
.sensitive-note {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  border: 1.5px solid var(--alerta); border-radius: var(--raio);
  font-size: 0.6875rem; font-weight: 700;
}
.field-type { font: 400 0.75rem var(--mono); color: var(--texto-2); }

/* ---- Abas e cabeçalhos ------------------------------------------------------------------------ */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--linha); margin-bottom: 28px; }
.tabs[hidden] { display: none; }
.tab {
  padding: 12px 16px 10px; border: 0; background: none; color: var(--texto-2);
  font: 600 0.9375rem var(--fonte); cursor: pointer;
  border-bottom: 4px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--texto); border-bottom-color: var(--linha); }
/* Aba ativa = categoria em foco: marcador amarelo. */
.tab.active { color: var(--texto); font-weight: 800; border-bottom-color: var(--amarelo); }

.section-head { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 20px; }
.section-head p { margin: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- Tabelas ---------------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--linha); border-radius: var(--raio); }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { text-align: left; padding: 12px 14px; vertical-align: middle; }
th {
  background: var(--superficie); color: var(--texto-2);
  font-size: 0.8125rem; font-weight: 700; white-space: nowrap; border-bottom: 1px solid var(--linha);
}
td { border-top: 1px solid var(--linha); }
tbody tr:first-child td { border-top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.app-id { font: 600 0.875rem var(--mono); }
.actions-col { width: 1%; white-space: nowrap; }
td .actions { flex-wrap: nowrap; }

/* ---- Painéis ---------------------------------------------------------------------------------- */

.card { border: 1px solid var(--linha); border-radius: var(--raio); padding: 20px; background: var(--fundo); }
#test-form { margin: 20px 0; max-width: 960px; }
#test-result { max-width: 960px; }
#test-route:disabled { border-style: dashed; }
.result-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; color: var(--texto-2); }
pre {
  margin: 0; padding: 16px; max-height: 520px; overflow: auto;
  background: var(--codigo-fundo); color: var(--codigo-texto); border-radius: var(--raio);
}
.param-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; }

/* ---- Editor de aplicação ---------------------------------------------------------------------- */

.editor-basics { display: grid; grid-template-columns: 1.2fr 1fr auto; gap: 0 24px; margin-bottom: 32px; }
.routes-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.routes-head h2 { margin: 0; }
#routes-summary { font-weight: 700; color: var(--texto-2); }
.routes-toolbar { display: flex; gap: 20px; align-items: center; margin-bottom: 14px; }
.routes-toolbar input[type=search] { max-width: 480px; }
.check.small { font-size: 0.875rem; white-space: nowrap; }

.route-group { border: 1px solid var(--linha); border-radius: var(--raio); margin-bottom: 10px; }
.route-group > summary {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; cursor: pointer; list-style: none;
}
.route-group > summary::-webkit-details-marker { display: none; }
/* Chevron da marca como indicador de abrir/fechar. */
.route-group > summary::before {
  content: ''; width: 12px; height: 10px; flex: none; background: var(--texto);
  clip-path: polygon(0 0, 32% 0, 50% 46%, 68% 0, 100% 0, 50% 100%);
  transform: rotate(-90deg); transition: transform 0.15s ease;
}
.route-group[open] > summary::before { transform: none; }
.route-group > summary strong { font-stretch: 112%; font-weight: 800; }
.route-group > summary .muted { color: var(--texto-2); }

.route { border-top: 1px solid var(--linha); }
.route-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; }
/* Rota liberada = item em foco: marcador amarelo. */
.route-row.selected { box-shadow: inset 4px 0 0 var(--amarelo); background: var(--superficie); padding-left: 20px; }
.route-row.selected code { font-weight: 700; }
.route-main { display: flex; align-items: start; gap: 10px; font-weight: 400; margin: 0; min-width: 0; }
.route-main input { cursor: pointer; }
.route-name { display: block; min-width: 0; padding: 0; border: 0; background: none; color: inherit;
  font: inherit; text-align: left; }
button.route-name { cursor: pointer; }
button.route-name:hover code { text-decoration: underline; text-underline-offset: 3px; }
.route-main input { margin-top: 3px; }
.route-main code { word-break: break-all; }
.route-summary { display: block; margin-top: 2px; color: var(--texto-2); }
.route-badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.field-panel:empty { display: none; }
.field-panel { padding: 14px 14px 16px 40px; border-top: 1px solid var(--linha); background: var(--superficie); }
.field-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.field-toolbar .field-filter { max-width: 320px; height: 34px; }
.field-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 2px 20px;
  max-height: 420px; overflow-y: auto; padding-right: 4px;
}
.field-item { font-weight: 400; font-size: 0.875rem; margin: 0; padding: 4px 0; }
.field-item code { font-size: 0.78rem; word-break: break-all; }

/* ---- Logs ------------------------------------------------------------------------------------- */

.logs-filters {
  display: grid; grid-template-columns: 150px 150px 1fr 1.6fr 1fr auto; gap: 0 14px; align-items: end;
  border: 1px solid var(--linha); border-radius: var(--raio); padding: 16px 16px 0; margin-bottom: 16px;
  background: var(--superficie);
}
.logs-filters input, .logs-filters select { background: var(--fundo); }
.logs-submit { display: flex; }
#logs-table-top { scroll-margin-top: 16px; }
.logs-table td { padding: 10px 12px; vertical-align: top; }
.logs-table code { word-break: break-all; }
.log-detail { display: block; margin-top: 6px; font: 400 0.75rem var(--mono); max-width: 46ch; color: var(--texto-2); }
.nowrap { white-space: nowrap; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; font-weight: 600; color: var(--texto-2); }

/* ---- Painel ---------------------------------------------------------------------------------- */

:root { --serie-ok: var(--cinza-400); --serie-err: var(--erro); --barra-neutra: var(--cinza-600); }
@media (prefers-color-scheme: dark) { :root { --barra-neutra: var(--cinza-200); } }

.dash-filters {
  display: grid; grid-template-columns: 220px 280px; gap: 0 14px; align-items: end;
  border: 1px solid var(--linha); border-radius: var(--raio); padding: 16px 16px 0; margin-bottom: 24px;
  background: var(--superficie);
}
.dash-filters select { background: var(--fundo); }
.dash-block { margin-bottom: 32px; }
.dash-block h2 { margin-bottom: 8px; }
.dash-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.dash-note { color: var(--texto-2); font-size: 0.8125rem; margin-bottom: 12px; }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px; }

.legend { display: flex; gap: 16px; font-size: 0.8125rem; color: var(--texto-2); }
.key { display: inline-flex; align-items: center; gap: 6px; }
.key::before { content: ''; width: 10px; height: 10px; border-radius: 2px; }
.key-ok::before { background: var(--serie-ok); }
.key-err::before { background: var(--serie-err); }

.hours-chart { width: 100%; height: auto; display: block; }
.hours-chart .bar-ok { fill: var(--serie-ok); }
.hours-chart .bar-err { fill: var(--serie-err); }
.hours-chart .grid { stroke: var(--linha); stroke-width: 1; }
.hours-chart .baseline { stroke: var(--texto-2); stroke-width: 1; }
.hours-chart .business-band { fill: var(--superficie); }
.hours-chart .axis-label { fill: var(--texto-2); font: 400 12px var(--fonte); }
.hours-chart .axis-note { fill: var(--texto-2); font: 600 12px var(--fonte); }
.hours-chart .hit { fill: transparent; cursor: default; }
.hours-chart .hit:hover { fill: var(--texto); fill-opacity: 0.04; }
.dash-table { margin-top: 8px; font-size: 0.875rem; }
.dash-table summary { cursor: pointer; color: var(--texto-2); font-weight: 600; }
.dash-table table.compact { width: auto; min-width: 320px; margin-top: 8px; }
.dash-table table.compact th, .dash-table table.compact td { padding: 6px 12px; }

.hbars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: 12px; align-items: center; }
.hbar-label { font: 500 0.8125rem var(--mono); overflow-wrap: anywhere; }
.hbar-label.is-text { font: 600 0.875rem var(--fonte); }
.hbar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar-fill { height: 14px; background: var(--barra-neutra); border-radius: 0 4px 4px 0; flex: none; max-width: calc(100% - 56px); }
.hbar-value { font-size: 0.8125rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; display: grid; gap: 2px;
  background: var(--preto); color: var(--branco); border-radius: var(--raio);
  padding: 8px 10px; font-size: 0.8125rem; box-shadow: 0 6px 16px rgba(10, 10, 10, 0.25);
}
@media (prefers-color-scheme: dark) { .tooltip { background: var(--branco); color: var(--preto); } }

/* ---- Diálogos --------------------------------------------------------------------------------- */

dialog {
  border: 1px solid var(--linha); border-radius: 8px; padding: 28px;
  width: min(580px, calc(100vw - 32px));
  background: var(--fundo); color: var(--texto);
  box-shadow: 0 24px 48px rgba(10, 10, 10, 0.25);
}
dialog::backdrop { background: rgba(10, 10, 10, 0.55); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.token-box {
  display: flex; gap: 8px; align-items: center; margin: 16px 0;
  border: 1px solid var(--linha); background: var(--superficie); border-radius: var(--raio); padding: 12px;
}
.token-box code { flex: 1; word-break: break-all; font-size: 0.875rem; font-weight: 600; }
.confirm-list { max-height: 240px; overflow-y: auto; font: 500 0.8125rem var(--mono); padding-left: 20px; color: var(--texto-2); }

/* ---- Telas pequenas e movimento reduzido ------------------------------------------------------ */

@media (max-width: 760px) {
  .entry { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .entry-brand { gap: 16px; padding: 28px 20px; }
  .entry-mark { width: 40px; height: 40px; }
  .entry-name { font-size: 2.75rem; margin-bottom: 8px; }
  .entry-panel { align-items: start; justify-items: stretch; padding: 28px 20px; border-left: 0; }
  .topbar { padding: 10px 16px; }
  main { padding: 24px 16px 48px; }
  .section-head { flex-direction: column; align-items: stretch; }
  .editor-basics { grid-template-columns: 1fr; }
  .route-row { flex-direction: column; align-items: stretch; }
  .route-badges { justify-content: flex-start; padding-left: 26px; }
  .field-panel { padding-left: 14px; }
  .routes-toolbar { flex-direction: column; align-items: stretch; }
  .field-list { grid-template-columns: 1fr; }
  .logs-filters { grid-template-columns: 1fr 1fr; }
  .logs-route, .logs-submit { grid-column: span 2; }
  .dash-filters, .dash-grid { grid-template-columns: 1fr; }
  .hbar { grid-template-columns: 1fr; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
