/* ============================================================================
   RFM AIRCHECK DESIGN SYSTEM
   ============================================================================ */
:root {
    /* RFM Colors */
    --bg: #0b0e11;
    --panel: #14171c;
    --panel-light: #1c2128;
    --panel-dark: #0d1015;
    --blue: #5aa0ff;
    --blue-light: #8cc2ff;
    --blue-dark: #3a80df;
    --text: #d8e4f0;
    --text-secondary: #a0b0c8;
    --text-muted: #66758a;
    
    /* Channel Colors (behalten für Peaks) */
    --color-left: #00ffaa;
    --color-right: #ff6b9d;
    
    /* Status Colors */
    --success: #00cc88;
    --warning: #ffaa33;
    --error: #ff6b6b;
    
    /* UI Colors */
    --border: #22262d;
    --shadow: rgba(0, 0, 0, 0.4);
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* ============================================================================
   RESET & BASE
   ============================================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    height: 100%;
    overflow: hidden;
    font-size: 14px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
}

/* ============================================================================
   TYPOGRAPHY
   ============================================================================ */
h1, h2, h3, h4, h5, h6 {
    font-weight: 500;
    line-height: 1.2;
}

.mono, code {
    font-family: 'JetBrains Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
}

/* ============================================================================
   APP LAYOUT - RFM STYLE
   ============================================================================ */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: calc(var(--dvh, 1vh) * 100);
    max-height: -webkit-fill-available;
    position: relative;
    overflow: hidden;
}

/* HEADER - RFM Style */
#header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    height: 44px;
}

#title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

/* RFM Logo - falls du das Bild hast */
#logo {
    height: 28px;
    width: auto;
    opacity: 0.95;
    filter: brightness(1.1);
}

/* Falls kein Bild, Text-Logo */
#logo:not([src]) {
    height: auto;
    font-size: 1.8em;
    filter: drop-shadow(0 0 8px rgba(90, 160, 255, 0.5));
}

#title-text {
    font-size: 18px;
    font-weight: 500;
    text-transform: uppercase;
    color: #ffffff;
    letter-spacing: 0.5px;
}

#status-area {
    display: flex;
    align-items: center;
    gap: 8px;
}

#server-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--panel-light);
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

#status {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
}

#status.connected {
    background: linear-gradient(135deg, var(--success), #00aa77);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 204, 136, 0.3);
}

#status.disconnected {
    background: linear-gradient(135deg, var(--error), #ff4444);
    color: white;
}

#status.connecting {
    background: linear-gradient(135deg, var(--warning), #ff9900);
    color: var(--bg);
}

/* MAIN CONTENT AREA */
#main {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

/* VISUALIZATION AREA - Full width */
#viz-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #000;
    min-height: 0;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* OVERLAY STATS - Bottom left (nicht oben blockieren) */
#viz-overlay {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: rgba(20, 23, 28, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(90, 160, 255, 0.2);
    border-radius: var(--radius-md);
    padding: 12px;
    font-size: 12px;
    pointer-events: none;
    min-width: 160px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.viz-stat {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
}

.viz-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.viz-value {
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    color: var(--blue-light);
}

/* CONTROL PANEL - RFM Style */
#control-panel {
    width: 320px;
    background: var(--panel);
    border-left: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
    flex-shrink: 0;
    transition: transform var(--transition-normal);
    z-index: 50;
}

#app.panel-hidden #control-panel {
    transform: translateX(100%);
}

.panel-section {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.panel-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--blue);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    min-height: 28px;
}

.info-label {
    color: var(--text-secondary);
    font-size: 12px;
    flex-shrink: 0;
}

.info-value {
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

.info-value.good { color: var(--success); }
.info-value.warning { color: var(--warning); }
.info-value.error { color: var(--error); }

/* SELECT Dropdown - RFM Style */
.info-select {
    background: var(--panel-light);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    font-family: inherit;
    font-size: 12px;
    min-width: 140px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.info-select:hover {
    border-color: var(--blue);
    background: var(--panel);
}

.info-select:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(90, 160, 255, 0.2);
}

/* PEAK METERS - RFM Style */
.meter-container {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    justify-content: flex-end;
}

.meter-bar {
    width: 80px;
    height: 6px;
    background: var(--panel-light);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.meter-fill {
    height: 100%;
    border-radius: 3px;
    transition: width var(--transition-fast);
}

.meter-fill.left {
    background: linear-gradient(90deg, var(--color-left), #00cc88);
}

.meter-fill.right {
    background: linear-gradient(90deg, var(--color-right), #ff4477);
}

.meter-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 600;
    min-width: 24px;
    text-align: right;
    color: var(--blue-light);
}

/* CONTROLS GRID - RFM Buttons */
.controls-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 12px;
}

/* BUTTONS - RFM Style */
.btn {
    background: var(--panel-light);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    user-select: none;
}

.btn:hover {
    background: var(--panel);
    border-color: var(--blue);
}

.btn:active {
    background: var(--panel-dark);
    transform: translateY(1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--blue), var(--blue-dark));
    color: var(--bg);
    font-weight: 600;
    border: none;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--blue-light), var(--blue));
    box-shadow: 0 2px 8px rgba(90, 160, 255, 0.3);
}

.btn-small {
    padding: 4px 8px;
    font-size: 11px;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px;
    width: 32px;
    height: 32px;
}

/* LOG CONTAINER */
#log-container {
    margin-top: 12px;
}

#log {
    height: 180px;
    background: var(--panel-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    overflow-y: auto;
    margin-bottom: 8px;
}

.log-entry {
    margin-bottom: 3px;
    padding: 4px 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.02);
    border-left: 3px solid transparent;
    font-size: 11px;
    line-height: 1.3;
}

.log-time {
    color: var(--text-muted);
    margin-right: 6px;
    font-size: 10px;
}

.log-info { border-left-color: var(--blue); }
.log-success { border-left-color: var(--success); }
.log-warning { border-left-color: var(--warning); }
.log-error { border-left-color: var(--error); }
.log-data { border-left-color: #9966ff; }

.log-controls {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* FOOTER - RFM Style */
#footer {
    background: var(--panel);
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    height: 48px;
    font-size: 12px;
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

#data-source {
    display: flex;
    align-items: center;
    gap: 6px;
}

.source-label {
    color: var(--text-secondary);
}

.source-value {
    font-family: 'JetBrains Mono', monospace;
    color: var(--blue);
    font-weight: 500;
}

#version-info {
    color: var(--text-muted);
}

.footer-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* TOGGLE PANEL BUTTON */
#toggle-panel {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    transition: all var(--transition-fast);
}

#toggle-panel:hover {
    background: rgba(90, 160, 255, 0.1);
    color: var(--blue);
    border-color: var(--blue);
}

/* AUTO-HIDE für mobile (von RFM Player übernommen) */
.dimmed {
    opacity: 0.25;
    transition: opacity 0.25s ease;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */
@media (max-width: 1200px) {
    #control-panel {
        width: 300px;
    }
}

@media (max-width: 768px) {
    /* Safe Area Support */
    #header {
        padding-top: max(6px, env(safe-area-inset-top, 6px));
        padding-left: max(12px, env(safe-area-inset-left, 12px));
        padding-right: max(12px, env(safe-area-inset-right, 12px));
        padding-bottom: 6px;
        height: 44px;
    }
    
    #footer {
        padding-top: 8px;
        padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
        padding-left: max(16px, env(safe-area-inset-left, 16px));
        padding-right: max(16px, env(safe-area-inset-right, 16px));
    }
    
    #title-text {
        font-size: 16px;
    }
    
    #server-time {
        display: none;
    }
    
    #status {
        display: none;
    }
    
    /* Control Panel für Mobile */
    #control-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 320px;
        transform: translateX(100%);
        padding-top: max(16px, env(safe-area-inset-top, 16px));
        padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
        padding-left: 16px;
        padding-right: 16px;
        z-index: 1000;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
        -webkit-overflow-scrolling: touch;
    }
    
    #app.panel-visible #control-panel {
        transform: translateX(0);
    }
    
    /* Overlay für Hintergrund beim geöffneten Panel */
    #app.panel-visible::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        z-index: 999;
        pointer-events: none;
    }
    
    /* Viz-Overlay für Mobile anpassen */
    #viz-overlay {
        bottom: max(16px, env(safe-area-inset-bottom, 16px));
        left: max(16px, env(safe-area-inset-left, 16px));
        right: max(16px, env(safe-area-inset-right, 16px));
        min-width: auto;
        font-size: 11px;
        padding: 10px;
        background: rgba(20, 23, 28, 0.95);
        backdrop-filter: blur(10px);
    }
    
    /* Touch-friendly Buttons */
    .btn, select {
        min-height: 44px; /* Apple's recommended minimum touch target */
    }
    
    .btn {
        padding: 12px 16px;
    }
    
    .btn-icon {
        width: 44px;
        height: 44px;
        padding: 10px;
    }
    
    /* Log für Mobile optimieren */
    #log {
        height: 150px;
        font-size: 10px;
    }
    
    /* Auto-hide UI on mobile */
    .auto-hide {
        transition: opacity 0.25s ease;
    }
    
    .auto-hide.dimmed {
        opacity: 0.25;
    }
    
    /* Verhindert Pull-to-Refresh */
    body {
        overscroll-behavior-y: none;
    }
    
    /* Bei sehr kleinen Screens */
    @media (max-width: 360px) {
        .controls-grid {
            grid-template-columns: 1fr;
        }
        
        #footer .footer-left {
            flex-direction: column;
            gap: 4px;
            align-items: flex-start;
        }
    }
}

/* ============================================================================
   HORIZONTAL ORIENTATION (Mobile Landscape)
   ============================================================================ */
@media (orientation: landscape) and (max-height: 500px) {
    /* Kompaktere Darstellung im Landscape */
    #header {
        height: 36px !important;
        padding: 4px 8px !important;
    }
    
    #footer {
        height: 36px !important;
        padding: 4px 8px !important;
    }
    
    #viz-overlay {
        bottom: 8px;
        left: 8px;
        padding: 6px 8px;
        font-size: 10px;
    }
    
    .viz-stat {
        margin-bottom: 3px;
    }
    
    #log {
        height: 100px;
    }
}

/* ============================================================================
   WAVEFORM/VISUALIZATION STYLING
   ============================================================================ */
/* Center line */
.waveform-center-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: rgba(90, 160, 255, 0.2);
    pointer-events: none;
}

/* Channel labels in waveform */
.channel-label {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(20, 23, 28, 0.8);
    border: 1px solid rgba(90, 160, 255, 0.2);
    border-radius: 4px;
    padding: 4px 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    pointer-events: none;
    z-index: 5;
}

.channel-label.left {
    color: var(--color-left);
}

.channel-label.right {
    color: var(--color-right);
    top: 32px;
}

/* Loading animation */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

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

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-sm {
    gap: var(--spacing-sm);
}

.gap-md {
    gap: var(--spacing-md);
}

/* Pulse animation for live data */
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

.pulse {
    animation: pulse 2s infinite;
}

/* Touch Feedback */
.touch-active {
    opacity: 0.8;
    transform: scale(0.98);
    transition: opacity 0.1s, transform 0.1s;
}

/* Prevent text selection on interactive elements */
.btn, select, [role="button"] {
    user-select: none;
    -webkit-user-select: none;
}

/* ============================================================================
   iOS SPECIFIC FIXES
   ============================================================================ */
@supports (-webkit-touch-callout: none) {
    /* iOS spezifische Fixes */
    #app {
        height: -webkit-fill-available;
    }
    
    /* Verhindert bounce/scrolling */
    body {
        position: fixed;
        width: 100%;
        overflow: hidden;
    }
    
    /* Bessere Tap Targets */
    button, select, [role="button"] {
        cursor: pointer;
    }
}

/* ============================================================================
   ANDROID CHROME FIXES
   ============================================================================ */
@media screen and (-webkit-min-device-pixel-ratio: 0) and (min-resolution: 0.001dpcm) {
    /* Chrome/Android Fixes */
    #viz-container {
        isolation: isolate;
    }
    
    .meter-fill {
        transform: translateZ(0);
    }
}

/* ============================================================================
   HIGH CONTRAST MODE SUPPORT
   ============================================================================ */
@media (prefers-contrast: high) {
    :root {
        --border: #000000;
        --text: #ffffff;
        --text-secondary: #cccccc;
    }
    
    .btn {
        border-width: 2px;
    }
}

/* ============================================================================
   REDUCED MOTION SUPPORT
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .loading {
        animation: none;
        border-top-color: transparent;
    }
    
    .pulse {
        animation: none;
    }
}

#rfm-loading {
    position: fixed;
    inset: 0;
    background: #0b0e11;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 9999;
}

#rfm-loading .loader-inner {
    text-align: center;
}

#rfm-loading .loader-logo {
    width: 96px;   /* oder was du willst */
    height: auto;
    opacity: 0.9;
}

#rfm-loading .loader-title {
    margin-top: 12px;
    font-size: 22px;
    color: #fff;
    font-weight: 600;
}

#rfm-loading .loader-sub {
    margin-top: 4px;
    font-size: 14px;
    color: var(--blue-light);
}
