/* ================================================================
   BATSOUND - NEXT GENERATION UI
   AI-powered bat echolocation detection interface with modern design
   ================================================================ */

/* ========== Design System - Pibico Corporate ========== */
:root {
    /* Glassmorphism Theme */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(209, 209, 209, 0.5);
    --glass-shadow: 0 8px 32px 0 rgba(70, 130, 180, 0.12);
    --glass-backdrop: blur(20px) saturate(180%);

    /* Pibico Gradient System */
    --aurora-1: linear-gradient(135deg, #4682b4 0%, #5a9bd4 100%);
    --aurora-2: linear-gradient(135deg, #8f1402 0%, #a52a17 100%);
    --aurora-3: linear-gradient(135deg, #4682b4 0%, #5a9bd4 100%);
    --aurora-4: linear-gradient(135deg, #28a745 0%, #34c759 100%);
    --aurora-5: linear-gradient(135deg, #ffb74d 0%, #ffa726 100%);

    /* Pibico Corporate Colors */
    --primary: #4682b4;
    --primary-light: #6fa3d4;
    --primary-dark: #2e6190;
    --secondary: #768089;
    --accent: #8f1402;
    --success: #28a745;
    --warning: #ffb74d;
    --error: #8f1402;
    --info: #4682b4;

    /* Surface Colors */
    --surface-1: rgba(255, 255, 255, 0.98);
    --surface-2: rgba(239, 244, 249, 0.95);
    --surface-3: rgba(239, 244, 249, 0.85);
    --surface-overlay: rgba(118, 128, 137, 0.08);

    /* Text Colors */
    --text-1: #000000;
    --text-2: #475569;
    --text-3: #768089;
    --text-inverse: #ffffff;

    /* Neumorphism */
    --neu-shadow-1: 12px 12px 24px #d1d1d1, -12px -12px 24px #ffffff;
    --neu-shadow-2: 6px 6px 12px #d1d1d1, -6px -6px 12px #ffffff;
    --neu-inset: inset 6px 6px 12px #d1d1d1, inset -6px -6px 12px #ffffff;

    /* Spacing Scale - Compact */
    --space-1: 2px;
    --space-2: 3px;
    --space-3: 6px;
    --space-4: 8px;
    --space-5: 12px;
    --space-6: 16px;
    --space-7: 24px;
    --space-8: 32px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Transitions */
    --ease-in-out-cubic: cubic-bezier(0.65, 0, 0.35, 1);
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Typography - Inter Tight */
    --font-sans: 'Inter Tight', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', Arial, sans-serif;
    --font-display: 'Inter Tight', var(--font-sans);
    --font-mono: 'SF Mono', 'Consolas', monospace;

    /* Z-index */
    --z-base: 1;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-modal-backdrop: 400;
    --z-modal: 500;
    --z-popover: 600;
    --z-toast: 700;
}

/* ========== Base Reset ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

html, body {
    width: 100%;
    min-height: 100vh;
    overscroll-behavior: none;
}

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1;
    color: var(--text-1);
    background: #eff4f9;
    position: relative;
}

/* Animated Background */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        radial-gradient(circle at 20% 50%, rgba(70, 130, 180, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(118, 128, 137, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(70, 130, 180, 0.08) 0%, transparent 50%);
    animation: aurora 20s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes aurora {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(30px, -50px) rotate(120deg); }
    66% { transform: translate(-20px, 20px) rotate(240deg); }
}

/* ========== App Container ========== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: relative;
    z-index: var(--z-base);
    padding: var(--space-5);
}

/* ========== Main Content Area ========== */
.main-content {
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.header {
    text-align: center;
    margin-bottom: var(--space-6);
}

.header h1 {
    font-family: var(--font-display);
    font-size: 2.5rem;
    font-weight: 800;
    background: var(--aurora-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    text-transform: uppercase;
}

.header .icon {
    font-size: 3rem;
    -webkit-text-fill-color: initial;
}

.header p {
    color: var(--text-2);
    font-size: 1.1rem;
    margin-top: var(--space-3);
}

/* ========== Cards ========== */
.card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    backdrop-filter: var(--glass-backdrop);
    -webkit-backdrop-filter: var(--glass-backdrop);
    box-shadow: var(--glass-shadow);
    padding: var(--space-6);
    margin-bottom: var(--space-5);
}

.upload-card {
    padding: var(--space-6);
}

.results-card {
    display: none;
}

.results-card.show {
    display: block;
}

/* ========== Upload Zone ========== */
.upload-zone {
    border: 3px dashed var(--glass-border);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    text-align: center;
    cursor: pointer;
    transition: all 0.4s var(--ease-out-expo);
    background: var(--surface-overlay);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: rgba(94, 53, 177, 0.1);
    transform: scale(1.01);
}

.upload-zone .upload-icon {
    font-size: 4rem;
    margin-bottom: var(--space-4);
}

.upload-zone h3 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: var(--space-2);
    color: var(--text-1);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.upload-zone p {
    color: var(--text-3);
}

.file-input {
    display: none;
}

/* ========== File Info ========== */
.file-info {
    display: none;
    background: rgba(94, 53, 177, 0.1);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-md);
    margin-top: var(--space-5);
    align-items: center;
    gap: var(--space-4);
    border: 1px solid rgba(94, 53, 177, 0.2);
}

.file-info.show {
    display: flex;
}

.file-info .file-icon {
    font-size: 2rem;
    color: var(--primary);
}

.file-info .file-details {
    flex: 1;
}

.file-info .file-name {
    font-weight: 600;
    color: var(--text-1);
}

.file-info .file-size {
    color: var(--text-3);
    font-size: 0.9rem;
}

.file-info .remove-btn {
    width: 36px;
    height: 36px;
    background: var(--error);
    border: none;
    border-radius: var(--radius-full);
    color: var(--text-inverse);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s var(--ease-out-expo);
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-info .remove-btn:hover {
    transform: scale(1.1) rotate(90deg);
}

/* ========== Settings Grid ========== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-5);
    margin-top: var(--space-5);
}

.setting-item label {
    display: block;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-1);
    margin-bottom: var(--space-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.setting-item input,
.setting-item select {
    width: 100%;
    padding: var(--space-4);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: var(--font-sans);
    background: var(--surface-overlay);
    color: var(--text-1);
    transition: all 0.3s var(--ease-out-expo);
}

.setting-item input:focus,
.setting-item select:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface-1);
    box-shadow: 0 0 0 4px rgba(94, 53, 177, 0.1);
}

/* ========== Control Buttons ========== */
.controls-buttons {
    display: flex;
    gap: var(--space-4);
    justify-content: center;
    margin-top: var(--space-6);
}

.control-btn {
    padding: var(--space-4) var(--space-6);
    border-radius: var(--radius-full);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    font-size: 15px;
    font-weight: 700;
    font-family: var(--font-sans);
    transition: all 0.4s var(--ease-out-expo);
    position: relative;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.control-btn:hover {
    transform: translateY(-4px);
}

.control-btn:active {
    transform: translateY(-2px);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.control-btn.btn-primary {
    background: var(--aurora-1);
    color: var(--text-inverse);
    box-shadow: 0 8px 24px rgba(94, 53, 177, 0.35);
}

.control-btn.btn-primary:hover {
    box-shadow: 0 12px 32px rgba(94, 53, 177, 0.45);
}

.control-btn.btn-secondary {
    background: linear-gradient(135deg, #94a3b8 0%, #64748b 100%);
    color: var(--text-inverse);
    box-shadow: 0 8px 24px rgba(100, 116, 139, 0.35);
}

/* ========== Progress Section ========== */
.progress-section {
    display: none;
    margin-top: var(--space-5);
    padding: var(--space-5);
    background: rgba(94, 53, 177, 0.1);
    border-radius: var(--radius-md);
}

.progress-section.show {
    display: block;
}

.progress-bar {
    height: 8px;
    background: var(--surface-overlay);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--aurora-1);
    width: 0%;
    transition: width 0.3s var(--ease-out-expo);
    border-radius: var(--radius-full);
}

.progress-text {
    text-align: center;
    margin-top: var(--space-3);
    color: var(--text-2);
    font-weight: 600;
}

/* ========== Error Message ========== */
.error-message {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #991b1b;
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius-md);
    margin-top: var(--space-5);
    display: none;
    font-weight: 500;
}

.error-message.show {
    display: block;
}

/* ========== Results Section ========== */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-5);
}

.results-header h2 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--aurora-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detection-count {
    background: var(--aurora-1);
    color: var(--text-inverse);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    font-weight: 700;
    font-size: 0.9rem;
}

/* ========== Detection Cards Grid ========== */
#detectionsList {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

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

.detection-card {
    background: var(--surface-1);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    transition: all 0.3s var(--ease-out-expo);
}

.detection-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.species-info h3 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: var(--space-1);
}

.species-info .common-name-es {
    display: block;
    color: var(--text-2);
    font-size: 0.95rem;
    margin-bottom: var(--space-1);
}

.species-info .scientific-name {
    font-style: italic;
    color: var(--text-3);
    font-size: 0.9rem;
}

.confidence-badge {
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    font-weight: 700;
    font-size: 0.85rem;
}

.confidence-high {
    background: rgba(102, 187, 106, 0.2);
    color: #2e7d32;
}

.confidence-medium {
    background: rgba(255, 183, 77, 0.2);
    color: #f57c00;
}

.confidence-low {
    background: rgba(229, 115, 115, 0.2);
    color: #c62828;
}

.detection-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-item .label {
    font-size: 0.75rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: var(--space-1);
}

.detail-item .value {
    font-weight: 600;
    color: var(--text-1);
}

.detection-media {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

.media-item {
    background: var(--surface-overlay);
    border-radius: var(--radius-md);
    padding: var(--space-3);
}

.media-item h4 {
    font-size: 0.85rem;
    color: var(--text-2);
    margin-bottom: var(--space-2);
    font-weight: 600;
}

.media-item img {
    width: 100%;
    border-radius: var(--radius-sm);
}

.media-item audio {
    width: 100%;
}

/* ========== Species Image ========== */
.species-image {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    background: var(--surface-overlay);
}

.species-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detection-header {
    display: flex;
    gap: var(--space-4);
    align-items: flex-start;
    margin-bottom: var(--space-4);
}

.detection-badges {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    align-items: flex-end;
    margin-left: auto;
}

.detection-count-badge {
    background: var(--aurora-1);
    color: var(--text-inverse);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-full);
    font-weight: 700;
    font-size: 0.85rem;
}

/* ========== Detections Content ========== */
.detections-content {
    margin-top: var(--space-4);
}

.detection-instance {
    background: var(--surface-overlay);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    cursor: pointer;
    transition: all 0.3s var(--ease-out-expo);
}

.detection-instance:hover {
    background: rgba(94, 53, 177, 0.08);
}

.detection-instance:last-child {
    margin-bottom: 0;
}

.instance-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.instance-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.expand-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: var(--text-inverse);
    border-radius: var(--radius-full);
    font-weight: 700;
    font-size: 1rem;
    transition: transform 0.3s var(--ease-out-expo);
}

.detection-instance.collapsed .expand-icon {
    background: var(--text-3);
}

.instance-time {
    font-weight: 600;
    color: var(--text-1);
    font-size: 0.9rem;
}

.instance-content {
    margin-top: var(--space-3);
    overflow: hidden;
    transition: all 0.3s var(--ease-out-expo);
}

.detection-instance.collapsed .instance-content {
    display: none;
}

.detection-instance .detection-media {
    margin-top: 0;
}

/* ========== Stacked Media (spectrogram + audio) ========== */
.media-item-stacked {
    margin-bottom: var(--space-2);
}

.media-item-stacked:last-child {
    margin-bottom: 0;
}

.media-item-stacked img {
    width: 100%;
    border-radius: var(--radius-sm);
}

.media-item-stacked audio {
    width: 100%;
}

/* ========== Other Detections Collapsible Section ========== */
.other-detections-section {
    margin-top: var(--space-4);
    border-top: 1px solid var(--glass-border);
    padding-top: var(--space-3);
}

.other-detections-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: var(--space-2) 0;
}

.other-detections-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-2);
}

.other-detections-section .expand-icon {
    width: 20px;
    height: 20px;
    font-size: 0.85rem;
}

.other-detections-content {
    margin-top: var(--space-3);
}

.detections-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.other-detections-section.collapsed .other-detections-content {
    display: none;
}

.other-detections-section.collapsed .expand-icon {
    background: var(--text-3);
}

/* ========== Primary Detection (first one) ========== */
.detection-instance.primary {
    cursor: default;
    background: transparent;
    padding: 0;
}

.detection-instance.primary:hover {
    background: transparent;
}

.no-results {
    text-align: center;
    padding: var(--space-8);
    color: var(--text-3);
}

.no-results .icon {
    font-size: 4rem;
    margin-bottom: var(--space-4);
}

/* ========== Toast ========== */
.toast-notification {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass-bg);
    backdrop-filter: var(--glass-backdrop);
    -webkit-backdrop-filter: var(--glass-backdrop);
    border: 1px solid var(--glass-border);
    color: var(--text-1);
    padding: var(--space-4) var(--space-6);
    border-radius: var(--radius-full);
    box-shadow: var(--glass-shadow);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    z-index: var(--z-toast);
    transition: bottom 0.5s var(--ease-out-expo);
    font-weight: 600;
}

.toast-notification.show {
    bottom: var(--space-6);
}

.toast-notification.error { background: var(--aurora-2); color: var(--text-inverse); }
.toast-notification.warning { background: var(--aurora-5); color: var(--text-1); }
.toast-notification.info { background: var(--aurora-3); color: var(--text-inverse); }

/* ========== Custom Scrollbar ========== */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--aurora-1);
    border-radius: var(--radius-full);
    border: 3px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
    background-clip: content-box;
}

/* ========== Responsive Design ========== */
@media (max-width: 768px) {
    .app-container {
        padding: var(--space-3);
    }

    .header h1 {
        font-size: 1.8rem;
    }

    .header .icon {
        font-size: 2.2rem;
    }

    .card {
        padding: var(--space-5);
    }

    .upload-zone {
        padding: var(--space-6);
    }

    .detection-media {
        grid-template-columns: 1fr;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .controls-buttons {
        flex-direction: column;
    }

    .control-btn {
        width: 100%;
    }
}

/* ========== Accessibility ========== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
}

/* ========== Dark Mode Support ========== */
@media (prefers-color-scheme: dark) {
    :root {
        --glass-bg: rgba(15, 23, 42, 0.8);
        --glass-border: rgba(255, 255, 255, 0.1);
        --surface-1: rgba(30, 41, 59, 0.95);
        --surface-2: rgba(30, 41, 59, 0.85);
        --surface-3: rgba(30, 41, 59, 0.75);
        --surface-overlay: rgba(255, 255, 255, 0.05);
        --text-1: #f1f5f9;
        --text-2: #cbd5e1;
        --text-3: #64748b;
    }

    body {
        background: linear-gradient(135deg, #4527a0 0%, #5e35b1 100%);
    }

    .detection-card {
        background: rgba(30, 41, 59, 0.9);
    }
}
