:root[data-theme="light"] {
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --navbar-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --footer-bg: #ffffff;
    --shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    --select-arrow: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23212529' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2%205%206%206%206-6'/%3e%3c/svg%3e");
}

:root[data-theme="dark"] {
    --bg-primary: #0f1026;
    --bg-secondary: #1a1d29;
    --bg-card: #1e2235;
    --text-primary: #e4e6eb;
    --text-secondary: #b0b3b8;
    --border-color: #2d3748;
    --navbar-bg: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    --footer-bg: #1e2235;
    --shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.4);
    --select-arrow: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23e4e6eb' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2%205%206%206%206-6'/%3e%3c/svg%3e");
}

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

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

.navbar {
    background: var(--navbar-bg) !important;
    box-shadow: var(--shadow);
    padding: 1rem 0;
}

.navbar-brand {
    color: white !important;
    font-weight: 700;
    font-size: 1.5rem;
}

.btn-theme {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-theme:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(20deg);
}

.card, .card-body, .modal-content {
    color: var(--text-primary);
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.75rem 1.5rem rgba(0, 0, 0, 0.2);
}

.card-header {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
}

.card-header h4 {
    color: var(--text-primary);
    margin: 0;
}

.form-control {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.6rem 0.9rem;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.input-group-text {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
    font-weight: 700;
}

.form-control:focus {
    background: var(--bg-secondary);
    border-color: #667eea;
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

.form-select {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.6rem 2.25rem 0.6rem 0.9rem;
    border-radius: 8px;
    background-image: var(--select-arrow);
    background-repeat: no-repeat;
    background-position: right 0.9rem center;
    background-size: 14px 10px;
    transition: all 0.3s ease;
}

.form-select:focus {
    background-color: var(--bg-secondary);
    border-color: #667eea;
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

.form-select option {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.form-label {
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.candidate-card {
    border: 2px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.candidate-card:hover {
    transform: scale(1.02);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.2);
}

.candidate-card.selected {
    border-color: #28a745;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.3);
}

.candidate-header {
    color: white;
    padding: 0.8rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.candidate-number {
    background: rgba(255, 255, 255, 0.3);
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1.2rem;
}

.candidate-body {
    background: var(--bg-secondary);
}

.candidate-icon {
    font-size: 3rem;
    color: var(--text-secondary);
}

.candidate-photo {
    width: 104px;
    height: 130px;
    object-fit: cover;
    border-radius: 12px;
    border: 3px solid var(--border-color);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.candidate-card:hover .candidate-photo {
    transform: scale(1.04);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.38);
}

.candidate-radio {
    position: absolute;
    opacity: 0;
}

.btn-vote {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    padding: 0.8rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 50px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-vote:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
    color: white;
}

.result-bar {
    animation: slideIn 0.5s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.result-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.result-name {
    font-weight: 600;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.result-avatar {
    width: 34px;
    height: 42px;
    object-fit: cover;
    border-radius: 7px;
    border: 2px solid var(--border-color);
}

.result-values {
    color: var(--text-secondary);
    font-weight: 600;
}

.result-progress {
    height: 35px;
    background: var(--bg-secondary);
    border-radius: 50px;
    overflow: hidden;
}

.progress-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    transition: width 1s ease;
}

.progress-animate {
    animation: growBar 1s ease;
}

@keyframes growBar {
    from {
        width: 0 !important;
    }
}

.footer {
    background: var(--footer-bg);
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.text-muted {
    color: var(--text-secondary) !important;
}

.alert {
    border-radius: 10px;
    border: none;
}

#mapBrasil {
    border-radius: 10px;
    overflow: hidden;
}

@media (max-width: 768px) {
    .result-info {
        flex-direction: column;
        gap: 0.3rem;
    }
    
    .candidate-header {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ============ Cores dos candidatos ============ */
:root {
    --cand-22: #0d6efd;
    --cand-22-soft: rgba(13, 110, 253, 0.18);
    --cand-13: #dc3545;
    --cand-13-soft: rgba(220, 53, 69, 0.18);
}

.bg-cand-22 { background: linear-gradient(135deg, #0d6efd, #0a58ca) !important; color: #fff !important; }
.bg-cand-13 { background: linear-gradient(135deg, #dc3545, #b02a37) !important; color: #fff !important; }
.text-cand-22 { color: var(--cand-22) !important; }
.text-cand-13 { color: var(--cand-13) !important; }

.title-gradient {
    background: linear-gradient(90deg, #0d6efd, #764ba2, #dc3545);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.cand-pill {
    display: inline-block;
    padding: 0.35rem 1rem;
    border-radius: 50px;
    font-weight: 700;
    color: #fff;
    font-size: 1.05rem;
    box-shadow: var(--shadow);
}
.cand-pill-22 { background: linear-gradient(135deg, #0d6efd, #0a58ca); }
.cand-pill-13 { background: linear-gradient(135deg, #dc3545, #b02a37); }

.live-dot {
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.live-dot span {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #20c997;
    box-shadow: 0 0 0 0 rgba(32, 201, 151, 0.7);
    animation: pulse 1.6s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(32, 201, 151, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(32, 201, 151, 0); }
    100% { box-shadow: 0 0 0 0 rgba(32, 201, 151, 0); }
}

.update-badge {
    font-size: 0.8rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    padding: 0.2rem 0.7rem;
    white-space: nowrap;
}

.qr-box {
    background: #fff;
    border-radius: 14px;
    padding: 14px;
    display: inline-flex;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}
.qr-box img, .qr-box canvas { display: block; }

.map-brasil {
    height: 430px;
    border-radius: 10px;
    background: var(--bg-secondary);
    z-index: 1;
}
.leaflet-container { background: transparent !important; font-family: inherit; }
.map-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem 0.2rem;
    flex-wrap: wrap;
    font-size: 0.78rem;
    color: var(--text-secondary);
}
.map-legend .lg-box {
    width: 22px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}

.ranking-list { max-height: 480px; overflow-y: auto; }
.ranking-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border-color);
    animation: slideIn 0.4s ease;
}
.ranking-item:last-child { border-bottom: none; }
.ranking-uf { font-weight: 700; min-width: 42px; }
.ranking-bars { display: flex; align-items: center; gap: 0.35rem; flex: 1; }
.ranking-bar {
    height: 8px;
    border-radius: 20px;
    min-width: 3px;
    transition: width 0.8s ease;
}
.ranking-bar.b22 { background: var(--cand-22); }
.ranking-bar.b13 { background: var(--cand-13); }
.ranking-total { font-size: 0.78rem; color: var(--text-secondary); white-space: nowrap; }

.chart-wrap { position: relative; width: 100%; }

.total-flash.flash { animation: flashNumber 0.9s ease; }
@keyframes flashNumber {
    0% { color: #20c997; transform: scale(1.4); display: inline-block; }
    100% { color: inherit; transform: scale(1); display: inline-block; }
}

.fade-up { animation: fadeUp 0.55s ease both; }
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

.changed { animation: changedGlow 0.8s ease; }
@keyframes changedGlow {
    0% { background: rgba(32, 201, 151, 0.28); }
    100% { background: transparent; }
}

/* ============ Admin ============ */
.admin-nav .nav-link { color: rgba(255, 255, 255, 0.85); font-weight: 600; }
.admin-nav .nav-link.active, .admin-nav .nav-link:hover { color: #fff; }

.kpi-card {
    position: relative;
    border-left: 5px solid transparent;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.kpi-photo {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 48px;
    height: 62px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    opacity: 0.95;
}
.kpi-card:hover { transform: translateY(-3px); }
.kpi-card.b22 { border-left-color: var(--cand-22); }
.kpi-card.b13 { border-left-color: var(--cand-13); }
.kpi-card.bpix { border-left-color: #20c997; }
.kpi-card.bpend { border-left-color: #ffc107; }
.kpi-label { color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.kpi-value { font-size: 1.9rem; font-weight: 800; line-height: 1.1; }

.table-enquete { color: var(--text-primary); margin-bottom: 0; }
.table-enquete th {
    color: var(--text-secondary);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-color: var(--border-color);
    background: var(--bg-secondary);
}
.table-enquete td { border-color: var(--border-color); vertical-align: middle; }
.table-enquete tbody tr { transition: background 0.3s ease; }
.table-enquete tbody tr:hover { background: var(--bg-secondary); }

.badge-status { font-size: 0.72rem; padding: 0.35em 0.65em; border-radius: 50px; }
.badge-pago { background: rgba(32, 201, 151, 0.18); color: #20c997; }
.badge-pendente { background: rgba(255, 193, 7, 0.18); color: #d39e00; }
.badge-expirado, .badge-cancelado { background: rgba(108, 117, 125, 0.2); color: var(--text-secondary); }

.pix-result { display: none; }
.pix-result.show { display: block; animation: fadeUp 0.4s ease; }
.pix-copia {
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
    font-weight: 500;
    word-break: break-all;
    color: var(--text-primary) !important;
    background: var(--bg-primary);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    padding: 0.7rem;
    max-height: 110px;
    overflow-y: auto;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.4rem;
}
.status-dot.on { background: #20c997; animation: pulse 1.8s infinite; }
.status-dot.off { background: #dc3545; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; }

.toast-box {
    position: fixed;
    top: 84px;
    right: 18px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-width: 340px;
}
.toast-item {
    color: #fff;
    padding: 0.8rem 1rem;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.28);
    font-weight: 600;
    animation: toastIn 0.35s ease;
}
.toast-success { background: #198754; }
.toast-warning { background: #b58100; }
.toast-danger { background: #b02a37; }
.toast-out { animation: toastOut 0.35s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(30px); } }

.map-tooltip {
    background: #111827 !important;
    color: #f8f9fa !important;
    border: none !important;
    border-radius: 8px !important;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35) !important;
    padding: 8px 10px !important;
}
.map-tooltip::before { border-top-color: #111827 !important; }
.map-tip { font-size: 0.82rem; line-height: 1.35; }

.kpi-value.flash, .ranking-uf.flash, .flash-value { animation: flashNumber 0.9s ease; }

/* Foto nos KPIs do admin: evita sobreposição do texto */
.kpi-photo ~ .card-body { padding-right: 72px; }

@media (max-width: 575.98px) {
    .kpi-photo { width: 38px; height: 50px; top: 10px; right: 10px; }
    .kpi-photo ~ .card-body { padding-right: 54px; }
    .kpi-value { font-size: 1.5rem; }
    .candidate-photo { width: 88px; height: 110px; }
    .result-avatar { width: 28px; height: 34px; }
}

/* ============ 2º Turno + anéis de progresso nas fotos ============ */
.badge-turno {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.42rem 1.15rem;
    border-radius: 50px;
    background: linear-gradient(135deg, #f7b733 0%, #fc4a1a 100%);
    color: #fff;
    font-weight: 800;
    font-size: 0.86rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    box-shadow: 0 6px 18px rgba(252, 74, 26, 0.35);
    animation: turnoGlow 2.6s ease-in-out infinite;
}
.badge-turno-sm {
    font-size: 0.62rem;
    padding: 0.25rem 0.7rem;
    vertical-align: middle;
    letter-spacing: 0.06em;
}
@keyframes turnoGlow {
    0%, 100% { box-shadow: 0 6px 18px rgba(252, 74, 26, 0.35); }
    50% { box-shadow: 0 6px 26px rgba(247, 183, 51, 0.65); }
}

.duel-wrap {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: clamp(1.2rem, 7vw, 4.5rem);
    margin-bottom: 1.8rem;
}
.duel-item { text-align: center; }
.duel-vs {
    align-self: center;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-secondary);
    opacity: 0.7;
}
.duel-name {
    margin-top: 0.65rem;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}
.duel-perc {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-secondary);
    line-height: 1.1;
}

.photo-ring {
    position: relative;
    width: 142px;
    height: 142px;
    margin: 0 auto;
}
.ring-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    overflow: visible;
}
.ring-bg {
    fill: none;
    stroke: var(--border-color);
    stroke-width: 8;
}
.ring-fill {
    fill: none;
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.9s cubic-bezier(0.25, 0.9, 0.3, 1), stroke-opacity 0.3s ease;
}
.ring-fill-22 {
    stroke: #0d6efd;
    filter: drop-shadow(0 0 5px rgba(13, 110, 253, 0.55));
}
.ring-fill-13 {
    stroke: #dc3545;
    filter: drop-shadow(0 0 5px rgba(220, 53, 69, 0.55));
}
.ring-photo {
    position: absolute;
    inset: 12px;
    width: calc(100% - 24px);
    height: calc(100% - 24px);
    border-radius: 50%;
    object-fit: cover;
    object-position: center 18%;
    border: 3px solid var(--bg-card);
    background: var(--bg-secondary);
}
.ring-number {
    position: absolute;
    right: 1px;
    bottom: 1px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 800;
    border: 2px solid var(--bg-card);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.ring-perc-line {
    margin: 0.6rem 0 0;
    font-size: 0.84rem;
    color: var(--text-secondary);
}
.ring-perc-line strong { color: var(--text-primary); }

/* Botão Atualizar PIX - sempre visível */
.btn-pix-atualizar {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%) !important;
    border: none !important;
    color: #ffffff !important;
    font-weight: 600 !important;
    box-shadow: 0 0.25rem 0.6rem rgba(34, 197, 94, 0.25) !important;
    padding: 0.35rem 0.9rem !important;
}

.btn-pix-atualizar:hover,
.btn-pix-atualizar:focus,
.btn-pix-atualizar:active {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%) !important;
    color: #ffffff !important;
    box-shadow: 0 0.4rem 0.9rem rgba(34, 197, 94, 0.35) !important;
}

.btn-pix-atualizar i {
    color: #ffffff !important;
}

/* Destaque ao selecionar candidato */
#formVoto .candidate-card {
    transition: all 0.25s ease-in-out !important;
    position: relative !important;
    overflow: visible !important;
}

#formVoto .candidate-card.selected {
    border: 6px solid #22c55e !important;
    box-shadow: 0 0 0 10px rgba(34, 197, 94, 0.32), 0 2rem 4rem rgba(34, 197, 94, 0.4) !important;
    transform: translateY(-12px) !important;
    z-index: 99999 !important;
    background-color: rgba(34, 197, 94, 0.08) !important;
    filter: brightness(1.05) !important;
}

/* Ícone QRCode visível nos dois temas */
.btn-qr-pix {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    padding: 0.25rem 0.5rem !important;
    opacity: 1 !important;
}

.btn-qr-pix:hover,
.btn-qr-pix:focus,
.btn-qr-pix:active {
    background: rgba(102, 126, 234, 0.14) !important;
    border-color: #667eea !important;
    color: var(--text-primary) !important;
}

.btn-qr-pix i {
    color: var(--text-primary) !important;
    opacity: 1 !important;
}

@media (max-width: 575.98px) {
    .photo-ring { width: 112px; height: 112px; }
    .ring-number { width: 27px; height: 27px; font-size: 0.75rem; }
    .duel-name { font-size: 0.85rem; }
    .duel-perc { font-size: 1.1rem; }
    .duel-vs { font-size: 1.2rem; }
    #formVoto .candidate-card.selected {
        transform: translateY(-6px) !important;
    }
}
