:root {
    /* Brand Colors */
    --dmk-primary: #C71B26; /* Maroon/Red */
    --dmk-secondary: #1A1A1A; /* Black */
    --dmk-light: #fce8ea;
    
    --tvk-primary: #FFD700; /* Yellow */
    --tvk-secondary: #D40000; /* Red */
    --tvk-light: #fffbea;
    
    --admk-primary: #008000; /* Green */
    --admk-light: #e6f2e6;
    
    --ntk-primary: #FF9933; /* BJP Saffron */
    
    --bg-main: #f5f7fa;
    --bg-surface: #ffffff;
    
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    --border-color: #e2e8f0;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Outfit', sans-serif;
}

/* Header */
.main-header {
    background-color: #0f172a;
    color: white;
    padding: 2rem 2rem 0;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 2rem;
}

.eyebrow {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    display: block;
    margin-bottom: 0.5rem;
}

.header-titles h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-meta {
    display: flex;
    gap: 2rem;
    text-align: right;
}

.meta-item {
    display: flex;
    flex-direction: column;
}

.meta-label {
    font-size: 0.75rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.meta-value {
    font-size: 1.25rem;
    font-weight: 600;
    font-family: 'Outfit', sans-serif;
}

/* Tabs */
.tabs {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    gap: 2rem;
    border-bottom: 1px solid #334155;
}

.tab-btn {
    background: none;
    border: none;
    color: #94a3b8;
    padding: 1rem 0;
    font-size: 1rem;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    position: relative;
    transition: color 0.2s ease;
}

.tab-btn:hover {
    color: white;
}

.tab-btn.active {
    color: white;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: #3b82f6;
    border-radius: 3px 3px 0 0;
}

/* Main Layout */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

.tab-content {
    position: absolute;
    top: -99999px;
    left: -99999px;
    width: 100%;
    height: 0;
    overflow: hidden;
    opacity: 0;
}

.tab-content.active {
    position: static;
    height: auto;
    overflow: visible;
    opacity: 1;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-title {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.kpi-value {
    font-size: 2.25rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
    line-height: 1.2;
}

.kpi-value.highlight {
    color: #0f172a;
}

.kpi-sub {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.kpi-card.winner-card {
    border-left: 4px solid transparent;
}

.kpi-card.winner-card.dmk {
    border-left-color: var(--dmk-primary);
    background: linear-gradient(to right, var(--dmk-light), #fff 20%);
}
.kpi-card.winner-card.dmk .kpi-value {
    color: var(--dmk-primary);
}

.kpi-card.winner-card.tvk {
    border-left-color: var(--tvk-primary);
    background: linear-gradient(to right, var(--tvk-light), #fff 20%);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.dashboard-grid.full {
    grid-template-columns: 1fr;
}

/* Panels */
.panel {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.panel-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.panel-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.panel-body {
    padding: 1.5rem;
}

.chart-container {
    height: 350px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Explorer Tools */
.explorer-header {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 1rem;
}

.filters {
    display: flex;
    gap: 1rem;
    flex: 1;
    justify-content: flex-end;
}

.search-input, .select-input {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s ease;
}

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

.search-input:focus, .select-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    background-color: #f8fafc;
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    position: relative;
    white-space: nowrap;
}

.data-table th:hover {
    color: var(--text-primary);
}

.data-table th::after {
    content: '↕';
    position: absolute;
    right: 0.5rem;
    opacity: 0.3;
}

.data-table th.asc::after { content: '↑'; opacity: 1; }
.data-table th.desc::after { content: '↓'; opacity: 1; }
.data-table th:not([data-sort])::after { content: ''; }

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.data-table tbody tr:hover {
    background-color: #f8fafc;
}

.data-table th.num, .data-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.data-table th.center, .data-table td.center {
    text-align: center;
}

/* Colors in Tables */
.dmk-col { color: var(--dmk-primary); font-weight: 500; }
.tvk-col { color: #b45309; font-weight: 500; } /* Darker yellow/orange for readability */
.admk-col { color: var(--admk-primary); font-weight: 500; }

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.dmk { background-color: var(--dmk-light); color: var(--dmk-primary); border: 1px solid rgba(199, 27, 38, 0.2); }
.badge.tvk { background-color: var(--tvk-light); color: #b45309; border: 1px solid rgba(255, 215, 0, 0.4); }
.badge.admk { background-color: var(--admk-light); color: var(--admk-primary); border: 1px solid rgba(0, 128, 0, 0.2); }
.badge.ntk { background-color: #fff3e6; color: var(--ntk-primary); border: 1px solid rgba(255, 153, 51, 0.3); }
.badge.tie { background-color: #f1f5f9; color: #64748b; }

/* Distribution Tab */
.stats-row {
    display: flex;
    justify-content: space-around;
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.stat-item {
    text-align: center;
}

.stat-val {
    font-size: 3rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-sub {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.stat-item.dmk .stat-val { color: var(--dmk-primary); }
.stat-item.tvk .stat-val { color: #b45309; }
.stat-item.admk .stat-val { color: var(--admk-primary); }

.distribution-bar {
    height: 40px;
    border-radius: 20px;
    display: flex;
    overflow: hidden;
    margin: 1rem 0;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.dist-segment {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    transition: width 0.5s ease;
}

.dist-segment.dmk { background-color: var(--dmk-primary); }
.dist-segment.tvk { background-color: var(--tvk-primary); color: #854d0e; }
.dist-segment.admk { background-color: var(--admk-primary); }

/* Utilities */
.text-success { color: #16a34a; }
.text-danger { color: #dc2626; }


.table-container {
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

/* Restructure Styles */
.hero-margin-card {
    background: linear-gradient(135deg, var(--dmk-primary), #90141c);
    color: white;
    border-radius: 12px;
    padding: 3rem;
    text-align: center;
    margin-bottom: 2rem;
    box-shadow: 0 10px 25px rgba(199, 27, 38, 0.2);
}
.hero-label {
    font-size: 1.25rem;
    font-weight: 500;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.hero-value {
    font-size: 5rem;
    font-weight: 800;
    margin: 1rem 0;
    text-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.hero-sub {
    font-size: 1.5rem;
    font-weight: 500;
}

.candidates-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.candidate-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.candidate-val {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.center-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
}
.head-to-head-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-bottom: 2rem;
}
.h2h-side {
    flex: 1;
    text-align: center;
}
.dmk-side { color: var(--dmk-primary); }
.tvk-side { color: var(--tvk-primary); }
.h2h-label { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }
.h2h-value { font-size: 3rem; font-weight: 800; }
.h2h-sub { font-size: 1rem; color: var(--text-muted); margin-top: 0.5rem; }
.h2h-divider {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-muted);
    margin: 0 2rem;
    opacity: 0.5;
}
.h2h-bar-container {
    width: 100%;
    height: 30px;
    background: var(--border-color);
    border-radius: 15px;
    display: flex;
    overflow: hidden;
    margin-top: 1rem;
}
.h2h-bar {
    height: 100%;
    transition: width 1s ease-out;
}
.dmk-bg { background-color: var(--dmk-primary); }
.tvk-bg { background-color: var(--tvk-primary); }

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .explorer-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .stats-row {
        flex-direction: column;
        gap: 2rem;
    }
    
    .tabs {
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 5px;
        -webkit-overflow-scrolling: touch;
    }

    .head-to-head-stats {
        flex-direction: column;
        gap: 1rem;
    }
    
    .h2h-value { font-size: 2rem; }
    .kpi-value { font-size: 1.75rem; }
    .hero-value { font-size: 3rem; }
    .h2h-divider { margin: 0.5rem 0; transform: rotate(90deg); }
    
    /* Top Header Overrides */
    .header-titles h1 { font-size: 1.5rem; line-height: 1.2; margin-top: 0.5rem; }
    .header-titles h2 { font-size: 0.8rem; }
    .eyebrow { font-size: 0.75rem; }
    
    .header-meta {
        flex-direction: row;
        justify-content: flex-start;
        gap: 1.5rem;
        text-align: left;
        width: 100%;
        margin-top: 0.5rem;
    }
    
    .container {
        padding: 0 1rem;
    }
    
    .main-header {
        padding: 1rem 1rem 0;
    }
    
    .filters {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-input, .select-input {
        min-width: 0;
        width: 100%;
    }
    
    .hero-margin-card {
        padding: 1.5rem;
    }
    
    /* Compact Tables for Mobile */
    .data-table th, 
    .data-table td {
        padding: 0.5rem 0.4rem;
        font-size: 0.75rem;
        white-space: nowrap;
    }

    .table-responsive {
        margin: 0 -1rem;
        padding: 0 1rem;
        width: calc(100% + 2rem);
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
}

/* Ensure no horizontal scroll on body */
body {
    overflow-x: hidden;
}

/* PDF Export Button Styling */
.pdf-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: #ef4444;
    color: white !important;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}
.pdf-btn:hover {
    background: #dc2626;
    transform: translateY(-1px);
}
.pdf-btn:active {
    transform: translateY(0);
}
.pdf-btn svg {
    stroke: white;
    fill: none;
}

@media print {
    /* Hide non-printable elements */
    .tabs,
    .filters,
    .pdf-btn,
    .search-input,
    .select-input,
    #exportPdfBtn,
    .explorer-header {
        display: none !important;
    }

    /* Reset sticky header positioning so it doesn't overlap text on subsequent pages */
    .main-header {
        position: static !important;
        background: #0f172a !important;
        padding: 2rem !important;
        margin-bottom: 2rem !important;
    }

    #detailed-explorer .sticky-header th {
        position: static !important;
    }

    /* Keep beautiful styling intact on print */
    body {
        background: #f8fafc !important;
        color: #1e293b !important;
    }

    .container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Convert CSS grids and flexbox to clean block flows to prevent elements overlapping in multi-page prints */
    .dashboard-grid, 
    .dashboard-row, 
    .dashboard-header,
    .metrics-grid, 
    .booth-stats-grid,
    .header-content {
        display: block !important;
    }

    .dashboard-grid > *, 
    .dashboard-row > *, 
    .dashboard-header > *,
    .metrics-grid > *, 
    .booth-stats-grid > *,
    .header-content > * {
        width: 100% !important;
        margin-bottom: 1.5rem !important;
        display: block !important;
        position: static !important;
        float: none !important;
    }

    .glass-panel, .panel, .metric-card, .booth-stats-card {
        background: rgba(255, 255, 255, 0.9) !important;
        border: 1px solid rgba(226, 232, 240, 0.8) !important;
        margin-bottom: 2rem !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        box-shadow: none !important;
    }

    /* Print all tabs sequentially */
    .tab-content {
        position: static !important;
        height: auto !important;
        overflow: visible !important;
        opacity: 1 !important;
        display: block !important;
        page-break-before: always !important;
    }
    
    .tab-content:first-of-type {
        page-break-before: avoid !important;
    }

    /* Prevent charts from being split or overlapping */
    .chart-container {
        position: relative !important;
        height: 280px !important;
        width: 100% !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* Expand tables completely without scrollbars */
    .table-responsive {
        overflow: visible !important;
        overflow-x: visible !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .data-table, .detailed-data-table {
        width: 100% !important;
        border-collapse: collapse !important;
    }

    .data-table th, .data-table td,
    .detailed-data-table th, .detailed-data-table td {
        padding: 0.5rem !important;
        border-bottom: 1px solid rgba(226, 232, 240, 0.8) !important;
        font-size: 0.8rem !important;
    }

    /* Avoid breaking rows inside table */
    tr {
        page-break-inside: avoid !important;
    }

    /* Force color prints for status badges, chart fills and text color indicators */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}
