:root {
    --bg-primary: #0a0e27;
    --bg-secondary: #1a1f3a;
    --bg-tertiary: #252b48;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --accent-primary: #3b82f6;
    --accent-secondary: #10b981;
    --accent-danger: #ef4444;
    --accent-warning: #f59e0b;
    --border-color: #374151;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
    flex-wrap: wrap;
    min-height: 50px;
}

.header-title {
    font-size: clamp(14px, 3vw, 18px);
    font-weight: 600;
    color: var(--accent-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: clamp(11px, 2.5vw, 13px);
    flex-wrap: wrap;
}

/* Main Container */
.container {
    display: flex;
    gap: 12px;
    padding: 12px;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 50px);
}

/* Responsive Column Layout */
@media (min-width: 1400px) {
    .left-column, .right-column {
        width: 320px;
    }
    .container {
        gap: 20px;
        padding: 20px;
    }
}

@media (min-width: 1200px) and (max-width: 1399px) {
    .left-column, .right-column {
        width: 280px;
    }
}

@media (min-width: 1024px) and (max-width: 1199px) {
    .left-column, .right-column {
        width: 250px;
    }
}

/* Desktop Layout */
@media (min-width: 1024px) {
    .left-column {
        display: flex;
        flex-direction: column;
        gap: 12px;
        flex-shrink: 0;
        overflow-y: auto;
        max-height: calc(100vh - 74px);
        padding-right: 4px;
    }

    .middle-column {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 12px;
        min-width: 0;
        overflow: hidden;
    }

    .right-column {
        display: flex;
        flex-direction: column;
        gap: 12px;
        flex-shrink: 0;
        overflow-y: auto;
        max-height: calc(100vh - 74px);
        padding-right: 4px;
    }
}

/* Tablet Layout */
@media (min-width: 768px) and (max-width: 1023px) {
    body {
        overflow: auto;
    }
    
    .container {
        flex-direction: column;
        padding: 12px;
        gap: 12px;
        height: auto;
        overflow: visible;
    }

    .left-column,
    .middle-column,
    .right-column {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .panel-header {
        cursor: pointer;
        user-select: none;
        position: relative;
    }

    .panel-header::after {
        content: '▼';
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        transition: transform 0.3s ease;
    }

    .panel.collapsed .panel-header::after {
        transform: translateY(-50%) rotate(-90deg);
    }

    .panel.collapsed .panel-content {
        display: none;
    }
}

/* Mobile Layout */
@media (max-width: 767px) {
    body {
        overflow: auto;
    }
    
    .container {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
        height: auto;
        overflow: visible;
    }

    .left-column,
    .middle-column,
    .right-column {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .panel-header {
        cursor: pointer;
        user-select: none;
        position: relative;
    }

    .panel-header::after {
        content: '▼';
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        transition: transform 0.3s ease;
    }

    .panel.collapsed .panel-header::after {
        transform: translateY(-50%) rotate(-90deg);
    }

    .panel.collapsed .panel-content {
        display: none;
    }
}

/* Panel Styles */
.panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    flex-shrink: 0;
}

.panel-header {
    font-size: clamp(13px, 2.5vw, 15px);
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--accent-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

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

/* Terminal Panel */
.terminal-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 250px;
}

/* Control Panel */
.control-panel {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-primary);
}

.control-panel::-webkit-scrollbar {
    width: 6px;
}

.control-panel::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.control-panel::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* Connection Status */
.connection-status {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-danger);
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.status-indicator.connected {
    background: var(--accent-secondary);
    box-shadow: 0 0 8px var(--accent-secondary);
}

/* Port Info */
.port-info {
    font-size: clamp(9px, 2vw, 11px);
    color: var(--text-secondary);
    margin-top: 8px;
    font-family: 'Courier New', monospace;
    word-break: break-all;
}

/* Buttons */
.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-size: clamp(11px, 2.5vw, 13px);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
    min-height: 36px;
}

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

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

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

.btn-secondary:hover {
    background: #374151;
}

.btn-danger {
    background: var(--accent-danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

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

/* Command Section */
.command-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: visible;
}

/* Image Management section styling */
.command-section > div:last-child {
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.command-input {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    color: var(--text-primary);
    font-size: clamp(11px, 2.5vw, 13px);
    font-family: 'Courier New', monospace;
    min-height: 36px;
}

.command-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.command-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(65px, 1fr));
    gap: 6px;
}

.command-preset {
    padding: 6px 4px;
    font-size: clamp(9px, 2vw, 11px);
    min-height: 32px;
}

/* Terminal Output */
.terminal {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    font-family: 'Courier New', monospace;
    font-size: clamp(10px, 2vw, 12px);
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-primary);
}

.terminal::-webkit-scrollbar {
    width: 6px;
}

.terminal::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.terminal::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.terminal-line {
    margin-bottom: 3px;
    line-height: 1.3;
    word-wrap: break-word;
}

.terminal-line.command {
    color: var(--accent-primary);
}

.terminal-line.response {
    color: var(--accent-secondary);
}

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

.terminal-line.warning {
    color: var(--accent-warning);
}

.terminal-line.info {
    color: var(--text-secondary);
}

/* Telemetry Panel */
.telemetry-panel {
    flex-shrink: 0;
}

/* Telemetry Grid */
.telemetry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 12px;
}

.telemetry-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: center;
}

.telemetry-label {
    font-size: clamp(9px, 2vw, 11px);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.telemetry-value {
    font-size: clamp(14px, 3.5vw, 18px);
    font-weight: 600;
    color: var(--accent-primary);
    font-family: 'Courier New', monospace;
}

/* Radio Configuration */
.radio-config {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.radio-section {
    padding: 8px;
    background: var(--bg-tertiary);
    border-radius: 6px;
}

.radio-section label {
    font-size: clamp(11px, 2.5vw, 13px);
    color: var(--text-secondary);
    display: block;
    margin-bottom: 6px;
}

.radio-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 6px;
}

.freq-grid {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 6px;
    align-items: center;
    margin-bottom: 6px;
}

.settings-input {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px;
    color: var(--text-primary);
    font-size: clamp(11px, 2.5vw, 13px);
    min-height: 32px;
}

.settings-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* LED Indicators */
.led-indicators {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 8px;
}

.led-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: clamp(9px, 2vw, 11px);
}

.led {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #374151;
    transition: all 0.2s ease;
    position: relative;
    flex-shrink: 0;
}

.led.active {
    background: var(--accent-secondary);
    box-shadow: 0 0 12px var(--accent-secondary);
}

.led.active::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 50%;
    background: radial-gradient(circle, transparent, var(--accent-secondary));
    opacity: 0.6;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.2); opacity: 0.3; }
}

/* Orientation Panel */
.orientation-panel {
    min-height: 280px;
}

.orientation-canvas {
    width: 100%;
    height: 200px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    position: relative;
    margin-bottom: 8px;
}

@media (min-width: 1200px) {
    .orientation-canvas {
        height: 250px;
    }
}

.orientation-values {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.orientation-value {
    text-align: center;
    padding: 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.orientation-label {
    font-size: clamp(9px, 2vw, 11px);
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 3px;
}

.orientation-data {
    font-size: clamp(12px, 3vw, 14px);
    font-weight: 600;
    color: var(--accent-primary);
    font-family: 'Courier New', monospace;
}

/* Settings Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 24px;
    max-width: 450px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    font-size: clamp(16px, 3.5vw, 18px);
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--accent-primary);
}

.settings-group {
    margin-bottom: 16px;
}

.settings-label {
    display: block;
    margin-bottom: 6px;
    font-size: clamp(11px, 2.5vw, 13px);
    color: var(--text-secondary);
}

/* Column-specific scrollbar styling */
.left-column::-webkit-scrollbar,
.right-column::-webkit-scrollbar {
    width: 6px;
}

.left-column::-webkit-scrollbar-track,
.right-column::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 3px;
}

.left-column::-webkit-scrollbar-thumb,
.right-column::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.left-column::-webkit-scrollbar-thumb:hover,
.right-column::-webkit-scrollbar-thumb:hover {
    background: #4b5563;
}

/* Responsive adjustments for very small screens */
@media (max-width: 480px) {
    .btn {
        min-height: 40px;
        padding: 10px 12px;
    }

    .command-preset {
        min-height: 36px;
        padding: 8px 6px;
    }

    .command-buttons {
        grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    }

    .header {
        padding: 8px 12px;
    }

    .container {
        padding: 8px;
        gap: 8px;
    }

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

/* Global scrollbar styling */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-primary);
}

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

*::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

*::-webkit-scrollbar-thumb:hover {
    background: #4b5563;
}