/* ============================================
   NocMig Analyzer — Stylesheet
   ============================================ */

:root {
    --bg: #0f1923;
    --bg-card: #182635;
    --bg-hover: #1e3347;
    --text: #e8edf2;
    --text-muted: #8899aa;
    --accent: #3b9dff;
    --accent-hover: #5bb0ff;
    --success: #2dd4a8;
    --warning: #f0b429;
    --danger: #ef4444;
    --border: #263a4d;
    --radius: 10px;
    --shadow: 0 4px 20px rgba(0,0,0,0.3);
}

* {
    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);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
}

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

/* ---- Navbar ---- */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 14px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
}

.logo-icon {
    font-size: 1.6em;
}

.logo-text {
    font-size: 1.2em;
    font-weight: 700;
    letter-spacing: -0.02em;
}

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

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95em;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: var(--accent);
}

/* ---- Main ---- */
main {
    padding: 40px 0 60px;
    /* flex: 1 set on body-level above */
}

h1 {
    font-size: 1.8em;
    font-weight: 700;
    margin-bottom: 8px;
}

h2 {
    font-size: 1.4em;
    font-weight: 600;
    margin-bottom: 16px;
}

h3 {
    font-size: 1.15em;
    font-weight: 600;
}

h4 {
    font-size: 0.95em;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 30px;
    max-width: 600px;
}

/* ---- Forms ---- */
.upload-form {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 30px;
    border: 1px solid var(--border);
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.95em;
}

.hint {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.85em;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-row .form-group {
    flex: 1;
}

input[type="date"],
input[type="number"],
input[type="text"],
textarea,
.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.95em;
    transition: border-color 0.2s;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}

/* File drop zone */
.file-drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(59, 157, 255, 0.05);
}

.file-drop-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.drop-icon {
    font-size: 2.5em;
    display: block;
    margin-bottom: 10px;
}

.drop-text p {
    color: var(--text-muted);
    margin: 4px 0;
}

.file-types {
    font-size: 0.85em;
}

.file-selected {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

.file-icon {
    font-size: 1.4em;
}

/* Map */
.map-container {
    height: 280px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 10px;
}

.coords-display {
    display: flex;
    gap: 10px;
}

.coords-display input {
    flex: 1;
}

/* ---- Buttons ---- */
.btn {
    padding: 12px 28px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

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

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

.btn-small {
    padding: 6px 14px;
    font-size: 0.85em;
}

.btn-remove {
    background: none;
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.2s;
}

.btn-remove:hover {
    background: var(--danger);
    color: #fff;
}

/* ---- Spinner ---- */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.loading-xc {
    color: var(--text-muted);
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 20px;
}

/* ---- Results ---- */
.results-section {
    margin-top: 50px;
    padding-top: 30px;
    border-top: 2px solid var(--border);
}

.result-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 30px;
}

.meta-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 18px;
    flex: 1;
    min-width: 140px;
}

.meta-label {
    display: block;
    font-size: 0.8em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.meta-value {
    font-weight: 600;
    font-size: 1.05em;
}

/* Spectrogram */
.spectrogram-section {
    margin-bottom: 30px;
}

.spectrogram-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    overflow-x: auto;
}

.spectrogram-img {
    width: 100%;
    height: auto;
    border-radius: 6px;
    display: block;
}

/* Detection cards */
.detections-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.detection-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: border-color 0.2s;
}

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

.detection-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
    gap: 20px;
}

.detection-species h3 {
    margin-bottom: 2px;
}

.scientific-name {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9em;
}

.detection-confidence {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

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

.confidence-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--warning), var(--success));
    border-radius: 4px;
    transition: width 0.5s ease;
}

.confidence-value {
    font-weight: 600;
    font-size: 0.95em;
    color: var(--success);
    min-width: 50px;
    text-align: right;
}

.detection-time {
    color: var(--text-muted);
    font-size: 0.9em;
    margin-bottom: 16px;
}

/* Detection spectrograms side by side */
.detection-spectrograms {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.spec-column h4 {
    margin-bottom: 8px;
}

/* Xeno-Canto */
.xc-recording {
    background: var(--bg);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}

.xc-recording .spectrogram-img {
    margin-bottom: 8px;
}

.xc-info {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
}

.xc-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9em;
}

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

.xc-quality, .xc-recordist {
    font-size: 0.8em;
    color: var(--text-muted);
}

.xc-recording audio {
    width: 100%;
    height: 30px;
    margin-top: 4px;
}

.no-ref {
    color: var(--text-muted);
    font-size: 0.9em;
    padding: 10px;
}

/* ---- Alternatives ---- */
.alternatives-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.alternatives-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
    margin-top: 10px;
}

.alternative-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
}

.alt-header {
    margin-bottom: 8px;
}

.alt-header strong {
    display: block;
}

.alt-probability {
    font-size: 0.9em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.cluster-badge {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 0.75em;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 6px;
}

/* ---- Admin ---- */
.admin-section {
    max-width: 800px;
}

.admin-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}

.species-input-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
}

.species-input-row input[type="text"] {
    flex: 1;
}

.primary-label {
    font-size: 0.85em;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

/* Clusters list */
.cluster-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
}

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

.cluster-desc {
    color: var(--text-muted);
    font-size: 0.9em;
    margin-bottom: 10px;
}

.cluster-members {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.member-badge {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85em;
}

.member-badge.primary {
    border-color: var(--accent);
    color: var(--accent);
}

/* Frequency chart */
.freq-chart {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 100px;
    margin-top: 14px;
    padding: 0 4px;
}

.freq-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}

.freq-fill {
    width: 100%;
    background: var(--accent);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    margin-top: auto;
}

.freq-label {
    font-size: 0.7em;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ---- States ---- */
.success {
    color: var(--success);
}

.error {
    color: var(--danger);
}

.no-detections {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* ---- Footer ---- */
.footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 24px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85em;
}

.footer-links {
    margin-top: 6px;
}

.footer a {
    color: var(--accent);
    text-decoration: none;
}

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

/* ---- XC type badge ---- */
.xc-type-badge {
    display: inline-block;
    background: rgba(59,157,255,0.15);
    color: var(--accent);
    border: 1px solid rgba(59,157,255,0.35);
    border-radius: 4px;
    padding: 1px 7px;
    font-size: 0.78em;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: lowercase;
    vertical-align: middle;
}

/* ---- Species autocomplete ---- */
.ac-wrapper {
    position: relative;
}

.species-display-input {
    width: 100%;
}

.ac-dropdown li:hover {
    background: var(--bg-hover);
}

/* ---- eBird occurrence section ---- */
.ebird-section {
    margin-top: 32px;
}

.ebird-section h3 {
    margin-bottom: 4px;
}

.ebird-section .subtitle {
    font-size: 0.88em;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.ebird-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.ebird-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    transition: border-color 0.2s;
}

.ebird-card.ebird-observed {
    border-left: 4px solid var(--success);
}

.ebird-card.ebird-not-observed {
    border-left: 4px solid var(--danger);
    opacity: 0.7;
}

.ebird-card-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}

.ebird-status-icon {
    font-size: 1.2em;
    line-height: 1;
    flex-shrink: 0;
    margin-top: 2px;
}

.ebird-card-header strong {
    display: block;
    font-size: 1em;
}

.ebird-card-header .scientific-name {
    font-size: 0.82em;
    color: var(--text-muted);
    font-style: italic;
}

.ebird-card-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.85em;
    color: var(--text-muted);
}

.ebird-status-text {
    font-weight: 600;
}

.ebird-observed .ebird-status-text {
    color: var(--success);
}

.ebird-not-observed .ebird-status-text {
    color: var(--danger);
}

.ebird-date, .ebird-count, .ebird-location {
    color: var(--text-muted);
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .detection-spectrograms {
        grid-template-columns: 1fr;
    }

    .result-meta {
        flex-direction: column;
    }

    .form-row {
        flex-direction: column;
    }

    .detection-header {
        flex-direction: column;
    }
}
