:root {
    --bg: #0f1117;
    --bg-surface: #1a1d27;
    --bg-elevated: #242836;
    --border: #2e3345;
    --text: #e4e6ed;
    --text-muted: #8b8fa3;
    --primary: #d94044;
    --primary-hover: #b8282c;
    --danger: #e5534b;
    --success: #3fb950;
    --warning: #d29922;
    --radius: 8px;
    --radius-sm: 4px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.6);
    border-bottom: 1px solid rgba(185, 28, 28, 0.4);
    flex-shrink: 0;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    max-width: 1152px;
    margin: 0 auto;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-logo {
    width: clamp(56px, 8vw, 88px);
    height: auto;
    display: block;
}

.header-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.header-name {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: #ffffff;
    text-transform: uppercase;
}

.header-subtitle {
    font-size: 12px;
    color: #ffffff;
    font-weight: 500;
    opacity: 0.8;
}

.nav-links {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex: 1;
}

.nav-btn {
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}

.nav-btn:not(.active) {
    background: #171920;
    border-color: #374151;
    color: var(--text);
}

.nav-btn:hover {
    background: #641e16;
    color: #fce8e6;
    border-color: #87231d;
}

.nav-btn.active {
    background: #641e16;
    color: #fce8e6;
    border-color: #b91c1c;
}

main {
    flex: 1;
    overflow: hidden;
}

.view {
    display: none;
    height: 100%;
}

.view.active {
    display: flex;
}

/* Map View */
#map-view {
    position: relative;
}

#map {
    flex: 1;
    height: 100%;
}

#sidebar {
    width: 300px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Source cards */
.source-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 4px;
}

.source-card:hover {
    background: var(--bg-elevated);
}

.source-card.active {
    background: var(--bg-elevated);
    outline: 1px solid var(--primary);
}

.source-card.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.source-card.disabled:hover {
    background: none;
}

.source-card .source-preview {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    overflow: hidden;
    position: relative;
}

.source-unavailable {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(229, 83, 75, 0.25);
    color: var(--danger);
    font-size: 18px;
    font-weight: 700;
}

.source-badge-error {
    background: rgba(229, 83, 75, 0.15) !important;
    color: var(--danger) !important;
    margin-left: 0 !important;
}

.source-card .source-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.source-card .source-name {
    font-size: 13px;
    font-weight: 500;
}

.source-card .source-badge {
    margin-left: auto;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    background: var(--bg);
    color: var(--text-muted);
}

.source-group-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 10px 10px 4px;
    opacity: 0.7;
}

.source-group-label:first-child {
    padding-top: 0;
}

.layer-category {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.6;
}

#bounds-info {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.8;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    gap: 6px;
}

.btn:hover {
    background: var(--border);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-secondary {
    border-color: #374151;
    background: #171920;
    color: var(--text);
}

.btn-secondary:hover {
    background: #641e16;
    color: #fce8e6;
    border-color: #87231d;
}

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 540px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal.wizard-modal {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.wizard-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.wizard-modal .modal-header,
.wizard-modal .modal-footer {
    flex-shrink: 0;
}

.modal-sm {
    width: 400px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text);
}

.wizard-step {
    padding: 20px;
}

.wizard-step h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 11px;
}

.zoom-range {
    display: flex;
    align-items: end;
    gap: 12px;
}

.zoom-input {
    flex: 1;
}

.zoom-input label {
    text-transform: none !important;
    font-size: 11px !important;
}

.zoom-input input {
    text-align: center;
}

.zoom-separator {
    color: var(--text-muted);
    padding-bottom: 8px;
}

.tile-estimate {
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 8px;
}

.tile-estimate strong {
    color: var(--text);
}

.tile-estimate.warning strong {
    color: var(--warning);
}

.tile-estimate.danger strong {
    color: var(--danger);
}

/* Layer checkboxes in wizard */
.wizard-layer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    cursor: pointer;
}

.wizard-layer:hover {
    background: var(--bg-elevated);
}

.wizard-layer input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

.wizard-layer .layer-name {
    font-size: 13px;
    font-weight: 500;
}

/* Per-source settings in wizard */
.source-settings-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
}

.source-settings-card h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
}

.source-settings-card .settings-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 8px;
}

.source-settings-card .settings-row-full {
    margin-bottom: 8px;
}

.source-settings-card label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.source-settings-card input,
.source-settings-card select {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 12px;
    outline: none;
}

.source-settings-card input:focus,
.source-settings-card select:focus {
    border-color: var(--primary);
}

.source-settings-card .tile-estimate {
    padding: 8px;
    font-size: 12px;
    margin-top: 4px;
}

/* Layer Previews */
.layer-previews {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.layer-preview-tile {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 2px solid transparent;
    position: relative;
}

.layer-preview-tile.selected {
    border-color: var(--primary);
}

.layer-preview-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.layer-preview-tile .preview-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px 6px;
    background: rgba(0, 0, 0, 0.7);
    font-size: 10px;
    font-weight: 500;
    text-align: center;
}

/* Export summary */
#export-summary {
    font-size: 13px;
    line-height: 2;
}

#export-summary .summary-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}

#export-summary .summary-label {
    color: var(--text-muted);
}

/* Downloads View */
.downloads-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 32px 24px;
    width: 100%;
    overflow-y: auto;
    height: 100%;
}

.downloads-container h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
}

.export-card {
    background: var(--bg-surface);
    border: 1px solid #641e16;
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 0 10px rgba(100, 30, 22, 0.35);
}

.export-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.export-card-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.export-status {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.export-status.queued {
    background: var(--bg-elevated);
    color: var(--text-muted);
}

.export-status.running {
    background: rgba(217, 64, 68, 0.15);
    color: var(--primary);
}

.export-status.complete {
    background: rgba(63, 185, 80, 0.15);
    color: var(--success);
}

.export-status.failed {
    background: rgba(229, 83, 75, 0.15);
    color: var(--danger);
}

.export-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.progress-bar {
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s;
}

.export-actions {
    display: flex;
    gap: 8px;
}

.muted {
    color: var(--text-muted);
    font-size: 13px;
}

/* Preview Overlay */
.preview-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 48px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.preview-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.preview-header-left h2 {
    font-size: 14px;
    font-weight: 600;
}

.preview-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

#preview-map {
    flex: 1;
}

/* Floating map action bar */
.map-action-bar {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(calc(-50% - 150px)); /* offset for sidebar width / 2 */
    z-index: 800;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* Leaflet overrides for dark theme */
.leaflet-container {
    background: var(--bg) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-surface) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-elevated) !important;
}

.leaflet-draw-toolbar a {
    background-color: var(--bg-surface) !important;
    border-color: var(--border) !important;
}

/* Zoom Indicator Control */
.zoom-indicator-control {
    margin-bottom: 0 !important;
    position: relative;
}

.zoom-indicator-badge {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: var(--bg-surface) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-decoration: none !important;
    cursor: pointer;
    line-height: 1;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.zoom-indicator-badge:hover {
    background: var(--bg-elevated) !important;
    color: var(--text) !important;
}

.zoom-slider-panel {
    position: absolute;
    left: 36px;
    top: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    width: 200px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 1000;
}

.zoom-slider-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
}

.zoom-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    outline: none;
}

.zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--bg-surface);
}

.zoom-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--bg-surface);
}

.zoom-slider-ticks {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 9px;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ── Login Overlay ── */

.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #121212;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    font-family: 'Roboto Mono', monospace;
    color: #f0f0f0;
}

.login-main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5vh 1rem 3rem;
    width: 100%;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    background-color: #1e1e1e;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(100, 30, 22, 0.5);
}

.site-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.site-brand-logo {
    width: 100%;
    max-width: 200px;
    height: auto;
    display: block;
}

.site-brand-name {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: #f87171;
    text-transform: uppercase;
    text-align: center;
}

.login-container h2 {
    color: #ffffff;
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 1.2rem;
    letter-spacing: 0.04em;
}

.login-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
}

.login-title-icon {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    background: transparent;
    border: none;
}

.login-title-icon img {
    width: 36px;
    height: 36px;
    display: block;
}

.login-label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
    color: #b9b9b9;
}

.login-container input[type="text"],
.login-container input[type="password"] {
    width: 100%;
    padding: 0.75rem;
    margin: 0 auto 1.25rem auto;
    font-size: 1rem;
    display: block;
    border: none;
    border-radius: 5px;
    background-color: #2a2a2a;
    color: #fff;
}

.login-container input[type="text"]:focus,
.login-container input[type="password"]:focus {
    outline: 2px solid #641e16;
}

.login-error {
    text-align: center;
    margin-bottom: 1rem;
    color: #ff6b6b;
    font-size: 0.9rem;
}

.login-submit {
    width: 100%;
    background-color: #641e16;
    color: #fff;
    padding: 0.75rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.login-submit:hover {
    background-color: #87231d;
}

.login-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.login-footer {
    text-align: center;
    margin-top: 1rem;
    color: #9aa0a6;
    font-size: 0.85rem;
}

/* ── User Info (header) ── */

#user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

#username-display {
    font-size: 13px;
    color: var(--text-muted);
}
