/* ======================================================================
   R2.1T.V1 | Sistema Visual Territorial e Atlas Vivo
   Camada canônica de harmonização visual do Territorial 2.0.

   Princípios:
   1. luz cívica como estado visual canônico;
   2. tema escuro nunca é ativado por preferência automática do dispositivo;
   3. profundidade, vidro, cor e movimento possuem função semântica;
   4. leitura pública e privada compartilham a mesma identidade;
   5. cor nunca é o único indicador de estado;
   6. mapa representa contexto e relação, nunca ranking.
   ====================================================================== */

:root {
    --tv2-civic-bg: #f5f7ff;
    --tv2-civic-bg-soft: #fbfcff;
    --tv2-civic-ink: #11213f;
    --tv2-civic-text: #3e4d68;
    --tv2-civic-muted: #6d7b94;
    --tv2-civic-faint: #98a4b8;
    --tv2-civic-line: rgba(82, 105, 157, .16);
    --tv2-civic-line-strong: rgba(82, 105, 157, .24);
    --tv2-civic-surface: rgba(255, 255, 255, .78);
    --tv2-civic-surface-strong: rgba(255, 255, 255, .94);
    --tv2-civic-surface-muted: rgba(248, 250, 255, .84);
    --tv2-civic-shadow:
        0 1px 0 rgba(255, 255, 255, .94) inset,
        0 18px 48px rgba(46, 64, 112, .08),
        0 5px 15px rgba(46, 64, 112, .05);
    --tv2-civic-shadow-hover:
        0 1px 0 rgba(255, 255, 255, .96) inset,
        0 24px 58px rgba(46, 64, 112, .12),
        0 7px 18px rgba(46, 64, 112, .07);
    --tv2-civic-radius-xs: 12px;
    --tv2-civic-radius-sm: 16px;
    --tv2-civic-radius-md: 22px;
    --tv2-civic-radius-lg: 30px;
    --tv2-civic-radius-xl: 38px;
    --tv2-civic-space-1: 6px;
    --tv2-civic-space-2: 10px;
    --tv2-civic-space-3: 14px;
    --tv2-civic-space-4: 18px;
    --tv2-civic-space-5: 24px;
    --tv2-civic-space-6: 32px;
    --tv2-civic-space-7: 42px;
    --tv2-civic-focus: 0 0 0 4px rgba(69, 103, 242, .14);
}

/* ----------------------------------------------------------------------
   01 | Luz cívica canônica
   ---------------------------------------------------------------------- */
.tv2-page,
.tv2-public-body,
.tv2-public-page,
.tv2-hv-public,
.tv2-temporal-public {
    color-scheme: light !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.tv2-page,
body[data-theme="dark"] .tv2-page,
.theme-dark .tv2-page {
    --tv2-ink: var(--tv2-civic-ink);
    --tv2-text: var(--tv2-civic-text);
    --tv2-muted: var(--tv2-civic-muted);
    --tv2-line: var(--tv2-civic-line);
    --tv2-paper: var(--tv2-civic-surface);
    --tv2-paper-strong: var(--tv2-civic-surface-strong);
    min-height: 100%;
    color: var(--tv2-civic-text);
    background:
        radial-gradient(920px 540px at 9% 4%, rgba(123, 85, 231, .08), transparent 64%),
        radial-gradient(840px 520px at 96% 16%, rgba(30, 167, 197, .08), transparent 66%),
        radial-gradient(720px 460px at 70% 96%, rgba(46, 158, 114, .055), transparent 70%),
        linear-gradient(145deg, #f8f9ff 0%, #f3f9fb 50%, #fffaf2 100%) !important;
}

.tv2-public-body,
.tv2-public-page,
.tv2-hv-public,
.tv2-temporal-public {
    color: var(--tv2-civic-text) !important;
    background:
        radial-gradient(900px 520px at 7% 4%, rgba(123, 85, 231, .07), transparent 64%),
        radial-gradient(800px 480px at 93% 24%, rgba(30, 167, 197, .07), transparent 65%),
        linear-gradient(145deg, #f8f9ff 0%, #f6fbfc 52%, #fffaf4 100%) !important;
}

/* Neutraliza herança acidental do tema global escuro dentro do Territorial. */
body[data-theme="dark"] .tv2-page input,
body[data-theme="dark"] .tv2-page select,
body[data-theme="dark"] .tv2-page textarea,
.theme-dark .tv2-page input,
.theme-dark .tv2-page select,
.theme-dark .tv2-page textarea,
.tv2-page input,
.tv2-page select,
.tv2-page textarea {
    color: var(--tv2-civic-ink) !important;
    border-color: var(--tv2-civic-line-strong) !important;
    background: rgba(255, 255, 255, .88) !important;
}

.tv2-page input::placeholder,
.tv2-page textarea::placeholder {
    color: #96a1b4;
    opacity: 1;
}

/* ----------------------------------------------------------------------
   02 | Superfícies e profundidade comuns
   ---------------------------------------------------------------------- */
.tv2-glass,
body[data-theme="dark"] .tv2-glass,
.theme-dark .tv2-glass {
    border: 1px solid var(--tv2-civic-line) !important;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, .88), rgba(252, 253, 255, .68)) padding-box,
        linear-gradient(145deg, rgba(255, 255, 255, .95), rgba(99, 118, 174, .16)) border-box !important;
    box-shadow: var(--tv2-civic-shadow) !important;
    backdrop-filter: blur(18px) saturate(1.08);
    -webkit-backdrop-filter: blur(18px) saturate(1.08);
}

.tv2-glass::selection,
.tv2-page ::selection,
.tv2-public-page ::selection {
    color: #132343;
    background: rgba(123, 85, 231, .18);
}

.tv2-page article,
.tv2-page section,
.tv2-page aside,
.tv2-public-page article,
.tv2-public-page section {
    min-width: 0;
}

.tv2-page .tv2-container {
    width: min(1500px, calc(100% - 38px));
}

.tv2-public-body .tv2-container,
.tv2-hv-public-shell,
.tv2-temporal-public-shell {
    width: min(1280px, calc(100% - 38px)) !important;
}

/* ----------------------------------------------------------------------
   03 | Tipografia territorial
   ---------------------------------------------------------------------- */
.tv2-page h1,
.tv2-page h2,
.tv2-page h3,
.tv2-public-page h1,
.tv2-public-page h2,
.tv2-public-page h3 {
    color: var(--tv2-civic-ink);
    text-wrap: balance;
    letter-spacing: -.024em;
}

.tv2-page h1,
.tv2-public-page h1 {
    font-weight: 900;
}

.tv2-page h2,
.tv2-public-page h2 {
    font-weight: 850;
}

.tv2-page p,
.tv2-page li,
.tv2-public-page p,
.tv2-public-page li {
    color: var(--tv2-civic-text);
}

.tv2-section-kicker,
.tv2-kicker,
.tv2-hv-public-kicker {
    letter-spacing: .075em;
    font-weight: 900;
}

/* ----------------------------------------------------------------------
   04 | Ritmo vertical e hierarquia
   ---------------------------------------------------------------------- */
.tv2-page .tv2-shell {
    padding-bottom: 64px;
}

.tv2-page .tv2-container > section,
.tv2-page .tv2-container > .tv2-glass {
    scroll-margin-top: 96px;
}

.tv2-page .tv2-container > section + section,
.tv2-page .tv2-container > section + .tv2-glass,
.tv2-page .tv2-container > .tv2-glass + section {
    margin-top: 20px;
}

/* ----------------------------------------------------------------------
   05 | Botões, chips e ações
   ---------------------------------------------------------------------- */
.tv2-button,
.tv2-public-nav a,
.tv2-hv-public-actions a {
    min-height: 42px;
    border-radius: 999px;
    font-weight: 850;
    letter-spacing: -.01em;
}

.tv2-button--glass,
body[data-theme="dark"] .tv2-button--glass,
.theme-dark .tv2-button--glass {
    color: #31415f !important;
    border-color: rgba(94, 113, 163, .18) !important;
    background: rgba(255, 255, 255, .78) !important;
    box-shadow: 0 9px 22px rgba(55, 73, 118, .055);
}

.tv2-button--glass:hover,
.tv2-button--glass:focus-visible {
    color: #213457 !important;
    border-color: rgba(69, 103, 242, .28) !important;
    background: rgba(255, 255, 255, .96) !important;
    box-shadow: 0 14px 30px rgba(55, 73, 118, .10);
}

.tv2-button--primary {
    border: 1px solid rgba(255, 255, 255, .18) !important;
    background: linear-gradient(135deg, #7658e8, #4567f2 58%, #2791d5) !important;
    box-shadow: 0 14px 30px rgba(80, 85, 205, .22) !important;
}

.tv2-button--primary:hover,
.tv2-button--primary:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 18px 36px rgba(80, 85, 205, .27) !important;
}

/* ----------------------------------------------------------------------
   06 | Cards secundários unificados
   ---------------------------------------------------------------------- */
.tv2-region-city,
.tv2-regional-card,
.tv2-temporal-marker__body,
.tv2-temporal-public-panel,
.tv2-regional-public-cards > a,
.tv2-regional-public-city-grid > article,
.tv2-hv-public-panel,
.tv2-hv-public-strip article,
.tv2-hv-public-cycle article,
.tv2-hv-signal,
.tv2-hv-institutional article {
    border-color: var(--tv2-civic-line) !important;
    background: rgba(255, 255, 255, .82) !important;
    box-shadow: 0 12px 32px rgba(55, 73, 118, .055);
}

.tv2-regional-card,
.tv2-region-city,
.tv2-temporal-marker__body {
    transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease;
}

.tv2-regional-card:hover,
.tv2-region-city:hover,
.tv2-temporal-marker__body:hover {
    transform: translateY(-2px);
    border-color: rgba(94, 105, 213, .24) !important;
    box-shadow: var(--tv2-civic-shadow-hover) !important;
}

/* ----------------------------------------------------------------------
   07 | Formularios e busca
   ---------------------------------------------------------------------- */
.tv2-page label > span,
.tv2-page fieldset legend,
.tv2-public-page label > span {
    color: var(--tv2-civic-ink);
    font-weight: 850;
}

.tv2-page input:focus,
.tv2-page select:focus,
.tv2-page textarea:focus {
    outline: none !important;
    border-color: rgba(69, 103, 242, .48) !important;
    box-shadow: var(--tv2-civic-focus) !important;
    background: #fff !important;
}

.tv2-page button:focus-visible,
.tv2-page a:focus-visible,
.tv2-public-page button:focus-visible,
.tv2-public-page a:focus-visible {
    outline: 3px solid rgba(69, 103, 242, .27) !important;
    outline-offset: 3px;
}

/* ----------------------------------------------------------------------
   08 | Navegação pública
   ---------------------------------------------------------------------- */
.tv2-public-nav,
.tv2-hv-public-nav {
    border: 1px solid rgba(94, 113, 163, .14);
    background: rgba(255, 255, 255, .86) !important;
    box-shadow: 0 12px 34px rgba(55, 73, 118, .07);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.tv2-hv-public-nav > a,
.tv2-hv-public-nav nav a,
.tv2-public-nav a {
    color: var(--tv2-civic-ink) !important;
}

/* ----------------------------------------------------------------------
   09 | Atlas Vivo, mapa territorial
   ---------------------------------------------------------------------- */
.tv2-map-panel {
    position: relative;
    overflow: hidden;
    padding: 24px;
    border-radius: var(--tv2-civic-radius-lg);
}

.tv2-map-panel::before {
    content: "";
    position: absolute;
    width: 420px;
    height: 420px;
    right: -180px;
    top: -220px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(30, 167, 197, .11), transparent 69%);
    pointer-events: none;
}

.tv2-map-panel__head {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 16px;
}

.tv2-map-panel__head > div:first-child {
    max-width: 820px;
}

.tv2-map-panel__head h2 {
    margin: 4px 0 6px;
}

.tv2-map-panel__head p {
    margin: 0;
    color: var(--tv2-civic-muted);
    line-height: 1.6;
}

.tv2-map-panel__legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 7px;
}

.tv2-map-panel__legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid rgba(94, 113, 163, .15);
    border-radius: 999px;
    color: #586782;
    background: rgba(255, 255, 255, .76);
    font-size: .72rem;
    font-weight: 780;
}

.tv2-map-panel__legend .material-icons {
    color: #6b76a8;
    font-size: 15px;
}

.tv2-map-panel__legend i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #7658e8;
    box-shadow: 0 0 0 4px rgba(118, 88, 232, .10);
}

.tv2-atlas-map {
    position: relative;
    z-index: 1;
    width: 100%;
    min-height: 390px;
    overflow: hidden;
    border: 1px solid rgba(82, 105, 157, .16);
    border-radius: 24px;
    background:
        radial-gradient(circle at 30% 25%, rgba(255, 255, 255, .94), transparent 30%),
        linear-gradient(145deg, #eef4fb, #f7fbff);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, .95) inset,
        0 18px 44px rgba(55, 73, 118, .08);
}

.tv2-atlas-map.is-compact {
    min-height: 310px;
}

.tv2-atlas-map .leaflet-control-zoom,
.tv2-atlas-map .leaflet-control-attribution {
    border: 0;
    box-shadow: 0 8px 22px rgba(41, 56, 91, .10);
}

.tv2-atlas-map .leaflet-control-zoom a {
    color: #31415f;
    border-color: #edf1f7;
    background: rgba(255, 255, 255, .94);
}

.tv2-atlas-map .leaflet-control-attribution {
    padding: 4px 8px;
    border-radius: 9px 0 0 0;
    color: #7a879e;
    background: rgba(255, 255, 255, .88);
    font-size: 10px;
}

.tv2-map-marker-shell {
    background: transparent !important;
    border: 0 !important;
}

.tv2-map-marker {
    position: relative;
    width: 22px;
    height: 22px;
    border: 4px solid #fff;
    border-radius: 50%;
    background: linear-gradient(145deg, #7b55e7, #4567f2);
    box-shadow:
        0 0 0 2px rgba(91, 89, 212, .24),
        0 8px 20px rgba(55, 69, 133, .28);
}

.tv2-map-marker::after {
    content: "";
    position: absolute;
    inset: -8px;
    border: 1px solid rgba(91, 89, 212, .20);
    border-radius: 50%;
    animation: tv2-map-pulse 2.8s ease-out infinite;
}

.tv2-atlas-map .leaflet-tooltip {
    padding: 9px 11px;
    border: 1px solid rgba(82, 105, 157, .16);
    border-radius: 12px;
    color: #263a60;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 12px 32px rgba(48, 63, 102, .12);
    font-size: 12px;
    font-weight: 760;
}

.tv2-map-fallback {
    display: none;
    min-height: 210px;
    place-items: center;
    padding: 28px;
    text-align: center;
}

.tv2-map-fallback.is-visible {
    display: grid;
}

.tv2-map-fallback .material-icons {
    display: block;
    margin-bottom: 8px;
    color: #7658e8;
    font-size: 34px;
}

.tv2-map-fallback strong {
    display: block;
    color: var(--tv2-civic-ink);
}

.tv2-map-fallback p {
    max-width: 620px;
    margin: 5px auto 0;
    color: var(--tv2-civic-muted);
}

.tv2-map-context {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.tv2-map-context article {
    padding: 12px 14px;
    border: 1px solid rgba(82, 105, 157, .13);
    border-radius: 15px;
    background: rgba(255, 255, 255, .64);
}

.tv2-map-context small {
    display: block;
    color: var(--tv2-civic-muted);
    font-size: .69rem;
}

.tv2-map-context strong {
    display: block;
    margin-top: 2px;
    color: var(--tv2-civic-ink);
    font-size: .92rem;
}

/* ----------------------------------------------------------------------
   10 | Harmonização de páginas recentes
   ---------------------------------------------------------------------- */
.tv2-temporal-hero,
.tv2-regional-hero,
.tv2-region-hero,
.tv2-hv-hero {
    border-radius: var(--tv2-civic-radius-xl) !important;
}

.tv2-region-stats article,
.tv2-region-city__stats span {
    border: 1px solid rgba(82, 105, 157, .10);
    background: rgba(250, 252, 255, .88) !important;
}

.tv2-region-trend,
.tv2-region-trend.is-empty {
    border-color: rgba(30, 167, 197, .13) !important;
    background: rgba(236, 250, 252, .62) !important;
}

.tv2-temporal-marker__dot {
    border-color: rgba(123, 85, 231, .20) !important;
    background: #fff !important;
    box-shadow: 0 8px 22px rgba(55, 73, 118, .08) !important;
}

/* ----------------------------------------------------------------------
   11 | Acessibilidade e movimento
   ---------------------------------------------------------------------- */
@keyframes tv2-map-pulse {
    0% { opacity: .68; transform: scale(.7); }
    70%, 100% { opacity: 0; transform: scale(1.55); }
}

@media (max-width: 900px) {
    .tv2-map-panel__head {
        align-items: flex-start;
        flex-direction: column;
    }
    .tv2-map-panel__legend {
        justify-content: flex-start;
    }
    .tv2-map-context {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 680px) {
    .tv2-page .tv2-container,
    .tv2-public-body .tv2-container,
    .tv2-hv-public-shell,
    .tv2-temporal-public-shell {
        width: min(100% - 22px, 1500px) !important;
    }
    .tv2-map-panel {
        padding: 16px;
        border-radius: 22px;
    }
    .tv2-atlas-map,
    .tv2-atlas-map.is-compact {
        min-height: 300px;
        border-radius: 18px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tv2-map-marker::after {
        animation: none !important;
    }
    .tv2-regional-card,
    .tv2-region-city,
    .tv2-temporal-marker__body,
    .tv2-button {
        transition: none !important;
    }
}
