/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 100vw;
    margin: 0 auto;
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: #2c3e50;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Main content layout */
.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* Mobile tab navigation - hidden on desktop */
.mobile-tab-nav {
    display: none;
    background: white;
    border-bottom: 1px solid #ddd;
    padding: 0;
}

/* Show mobile tabs on smaller screens */
@media (max-width: 1024px) {
    .mobile-tab-nav {
        display: flex !important;
    }
}

.mobile-tab-btn {
    flex: 1;
    padding: 1rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.mobile-tab-btn.active {
    background: #f8f9fa;
    border-bottom-color: #3498db;
    color: #3498db;
}

.mobile-tab-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Content wrapper */
.content-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Controls panel (sidebar on desktop) */
.controls-panel {
    width: 300px;
    background: white;
    border-right: 1px solid #ddd;
    padding: 1rem;
    overflow-y: auto;
    box-shadow: 2px 0 4px rgba(0,0,0,0.05);
}

/* Desktop main view with tabs */
.main-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Mobile panels - hidden on desktop */
.mobile-map-panel,
.mobile-hodograph-panel {
    display: none;
    flex: 1;
    background: white;
    overflow-y: auto;
}

.control-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #eee;
}

.control-section:last-child {
    border-bottom: none;
}

.control-section h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
}

/* Main view with tabs */
.main-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Tab navigation */
.tab-nav {
    background: #f8f9fa;
    border-bottom: 1px solid #ddd;
    display: flex;
    padding: 0;
}

.tab-btn {
    background: none;
    border: none;
    padding: 1rem 2rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover:not(:disabled) {
    background: #e9ecef;
    color: #495057;
}

.tab-btn.active {
    color: #2c3e50;
    border-bottom-color: #3498db;
    background: white;
}

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

/* Tab content */
.tab-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.tab-pane {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

.tab-pane.active {
    opacity: 1;
    visibility: visible;
}

/* Map styles */
#map {
    width: 100%;
    height: 100%;
}

/* Hodograph view */
.hodograph-view {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: white;
}

.hodograph-header {
    padding: 1.5rem;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
}

.hodograph-header h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.3rem;
    font-weight: 600;
}

.analysis-details {
    color: #666;
    font-size: 0.9rem;
}

.hodograph-display {
    flex: 1;
    padding: 1rem;
    text-align: center;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 0;
}

.hodograph-display img {
    max-width: 100%;
    max-height: 80vh;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.parameters-display {
    background: #f8f9fa;
    padding: 1.5rem;
    border-top: 1px solid #eee;
    font-size: 0.9rem;
}

.parameters-display h4 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 600;
}

.parameters-display p {
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
}

.parameters-display p:last-child {
    margin-bottom: 0;
}

/* Form elements */
.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #555;
}

input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.checkbox-group {
    margin-bottom: 1rem;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-group input[type="checkbox"] {
    margin-right: 0.5rem;
    width: auto;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    text-align: center;
    display: inline-block;
    text-decoration: none;
    margin-bottom: 0.5rem;
    width: 100%;
}

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

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #2980b9;
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #229954;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #7f8c8d;
}

/* Info sections */
.site-info,
.metar-info,
.analysis-info,
.vad-status {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    border: 1px solid #e9ecef;
    font-size: 0.9rem;
}

.site-info p,
.metar-info p,
.analysis-info p,
.vad-status p {
    margin-bottom: 0.5rem;
}

.site-info p:last-child,
.metar-info p:last-child,
.analysis-info p:last-child,
.vad-status p:last-child {
    margin-bottom: 0;
}

/* Status messages */
.status-messages {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 1000;
    max-width: 400px;
}

.status-message {
    padding: 1rem;
    margin-bottom: 0.5rem;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    animation: slideIn 0.3s ease-out;
}

.status-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.status-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.status-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    flex-direction: column;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

.loading-overlay p {
    color: white;
    font-size: 1.1rem;
}

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.analyst-controls {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: #eef6ff;
    border: 1px solid #c5ddf5;
    border-radius: 4px;
}

.analyst-label {
    font-weight: 500;
    color: #555;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.analyst-controls .checkbox-group {
    margin-bottom: 0.4rem;
}

.analyst-controls .checkbox-group label {
    font-size: 0.85rem;
}

.analyst-controls .input-group {
    margin-bottom: 0.75rem;
}

.analyst-controls .input-group label {
    font-size: 0.85rem;
}

.hodograph-info-box {
    background: rgba(200, 225, 255, 0.9);
    border: 1px solid #99b;
    border-radius: 6px;
    padding: 10px 14px;
    margin: 0 1rem 0.5rem 1rem;
    font-family: monospace;
    font-size: 12px;
    color: #222;
}

.hodograph-info-box .info-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    margin-bottom: 4px;
}

.hodograph-info-box .info-row:last-child {
    margin-bottom: 0;
}

.hodograph-info-box .info-item {
    white-space: nowrap;
}

@media (max-width: 600px) {
    .hodograph-info-box {
        font-size: 11px;
        padding: 8px 10px;
        margin: 0 0.5rem 0.5rem 0.5rem;
    }
    .hodograph-info-box .info-row {
        gap: 4px 12px;
    }
}

#interactiveHodographContainer {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#interactiveHodographContainer canvas {
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Hodograph loop scrubber */
.hodograph-scrubber {
    background: #f8f9fa;
    border-top: 1px solid #e1e4e8;
    padding: 0.6rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.scrubber-status {
    font-size: 0.8rem;
    color: #666;
    min-height: 1em;
}

.scrubber-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.scrubber-btn {
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
    color: #2c3e50;
    transition: background 0.15s, border-color 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.scrubber-btn:hover:not(:disabled) {
    background: #eef6ff;
    border-color: #3498db;
}

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

.scrubber-btn.is-playing {
    background: #3498db;
    border-color: #2980b9;
    color: white;
}

.scrubber-slider {
    flex: 1;
    height: 6px;
    accent-color: #3498db;
    cursor: pointer;
    min-width: 80px;
}

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

.scrubber-counter {
    font-family: monospace;
    font-size: 0.8rem;
    color: #444;
    min-width: 3.5em;
    text-align: right;
}

.scrubber-timestamp {
    font-family: monospace;
    font-size: 0.8rem;
    color: #2c3e50;
    text-align: center;
}

@media (max-width: 600px) {
    .hodograph-scrubber {
        padding: 0.5rem 0.6rem;
    }
    .scrubber-controls {
        gap: 0.35rem;
    }
    .scrubber-btn {
        width: 28px;
        height: 28px;
    }
}

/* Leaflet map customizations */
.leaflet-popup-content-wrapper {
    border-radius: 4px;
}

.leaflet-popup-content {
    margin: 8px 12px;
    font-size: 0.9rem;
}

/* Responsive design */
@media (max-width: 1024px) {
    /* Adjust content wrapper for mobile */
    .content-wrapper {
        flex-direction: column;
        position: relative;
    }
    
    /* Hide desktop main view on mobile */
    .main-view {
        display: none;
    }
    
    /* Hide controls panel by default on mobile */
    .controls-panel {
        display: none;
        width: 100%;
        border: none;
        box-shadow: none;
    }
    
    /* Show active panel on mobile */
    .controls-panel.active {
        display: block;
        flex: 1;
    }
    
    /* Show mobile panels when active */
    .mobile-map-panel.active,
    .mobile-hodograph-panel.active {
        display: block;
        flex: 1;
    }
    
    /* Adjust controls panel for mobile */
    .controls-panel {
        padding: 1rem;
        overflow-y: auto;
        max-height: calc(100vh - 140px);
    }
    
    /* Adjust map panel for mobile */
    .mobile-map-panel {
        min-height: calc(100vh - 140px);
        height: calc(100vh - 140px);
    }
    
    .mobile-map-panel #mobileMap {
        width: 100%;
        height: 100%;
    }
    
    /* Adjust header for mobile */
    header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }
    
    header h1 {
        font-size: 1.3rem;
    }
    
    /* Adjust status messages for mobile */
    .status-messages {
        top: 140px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    /* Adjust control sections for mobile */
    .control-section {
        margin-bottom: 1.5rem;
        padding-bottom: 1rem;
    }
    
    .control-section h3 {
        font-size: 1rem;
    }
    
    /* Adjust input groups for mobile */
    .input-group {
        margin-bottom: 1rem;
    }
    
    .input-group label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    /* Adjust buttons for mobile */
    .btn {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}

@media (min-width: 1025px) {
    /* Desktop layout - hide mobile tabs and show sidebar */
    .mobile-tab-nav {
        display: none !important;
    }
    
    .content-wrapper {
        flex-direction: row;
    }
    
    .controls-panel {
        display: block !important;
    }
    
    .main-view {
        display: flex !important;
    }
    
    /* Hide mobile panels on desktop */
    .mobile-map-panel,
    .mobile-hodograph-panel {
        display: none !important;
    }
}
/* ===== Save Loop button in the upper tab header ========================= */
.tab-nav .header-save-btn {
    margin-left: auto;
    align-self: center;
    margin-right: 0.75rem;
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    background: #2c7d40;
    color: #fff;
    border: 1px solid #1f5c2e;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}
.tab-nav .header-save-btn:hover { background: #38a052; }
.tab-nav .header-save-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.mobile-tab-nav .header-save-btn {
    margin-left: auto;
    align-self: center;
    margin-right: 0.5rem;
    padding: 0.35rem 0.6rem;
    font-size: 0.95rem;
    background: #2c7d40;
    color: #fff;
    border: 1px solid #1f5c2e;
    border-radius: 4px;
    cursor: pointer;
}
.mobile-tab-nav .header-save-btn:hover { background: #38a052; }
.mobile-tab-nav .header-save-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Archives tab ===================================================== */
.archives-view {
    padding: 1rem;
    height: 100%;
    overflow-y: auto;
}
.archives-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.archives-header h3 { margin: 0; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.archives-empty {
    color: #666;
    font-style: italic;
}
.archives-tree { display: flex; flex-direction: column; gap: 0.75rem; }
.archive-site {
    border: 1px solid #d0d7e2;
    border-radius: 6px;
    background: #f8fafc;
    overflow: hidden;
}
.archive-site-header {
    padding: 0.5rem 0.75rem;
    background: #e9eef5;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.archive-site-header .archive-site-count {
    font-weight: 400;
    font-size: 0.85rem;
    color: #555;
}
.archive-site-body {
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.archive-site.is-collapsed .archive-site-body { display: none; }
.archive-entry {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.6rem;
    background: #fff;
    border: 1px solid #e3e8ef;
    border-radius: 5px;
}
.archive-entry-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}
.archive-entry-title {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.9rem;
    font-weight: 500;
}
.archive-entry-meta {
    font-size: 0.75rem;
    color: #555;
}
.archive-entry-meta span + span::before {
    content: "·";
    margin: 0 0.4rem;
    color: #aaa;
}
.archive-entry-actions { display: flex; gap: 0.35rem; }
.archive-entry-actions button {
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
}
.archive-load-btn {
    background: #1d6fb7;
    color: #fff;
    border-color: #155896;
}
.archive-load-btn:hover { background: #2483d6; }
.archive-delete-btn {
    background: transparent;
    color: #b73a3a;
    border-color: #d8b2b2;
}
.archive-delete-btn:hover { background: #fbeaea; }
