/* Tokens e componentes compartilhados (página pública e painel). */

:root {
    --display: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --sans: 'Libre Franklin', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    --paper: #f6f5f2;
    --paper-2: #ecebe7;
    --paper-3: #e0ded8;
    --ink: #141414;
    --ink-2: #383838;
    --muted: #686868;
    --line: #d8d6d0;
    --line-strong: #bab7b0;
    /* Azul celeste (a "Celeste" uruguaia), escurecido no tema claro para ler bem como texto. */
    --brand: #1f72b8;
    --brand-ink: #175e98;
    --brand-contra: #ffffff;
    --celeste: #74b7e6;
    --sol: #f2b10f;
    --ok: #0f7a4a;
    --ok-bg: #e7f6ee;
    --alerta: #b54708;
    --alerta-bg: #fff4e5;
    --perigo: #b42318;
    --perigo-bg: #fdecea;
    --ao-vivo: #d92d20;

    --map-vazio: #d9d7d1;
    --map-linha: var(--paper);

    --topbar: 64px;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --paper: #0a0a0a;
    --paper-2: #151515;
    --paper-3: #1f1f1f;
    --ink: #f5f5f5;
    --ink-2: #cccccc;
    --muted: #a3a3a3;
    --line: #2a2a2a;
    --line-strong: #3d3d3d;
    --brand: #6cb8ea;
    --brand-ink: #9dd0f2;
    --brand-contra: #06213a;
    --celeste: #5aa6dc;
    --ok: #4ade80;
    --ok-bg: #0d2a1b;
    --alerta: #fdb022;
    --alerta-bg: #331b08;
    --perigo: #f97066;
    --perigo-bg: #3a0f0b;
    --ao-vivo: #f04438;
    --map-vazio: #262626;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---- Barra superior ---- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--topbar);
    background: color-mix(in srgb, var(--paper) 90%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--line);
}

.topbar-in {
    height: 100%;
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 0 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--display);
    font-size: 1.22rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.brand-mark { width: 33px; height: 22px; flex: none; border-radius: 2px; }
.brand-sep { color: var(--line-strong); font-family: var(--sans); font-weight: 300; }

.brand-scope {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.topnav {
    display: flex;
    align-items: center;
    gap: 18px;
    font-size: 0.86rem;
    white-space: nowrap;
}

.topnav a, .topnav button {
    background: none;
    border: 0;
    padding: 4px 0;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s;
}

.topnav a:hover, .topnav button:hover { color: var(--ink); }
.topnav .is-ativo { color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }
.topnav-sep { width: 1px; height: 18px; background: var(--line); }

.topbar-acoes { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.botao-icone {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: none;
    color: var(--ink-2);
    transition: background .15s, border-color .15s;
}
.botao-icone:hover { background: var(--paper-2); border-color: var(--line-strong); }
.botao-icone svg { width: 16px; height: 16px; }

/* ---- Controles ---- */

.niveis {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 3px;
    overflow: hidden;
    background: var(--paper);
}

.nivel {
    padding: 5px 11px;
    border: 0;
    background: none;
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
}
.nivel + .nivel { border-left: 1px solid var(--line); }
.nivel:hover { color: var(--ink); }
.nivel.is-on { background: var(--ink); color: var(--paper); }

.botao {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    background: var(--paper);
    color: var(--ink);
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background .15s, border-color .15s, opacity .15s;
}
.botao:hover { background: var(--paper-2); }
.botao:disabled { opacity: .45; cursor: not-allowed; }
.botao svg { width: 15px; height: 15px; }
.botao-primario { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.botao-primario:hover { background: var(--ink-2); }
.botao-marca { background: var(--brand); color: var(--brand-contra); border-color: var(--brand); }
.botao-marca:hover { background: var(--brand-ink); }
.botao-perigo { color: var(--perigo); border-color: color-mix(in srgb, var(--perigo) 45%, var(--line)); }
.botao-perigo:hover { background: var(--perigo-bg); }
.botao-pequeno { padding: 5px 10px; font-size: 0.76rem; }
.botao-fantasma { border-color: transparent; background: none; color: var(--muted); }
.botao-fantasma:hover { color: var(--ink); background: var(--paper-2); }

.campo {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    background: var(--paper);
    color: var(--ink);
    font-size: 0.86rem;
    transition: border-color .15s;
}
.campo:focus { outline: none; border-color: var(--ink); }
select.campo { padding-right: 28px; }

.rotulo {
    display: block;
    margin-bottom: 5px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.busca { position: relative; }
.busca svg { position: absolute; left: 9px; top: 50%; width: 14px; height: 14px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.busca .campo { padding-left: 30px; }

/* ---- Selos ---- */

.selo {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 6px;
    border: 1px solid var(--line);
    border-radius: 2px;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
    vertical-align: middle;
}
.selo-eleito { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); background: var(--ok-bg); }
.selo-turno { color: #fff; border-color: #2f5bd3; background: #2f5bd3; }
.selo-lidera { color: var(--alerta); border-color: color-mix(in srgb, var(--alerta) 45%, transparent); background: var(--alerta-bg); }

.ao-vivo {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ao-vivo);
}
.ao-vivo::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ao-vivo);
    animation: pulsar 2s ease-in-out infinite;
}
.ao-vivo.is-off { color: var(--muted); }
.ao-vivo.is-off::before { background: var(--muted); animation: none; }
.ao-vivo.is-pausa { color: var(--alerta); }
.ao-vivo.is-pausa::before { background: var(--alerta); animation: none; }

@keyframes pulsar {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .35; transform: scale(.8); }
}

/* ---- Barras e tabelas ---- */

.barra { height: 6px; background: var(--paper-3); border-radius: 99px; overflow: hidden; }
.barra > span { display: block; height: 100%; width: 0; background: var(--ink); border-radius: 99px; transition: width .7s cubic-bezier(.16, 1, .3, 1); }

.tabela-wrap { overflow-x: auto; }
.tabela { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.tabela thead th {
    text-align: left;
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 11px 10px 9px;
    border-bottom: 2px solid var(--ink);
    white-space: nowrap;
    user-select: none;
}
.tabela thead th.ordenavel { cursor: pointer; }
.tabela thead th.ordenavel:hover { color: var(--ink); }
.tabela thead th[aria-sort="ascending"]::after { content: " ↑"; }
.tabela thead th[aria-sort="descending"]::after { content: " ↓"; }
.tabela th.num, .tabela td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tabela tbody td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tabela tbody tr { transition: background .15s; }
.tabela tbody tr:hover { background: var(--paper-2); }
.tabela tbody tr.clicavel { cursor: pointer; }

.ponto { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; vertical-align: middle; }

/* ---- Dica flutuante ---- */

.tip {
    position: fixed;
    z-index: 80;
    pointer-events: none;
    opacity: 0;
    transition: opacity .12s;
    min-width: 240px;
    max-width: 320px;
    padding: 10px 12px;
    background: var(--paper-2);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
    font-size: 0.8rem;
}
.tip.is-on { opacity: 1; }
.tip-tit { font-family: var(--display); font-size: 1.02rem; font-weight: 600; line-height: 1.15; }
.tip-sub { margin-top: 2px; color: var(--muted); font-size: 0.7rem; letter-spacing: .02em; }
.tip-linhas { margin-top: 8px; display: grid; gap: 4px; }
.tip-linha { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; align-items: center; gap: 8px; }
.tip-linha .nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip-linha .pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.tip-linha .votos { color: var(--muted); font-size: 0.72rem; font-variant-numeric: tabular-nums; min-width: 5.5em; text-align: right; }
.tip-rodape { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.7rem; }

/* ---- Mapa ---- */

.mapa-svg { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; }
.mapa-svg .mun, .mapa-svg .grupo { fill: var(--map-vazio); stroke: none; }
.mapa-svg.interagindo path { shape-rendering: optimizeSpeed; }
.mapa-svg:not(.nivel-municipios) .camada-mun,
.mapa-svg:not(.nivel-departamentos) .camada-depto,
.mapa-svg:not(.nivel-circunscricoes) .camada-circ,
.mapa-svg:not(.nivel-circunscricoesEst) .camada-circest { display: none; }
.mapa-svg .linhas { fill: none; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.mapa-svg .linhas-mun { stroke: var(--map-linha); stroke-width: .7; }
.mapa-svg .linhas-depto { stroke: var(--map-linha); stroke-width: .7; }
.mapa-svg .linhas-contorno { stroke: var(--line-strong); stroke-width: .6; opacity: .6; }
.mapa-svg .linhas-circ, .mapa-svg .linhas-circest { stroke: var(--map-linha); stroke-width: 1.4; display: none; }
.mapa-svg:not(.nivel-municipios) .linhas-mun { display: none; }
.mapa-svg.nivel-circunscricoes .linhas-depto, .mapa-svg.nivel-circunscricoesEst .linhas-depto { display: none; }
.mapa-svg.nivel-circunscricoes .linhas-circ, .mapa-svg.nivel-circunscricoesEst .linhas-circest { display: inline; }
.mapa-svg .realce { fill: none; stroke: var(--ink); vector-effect: non-scaling-stroke; stroke-linejoin: round; pointer-events: none; }
.mapa-svg .realce-hover { stroke-width: 1.4; }
.mapa-svg .realce-foco { stroke-width: 2.4; }
.mapa-svg .realce-selecao { stroke: #fbbf24; stroke-width: 2; }
.mapa-svg.arrastando { cursor: grabbing; }
.mapa-host { position: relative; }

/* Dotplots de cadeiras sobre o mapa (como no Simulador Parlamentar Brasileiro) */
.mapa-marcadores { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.marcador-cadeiras { position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer; }
.marcador-cadeiras .dotplot { display: block; overflow: visible; transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.marcador-cadeiras:hover .dotplot { transform: scale(1.15); }
.marcador-cadeiras.passivo { pointer-events: none; }
.marcador-cadeiras .dotplot circle { stroke: var(--paper); stroke-width: 0.1875; }
.mapa-svg .guia { stroke: var(--ink); stroke-width: 1.5; opacity: 0.9; vector-effect: non-scaling-stroke; pointer-events: none; }
.mapa-svg .guia-ponto { fill: var(--ink); stroke: var(--paper); stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.mapa-dica-zoom {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, .38);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}
.mapa-dica-zoom.is-on { opacity: 1; }
.mapa-caixa { fill: color-mix(in srgb, #3b82f6 18%, transparent); stroke: #3b82f6; stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }

/* ---- Avisos ---- */

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 100;
    transform: translate(-50%, 20px);
    opacity: 0;
    pointer-events: none;
    padding: 10px 18px;
    border-radius: 3px;
    background: var(--ink);
    color: var(--paper);
    font-size: 0.84rem;
    font-weight: 500;
    transition: opacity .2s, transform .2s;
    max-width: calc(100vw - 32px);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-erro { background: var(--perigo); color: #fff; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; }
