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

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

/* Navbar */
.navbar {
    background: #1e40af;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 600;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.nav-links a {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: white;
}

.btn-logout {
    background: rgba(255,255,255,0.1);
    padding: 0.5rem 1rem;
    border-radius: 6px;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Alerts */
.alert {
    padding: 1rem 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.alert-error {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.alert-success {
    background: #d1fae5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #2563eb;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
}

.btn-primary:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}

.btn-secondary {
    background: white;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-secondary:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

.btn-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 120px);
}

.login-box {
    background: white;
    padding: 3rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.login-box .subtitle {
    color: #6b7280;
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* Page header */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.page-header p {
    color: #6b7280;
}

/* Upload section */
.upload-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

@media (max-width: 768px) {
    .upload-section {
        grid-template-columns: 1fr;
    }
}

.upload-form {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.file-upload-area {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 1.5rem;
}

.file-upload-area:hover,
.file-upload-area.dragover {
    border-color: #2563eb;
    background: #eff6ff;
}

.file-upload-area input[type="file"] {
    display: none;
}

.upload-icon {
    color: #9ca3af;
    margin-bottom: 1rem;
}

.upload-text {
    font-size: 1.125rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.upload-subtext {
    color: #6b7280;
    font-size: 0.875rem;
}

.file-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #eff6ff;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.btn-clear {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #6b7280;
    cursor: pointer;
}

.format-help {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.format-help h3 {
    margin-bottom: 1rem;
}

.format-help ul {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.format-help li {
    margin-bottom: 0.5rem;
}

.format-help code {
    background: #f3f4f6;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
}

.format-help .note {
    color: #6b7280;
    font-size: 0.875rem;
    font-style: italic;
}

/* Select page */
.select-container {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 1.5rem;
    height: calc(100vh - 200px);
    min-height: 500px;
}

@media (max-width: 900px) {
    .select-container {
        grid-template-columns: 1fr;
        height: auto;
    }
}

.select-sidebar {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - 200px);
}

.search-box {
    position: relative;
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.search-box input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.9rem;
}

.search-box input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.search-icon {
    position: absolute;
    left: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    pointer-events: none;
}

.select-controls {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    flex-wrap: wrap;
}

.territory-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    min-height: 200px;
}

.territory-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.territory-item:hover {
    background: #f3f4f6;
}

.territory-item.hidden {
    display: none;
}

.territory-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.territory-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.territory-number {
    font-weight: 600;
}

.territory-area {
    font-size: 0.875rem;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.territory-category {
    font-size: 0.75rem;
    color: #9ca3af;
}

.select-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    gap: 1rem;
}

.selection-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.selected-count {
    color: #1f2937;
    font-size: 0.9rem;
    font-weight: 500;
}

.visible-count {
    color: #9ca3af;
    font-size: 0.75rem;
}

.map-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

#map {
    height: 100%;
    min-height: 500px;
}

/* Results page */
.results-container {
    max-width: 1000px;
}

.progress-section {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 1.5rem;
}

.progress-section.complete {
    border-left: 4px solid #10b981;
}

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

.progress-header h2 {
    font-size: 1.25rem;
}

.progress-status {
    color: #6b7280;
}

.progress-bar-container {
    background: #e5e7eb;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-bar {
    background: #2563eb;
    height: 100%;
    transition: width 0.3s ease;
}

.progress-details {
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

.territory-progress {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.territory-progress-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #f9fafb;
    border-radius: 8px;
}

.territory-progress-item.processing {
    background: #eff6ff;
}

.territory-progress-item.complete {
    background: #d1fae5;
}

.territory-progress-item.error {
    background: #fee2e2;
}

.status-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #d1d5db;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.territory-progress-item.complete .spinner {
    display: none;
}

.territory-progress-item.complete .status-icon::after {
    content: '\2713';
    color: #059669;
    font-weight: bold;
}

.territory-progress-item.error .spinner {
    display: none;
}

.territory-progress-item.error .status-icon::after {
    content: '\2717';
    color: #dc2626;
    font-weight: bold;
}

.territory-name {
    flex: 1;
}

.territory-count {
    color: #6b7280;
    font-size: 0.875rem;
}

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

/* Debug section */
.debug-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
}

.debug-log {
    margin-top: 1rem;
    background: #1f2937;
    border-radius: 8px;
    padding: 1rem;
    max-height: 400px;
    overflow: auto;
}

.debug-log pre {
    color: #10b981;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
}

.stat-error {
    color: #dc2626 !important;
}

/* Results section */
.results-section {
    margin-top: 1.5rem;
}

.results-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.summary-stat {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: #1e40af;
}

.stat-label {
    color: #6b7280;
    font-size: 0.875rem;
}

.export-buttons {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 1.5rem;
}

.export-buttons h3 {
    margin-bottom: 1rem;
}

.address-list-section {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.address-list-section h3 {
    margin-bottom: 1rem;
}

.address-filters {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.search-input,
.territory-filter {
    padding: 0.5rem 1rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.875rem;
}

.search-input {
    flex: 1;
}

.territory-filter {
    min-width: 150px;
}

.address-list {
    max-height: 500px;
    overflow-y: auto;
}

.territory-section {
    margin-bottom: 1.5rem;
}

.territory-section h4 {
    font-size: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0.75rem;
}

.address-items {
    list-style: none;
}

.address-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f3f4f6;
}

.address-text {
    font-weight: 500;
}

.address-city {
    color: #6b7280;
    font-size: 0.875rem;
}

.no-results {
    text-align: center;
    color: #6b7280;
    padding: 2rem;
}

/* Data Status Banner */
.data-status-banner {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
}

.data-status-banner h3 {
    color: #92400e;
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.data-source-item {
    padding: 0.5rem 0;
    font-size: 0.875rem;
    color: #78350f;
}

.data-source-item.unavailable strong {
    color: #b45309;
}

/* Source Breakdown Section */
.source-breakdown {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 1.5rem;
}

.source-breakdown h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: #374151;
}

.source-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.source-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 8px;
    text-align: center;
}

.source-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-bottom: 0.5rem;
}

.county-icon {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
}

.oa-icon {
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
}

.osm-icon {
    background: linear-gradient(135deg, #10b981, #059669);
}

.source-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: #374151;
    margin-bottom: 0.25rem;
}

.source-count {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1f2937;
}

.source-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    margin-top: 0.5rem;
}

.source-status.available {
    background: #d1fae5;
    color: #065f46;
}

.source-status.unavailable {
    background: #fee2e2;
    color: #991b1b;
}

/* Verification Legend */
.verification-legend {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: #6b7280;
}

.legend-item .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.legend-item.verified .dot {
    background: #10b981;
}

.legend-item.partial .dot {
    background: #f59e0b;
}

.legend-item.unverified .dot {
    background: #ef4444;
}

/* Address Item with Verification */
.address-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid #f3f4f6;
    border-left: 3px solid transparent;
}

.address-item.verification-verified {
    border-left-color: #10b981;
    background: #f0fdf4;
}

.address-item.verification-partial {
    border-left-color: #f59e0b;
    background: #fffbeb;
}

.address-item.verification-unverified {
    border-left-color: #ef4444;
    background: #fef2f2;
}

.address-main {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.verification-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.verification-verified .verification-indicator {
    background: #10b981;
}

.verification-partial .verification-indicator {
    background: #f59e0b;
}

.verification-unverified .verification-indicator {
    background: #ef4444;
}

.address-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.source-badges {
    display: flex;
    gap: 0.25rem;
}

.source-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    font-size: 0.625rem;
    font-weight: 700;
    color: white;
}

.source-badge.county {
    background: #3b82f6;
}

.source-badge.openaddresses {
    background: #8b5cf6;
}

.source-badge.osm {
    background: #10b981;
}

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

    .verification-legend {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .address-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .address-meta {
        width: 100%;
        justify-content: space-between;
    }
}

/* Data Sources Page */
.data-sources-container {
    max-width: 1200px;
}

.info-banner {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.info-banner h3 {
    color: #1e40af;
    margin-bottom: 0.75rem;
}

.info-banner ol {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.info-banner li {
    margin-bottom: 0.5rem;
}

.county-section {
    margin-bottom: 2rem;
}

.county-section h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e5e7eb;
}

.data-files-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .data-files-grid {
        grid-template-columns: 1fr;
    }
}

.data-file-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

.data-file-card.available {
    border-left: 4px solid #10b981;
}

.data-file-card.missing {
    border-left: 4px solid #f59e0b;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}

.card-header h3 {
    font-size: 1rem;
    margin: 0;
}

.status-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-weight: 500;
}

.status-badge.success {
    background: #d1fae5;
    color: #065f46;
}

.status-badge.warning {
    background: #fef3c7;
    color: #92400e;
}

.card-body {
    padding: 1.5rem;
}

.file-info {
    background: #f0fdf4;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.file-info p {
    margin: 0.25rem 0;
    font-size: 0.875rem;
}

.instructions {
    background: #fffbeb;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    color: #92400e;
}

.upload-section h4 {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 0.75rem;
}

.file-drop-zone {
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 1rem;
}

.file-drop-zone:hover,
.file-drop-zone.dragover {
    border-color: #3b82f6;
    background: #eff6ff;
}

.drop-content svg {
    color: #9ca3af;
    margin-bottom: 0.5rem;
}

.drop-content p {
    margin: 0.5rem 0;
    color: #6b7280;
}

.browse-link {
    color: #3b82f6;
    text-decoration: underline;
}

.file-types {
    font-size: 0.75rem;
    color: #9ca3af;
}

.selected-file {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #eff6ff;
    padding: 0.75rem 1rem;
    border-radius: 6px;
}

.selected-file .file-name {
    font-size: 0.875rem;
    color: #1e40af;
    font-weight: 500;
}

.selected-file .btn-clear {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #6b7280;
    cursor: pointer;
    padding: 0 0.5rem;
}

.selected-file .btn-clear:hover {
    color: #dc2626;
}

.upload-progress {
    margin-top: 1rem;
}

.upload-progress .progress-bar-container {
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    overflow: hidden;
}

.upload-progress .progress-bar {
    height: 100%;
    background: #3b82f6;
    width: 100%;
    animation: progress-indeterminate 1.5s infinite;
}

@keyframes progress-indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.upload-progress .progress-text {
    font-size: 0.75rem;
    color: #6b7280;
    display: block;
    margin-top: 0.5rem;
    text-align: center;
}

.osm-info {
    margin-top: 2rem;
}

.osm-info .data-file-card {
    max-width: 600px;
}
