:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242836;
    --border: #2e3347;
    --text: #e4e6f0;
    --text-dim: #8b8fa3;
    --primary: #6c63ff;
    --primary-hover: #5a52e0;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #ef4444;
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Navigation ────────────────────────────────────────── */

.nav {
    display: flex;
    align-items: center;
    gap: 32px;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.nav-brand {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.nav-links { display: flex; gap: 8px; }

.nav-links a {
    color: var(--text-dim);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-links a:hover, .nav-links a.active {
    color: var(--text);
    background: var(--surface2);
}

/* ── Layout ────────────────────────────────────────────── */

.page-layout {
    display: flex;
    height: calc(100vh - 57px);
}

.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

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

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ── Buttons ───────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}
.btn-danger:hover { background: var(--danger); color: white; }

.btn-success {
    background: var(--success);
    color: var(--bg);
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Forms ─────────────────────────────────────────────── */

.form-group {
    margin-bottom: 12px;
}

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

input[type="text"], input[type="number"], textarea, select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
}

textarea { resize: vertical; min-height: 80px; }

/* ── Cards ─────────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

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

/* ── Type list items ───────────────────────────────────── */

.type-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid transparent;
}

.type-item:hover { background: var(--surface2); }

.type-item.active {
    background: var(--surface2);
    border-color: var(--primary);
}

.type-item .type-name {
    font-weight: 500;
    font-size: 14px;
}

.type-item .type-count {
    font-size: 12px;
    color: var(--text-dim);
}

.badge {
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: auto;
}

/* ── Image grid ────────────────────────────────────────── */

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.image-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.image-card .image-wrapper {
    position: relative;
    width: 100%;
    height: 300px;
    overflow: hidden;
    background: var(--bg);
}

.image-card .image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.image-card .image-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.image-card .coord-text {
    font-size: 12px;
    color: var(--text-dim);
    font-family: monospace;
}

.image-card .image-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── Crop modal ────────────────────────────────────────── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.visible { display: flex; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90vw;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

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

.modal-header h3 { font-size: 16px; }

.modal-body {
    padding: 20px;
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body img {
    max-width: 100%;
    max-height: 60vh;
}

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

/* ── Progress bar ──────────────────────────────────────── */

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

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

/* ── Map container ─────────────────────────────────────── */

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

/* ── Results panel ─────────────────────────────────────── */

.result-item {
    display: flex;
    gap: 12px;
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 8px;
    background: var(--surface2);
}

.result-item img {
    width: 60px;
    height: 60px;
    border-radius: 4px;
    object-fit: cover;
}

.result-info { flex: 1; }
.result-info .score { font-weight: 600; color: var(--success); }

.confidence-high { color: var(--success); }
.confidence-med { color: var(--warning); }
.confidence-low { color: var(--danger); }

/* ── Empty state ───────────────────────────────────────── */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px;
    color: var(--text-dim);
    text-align: center;
}

.empty-state .icon { font-size: 48px; opacity: 0.3; }
.empty-state p { font-size: 14px; max-width: 300px; }

/* ── Loading spinner ───────────────────────────────────── */

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ── Scan status ───────────────────────────────────────── */

.scan-status {
    padding: 12px;
    border-radius: var(--radius);
    background: var(--surface2);
    border: 1px solid var(--border);
    margin-bottom: 12px;
}

.status-label {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-running { background: rgba(108, 99, 255, 0.2); color: var(--primary); }
.status-completed { background: rgba(52, 211, 153, 0.2); color: var(--success); }
.status-failed { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.status-pending { background: rgba(139, 143, 163, 0.2); color: var(--text-dim); }

/* ── Landing page ──────────────────────────────────────── */

.landing {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 57px);
    text-align: center;
    gap: 24px;
    padding: 48px;
}

.landing h1 {
    font-size: 36px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--success));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.landing p {
    font-size: 16px;
    color: var(--text-dim);
    max-width: 500px;
    line-height: 1.6;
}

.landing-cards {
    display: flex;
    gap: 24px;
    margin-top: 16px;
}

.landing-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    width: 260px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s;
}

.landing-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.landing-card h3 { margin-bottom: 8px; font-size: 18px; }
.landing-card p { font-size: 13px; color: var(--text-dim); }

.landing-card .step-num {
    display: inline-block;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 12px;
}

/* ── Leaflet popup override ────────────────────────────── */

.leaflet-popup-content-wrapper {
    background: var(--surface) !important;
    color: var(--text) !important;
    border-radius: var(--radius) !important;
}

.leaflet-popup-tip { background: var(--surface) !important; }

.leaflet-popup-content img {
    max-width: 200px;
    border-radius: 4px;
}

/* ── 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-dim); }
