/* =========================================================================
   UFO Explorer — Styles
   ========================================================================= */

:root {
    --bg: #0d1117;
    --bg-panel: #161b22;
    --bg-card: #1c2128;
    --bg-input: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --green: #3fb950;
    --orange: #f28e2b;
    --red: #e15759;
}

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

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

/* ---- Header ---- */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

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

#header h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent);
}

.stats-badge {
    font-size: 12px;
    color: var(--text-muted);
}

.tabs {
    display: flex;
    gap: 4px;
}

.tab {
    padding: 6px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}

.tab:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ---- Filters Bar ---- */
#filters-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-group label {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.filter-sep {
    color: var(--text-muted);
}

input[type="number"],
select,
input[type="text"] {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 13px;
    outline: none;
}

input[type="number"] {
    width: 70px;
}

select {
    max-width: 140px;
}

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

.btn {
    padding: 5px 14px;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

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

.btn-secondary {
    background: transparent;
    color: var(--text-muted);
}

.btn-secondary:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.btn-small {
    padding: 3px 10px;
    font-size: 12px;
}

/* ---- Main ---- */
#main {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.panel {
    display: none;
    position: absolute;
    inset: 0;
    overflow: auto;
}

.panel.active {
    display: flex;
    flex-direction: column;
}

.panel-status {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(22, 27, 34, 0.9);
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 1000;
    pointer-events: none;
}

.btn-load-all {
    position: absolute;
    bottom: 12px;
    left: 200px;
    z-index: 1000;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: background 0.15s;
}

.btn-load-all:hover {
    background: #79c0ff;
}

/* ---- Map ---- */
#map {
    flex: 1;
    z-index: 1;
}

/* Map mode toggle (Clusters / Heatmap) */
.map-mode-toggle {
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 1000;
    display: flex;
    background: rgba(22, 27, 34, 0.92);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.map-mode-btn {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
}

.map-mode-btn:hover {
    background: rgba(88, 166, 255, 0.15);
    color: var(--text);
}

.map-mode-btn.active {
    background: var(--accent);
    color: #fff;
}

#coords-filter {
    padding: 5px 8px;
    font-size: 12px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-left: 1px solid var(--border);
    cursor: pointer;
    outline: none;
}

#coords-filter:hover {
    color: var(--text);
}

/* Fix Leaflet dark theme clashing */
.leaflet-popup-content-wrapper {
    background: var(--bg-card);
    color: var(--text);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.leaflet-popup-tip {
    background: var(--bg-card);
}

.leaflet-popup-content {
    margin: 10px 14px;
    font-size: 13px;
    line-height: 1.5;
}

.popup-date {
    font-weight: 600;
    color: var(--accent);
}

.popup-loc {
    color: var(--text-muted);
    font-size: 12px;
}

.popup-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 12px;
}

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

/* Leaflet cluster overrides for dark theme */
.marker-cluster-small {
    background-color: rgba(88, 166, 255, 0.3) !important;
}
.marker-cluster-small div {
    background-color: rgba(88, 166, 255, 0.6) !important;
    color: #fff !important;
}
.marker-cluster-medium {
    background-color: rgba(242, 142, 43, 0.3) !important;
}
.marker-cluster-medium div {
    background-color: rgba(242, 142, 43, 0.6) !important;
    color: #fff !important;
}
.marker-cluster-large {
    background-color: rgba(225, 87, 89, 0.3) !important;
}
.marker-cluster-large div {
    background-color: rgba(225, 87, 89, 0.6) !important;
    color: #fff !important;
}

/* ---- Timeline ---- */
.timeline-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    flex-shrink: 0;
}

#timeline-title {
    font-size: 15px;
    font-weight: 600;
}

.chart-container {
    flex: 1;
    padding: 0 16px 16px;
    min-height: 0;
}

#timeline-chart {
    width: 100% !important;
}

/* ---- Search ---- */
.search-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    flex-shrink: 0;
}

.search-bar input[type="text"] {
    flex: 1;
    padding: 8px 12px;
    font-size: 14px;
}

.search-info {
    padding: 0 16px 8px;
    font-size: 13px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-results {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px;
}

#btn-load-more {
    margin: 12px 16px;
    width: calc(100% - 32px);
}

/* ---- Result Card ---- */
.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.result-card:hover {
    border-color: var(--accent);
}

.result-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.result-date {
    font-weight: 600;
    font-size: 14px;
    color: var(--accent);
}

.result-loc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.result-desc {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    max-height: 3.6em;
    overflow: hidden;
    margin-bottom: 4px;
}

.result-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* ---- Badges ---- */
.source-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
}

.shape-tag {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.collection-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    background: #6c5ce7;
    color: #fff;
}

/* Loading animation */
.loading-pulse {
    animation: pulse 1.5s ease-in-out infinite;
    color: var(--accent);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 90vw;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

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

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

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

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

.modal-body {
    padding: 18px;
    overflow-y: auto;
    flex: 1;
}

/* ---- Detail Grid ---- */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.detail-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
}

.detail-section h3 {
    font-size: 13px;
    color: var(--accent);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-section h3 a {
    color: var(--accent);
    text-decoration: none;
}

.detail-section h3 a:hover {
    text-decoration: underline;
}

.detail-full-width {
    grid-column: 1 / -1;
}

.detail-row {
    font-size: 13px;
    margin-bottom: 4px;
    line-height: 1.5;
}

.detail-label {
    color: var(--text-muted);
    font-weight: 500;
}

.detail-desc {
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 300px;
    overflow-y: auto;
    padding: 8px;
    background: var(--bg);
    border-radius: 4px;
}

.detail-minimap {
    height: 150px;
    border-radius: 4px;
    margin-top: 8px;
}

/* ---- Duplicate rows ---- */
.dupe-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
}

.dupe-row:hover {
    background: var(--bg);
}

.dupe-score {
    font-weight: 600;
    color: var(--green);
}

.dupe-method {
    font-size: 11px;
    color: var(--text-muted);
}

/* ---- Duplicates Panel ---- */
.dupes-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.dupes-results {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px;
}

#btn-dupes-more {
    margin: 12px 16px;
    width: calc(100% - 32px);
}

/* ---- Duplicate Pair Card ---- */
.dupe-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 8px;
    overflow: hidden;
}

.dupe-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border);
}

.dupe-card-score {
    font-weight: 700;
    font-size: 14px;
}

.dupe-card-method {
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
}

.dupe-card-pair {
    display: flex;
    gap: 0;
}

.dupe-card-side {
    flex: 1;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    min-width: 0;
}

.dupe-card-side:hover {
    background: rgba(88, 166, 255, 0.05);
}

.dupe-card-side:first-child {
    border-right: 1px solid var(--border);
}

.dupe-card-vs {
    display: flex;
    align-items: center;
    padding: 0 8px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.dupe-card-date {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    margin-top: 4px;
}

.dupe-card-loc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.dupe-card-desc {
    font-size: 12px;
    line-height: 1.4;
    color: var(--text);
    max-height: 2.8em;
    overflow: hidden;
    margin-top: 4px;
}

/* ---- Raw JSON ---- */
.raw-json {
    font-size: 12px;
    line-height: 1.4;
    background: var(--bg);
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ---- Methodology Page ---- */
.methodology {
    max-width: 920px;
    margin: 0 auto;
    padding: 24px 32px 60px;
    line-height: 1.7;
    font-size: 14px;
}

.methodology h2 {
    font-size: 22px;
    color: var(--accent);
    margin: 40px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.methodology h2:first-child {
    margin-top: 0;
}

.methodology h3 {
    font-size: 17px;
    color: var(--text);
    margin: 28px 0 10px;
}

.methodology h4 {
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 20px 0 8px;
}

.methodology p {
    margin: 8px 0 12px;
    color: var(--text);
}

.methodology .meth-intro {
    font-size: 15px;
    color: var(--text-muted);
    border-left: 3px solid var(--accent);
    padding-left: 14px;
    margin-bottom: 20px;
}

.methodology ul,
.methodology ol {
    margin: 8px 0 12px 20px;
    color: var(--text);
}

.methodology li {
    margin-bottom: 4px;
}

.methodology li ul,
.methodology li ol {
    margin-top: 4px;
    margin-bottom: 4px;
}

.methodology table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0 16px;
    font-size: 13px;
}

.methodology th {
    text-align: left;
    padding: 8px 10px;
    background: var(--bg-input);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--border);
}

.methodology td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.methodology tr:hover td {
    background: rgba(88, 166, 255, 0.03);
}

.methodology code {
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    font-size: 12px;
    background: var(--bg-input);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--accent);
}

.methodology pre {
    background: var(--bg-input);
    padding: 12px 16px;
    border-radius: 6px;
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    font-size: 13px;
    overflow-x: auto;
    margin: 10px 0 16px;
    border: 1px solid var(--border);
    color: var(--green);
}

.methodology em {
    color: var(--text-muted);
}

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

/* ---- Error ---- */
.error {
    color: var(--red);
}

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

::-webkit-scrollbar-track {
    background: var(--bg);
}

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

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

/* ---- Insights ---- */
.insights-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    flex-shrink: 0;
}

.insights-title {
    font-size: 15px;
    font-weight: 600;
}

.insights-status {
    font-size: 12px;
    color: var(--text-muted);
}

.insights-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 0 16px 16px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.insight-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px;
    display: flex;
    flex-direction: column;
}

.insight-card h3 {
    font-size: 13px;
    color: var(--accent);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.insight-chart-wrap {
    flex: 1;
    position: relative;
    min-height: 280px;
}

.insights-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 60px 20px;
    font-size: 14px;
}

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