/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f0f1a;
    --bg-surface: #171728;
    --bg-panel: #1e1e38;
    --bg-elevated: #252545;
    --text: #eaeaf0;
    --text-muted: #8888a0;
    --text-dim: #555570;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --accent-glow: rgba(233, 69, 96, 0.15);
    --border: #2a2a48;
    --border-light: #35355a;
    --success: #4ecca3;
    --warning: #ffc107;
    --shadow: 0 2px 12px rgba(0,0,0,0.4);
    --radius: 10px;
    --radius-sm: 6px;
}

html { font-size: 14px; scroll-behavior: smooth; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* === Header === */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1.5rem;
    background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg) 100%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
}
#header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.header-right { display: flex; align-items: center; gap: 1rem; }
.poll-filter {
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}
.poll-filter:hover, .poll-filter:focus { border-color: var(--accent); }
.poll-filter option { background: var(--bg-panel); color: var(--text); }

/* === Buttons === */
.btn {
    padding: 0.5rem 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: all 0.2s ease;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(233, 69, 96, 0.3);
}
.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px rgba(233, 69, 96, 0.4);
    transform: translateY(-1px);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-danger {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-danger:hover:not(:disabled) {
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent);
    border-color: var(--accent);
}
.btn-danger:active:not(:disabled) { transform: translateY(0); }
.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.15s;
}
.btn-close:hover { color: var(--text); background: var(--bg-elevated); }

/* === Tabs === */
.tab {
    padding: 0.4rem 0.9rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 500;
    transition: all 0.2s;
}
.tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    box-shadow: 0 2px 6px rgba(233, 69, 96, 0.25);
}
.tab:hover:not(.active) {
    border-color: var(--text-muted);
    color: var(--text);
}

/* === Layout === */
.top-section {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 1rem;
    padding: 1rem 1.5rem;
    min-height: 450px;
}
.middle-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 0 1.5rem 1rem;
}
.bottom-section {
    padding: 0 1.5rem 2rem;
}

/* === Card style (shared) === */
.map-container,
.control-panel,
.horseshoe-container,
.oevk-detail-panel {
    background: var(--bg-surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

/* === Map === */
.map-container {
    position: relative;
    overflow: hidden;
    min-height: 420px;
}
#map-svg {
    width: 100%;
    height: 100%;
    display: block;
    background: radial-gradient(ellipse at center, var(--bg-panel) 0%, var(--bg-surface) 70%);
}
#map-oevk path {
    stroke: rgba(255,255,255,0.55);
    stroke-width: 0.7;
    cursor: pointer;
    transition: filter 0.12s, stroke-width 0.12s;
}
#map-oevk path:hover {
    filter: brightness(1.3) saturate(1.2);
    stroke: rgba(255,255,255,0.9);
    stroke-width: 1.5;
}
#map-oevk path.selected {
    stroke: white;
    stroke-width: 2;
    filter: brightness(1.2);
}
#map-counties path {
    fill: none;
    stroke: rgba(255,255,255,0.08);
    stroke-width: 1.2;
    pointer-events: none;
}

/* === Tooltip === */
.tooltip {
    position: absolute;
    padding: 0.5rem 0.8rem;
    background: rgba(15, 15, 26, 0.95);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    pointer-events: none;
    z-index: 50;
    white-space: nowrap;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
}
.tooltip .tt-name { font-weight: 600; margin-bottom: 0.15rem; }
.tooltip .tt-winner { color: var(--success); font-weight: 600; }

/* === Control Panel === */
.control-panel {
    padding: 1rem 1.1rem;
    overflow-y: auto;
    max-height: 620px;
}
.panel-section {
    margin-bottom: 1.4rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.panel-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.panel-section h3 {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.7rem;
    color: var(--accent);
}

/* === Slider === */
.slider-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.slider-group input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
    height: 4px;
}
.slider-value {
    min-width: 3.5rem;
    text-align: right;
    font-weight: 700;
    font-size: 1.1rem;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}
.turnout-info { margin-top: 0.4rem; font-size: 0.78rem; color: var(--text-muted); }
.list-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.75rem; }

/* === List votes inputs === */
.list-vote-row {
    display: grid;
    grid-template-columns: 14px 1fr auto;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.35rem;
    font-size: 0.78rem;
}
.list-vote-row .party-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
}
.list-vote-row .party-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}
.list-vote-row input[type="number"] {
    width: 110px;
    padding: 0.35rem 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
    transition: border-color 0.15s;
}
.list-vote-row input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* === Mandate Summary === */
#mandate-summary { font-size: 0.78rem; }
.mandate-row {
    display: grid;
    grid-template-columns: 14px 1fr 38px 38px 50px;
    gap: 0.4rem;
    align-items: center;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
}
.mandate-row:last-child { border-bottom: none; }
.mandate-row.header {
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.5rem;
    margin-bottom: 0.2rem;
}
.mandate-row .num { text-align: right; font-variant-numeric: tabular-nums; }
.mandate-total { font-weight: 800; color: var(--accent); font-size: 0.9rem; }

/* === Horseshoe === */
.horseshoe-container {
    padding: 1.25rem;
    text-align: center;
}
#horseshoe-svg { width: 100%; max-height: 300px; }
#horseshoe-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem 1rem;
    margin-top: 0.8rem;
    font-size: 0.78rem;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.5rem;
    background: var(--bg-panel);
    border-radius: 20px;
    font-weight: 500;
}
.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
}

/* === OEVK Detail Panel === */
.oevk-detail-panel {
    padding: 1rem 1.1rem;
    overflow-y: auto;
    max-height: 400px;
}
.oevk-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.oevk-detail-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
}

/* === Candidate row in OEVK detail === */
.candidate-row {
    display: grid;
    grid-template-columns: 14px 1fr 80px 55px;
    gap: 0.5rem;
    align-items: center;
    padding: 0.45rem 0.3rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    border-radius: 4px;
    margin-bottom: 1px;
}
.candidate-row.winner {
    background: rgba(78, 204, 163, 0.08);
    border-left: 3px solid var(--success);
    padding-left: 0.5rem;
}
.candidate-name { font-weight: 600; }
.candidate-party { color: var(--text-muted); font-size: 0.72rem; }
.candidate-row input[type="number"] {
    width: 100%;
    padding: 0.3rem 0.4rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.8rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    transition: border-color 0.15s;
}
.candidate-row input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}
.candidate-pct {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--text-muted);
}

/* === Tables === */
.table-tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; }
.table-container { display: none; }
.table-container.active { display: block; }
.table-container {
    max-height: 500px;
    overflow-y: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.table-container table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    background: var(--bg-surface);
}
.table-container th,
.table-container td {
    padding: 0.55rem 0.7rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.table-container th {
    background: var(--bg-panel);
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 2;
}
.table-container th:hover { color: var(--text); }
.table-container td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.table-container tr { transition: background 0.1s; }
.table-container tbody tr:hover { background: rgba(233, 69, 96, 0.04); }
.table-container tbody tr:nth-child(even) { background: rgba(255,255,255,0.01); }
.table-container tbody tr:nth-child(even):hover { background: rgba(233, 69, 96, 0.04); }

/* === Party color dot (shared) === */
.party-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
    flex-shrink: 0;
}

/* === Utility === */
.hidden { display: none !important; }
.text-right { text-align: right; }

/* === Responsive === */
@media (max-width: 1100px) {
    .top-section { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
    .top-section {
        grid-template-columns: 1fr;
        min-height: auto;
    }
    .middle-section { grid-template-columns: 1fr; }
    .map-container { min-height: 280px; }
    .control-panel { max-height: none; }
    #header {
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
        gap: 0.4rem;
    }
    #header h1 { font-size: 1rem; }
    .header-right {
        flex-wrap: wrap;
        gap: 0.4rem;
    }
    .top-section, .middle-section, .bottom-section { padding-left: 0.75rem; padding-right: 0.75rem; }
    .btn { font-size: 0.75rem; padding: 0.4rem 0.8rem; }
    #btn-auto-fill, #btn-reset, .poll-filter { display: none; }
    #btn-live { order: -1; }
}
@media (max-width: 500px) {
    .header-right { flex-direction: row; flex-wrap: wrap; gap: 0.3rem; }
    .candidate-row { grid-template-columns: 10px 1fr 60px 45px; gap: 0.3rem; }
    .list-vote-row input[type="number"] { width: 80px; }
    .live-view-tabs { flex-wrap: wrap; }
    .live-view-tabs .tab { flex: 1; text-align: center; min-width: 0; padding: 0.3rem 0.4rem; font-size: 0.68rem; }
    .live-turnout-tile .tile-value { font-size: 1rem; }
    .mandate-row { grid-template-columns: 10px 1fr 30px 30px 40px; gap: 0.25rem; font-size: 0.72rem; }
    .list-vote-row { font-size: 0.72rem; }
    .list-vote-row .num { font-size: 0.72rem; }
}

/* === Loading === */
#loading-indicator {
    color: var(--accent);
    font-size: 0.82rem;
    font-weight: 500;
    animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* === Selection highlight on map === */
#map-svg .selected-oevk {
    stroke: white !important;
    stroke-width: 2.5 !important;
    filter: drop-shadow(0 0 6px rgba(255,255,255,0.4));
}

/* === Live mode === */
#btn-live {
    position: relative;
}
#btn-live.active {
    background: var(--success);
    color: #0a1a14;
    border-color: var(--success);
}
#btn-live.active::before {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 7px;
    height: 7px;
    background: #ff3838;
    border-radius: 50%;
    box-shadow: 0 0 6px #ff3838;
    animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

#live-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    margin-bottom: 0.8rem;
    box-shadow: var(--shadow);
}
#live-panel.hidden { display: none; }

.live-status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.6rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
}
.live-status-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.live-source-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.live-source-badge.napkozi { background: rgba(78, 204, 163, 0.18); color: var(--success); }
.live-source-badge.szavossz { background: rgba(233, 69, 96, 0.2); color: var(--accent); }
.live-source-badge.none { background: var(--bg-elevated); color: var(--text-dim); }

.live-controls { display: flex; gap: 0.4rem; align-items: center; }
.live-controls .btn { padding: 0.3rem 0.7rem; font-size: 0.72rem; }
.live-last-update {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.live-error {
    color: #ff8888;
    font-size: 0.72rem;
    padding: 0.3rem 0.5rem;
    background: rgba(255, 56, 56, 0.1);
    border-radius: var(--radius-sm);
    margin-top: 0.3rem;
}

.live-turnout-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}
.live-turnout-tile {
    background: var(--bg-elevated);
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.live-turnout-tile .tile-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.live-turnout-tile .tile-value {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    margin-top: 0.1rem;
}
.live-turnout-tile .tile-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.live-events-details {
    margin-bottom: 0.5rem;
}
.live-events-details summary {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.3rem 0;
    user-select: none;
}
.live-events-details summary:hover { color: var(--text); }
.live-events-details summary span { color: var(--warning); }
#live-events-list {
    max-height: 160px;
    overflow-y: auto;
    font-size: 0.75rem;
    margin-top: 0.3rem;
}
#live-events-list:empty::after {
    content: 'Nincs rendkivuli esemeny.';
    display: block;
    color: var(--text-dim);
    font-style: italic;
    text-align: center;
    padding: 0.4rem 0;
}
.live-event-item {
    padding: 0.4rem 0.5rem;
    border-left: 3px solid var(--warning);
    background: var(--bg-elevated);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin-bottom: 0.3rem;
}
.live-event-item .ev-time {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.live-event-item .ev-text {
    color: var(--text);
    margin-top: 0.15rem;
}
.live-event-item .ev-loc {
    color: var(--accent);
    font-weight: 600;
    font-size: 0.8rem;
}
.live-event-item .ev-action {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 0.2rem;
    font-style: italic;
}

/* Map view-mode toggle (turnout heat vs winners) */
.live-view-tabs { display: flex; gap: 0.3rem; margin-bottom: 0.5rem; }
.live-view-tabs .tab {
    padding: 0.3rem 0.7rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.15s;
}
.live-view-tabs .tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.live-view-tabs .tab:hover:not(.active) { color: var(--text); }
