/* ===================================
   Global Styles & Layout
   =================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1a1a1a;
    color: #e0e0e0;
    overflow: hidden;
    height: 100vh;
}

#app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
}

#main-content {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* ===================================
   View Mode Control
   =================================== */

#view-mode-control {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(40, 40, 40, 0.6);
    border-radius: 6px;
    margin: 8px 0;
}

#view-mode-control label {
    color: #ccc;
    font-size: 12px;
    font-weight: 600;
    margin-right: 5px;
}

.view-button {
    background: #333;
    color: #aaa;
    border: 1px solid #555;
    padding: 5px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s;
}

.view-button:hover {
    background: #444;
    color: #fff;
}

.view-button.active {
    background: #4a9eff;
    color: #fff;
    border-color: #4a9eff;
}

/* ===================================
   Simulation Speed Control
   =================================== */

#sim-speed-control {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(40, 40, 40, 0.6);
    border-radius: 6px;
    margin: 8px 0;
}

#sim-speed-control label {
    color: #ccc;
    font-size: 12px;
    font-weight: 600;
    margin-right: 5px;
}

.speed-button {
    background: #333;
    color: #aaa;
    border: 1px solid #555;
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s;
}

.speed-button:hover {
    background: #444;
    color: #fff;
}

.speed-button.active {
    background: #4a9eff;
    color: #fff;
    border-color: #4a9eff;
}

/* ===================================
   Map Container (Left Side)
   =================================== */

#map-container {
    flex: 1;
    position: relative;
    min-width: 0;
    overflow: visible;
}

#map {
    width: 100%;
    height: 100%;
    background: #0d1117;
}

#view-3d {
    width: 100%;
    height: 100%;
    background: #87CEEB;
}

/* Instrument Overlays */
.instrument-overlay {
    position: absolute;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid #444;
    border-radius: 50%;
    padding: 5px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}

/* Bottom instrument panel - all in a row */
.instrument-bottom-right {
    bottom: 10px;
    right: 20px;
}

.instrument-top-center {
    bottom: 10px;
    right: 280px;  /* Airspeed + gap */
}

/* Turn coordinator removed - gap closed */

.instrument-left-center {
    bottom: 10px;
    right: 540px;  /* Moved from 800px to close gap */
}
.instrument-vor {
    bottom: 10px;
    right: 800px;  /* Moved from 1060px to close gap */
}

.instrument-altimeter {
    bottom: 10px;
    right: 1060px;  /* Moved from 1320px to close gap */
}

#airspeed-indicator,
#attitude-indicator,
#heading-indicator,
#turn-coordinator,
#altimeter {
    display: block;
    border-radius: 50%;
}

/* Debug Overlay */
#debug-overlay {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    color: #0f0;
}

.debug-section {
    margin-bottom: 12px;
}

.debug-section:last-child {
    margin-bottom: 0;
}

.debug-section strong {
    display: block;
    color: #fff;
    margin-bottom: 6px;
    border-bottom: 1px solid #333;
    padding-bottom: 3px;
}

.debug-section div {
    padding: 2px 0;
}

.debug-section span {
    color: #0ff;
    font-weight: bold;
}

/* ===================================
   NAV Radio Panel (Bottom Left)
   =================================== */

.nav-radio-panel {
    background: linear-gradient(180deg, #2a2a2a 0%, #1a1a1a 100%);
    border: 2px solid #444;
    border-radius: 8px;
    padding: 15px;
    font-family: 'Arial', sans-serif;
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.7);
    margin-bottom: 20px;
}

.nav-radio-header {
    font-size: 12px;
    font-weight: bold;
    color: #888;
    margin-bottom: 10px;
    text-align: center;
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
}

.nav-radio-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.nav-radio-label {
    font-size: 14px;
    font-weight: bold;
    color: #aaa;
    width: 50px;
}

.nav-frequency-box {
    flex: 1;
    background: #000;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-frequency-box.active {
    border-color: #0f0;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.3);
}

.nav-ident {
    color: #0f0;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: bold;
}

.nav-freq {
    color: #0f0;
    font-family: 'Courier New', monospace;
    font-size: 16px;
    font-weight: bold;
}

.nav-vor-select-row {
    margin-bottom: 12px;
    padding-left: 60px;
}

.nav-vor-dropdown {
    width: 100%;
    background: #1a1a1a;
    color: #0f0;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 6px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    cursor: pointer;
}

.nav-vor-dropdown:focus {
    outline: none;
    border-color: #0f0;
    box-shadow: 0 0 5px rgba(0, 255, 0, 0.3);
}

.nav-vor-dropdown option {
    background: #1a1a1a;
    color: #0f0;
}

.nav-select-btn {
    width: 35px;
    height: 35px;
    background: #333;
    border: 2px solid #555;
    border-radius: 50%;
    color: #888;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-select-btn:hover {
    background: #444;
    border-color: #666;
}

.nav-select-btn.selected {
    background: #0f0;
    border-color: #0f0;
    color: #000;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

/* ===================================
   Panel Container (Right Side)
   =================================== */

#panel-container {
    width: 420px;
    background: #242424;
    border-left: 2px solid #333;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.panel-header {
    background: #1a1a1a;
    padding: 20px;
    border-bottom: 2px solid #444;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
}

.panel-header h1 {
    font-size: 24px;
    color: #fff;
    margin: 0;
    flex: 0 0 auto;
}

.sim-status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

#sim-status-text {
    color: #0f0;
    font-weight: bold;
}

/* ===================================
   Instrument Section
   =================================== */

.instrument-section {
    padding: 20px;
    border-bottom: 2px solid #333;
}

.instrument-section h2 {
    font-size: 18px;
    margin-bottom: 15px;
    color: #fff;
}

.instrument-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #1a1a1a;
    border-radius: 8px;
    padding: 20px;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.5);
}

#vor-instrument {
    display: block;
    border-radius: 4px;
    max-width: 100%;
    height: auto;
}

.instrument-hint {
    text-align: center;
    margin-top: 10px;
    padding: 8px;
    background: rgba(13, 110, 253, 0.1);
    border-radius: 4px;
    font-size: 12px;
    color: #aaa;
}

.instrument-hint strong {
    color: #0d6efd;
}

/* ===================================
   Controls Section
   =================================== */

.controls-section {
    padding: 20px;
    flex: 1;
}

.controls-section h3 {
    font-size: 16px;
    color: #fff;
    margin-bottom: 15px;
    margin-top: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid #444;
}

.controls-section h3:first-child {
    margin-top: 0;
}

.control-group {
    margin-bottom: 20px;
}

.control-group label {
    display: block;
    font-size: 13px;
    color: #aaa;
    margin-bottom: 8px;
    font-weight: 500;
}

.input-with-value {
    display: flex;
    align-items: center;
    gap: 10px;
}

input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #333;
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #0d6efd;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #0d6efd;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

input[type="number"] {
    width: 80px;
    padding: 8px 10px;
    background: #333;
    border: 1px solid #555;
    border-radius: 4px;
    color: #fff;
    font-size: 14px;
}

input[type="number"]:focus {
    outline: none;
    border-color: #0d6efd;
}

/* Wind controls in one line */
.wind-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.wind-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wind-input input[type="number"] {
    width: 70px;
}

.input-with-value span {
    font-weight: bold;
    color: #0ff;
    min-width: 60px;
}

/* OBS Controls */
.obs-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-arrow {
    background: #333;
    border: 1px solid #555;
    color: #fff;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-arrow:hover {
    background: #444;
}

.btn-arrow:active {
    background: #555;
}

/* VOR Info */
#selected-vor-info {
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 10px;
    font-size: 13px;
}

#vor-ident {
    font-weight: bold;
    color: #0ff;
    font-size: 16px;
    margin-bottom: 4px;
}

#vor-freq, #vor-dme {
    color: #aaa;
    font-size: 12px;
}

select {
    width: 100%;
    padding: 8px 10px;
    background: #333;
    border: 1px solid #555;
    border-radius: 4px;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: #0d6efd;
}

/* Checkbox */
input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin-right: 8px;
}

.control-group label input[type="checkbox"] {
    display: inline;
}

/* Buttons */
button {
    background: #0d6efd;
    border: none;
    color: #fff;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

button:hover {
    background: #0b5ed7;
}

button:active {
    background: #0a58ca;
}

#btn-pause {
    background: #dc3545;
}

#btn-pause:hover {
    background: #bb2d3b;
}

/* ===================================
   Debug Info Panel
   =================================== */

.debug-section-panel {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 20px;
}

.debug-section-panel h3 {
    margin-bottom: 12px;
    color: #fff;
    font-size: 14px;
}

.debug-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.debug-info-row {
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.debug-label {
    color: #888;
    margin-right: 5px;
}

.debug-value {
    color: #0ff;
    font-weight: bold;
}

/* ===================================
   Keyboard Help
   =================================== */

.keyboard-help {
    background: #1a1a1a;
    border-top: 1px solid #333;
    padding: 15px 20px;
    margin-top: 10px;
}

.keyboard-help h4 {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
}

.keyboard-help table {
    width: 100%;
    font-size: 12px;
}

.keyboard-help td {
    padding: 4px 0;
}

.keyboard-help td:first-child {
    width: 40%;
    color: #aaa;
}

kbd {
    display: inline-block;
    padding: 2px 6px;
    background: #333;
    border: 1px solid #555;
    border-radius: 3px;
    font-family: monospace;
    font-size: 11px;
    color: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ===================================
   Responsive
   =================================== */

@media (max-width: 1024px) {
    #panel-container {
        width: 360px;
    }
    
    #vor-instrument {
        width: 250px;
        height: 250px;
    }
}

/* ===================================
   Autopilot Panel - Top Bar
   =================================== */

#autopilot-panel {
    width: 100%;
    height: 70px;
    background: linear-gradient(180deg, #2a2a2a 0%, #1a1a1a 100%);
    border-bottom: 2px solid #444;
    display: flex;
    align-items: center;
    padding: 10px 20px;
    gap: 25px;
    z-index: 2000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
}

/* Master AP Switch */
.ap-master-switch {
    display: flex;
    align-items: center;
    padding-right: 20px;
    border-right: 2px solid #444;
}

.ap-switch {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.ap-switch input[type="checkbox"] {
    width: 40px;
    height: 40px;
    margin: 0;
    cursor: pointer;
    appearance: none;
    background: #333;
    border: 3px solid #666;
    border-radius: 8px;
    position: relative;
    transition: all 0.2s;
}

.ap-switch input[type="checkbox"]:checked {
    background: #0a0;
    border-color: #0f0;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

.ap-switch input[type="checkbox"]:checked::before {
    content: "✓";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 24px;
    font-weight: bold;
}

.ap-switch-label {
    margin-top: 5px;
    font-size: 12px;
    font-weight: bold;
    color: #aaa;
}

.ap-switch input[type="checkbox"]:checked ~ .ap-switch-label {
    color: #0f0;
}

/* Session Tracking Indicator */
.session-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(220, 38, 38, 0.1);
    border: 2px solid rgba(220, 38, 38, 0.3);
    border-radius: 6px;
    margin-left: 20px;
}

.recording-dot {
    width: 10px;
    height: 10px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse-recording 2s ease-in-out infinite;
}

@keyframes pulse-recording {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 5px rgba(239, 68, 68, 0.5);
    }
    50% {
        opacity: 0.5;
        box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
    }
}

.session-text {
    font-size: 11px;
    font-weight: 700;
    color: #ef4444;
    letter-spacing: 0.5px;
}

/* AP Controls Container */
.ap-controls {
    display: flex;
    gap: 25px;
    align-items: center;
}

/* AP Mode Group */
.ap-mode {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

/* AP Mode Button */
.ap-mode-button {
    width: 50px;
    height: 50px;
    background: #333;
    border: 2px solid #555;
    border-radius: 4px;
    color: #999;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.ap-mode-button:hover {
    background: #444;
    border-color: #666;
}

.ap-mode-button.active {
    background: #0a0;
    border-color: #0f0;
    color: #fff;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.4);
}

/* AP Display (Digital Readout) */
.ap-display {
    font-size: 16px;
    font-weight: bold;
    color: #0f0;
    background: #000;
    padding: 4px 10px;
    border-radius: 3px;
    min-width: 65px;
    text-align: center;
    font-family: 'Courier New', monospace;
    border: 1px solid #333;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6);
}

.ap-knob {
    cursor: pointer;
    transition: transform 0.1s;
}

.ap-knob:active {
    transform: scale(0.95);
}

/* NAV Mode Status Display */
.ap-display.nav-status {
    min-width: 65px;
    color: #888;
}

.ap-display.nav-status.active {
    color: #0f0;
}

/* Adjust map container to account for top bar */
#map-container {
    margin-top: 70px;
}

@media (max-width: 768px) {
    #app {
        flex-direction: column;
    }
    
    #map-container {
        height: 50vh;
    }
    
    #panel-container {
        width: 100%;
        height: 50vh;
    }
    
    #debug-overlay {
        font-size: 11px;
        padding: 10px;
    }
    
    #autopilot-panel {
        right: 0;
        height: 60px;
        gap: 15px;
        padding: 0 10px;
    }
    
    .ap-controls {
        gap: 15px;
