/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    text-align: center;
    padding: 40px 0;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: white;
    margin-bottom: 30px;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 300;
}

/* Controls */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: end;
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 25px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.control-group {
    display: flex;
    flex-direction: column;
    min-width: 200px;
    flex: 1;
    max-width: 100%;
}

.control-group label {
    font-weight: 600;
    margin-bottom: 5px;
    color: #555;
    font-size: 0.9rem;
}

.race-select, .search-input {
    padding: 10px 12px;
    border: 2px solid #e1e5e9;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.race-select:focus, .search-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.clear-btn {
    padding: 10px 20px;
    background-color: #95a5a6;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.clear-btn:hover {
    background-color: #7f8c8d;
}

.view-toggle {
    display: flex;
    border: 2px solid #e1e5e9;
    border-radius: 6px;
    overflow: hidden;
}

.toggle-btn {
    padding: 10px 16px;
    background-color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    border-right: 1px solid #e1e5e9;
}

.toggle-btn:last-child {
    border-right: none;
}

.toggle-btn.active {
    background-color: #3498db;
    color: white;
}

.toggle-btn:not(.active):hover {
    background-color: #f8f9fa;
}

/* Info Section */
.info-section {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.data-info {
    background: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.data-info h3 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.data-info p {
    color: #555;
    line-height: 1.6;
    margin: 0 0 15px 0;
}

.data-info p:last-child {
    margin-bottom: 0;
}

.credits {
    font-size: 0.9rem;
    color: #7f8c8d;
    font-style: italic;
}

.credits a {
    color: #3498db;
    text-decoration: none;
}

.credits a:hover {
    text-decoration: underline;
}

.ballot-book-promo {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    text-align: center;
}

.promo-content strong {
    display: block;
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.promo-content p {
    margin: 10px 0 15px 0;
    opacity: 0.9;
    font-size: 0.95rem;
}

.ballot-book-link {
    display: inline-block;
    background: white;
    color: #2980b9;
    padding: 10px 20px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ballot-book-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    text-decoration: none;
}

/* Stats Summary */
.stats-summary {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 25px;
    text-align: center;
}

.stats-summary h3 {
    color: #2c3e50;
    margin-bottom: 10px;
}

/* Table */
.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
    margin-bottom: 30px;
}

/* Race Groups */
.race-groups-container {
    margin-bottom: 30px;
}

.race-group {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    overflow: hidden;
}

.race-header {
    background-color: #34495e;
    color: white;
    padding: 20px 25px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s ease;
}

.race-header:hover {
    background-color: #2c3e50;
}

.race-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.race-summary {
    font-size: 0.9rem;
    opacity: 0.9;
    margin: 5px 0 0 0;
}

.expand-icon {
    font-size: 1.2rem;
    transition: transform 0.3s ease;
}

.race-group.expanded .expand-icon {
    transform: rotate(180deg);
}

.race-candidates {
    display: none;
    padding: 0;
}

.race-group.expanded .race-candidates {
    display: block;
}

.candidate-card {
    border-bottom: 1px solid #e8ecef;
    padding: 20px 25px;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr auto;
    gap: 20px;
    align-items: center;
}

.candidate-card:last-child {
    border-bottom: none;
}

.candidate-card:hover {
    background-color: #f8f9fa;
}

.candidate-info h4 {
    margin: 0 0 5px 0;
    color: #2c3e50;
    font-size: 1rem;
}

.candidate-info .committee {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin: 0;
}

.candidate-metric {
    text-align: center;
}

.candidate-metric .label {
    font-size: 0.75rem;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 3px;
}

.candidate-metric .value {
    font-weight: 600;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.candidate-actions {
    text-align: right;
}

.candidates-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.candidates-table thead {
    background-color: #34495e;
    color: white;
}

.candidates-table th {
    padding: 15px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    min-width: 100px;
}

.candidates-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background-color 0.2s ease;
}

.candidates-table th.sortable:hover {
    background-color: #2c3e50;
}

.candidates-table th.sortable:after {
    content: ' ↕';
    opacity: 0.5;
    font-size: 12px;
    white-space: nowrap;
}

.candidates-table th.sort-asc:after {
    content: ' ↑';
    opacity: 1;
}

.candidates-table th.sort-desc:after {
    content: ' ↓';
    opacity: 1;
}

.candidates-table tbody tr {
    border-bottom: 1px solid #e8ecef;
    transition: background-color 0.2s ease;
}

.candidates-table tbody tr:hover {
    background-color: #f8f9fa;
}

.candidates-table tbody tr:nth-child(even) {
    background-color: #fafbfc;
}

.candidates-table tbody tr:nth-child(even):hover {
    background-color: #f0f1f2;
}

.candidates-table td {
    padding: 12px;
    vertical-align: middle;
}

.candidate-name {
    font-weight: 600;
    color: #2c3e50;
}

.committee-name {
    font-size: 0.85em;
    color: #7f8c8d;
    margin-top: 2px;
}

.race-info {
    font-size: 0.9em;
}

.jurisdiction {
    font-weight: 500;
    color: #2c3e50;
}

.office-district {
    color: #7f8c8d;
    font-size: 0.85em;
}

.currency {
    font-weight: 600;
    text-align: right;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.currency.positive {
    color: #27ae60;
}

.currency.negative {
    color: #e74c3c;
}

.currency.zero {
    color: #95a5a6;
}

.reports-count {
    text-align: center;
    font-weight: 500;
}

.no-reports {
    color: #e67e22;
    font-style: italic;
    font-size: 0.85em;
    font-weight: 500;
}

.details-btn {
    padding: 6px 12px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.details-btn:hover {
    background-color: #2980b9;
}

.external-link {
    display: inline-block;
    margin-left: 8px;
    color: #3498db;
    text-decoration: none;
    font-size: 12px;
}

.external-link:hover {
    text-decoration: underline;
}

.jurisdiction-link {
    color: #3498db;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.jurisdiction-link:hover {
    color: #2980b9;
    text-decoration: underline;
}

/* No Results */
.no-results {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
    font-size: 1.1rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    z-index: 1000;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    margin: 20px;
}

.modal-content {
    width: 800px;
    max-width: 100%;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 30px;
    border-bottom: 1px solid #e8ecef;
    background-color: #f8f9fa;
}

.modal-header h2 {
    color: #2c3e50;
    margin: 0;
}

.close {
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: #000;
}

.modal-body {
    padding: 30px;
}

.candidate-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 6px;
}

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

.summary-item .label {
    font-size: 0.85rem;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
}

.summary-item .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #2c3e50;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.reports-section h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

.reports-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.reports-table th {
    background-color: #f8f9fa;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: #555;
    border-bottom: 2px solid #e8ecef;
}

.reports-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #e8ecef;
}

.reports-table .currency {
    text-align: right;
}

/* Footer */
.footer {
    text-align: center;
    padding: 30px 20px;
    color: #7f8c8d;
    font-size: 0.9rem;
    border-top: 1px solid #e8ecef;
    margin-top: 40px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
        padding: 20px 15px;
        gap: 15px;
    }
    
    .control-group {
        min-width: 0;
        width: 100%;
        max-width: 100%;
    }
    
    .race-select, .search-input {
        min-width: 0;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .candidates-table {
        font-size: 12px;
    }
    
    .candidates-table th,
    .candidates-table td {
        padding: 8px 6px;
    }
    
    /* Improve details button for tablets */
    .details-btn {
        padding: 10px 14px;
        font-size: 13px;
        min-height: 40px;
        touch-action: manipulation;
    }
    
    .modal {
        top: 0;
        left: 0;
        transform: none;
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
    }
    
    .modal-content {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
    }
    
    .modal-header {
        padding: 15px 20px;
        flex-shrink: 0;
    }
    
    .modal-body {
        padding: 20px;
        flex: 1;
        overflow-y: auto;
    }
    
    .candidate-summary {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* Make reports table mobile-friendly */
    .reports-section {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .reports-table {
        min-width: 600px;
        font-size: 12px;
    }
    
    .reports-table th,
    .reports-table td {
        padding: 8px 6px;
        white-space: nowrap;
    }
    
    .info-section {
        grid-template-columns: 1fr;
    }
    
    .candidate-card {
        grid-template-columns: 1fr;
        gap: 15px;
        text-align: center;
    }
    
    .candidate-actions {
        text-align: center;
    }
}

@media (max-width: 480px) {
    .candidates-table th:nth-child(n+4),
    .candidates-table td:nth-child(n+4) {
        display: none;
    }
    
    .candidates-table th:nth-child(8),
    .candidates-table td:nth-child(8) {
        display: table-cell;
    }
    
    /* Improve details button for mobile */
    .details-btn {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
        min-width: 100px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Make table cells more touch-friendly */
    .candidates-table td {
        padding: 12px 8px;
        min-height: 44px;
    }
    
    /* Improve candidate name display on mobile */
    .candidate-name {
        font-size: 14px;
        line-height: 1.3;
    }
    
    .committee-name {
        font-size: 12px;
        line-height: 1.2;
        margin-top: 4px;
    }
    
    /* Alternative mobile layout - show table as cards on very small screens */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }
    
    /* Add scroll hint for mobile users */
    .table-container.scrollable::after {
        content: "← Scroll to see more →";
        position: absolute;
        bottom: 10px;
        right: 10px;
        background: rgba(52, 73, 94, 0.9);
        color: white;
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 11px;
        pointer-events: none;
        opacity: 0.7;
        z-index: 10;
        animation: fadeInOut 3s ease-in-out infinite;
    }
    
    @keyframes fadeInOut {
        0%, 100% { opacity: 0.7; }
        50% { opacity: 0.3; }
    }
    
    .candidates-table {
        min-width: 600px; /* Ensure table doesn't get too cramped */
    }
    
    /* Improve horizontal scrolling indicator */
    .table-container::-webkit-scrollbar {
        height: 8px;
    }
    
    .table-container::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 4px;
    }
    
    .table-container::-webkit-scrollbar-thumb {
        background: #c1c1c1;
        border-radius: 4px;
    }
    
    .table-container::-webkit-scrollbar-thumb:hover {
        background: #a8a8a8;
    }
    
    /* Enhanced modal styles for very small screens */
    .modal-header h2 {
        font-size: 1.3rem;
        line-height: 1.2;
    }
    
    .close {
        font-size: 24px;
        padding: 5px;
        min-width: 40px;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Improve candidate summary on mobile */
    .summary-item .value {
        font-size: 1.2rem;
        word-break: break-word;
    }
    
    /* Make reports table more compact on mobile */
    .reports-table {
        font-size: 11px;
    }
    
    .reports-table th,
    .reports-table td {
        padding: 6px 4px;
    }
    
    /* Add scroll hint to reports table */
    .reports-section {
        position: relative;
    }
    
    .reports-section.scrollable::after {
        content: "← Scroll to see all columns →";
        position: absolute;
        bottom: 10px;
        right: 10px;
        background: rgba(52, 73, 94, 0.9);
        color: white;
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 10px;
        pointer-events: none;
        opacity: 0.7;
        z-index: 10;
        animation: fadeInOut 3s ease-in-out infinite;
    }
    
    /* Hide scroll hint when there's only one row to prevent overlap */
    .reports-section.scrollable.single-row::after {
        display: none;
    }
}
