/* Vigia.ia — folha de estilos do MVP */
:root {
  --paper: #f6f4ef;
  --paper-2: #efece4;
  --ink: #17212b;
  --ink-2: #3d4a57;
  --ink-3: #6b7784;
  --line: #ddd8cc;
  --navy: #0f2a44;
  --navy-2: #163a5c;
  --wine: #8b1e2d;
  --wine-2: #a9303f;
  --gold: #c9a227;
  --teal: #1f7a8c;
  --teal-2: #2a9db3;
  --ok: #2e7d4f;
  --warn: #c77d0a;
  --crit: #b3261e;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(23, 33, 43, .06), 0 8px 24px -12px rgba(23, 33, 43, .18);
  --radius: 14px;
  --font-head: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 90% -10%, rgba(201, 162, 39, .10), transparent 60%),
    radial-gradient(900px 400px at -10% 0%, rgba(31, 122, 140, .10), transparent 60%),
    var(--paper);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal); }
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; letter-spacing: -.01em; margin: 0; color: var(--navy); }
h1 { font-size: clamp(1.6rem, 2.4vw, 2.2rem); line-height: 1.15; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
small, .muted { color: var(--ink-3); }
code, .mono { font-family: var(--font-mono); font-size: .85em; }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--navy); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 8px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 18px;
  padding: 10px 22px; background: rgba(15, 42, 68, .96); color: #fff;
  backdrop-filter: blur(8px); box-shadow: 0 2px 12px rgba(0, 0, 0, .25);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { color: var(--gold); display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid rgba(201, 162, 39, .5); border-radius: 10px; background: rgba(255,255,255,.04); }
.brand-title { font-family: var(--font-head); font-size: 1.35rem; font-weight: 700; line-height: 1; }
.brand-title span { color: var(--gold); }
.brand-sub { font-size: .72rem; color: rgba(255,255,255,.7); margin-top: 3px; letter-spacing: .02em; }
.topnav { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.topnav a { color: rgba(255,255,255,.82); text-decoration: none; font-size: .86rem; font-weight: 500; padding: 8px 12px; border-radius: 999px; transition: background .15s, color .15s; }
.topnav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.topnav a.active { background: var(--gold); color: var(--navy); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.badge-env { font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--gold); border: 1px solid rgba(201,162,39,.55); padding: 4px 8px; border-radius: 6px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--wine); display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.user-name { font-size: .8rem; line-height: 1.2; }
.user-name small { color: rgba(255,255,255,.65); font-size: .7rem; }

/* Layout */
.content { max-width: 1440px; margin: 0 auto; padding: 26px 22px 60px; }
.view-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 20px; flex-wrap: wrap; }
.view-header p { margin: 6px 0 0; color: var(--ink-2); max-width: 78ch; }
.eyebrow { font-size: .72rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--wine); margin-bottom: 6px; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-map { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
.grid-side { grid-template-columns: minmax(0, 1fr) 360px; }
.span-2 { grid-column: span 2; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3, .grid-map, .grid-side { grid-template-columns: 1fr; } .span-2 { grid-column: auto; } }
@media (max-width: 700px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } .topbar { grid-template-columns: 1fr; } .topbar-right { display: none; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h3 { font-size: 1rem; }
.card-head .hint { font-size: .74rem; color: var(--ink-3); }
.kpi { position: relative; overflow: hidden; }
.kpi .kpi-label { font-size: .78rem; color: var(--ink-3); font-weight: 500; }
.kpi .kpi-value { font-family: var(--font-head); font-size: 2.2rem; font-weight: 600; color: var(--navy); line-height: 1.1; margin-top: 4px; }
.kpi .kpi-delta { font-size: .78rem; margin-top: 6px; font-weight: 500; }
.kpi .kpi-delta.up { color: var(--crit); }
.kpi .kpi-delta.ok { color: var(--ok); }
.kpi::after { content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; background: radial-gradient(circle, rgba(201,162,39,.16), transparent 70%); }

/* Controls */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.chip { border: 1px solid var(--line); background: #fff; color: var(--ink-2); border-radius: 999px; padding: 6px 12px; font-size: .8rem; cursor: pointer; font-family: inherit; transition: all .15s; }
.chip:hover { border-color: var(--teal); color: var(--teal); }
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn { text-decoration: none; border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 600; font-size: .84rem; cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 8px; transition: transform .1s, box-shadow .15s, background .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--wine); color: #fff; box-shadow: 0 6px 16px -8px rgba(139,30,45,.7); }
.btn-primary:hover { background: var(--wine-2); }
.btn-secondary { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn-secondary:hover { border-color: var(--navy); }
.btn-ghost { background: transparent; color: var(--teal); padding-inline: 8px; }
select, input[type="text"], textarea { font-family: inherit; font-size: .88rem; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff; color: var(--ink); }
input[type="range"] { accent-color: var(--wine); width: 100%; }
label.field { display: grid; gap: 4px; font-size: .78rem; color: var(--ink-3); font-weight: 500; }
label.field strong { color: var(--ink); }
label.field.inline-text { display: block; }
label.field.inline-text input { margin-top: 6px; }

/* Tables */
.table-wrap { overflow: auto; border-radius: 10px; border: 1px solid var(--line); }
table.data { width: 100%; border-collapse: collapse; font-size: .84rem; }
table.data th { text-align: left; background: var(--paper-2); color: var(--ink-2); font-weight: 600; padding: 10px 12px; position: sticky; top: 0; white-space: nowrap; font-size: .76rem; letter-spacing: .03em; text-transform: uppercase; }
table.data td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
table.data tr:hover td { background: rgba(31,122,140,.05); }
table.data tr.clickable { cursor: pointer; }

/* Tags */
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--paper-2); color: var(--ink-2); white-space: nowrap; }
.tag.eixo-Saúde { background: #fde8ea; color: #8b1e2d; }
.tag.eixo-Educação { background: #e6effa; color: #1e4f8b; }
.tag.eixo-Assistência { background: #fff2dc; color: #8a5a00; }
.tag.eixo-Acessibilidade { background: #ece6f7; color: #4d2e8a; }
.tag.eixo-Meio { background: #e3f3e8; color: #1f6a3a; }
.tag.eixo-Segurança { background: #e9edf1; color: #2d3b48; }
.tag.eixo-Infraestrutura { background: #e5f2f5; color: #135b6a; }
.tag.eixo-Crise { background: #fff0e0; color: #a34d00; }
.sev { display: inline-flex; align-items: center; gap: 6px; font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.sev::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.sev.crítica { color: var(--crit); }
.sev.alta { color: var(--warn); }
.sev.média { color: var(--teal); }

/* Map */
.map-wrap { position: relative; }
.map-svg { width: 100%; height: auto; display: block; }
.map-legend { position: absolute; right: 12px; bottom: 28px; background: rgba(255,255,255,.9); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: .72rem; color: var(--ink-2); display: grid; gap: 4px; }
.legend-scale { width: 120px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #f8d99a, #e8853a, #b3261e); }
.map-tooltip { position: absolute; pointer-events: none; background: var(--navy); color: #fff; padding: 8px 10px; border-radius: 8px; font-size: .76rem; transform: translate(-50%, calc(-100% - 12px)); opacity: 0; transition: opacity .12s; white-space: nowrap; box-shadow: var(--shadow); }
.map-tooltip.show { opacity: 1; }

/* Charts */
.chart { width: 100%; height: auto; display: block; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 48px; align-items: center; gap: 10px; font-size: .82rem; padding: 5px 0; }
.bar-track { height: 10px; background: var(--paper-2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--teal), var(--navy)); transition: width .5s ease; }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* Pipeline */
.pipeline { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.pipe-step { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--paper); position: relative; }
.pipe-step .st { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ok); font-weight: 700; }
.pipe-step .nm { font-weight: 600; font-size: .82rem; margin: 3px 0; }
.pipe-step .sv { font-size: .72rem; color: var(--ink-3); }
.pipe-step .du { font-family: var(--font-mono); font-size: .7rem; color: var(--ink-2); margin-top: 6px; }
@media (max-width: 1100px) { .pipeline { grid-template-columns: repeat(3, 1fr); } }

/* Document viewer */
.doc-page { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 18px 22px; margin-bottom: 12px; font-family: 'Times New Roman', Georgia, serif; font-size: .95rem; line-height: 1.6; box-shadow: inset 0 0 0 1px rgba(0,0,0,.02); }
.doc-page .pg { font-family: var(--font-mono); font-size: .68rem; color: var(--ink-3); margin-bottom: 8px; display: flex; justify-content: space-between; }
.doc-page p { margin: 0; }
.doc-page mark { padding: 0 2px; border-radius: 3px; }
mark.entidade { background: #cfe6f7; }
mark.carencia { background: #fbd0d4; }
mark.perfil { background: #ece6f7; }
mark.temporal { background: #fdf0c2; }
mark.protocolo { background: #d9f0e3; }
mark.inferencia { background: #ffe2c2; }
mark.documento { background: #e2e6ea; }
mark.causa_raiz { background: #ffd8a8; }
mark.contradicao { background: #ffb3ab; }
.legend-inline { display: flex; gap: 10px; flex-wrap: wrap; font-size: .72rem; color: var(--ink-2); margin: 8px 0 14px; }
.legend-inline span { display: inline-flex; align-items: center; gap: 4px; }
.legend-inline i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.kv { display: grid; grid-template-columns: 118px 1fr; gap: 8px 12px; font-size: .84rem; }
.kv dd { min-width: 0; overflow-wrap: anywhere; }
.kv .tag { white-space: normal; margin: 0 4px 4px 0; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.confidence { display: inline-block; height: 6px; width: 90px; background: var(--paper-2); border-radius: 3px; overflow: hidden; vertical-align: middle; margin-left: 6px; }
.confidence i { display: block; height: 100%; background: var(--ok); }
.cite { display: inline-block; font-family: var(--font-mono); font-size: .7rem; background: var(--paper-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; color: var(--ink-2); cursor: pointer; }
.cite:hover { border-color: var(--teal); color: var(--teal); }
.doc-page.flash { animation: flash 1.2s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--gold); } 100% { box-shadow: none; } }

/* Clusters */
.cluster-card { cursor: pointer; transition: transform .12s, border-color .12s; }
.cluster-card:hover { transform: translateY(-2px); border-color: var(--teal); }
.cluster-card.selected { border-color: var(--wine); box-shadow: 0 0 0 2px rgba(139,30,45,.15); }
.cluster-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.cluster-n { font-family: var(--font-head); font-size: 1.6rem; color: var(--navy); }
.pill-new { font-size: .66rem; font-weight: 700; color: #fff; background: var(--wine); border-radius: 5px; padding: 2px 6px; text-transform: uppercase; letter-spacing: .05em; }
.pill-shadow { font-size: .66rem; font-weight: 700; color: var(--navy); background: rgba(201,162,39,.35); border-radius: 5px; padding: 2px 6px; text-transform: uppercase; letter-spacing: .05em; }
.graph-svg { width: 100%; height: 520px; background: radial-gradient(circle at 50% 50%, #fff, var(--paper)); border-radius: 10px; border: 1px solid var(--line); }
.graph-svg text { font-family: var(--font-body); font-size: 11px; fill: var(--ink); pointer-events: none; }
.graph-svg .edge { stroke: #9aa5b1; stroke-width: 1.2; }
.graph-svg .edge-label { font-size: 9px; fill: var(--ink-3); }
.graph-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .74rem; color: var(--ink-2); margin-top: 8px; }
.graph-legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 4px; }

/* Alerts */
.alert-item { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; margin-bottom: 10px; }
.alert-item.crítica { border-left: 4px solid var(--crit); }
.alert-item.alta { border-left: 4px solid var(--warn); }
.alert-item.média { border-left: 4px solid var(--teal); }
.alert-title { font-weight: 600; margin: 4px 0; }
.alert-meta { font-size: .74rem; color: var(--ink-3); display: flex; gap: 12px; flex-wrap: wrap; }
.minuta { white-space: pre-wrap; font-family: 'Times New Roman', Georgia, serif; font-size: .92rem; line-height: 1.55; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 20px 24px; min-height: 200px; }
.typing::after { content: '▍'; animation: blink 1s steps(1) infinite; color: var(--wine); }
@keyframes blink { 50% { opacity: 0; } }

/* Timeline */
.tl { position: relative; padding-left: 26px; }
.tl::before { content: ''; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 18px; }
.tl-item::before { content: ''; position: absolute; left: -23px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--teal); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--teal); }
.tl-item.falha::before { background: var(--crit); box-shadow: 0 0 0 2px var(--crit); }
.tl-item.contradicao::before { background: var(--warn); box-shadow: 0 0 0 2px var(--warn); }
.tl-item.alerta::before { background: var(--wine); box-shadow: 0 0 0 2px var(--wine); }
.tl-item.gestao::before, .tl-item.controle::before { background: var(--navy); box-shadow: 0 0 0 2px var(--navy); }
.tl-date { font-family: var(--font-mono); font-size: .74rem; color: var(--ink-3); }
.tl-ev { font-weight: 500; }
.tl-src { font-size: .74rem; color: var(--ink-3); }

/* Chat */
.chat-wrap { display: grid; grid-template-rows: 1fr auto; height: 640px; }
.chat-log { overflow: auto; padding: 8px 4px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 80%; padding: 12px 14px; border-radius: 14px; font-size: .9rem; line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .fontes { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.chat-input { display: flex; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.chat-input input { flex: 1; }
.suggestions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }

/* Arquitetura */
.arch-row { display: grid; grid-template-columns: 200px 1fr 220px; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); font-size: .86rem; align-items: start; }
.arch-row:first-of-type { border-top: 0; }
.arch-row .cam { font-weight: 600; color: var(--navy); }
.arch-row .rf { font-family: var(--font-mono); font-size: .74rem; color: var(--ink-2); }
.flow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: stretch; margin-top: 8px; }
.flow-box { background: var(--navy); color: #fff; border-radius: 10px; padding: 10px; font-size: .74rem; text-align: center; display: grid; place-items: center; min-height: 68px; }
.flow-box b { display: block; font-size: .8rem; color: var(--gold); margin-bottom: 2px; }
@media (max-width: 1100px) { .flow { grid-template-columns: repeat(4, 1fr); } .arch-row { grid-template-columns: 1fr; } }

/* Footer, toast */
.footer { max-width: 1440px; margin: 0 auto; padding: 18px 22px 40px; font-size: .74rem; color: var(--ink-3); display: flex; justify-content: space-between; gap: 18px; border-top: 1px solid var(--line); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .84rem; opacity: 0; transition: all .2s; box-shadow: var(--shadow); pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(15,42,68,.45); display: grid; place-items: center; z-index: 80; padding: 20px; }
.modal { background: var(--paper); border-radius: 16px; max-width: 760px; width: 100%; max-height: 88vh; overflow: auto; padding: 22px 24px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.4); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.fade-in { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
