:root {
    --bg-gradient: #050505;
    --glass-bg: rgba(10, 15, 12, 0.9);
    /* More solid, professional */
    --glass-border: rgba(255, 255, 255, 0.15);
    --primary: #00E676;
    --primary-dim: rgba(0, 230, 118, 0.15);
    --text-main: #E0E0E0;
    --text-muted: #8899A6;
    --card-radius: 8px;
    /* Tighter corners */
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Georgia", serif;
    background: #050A08;
    /* Fallback for Canvas */
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
}

#dot-grid-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
}

/* Main Container - Professional Structure */
.app-container {
    position: relative;
    z-index: 10;
    background: rgba(10, 15, 12, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--card-radius);
    padding: 32px;
    width: 100%;
    max-width: 960px;
    margin: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 32px;
}

.header-section {
    grid-column: 1 / -1;
    text-align: center;
    margin-bottom: 20px;
}

h1 {
    font-family: "Georgia", serif;
    font-size: 32px;
    font-weight: 700;
    margin: 0 0 8px 0;
    color: #fff;
    /* Removed gradient text for more traditional look */
    letter-spacing: normal;
}

.subtitle {
    color: var(--text-muted);
    font-size: 14px;
    font-style: italic;
    opacity: 0.8;
}

.input-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.mode-switch {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    padding: 4px;
    border-radius: 12px;
    margin-bottom: 10px;
}

.mode-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-family: "Georgia", serif;
}

.mode-btn.active {
    background: var(--glass-border);
    color: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.viewport {
    background: #000;
    border-radius: 6px;
    aspect-ratio: 1/1;
    width: 100%;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    display: flex;
    justify-content: center;
    align-items: center;
}

#webcam-canvas,
#uploaded-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#uploaded-image {
    display: none;
}

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

.controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-main {
    background: var(--primary);
    color: #052e16;
    border: none;
    padding: 14px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.1s;
    width: 100%;
    font-family: "Georgia", serif;
    letter-spacing: normal;
}

.btn-main:hover {
    filter: brightness(1.1);
}

.btn-main:active {
    transform: scale(0.98);
}

.file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 100%;
}

#file-upload {
    font-size: 100px;
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: white;
    border: 1px solid var(--glass-border);
    padding: 16px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    width: 100%;
    transition: background 0.2s;
    font-family: "Georgia", serif;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.analysis-section {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 24px;
    border: 1px solid var(--glass-border);
    height: 100%;
    display: flex;
    flex-direction: column;
}

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

.predictions-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.prediction-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pred-header {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 500;
}

.pred-bar-bg {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.pred-bar-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 10px var(--primary-dim);
}

/* Description Box - Professional Dashboard Style */
.verde-description {
    margin-top: 20px;
    margin-bottom: 20px;
    padding: 20px;
    background: rgba(0, 30, 20, 0.4);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
    flex-grow: 1;
    /* Fill available space */
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.desc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.desc-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 1.5px;
}

.desc-badge {
    background: rgba(0, 230, 118, 0.2);
    color: #00E676;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.verde-description p {
    margin: 0;
}

.desc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: auto;
    /* Push to bottom of container if extra space */
}

.desc-item {
    background: rgba(255, 255, 255, 0.03);
    padding: 10px;
    border-radius: 8px;
}

.desc-label {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

.desc-value {
    font-family: 'Outfit', sans-serif;
    font-size: 14px;
    color: white;
    font-weight: 600;
}

.monitoring-status {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    cursor: help;
    transition: color 0.2s;
}

.monitoring-status:hover {
    color: white;
}

.monitoring-status::after {
    content: "Verde analyzes the last 20 frames to detect rapid negative shifts in classification confidence (e.g. sudden drop in forest health).";
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid var(--glass-border);
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 11px;
    width: 240px;
    text-transform: none;
    letter-spacing: 0;
    line-height: 1.4;
    margin-bottom: 10px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    z-index: 200;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.monitoring-status:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-5px);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--primary);
    /* Animation keyframes removed */
}

.trend-alert {
    grid-column: 1 / -1;
    background: rgba(255, 69, 58, 0.15);
    border: 1px solid rgba(255, 69, 58, 0.4);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    animation: slideDown 0.5s ease-out;
    margin-bottom: 20px;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert-icon {
    font-size: 24px;
}

.alert-title {
    color: #FF453A;
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.alert-msg {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    border-radius: var(--card-radius);
    backdrop-filter: blur(5px);
}

.loader {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Close Button */
.close-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.8);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 1000;
    /* Ensure it's above everything */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.05);
}

@media (max-width: 768px) {
    .app-container {
        grid-template-columns: 1fr;
        padding: 24px;
    }

    .viewport {
        aspect-ratio: 4/3;
    }
}

/* Floating Reopen Button (hidden by default) */
/* Reopen Button - Professional Technical */
.reopen-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 10px 20px;
    border-radius: 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    box-shadow: none;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: all 0.1s ease;
    font-family: "Georgia", serif;
    font-size: 14px;
    font-weight: 700;
    color: #00E676;
}

.reopen-btn:hover {
    text-decoration: underline;
    transform: translateY(-1px);
    filter: brightness(1.2);
}

/* App hidden state */
.app-container.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.98);
    /* Less scaling, more subtle */
    transition: all 0.2s ease-in-out;
}

/* =========================================
   SPECTRAL ANALYSIS & REPORTING STYLES
   ========================================= */

/* Spectral Overlay Canvas */
.spectral-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
    mix-blend-mode: color;
    /* Blends the false color with original luminosity for realism */
    opacity: 0.9;
}

/* Viewport Controls */
.viewport-overlay-controls {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 10;
    display: flex;
    gap: 12px;
}

.spectral-toggle-wrapper {
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 6px 12px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(4px);
}

.spectral-label {
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 1px;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333;
    transition: .4s;
    border-radius: 34px;
    border: 1px solid #555;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 12px;
    width: 12px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.toggle-slider {
    background-color: var(--primary);
    border-color: var(--primary);
}

input:checked+.toggle-slider:before {
    transform: translateX(14px);
    background-color: #003300;
}

/* Spectral Legend */
.spectral-legend {
    position: absolute;
    bottom: 16px;
    right: 16px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.8);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 160px;
}

.legend-gradient {
    height: 8px;
    background: linear-gradient(to right, #8B4513, #CD853F, #FFFF00, #00FF00);
    /* VARI approximation gradient */
    border-radius: 4px;
    width: 100%;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 8px;
    color: #aaa;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* Report Modal - Government Style */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #0A0F0C;
    border: 1px solid #333;
    width: 100%;
    max-width: 500px;
    border-radius: 4px;
    /* Sharper corners for documents */
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
}

.modal-header {
    background: #111;
    border-bottom: 1px solid #333;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-family: "Georgia", serif;
    font-size: 18px;
    color: #fff;
    font-weight: bold;
}

.modal-close {
    background: none;
    border: none;
    color: #666;
    font-size: 18px;
    cursor: pointer;
}

.modal-close:hover {
    color: #fff;
}

.report-body {
    padding: 32px;
    font-family: "Georgia", serif;
    color: #ccc;
    font-size: 14px;
    line-height: 1.6;
}

.report-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.report-subheader {
    font-size: 10px;
    color: #666;
    margin-bottom: 8px;
    border-bottom: 1px solid #222;
    padding-bottom: 4px;
}

.report-row {
    display: flex;
    justify-content: space-between;
}

.report-label {
    color: #666;
}

.report-value {
    color: #fff;
}

.report-value.highlight {
    color: var(--primary);
    font-weight: 700;
}

.report-divider {
    height: 1px;
    background: #222;
    margin: 20px 0;
    border-top: 1px dashed #444;
}

.report-actions {
    margin-top: 32px;
    display: flex;
    gap: 12px;
}

.btn-print {
    flex: 1;
    background: #fff;
    color: #000;
    border: none;
    padding: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    text-transform: uppercase;
}

.btn-download {
    flex: 1;
    background: transparent;
    border: 1px solid #444;
    color: #888;
    padding: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    cursor: pointer;
    text-transform: uppercase;
}

.btn-download:hover {
    border-color: #fff;
    color: #fff;
}

@media print {
    body * {
        visibility: hidden;
    }

    .modal-content,
    .modal-content * {
        visibility: visible;
    }

    .modal-content {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        border: none;
        box-shadow: none;
    }

    .report-actions,
    .modal-close {
        display: none;
    }
}

/* =========================================
   AUTONOMOUS SYSTEM LOG
   ========================================= */
.mission-log-panel {
    position: fixed;
    top: 24px;
    right: 24px;
    bottom: 24px;
    width: 300px;
    background: rgba(10, 12, 11, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    z-index: 1500;
    display: flex;
    flex-direction: column;
    padding: 0;
    box-shadow: -20px 0 50px rgba(0, 0, 0, 0.5);
    transform: translateX(500px);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s;
    font-family: 'JetBrains Mono', monospace;
    overflow: hidden;
    pointer-events: none;
}

.mission-log-panel.visible {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.log-title {
    font-size: 11px;
    font-weight: 700;
    color: #ddd;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.live-indicator {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--primary);
    /* animation: pulse 2s infinite; REMOVED */
}

.btn-clear {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 9px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s;
    font-family: 'JetBrains Mono', monospace;
}

.btn-clear:hover {
    border-color: rgba(255, 255, 255, 0.3);
    color: #fff;
}

.log-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 4px;
    /* Space for scrollbar */
}

/* Custom Scrollbar for Log */
.log-content::-webkit-scrollbar {
    width: 4px;
}

.log-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}

.log-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

/* Log Card */
.log-card {
    background: transparent;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: background 0.2s;
}

.log-card:hover {
    background: rgba(255, 255, 255, 0.02);
}

.log-card.alert {
    /* Minimal alert styling */
    border-left: 2px solid #FF453A;
}

.log-card-header {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: #555;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.log-card-body {
    display: flex;
    gap: 12px;
    align-items: center;
}

.log-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: #000;
}

.log-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
}

.log-type {
    font-size: 10px;
    font-weight: 700;
    color: #eee;
    margin-bottom: 2px;
}

.log-type.danger {
    color: #FF453A;
    text-shadow: 0 0 10px rgba(255, 69, 58, 0.3);
}

.log-coords {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: #888;
}

.log-risk {
    font-size: 9px;
    color: #aaa;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Alert Flash */
.screen-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    border: 4px solid #FF453A;
    pointer-events: none;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.2s;
}

.screen-flash.active {
    opacity: 1;
    animation: monitorFlash 1s infinite alternate;
}

.reopen-log-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 8px 16px;
    border-radius: 4px;
    background: rgba(5, 10, 8, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    z-index: 1400;
    /* Below log panel but above map */
    transition: all 0.2s;
    text-transform: uppercase;
}

.reopen-log-btn:hover {
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
}


@keyframes monitorFlash {
    from {
        box-shadow: inset 0 0 50px rgba(255, 69, 58, 0.2);
    }

    to {
        box-shadow: inset 0 0 100px rgba(255, 69, 58, 0.6);
    }
}