/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f7fa;
    color: #2d3748;
    overflow-x: hidden;
}

/* Login Page */
#login {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

#logincontent {
    background: white;
    border-radius: 16px;
    padding: 3rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    max-width: 400px;
    width: 90%;
    text-align: center;
}

#loginlogo {
    max-width: 200px;
    margin-bottom: 2rem;
}

.loginpage {
    width: 100%;
    margin-bottom: 1rem;
}

input.loginpage {
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
}

input.loginpage:focus {
    outline: none;
    border-color: #667eea;
}

button.loginpage {
    background: #667eea;
    color: white;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
}

button.loginpage:hover {
    background: #5a67d8;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.error-message {
    color: #e53e3e;
    margin-top: 1rem;
    font-size: 14px;
}

/* Navigation */
#navigation {
    background: #2d3748;
    color: white;
    height: 70px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.nav-logo {
    height: 40px;
    margin-right: 30px;
}

.nav-buttons {
    display: flex;
    gap: 10px;
    flex: 1;
}

.nav {
    background: transparent;
    border: none;
    color: #a0aec0;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
}

.nav:hover, .nav.active {
    background: #4a5568;
    color: white;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 15px;
    color: #e2e8f0;
}

.nav-logout {
    background: #e53e3e;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
}

.nav-logout:hover {
    background: #c53030;
}

/* Main Content */
#main-content {
    margin-top: 70px;
    min-height: calc(100vh - 70px);
}

.view-container {
    height: calc(100vh - 70px);
    overflow: hidden;
}

.view-container.active {
    display: block;
}

.view-header {
    background: white;
    padding: 20px 30px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.view-header h2 {
    color: #2d3748;
    font-size: 24px;
    font-weight: 600;
}

.view-content {
    padding: 20px 30px;
    height: calc(100% - 80px);
    overflow-y: auto;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a67d8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.btn-secondary:hover {
    background: #cbd5e0;
}

.control-btn {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    color: #4a5568;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 13px;
    font-weight: 500;
}

.control-btn:hover, .control-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.control-group {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #4a5568;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 30px;
}

/* Modal */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.close {
    position: absolute;
    top: 15px;
    right: 20px;
    color: #a0aec0;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

.close:hover {
    color: #2d3748;
}

/* Loading */
#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e2e8f0;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 70px;
    right: 0;
    width: 300px;
    height: calc(100vh - 70px);
    background: white;
    border-left: 1px solid #e2e8f0;
    padding: 20px;
    overflow-y: auto;
    box-shadow: -2px 0 10px rgba(0,0,0,0.05);
}

.sidebar h3 {
    margin-bottom: 20px;
    color: #2d3748;
    font-size: 18px;
    font-weight: 600;
}

.sidebar-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #f7fafc;
}

.sidebar-section:last-child {
    border-bottom: none;
}

.sidebar-section label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #4a5568;
    font-size: 14px;
}

.sidebar-section select,
.sidebar-section input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
}

/* User Sections */
.user-sections {
    display: grid;
    gap: 30px;
}

.user-section {
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.user-section h3 {
    margin-bottom: 20px;
    color: #2d3748;
    font-size: 18px;
    font-weight: 600;
}

/* Loading Modal Styles */
.loading-modal {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.7);
}

.loading-modal.hidden {
    display: none !important;
}

.loading-modal .loading-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    min-width: 400px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.loading-modal h2 {
    margin: 0 0 20px 0;
    color: #2d3748;
    font-size: 24px;
    text-align: center;
}

.loading-progress {
    margin: 20px 0;
}

.loading-item {
    display: flex;
    align-items: center;
    padding: 10px;
    margin: 5px 0;
    background: #f7fafc;
    border-radius: 6px;
    transition: all 0.3s;
}

.loading-item.complete {
    background: #e6fffa;
}

.loading-item.error {
    background: #fff5f5;
}

.loading-icon {
    font-size: 20px;
    margin-right: 15px;
    width: 25px;
    text-align: center;
}

.loading-item.complete .loading-icon {
    color: #48bb78;
}

.loading-item.error .loading-icon {
    color: #f56565;
}

.loading-text {
    flex: 1;
    color: #4a5568;
}

.loading-bar {
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    margin-top: 20px;
    overflow: hidden;
}

.loading-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 768px) {
    .nav-buttons {
        display: none;
    }
    
    .sidebar {
        width: 100%;
        position: relative;
        height: auto;
        box-shadow: none;
        border-left: none;
        border-top: 1px solid #e2e8f0;
    }
    
    .view-content {
        padding: 15px;
    }
    
    .modal-content {
        margin: 20px;
        width: calc(100% - 40px);
    }
}

/* Table Controls */
.table-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.table-controls select {
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.chart-container {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.chart-container h4 {
    margin-bottom: 15px;
    color: #2d3748;
    font-size: 16px;
    font-weight: 600;
}

/* Vote mode controls */
.vote-mode-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 10px;
}

.vote-btn {
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 12px;
}

.vote-btn:hover {
    background: #f0f0f0;
}

.vote-btn.active {
    background: #4c51bf;
    color: white;
    border-color: #4c51bf;
}

.vote-btn[data-party="0"] { border-left: 4px solid #7AE3FB; }
.vote-btn[data-party="1"] { border-left: 4px solid #0E8AE4; }
.vote-btn[data-party="2"] { border-left: 4px solid #E02A28; }
.vote-btn[data-party="4"] { border-left: 4px solid #7AE3FB; }
.vote-btn[data-party="5"] { border-left: 4px solid #E8861F; }

/* Map popup styles */
.map-popup {
    padding: 10px;
    min-width: 200px;
}

.map-popup h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: bold;
}

.map-popup p {
    margin: 5px 0;
    font-size: 12px;
}

/* Segments Styles */
.segments-list {
    padding: 20px;
}

.segments-table {
    width: 100%;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.segments-table thead {
    background: #f7fafc;
}

.segments-table th,
.segments-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.segments-table th {
    font-weight: 600;
    color: #4a5568;
    font-size: 13px;
    text-transform: uppercase;
}

.segments-table tbody tr:hover {
    background: #f7fafc;
}

.segment-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: transparent;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 6px 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-icon:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.progress-bar {
    width: 100px;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
    display: inline-block;
    margin-right: 10px;
}

.progress-fill {
    height: 100%;
    background: #48bb78;
    transition: width 0.3s;
}

.progress-fill.pending {
    background: #ed8936;
}

.no-segments {
    text-align: center;
    color: #a0aec0;
    padding: 40px;
    font-size: 16px;
}

/* Correlations Table */
.modal-content.large {
    max-width: 900px;
    width: 90%;
}

.correlations-content {
    max-height: 500px;
    overflow-y: auto;
    margin: 20px 0;
}

.correlations-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.correlations-table th,
.correlations-table td {
    padding: 8px;
    border: 1px solid #e2e8f0;
}

.correlations-table th {
    background: #f7fafc;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

.question-cell {
    min-width: 250px;
}

.parent-question {
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 4px;
}

.sub-question {
    color: #718096;
    font-size: 12px;
}

.correlation-cell {
    text-align: center;
    min-width: 80px;
}

.corr-value {
    font-weight: 600;
    font-size: 12px;
}

.det-value {
    font-size: 10px;
    color: #718096;
    margin-top: 2px;
}

/* Selection Mode */
.selection-mode {
    margin: 10px 0;
}

.selection-mode input[type="radio"] {
    margin-right: 8px;
}

.selection-mode label {
    font-weight: normal;
    cursor: pointer;
}

/* Correlation Table Styles */
.correlation-table-container {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

#correlation-display-table {
    width: 100%;
    font-size: 13px;
}

#correlation-display-table th {
    background: #f7fafc;
    font-weight: 600;
    color: #4a5568;
    padding: 10px 8px;
    text-align: left;
}

#correlation-display-table td {
    padding: 8px;
    border-bottom: 1px solid #e2e8f0;
}

#correlation-display-table tbody tr:hover {
    background: #f7fafc;
}

.segment-selector {
    margin-bottom: 20px;
    padding: 15px;
    background: #f7fafc;
    border-radius: 6px;
}

.segment-selector label {
    font-weight: 600;
    margin-bottom: 5px;
    display: block;
}

.segment-selector select {
    width: 100%;
    padding: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    margin-bottom: 10px;
}

.segment-selector button {
    width: 100%;
}

#table-content-sidebar .button-block {
    margin-bottom: 15px;
}

#table-content-sidebar .button-block button {
    flex: 1;
}

#download-table {
    margin: 10px 0;
    width: 100%;
}

.filter {
    margin: 5px 0;
    width: 100%;
    text-align: left;
}

/* Filter and Grouping Styles */
#table-filters {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

#table-filters h4 {
    font-size: 14px;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 10px;
}

.filter-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 20px;
}

.filter-buttons .filter {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 13px;
    text-align: left;
}

.filter-buttons .filter:hover {
    background: #f7fafc;
    border-color: #cbd5e0;
}

.filter-buttons .filter.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.grouping-controls button {
    width: 100%;
    padding: 10px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 14px;
}

.grouping-controls button:hover {
    background: #f7fafc;
    border-color: #cbd5e0;
}

.grouping-controls button.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* Tabulator Custom Styles */
#correlation-table {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.tabulator .tabulator-header {
    background: #f7fafc;
    border-bottom: 2px solid #e2e8f0;
}

.tabulator .tabulator-header .tabulator-col {
    background: #f7fafc;
    border-right: 1px solid #e2e8f0;
}

.tabulator .tabulator-header .tabulator-col-title {
    font-weight: 600;
    color: #4a5568;
    font-size: 13px;
}

.tabulator .tabulator-row {
    border-bottom: 1px solid #e2e8f0;
}

.tabulator .tabulator-row:hover {
    background: #f7fafc;
}

.tabulator .tabulator-group {
    background: #edf2f7;
    font-weight: 600;
    color: #2d3748;
    border: none;
}

.tabulator .tabulator-group:hover {
    background: #e2e8f0;
}

.tabulator .tabulator-arrow {
    border-color: #4a5568;
}

/* Table sidebar styling */
#table-sidebar {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    height: calc(100vh - 120px);
    overflow-y: auto;
}

#table-sidebar h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #2d3748;
}

#table-sidebar .sidebar-section {
    margin-bottom: 25px;
}

/* Fix for Tabulator rendering issues */
.tabulator {
    font-size: 14px;
}

.tabulator .tabulator-cell {
    padding: 4px 8px;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tabulator .tabulator-tableholder {
    background-color: white;
}

.tabulator .tabulator-header-filter input {
    width: 100%;
    box-sizing: border-box;
    padding: 4px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 12px;
}