/* ===========================================
   PDG Voting Analysis - Styles
   Partido de la Gente - Distrito 7
   =========================================== */

/* CSS Variables - PDG Brand Colors */
:root {
    --pdg-primary: #1a365d;
    --pdg-primary-light: #2c5282;
    --pdg-primary-dark: #002b36;
    --pdg-accent: #00d2ff;
    --pdg-accent-light: #63b3ed;

    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --bg-surface: #0f172a;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.15);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.15);

    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Political Spectrum Colors */
    --color-pdg: #00d2ff;
    --color-left: #ff4d4d;
    --color-right: #4d79ff;
    --color-neutral: #94a3b8;
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--pdg-primary) 0%, var(--pdg-primary-dark) 100%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    width: 56px;
    height: 56px;
    object-fit: contain;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.title-section h1 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #fff 0%, var(--pdg-accent-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
}

.nav-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.selector {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    min-width: 200px;
}

.selector:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.selector:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--pdg-accent);
}

.selector option {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* Main Content */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    border: 1px solid var(--border);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--pdg-accent) 0%, var(--pdg-accent-light) 100%);
    opacity: 0;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--pdg-accent);
}

.stat-card:hover::before {
    opacity: 1;
}

.stat-card.primary {
    background: linear-gradient(135deg, var(--pdg-primary) 0%, var(--pdg-primary-dark) 100%);
}

.stat-card.accent {
    background: linear-gradient(135deg, var(--pdg-accent) 0%, var(--pdg-primary) 100%);
}

.stat-icon {
    font-size: 2.5rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 0.25rem;
}

.stat-card.primary .stat-label,
.stat-card.accent .stat-label {
    color: rgba(255, 255, 255, 0.8);
}

/* Rankings Section */
.rankings-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.ranking-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 1.5rem;
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.6) 0%, rgba(15, 23, 42, 0.8) 100%);
    transition: var(--transition);
}

.ranking-card:hover {
    border-color: var(--pdg-accent);
    transform: translateY(-2px);
}

.ranking-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.75rem;
}

.ranking-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.ranking-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ranking-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius);
    transition: var(--transition);
}

.ranking-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.rank-badge {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 800;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.rank-1 {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.2);
}

.rank-2 {
    background: rgba(148, 163, 184, 0.2);
    color: #cbd5e1;
}

.rank-3 {
    background: rgba(200, 100, 50, 0.2);
    color: #fdba74;
}

.rank-info {
    display: flex;
    align-items: center;
    flex: 1;
}

.rank-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.rank-votes {
    font-weight: 700;
    color: var(--pdg-accent);
    font-size: 0.95rem;
}

/* Map Section */
.map-section {
    margin-bottom: 1rem;
}

.map-card {
    height: 600px;
    display: flex;
    flex-direction: column;
}

#map {
    flex: 1;
    z-index: 1;
    background: var(--bg-dark);
}

.map-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: flex-end;
}

.layer-toggles {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px;
    border-radius: var(--radius);
    gap: 4px;
}

.layer-btn {
    background: transparent;
    border: none;
    padding: 6px 12px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.layer-btn.active,
.layer-btn:hover {
    background: var(--pdg-primary);
    color: white;
}

.map-legend {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot.pdg {
    background: var(--color-pdg);
    box-shadow: 0 0 8px var(--color-pdg);
}

.dot.left {
    background: var(--color-left);
}

.dot.right {
    background: var(--color-right);
}

/* Strategy & Simulator */
.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.strategy-section {
    margin-bottom: 1rem;
}

/* Simulator Styles */
.simulator-card {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.simulator-controls {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sim-control {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sim-control label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.sim-control input[type="range"] {
    width: 100%;
    accent-color: var(--pdg-accent);
}

.sim-result {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
}

.sim-stat {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.9rem;
}

.positive {
    color: var(--success);
}

.warning {
    background: #f59e0b !important;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.4);
}

.strategy-grid {
    display: grid;
    grid-template-columns: 1fr;
    /* Stacked in 1 column inside grid-2-col */
    gap: 1rem;
}

.strategy-card {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.9) 100%);
    border-radius: var(--radius-lg);
    border: 1px solid var(--pdg-accent);
    padding: 2rem;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.strategy-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.ai-badge {
    padding: 0.4rem 1rem;
    border-radius: 999px;
    background: linear-gradient(90deg, #00d2ff 0%, #3a7bd5 100%);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    box-shadow: 0 0 15px rgba(0, 210, 255, 0.4);
}

.strategy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

.insight-item {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: var(--transition);
}

.insight-item:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateY(-5px);
    border-color: var(--color-pdg);
}

.insight-icon {
    font-size: 2rem;
    background: rgba(0, 210, 255, 0.1);
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 15px;
}

.insight-text h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--color-pdg);
}

.insight-text p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Charts Section */
.charts-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.chart-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.chart-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: var(--transition);
}

.chart-card:hover {
    border-color: var(--pdg-accent);
    box-shadow: var(--shadow);
}

.chart-card.large {
    grid-column: span 1;
}

.chart-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
}

.chart-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-badge {
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--success-bg);
    color: var(--success);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chart-container {
    padding: 1.5rem;
    height: 350px;
    position: relative;
}

.chart-container.pie {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Tables */
.table-section {
    margin-top: 1rem;
}

.table-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
}

.table-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
    flex-wrap: wrap;
    gap: 1rem;
}

.table-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.table-actions {
    display: flex;
    gap: 0.75rem;
}

.search-input {
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-primary);
    font-size: 0.875rem;
    min-width: 220px;
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--pdg-accent);
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.2);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 1rem 1.25rem;
    text-align: left;
}

th {
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

td {
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    transition: var(--transition);
}

tbody tr {
    transition: var(--transition);
}

tbody tr:hover {
    background: var(--bg-card-hover);
}

tbody tr:hover td {
    color: var(--text-primary);
}

.bar-col {
    min-width: 200px;
}

/* Progress Bar in Table */
.progress-bar {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--pdg-accent) 0%, var(--pdg-accent-light) 100%);
    border-radius: 999px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-value {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

/* Comuna Badge */
.comuna-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    background: rgba(49, 130, 206, 0.15);
    color: var(--pdg-accent-light);
    font-size: 0.8rem;
    font-weight: 500;
}

/* Custom Popup Styles */
.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.leaflet-popup-tip {
    background: var(--bg-card);
}

.popup-content h4 {
    margin-bottom: 0.5rem;
    color: var(--color-pdg);
}

.popup-stats {
    font-size: 0.8rem;
    display: grid;
    gap: 0.25rem;
}

.winner-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 700;
    margin-top: 5px;
}

.winner-badge.pdg {
    background: var(--color-pdg);
    color: var(--pdg-primary-dark);
}

.winner-badge.left {
    background: var(--color-left);
    color: white;
}

.winner-badge.right {
    background: var(--color-right);
    color: white;
}

/* Footer */
.footer {
    background: var(--pdg-primary-dark);
    border-top: 1px solid var(--border);
    padding: 2rem;
    margin-top: 3rem;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    text-align: center;
}

.footer-logo {
    width: 40px;
    height: 40px;
    opacity: 0.8;
}

.footer p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.footer-note {
    font-size: 0.75rem !important;
    color: var(--text-muted) !important;
}

/* Responsive */
@media (max-width: 768px) {
    .header-content {
        padding: 1rem;
    }

    .title-section h1 {
        font-size: 1.25rem;
    }

    .main-content {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .chart-row {
        grid-template-columns: 1fr;
    }

    .selector {
        min-width: 150px;
    }

    th,
    td {
        padding: 0.75rem;
    }

    .search-input {
        min-width: 150px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .logo-section {
        flex-direction: column;
        text-align: center;
    }

    .table-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .stat-value {
        font-size: 1.5rem;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-card,
.chart-card,
.table-card {
    animation: fadeIn 0.5s ease-out forwards;
}

.chart-card:nth-child(2) {
    animation-delay: 0.1s;
}

.chart-card:nth-child(3) {
    animation-delay: 0.2s;
}

.chart-card:nth-child(4) {
    animation-delay: 0.3s;
}

/* Loading State */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
}

.loading::after {
    content: '';
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--pdg-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}