/* ============================================================
   ClearDeck Cockpit CSS — v1.0
   Dark theme, tablet layout, QAB, bottom nav, split screen
   ============================================================ */

/* ──────────────────────────────────────────────────────────
   THEME SYSTEM
   Higher specificity (html[attr] 0-1-1) beats :root (0-1-0)
   ────────────────────────────────────────────────────────── */

/* ── True Black / Cockpit Night Mode ── */
html[data-theme="night"] {
    --ink: #000000;
    --ink-light: #080808;
    --sky: #0d0d0d;
    --glass: rgba(255,255,255,0.02);
    --glass-border: rgba(255,255,255,0.05);
    --glass-hover: rgba(255,255,255,0.04);
}

/* ── Night Vision (Red) — preserves rod cells ── */
html[data-theme="night-vision"] {
    --ink: #0c0000;
    --ink-light: #140000;
    --sky: #1c0404;
    --accent: #d43000;
    --accent-dim: #b02600;
    --accent-glow: rgba(212,48,0,0.2);
    --orange: #ff3300;
    --orange-dim: #cc2200;
    --orange-glow: rgba(255,51,0,0.15);
    --glass: rgba(180,0,0,0.04);
    --glass-border: rgba(200,0,0,0.1);
    --glass-hover: rgba(180,0,0,0.07);
    --text: #ff5533;
    --text-bright: #ff3311;
    --text-dim: rgba(255,85,51,0.5);
    --success: #cc2200;
    --danger: #ff0000;
    --warning: #ff4400;
    --vfr: #cc2200;
    --mvfr: #882200;
    --ifr: #ff0000;
    --lifr: #cc0044;
    --radar-green: #ff2200;
}

html[data-theme="night-vision"] body {
    filter: url('#cd-red-filter');
}

/* ── Day Mode (High-contrast sunlight) ── */
html[data-theme="day"] {
    --ink: #e8f0f8;
    --ink-light: #f0f6fc;
    --sky: #d0dce8;
    --accent: #0059b3;
    --accent-dim: #004799;
    --accent-glow: rgba(0,89,179,0.15);
    --orange: #c05500;
    --orange-dim: #a04400;
    --orange-glow: rgba(192,85,0,0.12);
    --glass: rgba(0,40,100,0.06);
    --glass-border: rgba(0,40,100,0.12);
    --glass-hover: rgba(0,40,100,0.09);
    --text: #1a2744;
    --text-bright: #0a1628;
    --text-dim: rgba(26,39,68,0.55);
    --success: #0059b3;
    --danger: #cc0011;
    --warning: #aa5500;
    --vfr: #0059b3;
    --mvfr: #2266aa;
    --ifr: #cc0011;
    --lifr: #990044;
    --radar-green: #005599;
}

html[data-theme="day"] .nav,
html[data-theme="day"] #cd-bottom-bar {
    background: rgba(232,240,248,0.94) !important;
}

html[data-theme="day"] body {
    background: var(--ink);
    color: var(--text);
}

/* ──────────────────────────────────────────────────────────
   FONT SIZE OPTIONS
   ────────────────────────────────────────────────────────── */

html[data-font="large"] {
    font-size: 17px;
}

html[data-font="xlarge"] {
    font-size: 20px;
}

html[data-font="large"] .nav-brand,
html[data-font="xlarge"] .nav-brand {
    font-size: 1.3em;
}

/* ──────────────────────────────────────────────────────────
   DECLUTTER MODE — hide non-critical chrome
   ────────────────────────────────────────────────────────── */

html[data-declutter="1"] .cd-non-critical,
html[data-declutter="1"] .nav-links,
html[data-declutter="1"] .nav-right,
html[data-declutter="1"] .page-title,
html[data-declutter="1"] .section-header {
    display: none !important;
}

html[data-declutter="1"] .nav {
    height: 48px !important;
    padding: 0 16px !important;
}

html[data-declutter="1"] .nav-brand span {
    display: none !important;
}

/* ──────────────────────────────────────────────────────────
   BOTTOM BAR (QAB + NAV combined)
   Fixed at bottom of viewport
   ────────────────────────────────────────────────────────── */

#cd-bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9900;
    background: rgba(10,15,26,0.96);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid rgba(255,255,255,0.07);
    display: flex;
    flex-direction: column;
    user-select: none;
    -webkit-user-select: none;
    /* Safe area for notch/home bar */
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ──────────────────────────────────────────────────────────
   QUICK ACCESS BAR (top row of bottom bar)
   ────────────────────────────────────────────────────────── */

#cd-qab {
    display: flex;
    align-items: center;
    gap: 0;
    height: 34px;
    padding: 0 8px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    overflow: hidden;
}

.cd-qab-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    height: 100%;
    cursor: pointer;
    border-right: 1px solid rgba(255,255,255,0.06);
    transition: background 0.15s;
    min-width: 60px;
    white-space: nowrap;
}

.cd-qab-item:hover,
.cd-qab-item:active {
    background: rgba(255,255,255,0.05);
}

.cd-qab-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text-dim, rgba(200,214,229,0.5));
    font-family: 'Space Grotesk', monospace;
    text-transform: uppercase;
}

.cd-qab-val {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent, #00d4aa);
    font-family: 'Space Grotesk', monospace;
    letter-spacing: 0.03em;
}

.cd-qab-item.cd-qab-alt .cd-qab-val { color: #4ad0e8; }
.cd-qab-item.cd-qab-gs  .cd-qab-val { color: #00d4aa; }
.cd-qab-item.cd-qab-hdg .cd-qab-val { color: #ffa502; }
.cd-qab-item.cd-qab-freq .cd-qab-val { color: #ff9f43; }
.cd-qab-item.cd-qab-near .cd-qab-val { color: #c8d6e5; }

html[data-theme="night-vision"] .cd-qab-val { color: #ff4422 !important; }
html[data-theme="day"] .cd-qab-val { color: #0059b3 !important; }
html[data-theme="day"] .cd-qab-item.cd-qab-hdg .cd-qab-val { color: #885500 !important; }

.cd-qab-sep {
    flex: 1;
    min-width: 8px;
}

.cd-qab-time {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 0 10px;
    border-right: 1px solid rgba(255,255,255,0.06);
    line-height: 1.2;
}

.cd-qab-utc {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-bright, #f0f4f8);
    font-family: 'Space Grotesk', monospace;
    letter-spacing: 0.04em;
}

.cd-qab-local {
    font-size: 10px;
    color: var(--text-dim, rgba(200,214,229,0.5));
    font-family: 'Space Grotesk', monospace;
}

.cd-qab-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 6px;
}

.cd-qab-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 14px;
    color: var(--text-dim, rgba(200,214,229,0.5));
    transition: all 0.15s;
    min-width: 28px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.cd-qab-btn:hover,
.cd-qab-btn:active {
    background: rgba(255,255,255,0.08);
    color: var(--text-bright, #f0f4f8);
}

.cd-qab-btn.active {
    color: var(--accent, #00d4aa);
}

/* ──────────────────────────────────────────────────────────
   BOTTOM NAVIGATION BAR
   ────────────────────────────────────────────────────────── */

#cd-bottom-nav {
    display: flex;
    align-items: stretch;
    height: 56px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}

#cd-bottom-nav::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.cd-nav-link {
    flex: 1;
    min-width: 54px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-dim, rgba(200,214,229,0.5));
    transition: color 0.15s, background 0.15s;
    border-right: 1px solid rgba(255,255,255,0.04);
    cursor: pointer;
    min-height: 44px;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.cd-nav-link:last-child { border-right: none; }

.cd-nav-link:hover,
.cd-nav-link:active {
    background: rgba(255,255,255,0.04);
    color: var(--text-bright, #f0f4f8);
}

.cd-nav-link.active {
    color: var(--accent, #00d4aa);
    background: rgba(0,212,170,0.06);
}

.cd-nav-link.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 2px;
    background: var(--accent, #00d4aa);
    border-radius: 0 0 2px 2px;
}

html[data-theme="night-vision"] .cd-nav-link.active {
    color: #ff4422 !important;
    background: rgba(255,68,34,0.06) !important;
}
html[data-theme="night-vision"] .cd-nav-link.active::before {
    background: #ff4422 !important;
}

html[data-theme="day"] .cd-nav-link.active {
    color: #0059b3 !important;
    background: rgba(0,89,179,0.07) !important;
}
html[data-theme="day"] .cd-nav-link.active::before {
    background: #0059b3 !important;
}

.cd-nav-icon {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cd-nav-icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    stroke: none;
}

.cd-nav-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    font-family: 'Space Grotesk', sans-serif;
    text-transform: uppercase;
    line-height: 1;
}

/* ── Split screen link (special) ── */
.cd-nav-link.cd-split-link {
    border-left: 1px solid rgba(255,255,255,0.04);
}

/* ──────────────────────────────────────────────────────────
   BODY PADDING — make room for bottom bar
   ────────────────────────────────────────────────────────── */

body.cd-has-bottom-bar {
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
}

/* ──────────────────────────────────────────────────────────
   TABLET-FIRST RESPONSIVE
   iPad 10.9" = 820px+, iPad Pro 12.9" = 1024px+
   ────────────────────────────────────────────────────────── */

/* All touch targets ≥ 44px */
@media (pointer: coarse) {
    button, .btn, a.btn, [role="button"],
    input[type="button"], input[type="submit"],
    select, .tab, .filter-btn, .action-btn,
    .tab-btn, .mode-btn {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 10px 16px !important;
    }

    /* Table rows bigger for tap */
    table tr { min-height: 44px; }
    td, th { padding: 10px 12px !important; }

    /* Bigger input fields */
    input, select, textarea {
        min-height: 44px !important;
        font-size: 16px !important; /* prevents iOS zoom */
        padding: 10px 14px !important;
    }
}

/* iPad portrait (820px) */
@media (min-width: 820px) and (max-width: 1024px) {
    .nav {
        padding: 0 20px !important;
        height: 54px !important;
    }

    /* Hide desktop nav links - bottom nav handles navigation */
    .nav-links {
        display: none !important;
    }

    .main-content,
    .content-wrapper,
    main {
        padding: 16px 20px !important;
    }

    /* Wider card grids on tablet */
    .stats-grid,
    .cards-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 12px !important;
    }

    /* Better table display */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* iPad Pro landscape (1024px+) */
@media (min-width: 1024px) and (max-width: 1366px) {
    .nav {
        padding: 0 24px !important;
    }
}

/* Landscape: extra compact QAB */
@media (orientation: landscape) and (max-height: 500px) {
    #cd-bottom-bar {
        flex-direction: row;
        height: 44px;
    }

    #cd-qab {
        flex: 1;
        border-bottom: none;
        border-right: 1px solid rgba(255,255,255,0.05);
        height: 44px;
    }

    #cd-bottom-nav {
        height: 44px;
        width: 340px;
        flex-shrink: 0;
    }

    .cd-nav-label { display: none; }
    .cd-nav-icon { width: 20px; height: 20px; }

    body.cd-has-bottom-bar {
        padding-bottom: calc(44px + env(safe-area-inset-bottom, 0px));
    }
}

/* ──────────────────────────────────────────────────────────
   EMBEDDED MODE (inside split-screen iframes)
   ────────────────────────────────────────────────────────── */

html[data-embedded="1"] .nav {
    display: none !important;
}

html[data-embedded="1"] #cd-bottom-bar {
    display: none !important;
}

html[data-embedded="1"] body {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

html[data-embedded="1"] .main-content,
html[data-embedded="1"] main,
html[data-embedded="1"] .content-wrapper {
    padding-top: 12px !important;
}

/* ──────────────────────────────────────────────────────────
   THEME TOGGLE POPUP
   ────────────────────────────────────────────────────────── */

#cd-theme-popup {
    position: fixed;
    bottom: calc(90px + env(safe-area-inset-bottom, 0px) + 8px);
    right: 12px;
    background: var(--sky, #1a2744);
    border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
    border-radius: 10px;
    padding: 8px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    min-width: 160px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.18s, transform 0.18s;
    pointer-events: none;
}

#cd-theme-popup.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.cd-theme-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text, #c8d6e5);
    transition: background 0.12s;
    font-family: 'DM Sans', sans-serif;
    min-height: 40px;
}

.cd-theme-option:hover {
    background: rgba(255,255,255,0.06);
}

.cd-theme-option.active {
    background: rgba(0,212,170,0.1);
    color: var(--accent, #00d4aa);
}

.cd-theme-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Font size popup */
#cd-font-popup {
    position: fixed;
    bottom: calc(90px + env(safe-area-inset-bottom, 0px) + 8px);
    right: 12px;
    background: var(--sky, #1a2744);
    border: 1px solid var(--glass-border, rgba(255,255,255,0.08));
    border-radius: 10px;
    padding: 8px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    min-width: 150px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.18s, transform 0.18s;
    pointer-events: none;
}

#cd-font-popup.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.cd-font-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 500;
    color: var(--text, #c8d6e5);
    transition: background 0.12s;
    font-family: 'DM Sans', sans-serif;
    min-height: 40px;
}

.cd-font-option:hover { background: rgba(255,255,255,0.06); }
.cd-font-option.active { background: rgba(0,212,170,0.1); color: var(--accent, #00d4aa); }

/* ──────────────────────────────────────────────────────────
   SPLIT SCREEN (split.html)
   ────────────────────────────────────────────────────────── */

.cd-split-container {
    display: flex;
    width: 100vw;
    height: calc(100vh - 90px - env(safe-area-inset-bottom, 0px));
    overflow: hidden;
    background: var(--ink, #0a0f1a);
}

.cd-split-panel {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-width: 200px;
    position: relative;
}

.cd-split-panel iframe {
    width: 100%;
    flex: 1;
    border: none;
    background: var(--ink, #0a0f1a);
    min-height: 0;
}

.cd-split-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: rgba(10,15,26,0.9);
    border-bottom: 1px solid rgba(255,255,255,0.07);
    height: 38px;
    flex-shrink: 0;
}

.cd-split-title {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-dim, rgba(200,214,229,0.5));
    font-family: 'Space Grotesk', sans-serif;
}

.cd-split-actions {
    display: flex;
    gap: 4px;
}

.cd-split-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 5px;
    color: var(--text-dim, rgba(200,214,229,0.5));
    cursor: pointer;
    font-size: 11px;
    padding: 3px 8px;
    min-height: 28px;
    transition: all 0.15s;
}

.cd-split-btn:hover {
    background: rgba(255,255,255,0.07);
    color: var(--text-bright, #f0f4f8);
}

.cd-split-panel-select {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 5px;
    color: var(--text, #c8d6e5);
    font-size: 12px;
    font-weight: 600;
    padding: 2px 6px;
    cursor: pointer;
    min-height: 28px;
    outline: none;
}

/* Drag handle */
.cd-split-handle {
    width: 6px;
    background: rgba(255,255,255,0.05);
    cursor: col-resize;
    flex-shrink: 0;
    position: relative;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cd-split-handle:hover,
.cd-split-handle.dragging {
    background: rgba(0,212,170,0.25);
}

.cd-split-handle::before {
    content: '';
    width: 2px;
    height: 40px;
    background: rgba(255,255,255,0.15);
    border-radius: 1px;
}

.cd-split-handle:hover::before,
.cd-split-handle.dragging::before {
    background: var(--accent, #00d4aa);
}

/* Split screen top bar */
.cd-split-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 48px;
    background: rgba(10,15,26,0.96);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}

.cd-split-logo {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-bright, #f0f4f8);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.cd-split-logo span {
    color: var(--accent, #00d4aa);
}

.cd-split-presets {
    display: flex;
    gap: 6px;
    align-items: center;
}

.cd-split-preset {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 6px;
    color: var(--text-dim, rgba(200,214,229,0.5));
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    padding: 5px 10px;
    min-height: 32px;
    transition: all 0.15s;
    font-family: 'Space Grotesk', sans-serif;
    letter-spacing: 0.04em;
}

.cd-split-preset:hover {
    background: rgba(0,212,170,0.08);
    border-color: rgba(0,212,170,0.2);
    color: var(--accent, #00d4aa);
}

.cd-split-preset.active {
    background: rgba(0,212,170,0.12);
    border-color: rgba(0,212,170,0.35);
    color: var(--accent, #00d4aa);
}

/* ──────────────────────────────────────────────────────────
   OFFLINE INDICATOR (enhanced)
   ────────────────────────────────────────────────────────── */

.cd-offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: #c05500;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    z-index: 99999;
    font-family: 'Space Grotesk', sans-serif;
    letter-spacing: 0.04em;
}

.cd-offline-banner.hidden {
    display: none;
}

/* ──────────────────────────────────────────────────────────
   MISC ENHANCEMENTS
   ────────────────────────────────────────────────────────── */

/* Smoother scrolling on tablets */
* {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Prevent text resize on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* High-contrast focus rings for accessibility */
:focus-visible {
    outline: 2px solid var(--accent, #00d4aa);
    outline-offset: 2px;
}

/* Swipe hint (shown once) */
.cd-swipe-hint {
    position: fixed;
    bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: var(--text, #c8d6e5);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    z-index: 9800;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.cd-swipe-hint.visible {
    opacity: 1;
}

/* Page transition overlay */
.cd-page-transition {
    position: fixed;
    inset: 0;
    background: var(--ink, #0a0f1a);
    z-index: 99998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.cd-page-transition.active {
    opacity: 1;
    pointer-events: all;
}
