/* ═══════════════════════════════════════════
   Mobile Adaptation — Tablet & Phone
   Breakpoints:
     tablet:  768px — 1024px
     phone:   ≤ 767px
   ═══════════════════════════════════════════ */

/* ─── Touch device global ─── */
.touch-device {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}
.touch-device * {
    touch-action: manipulation;
}
/* Bigger tap targets on touch (WCAG minimum 44×44) */
.touch-device .hud-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 8px 14px;
}
/* Touch-friendly buttons inside panels */
.touch-device .dc-close,
.touch-device .aar-close {
    min-width: 36px;
    min-height: 36px;
    font-size: 14px;
}
.touch-device .dc-obj-btn {
    min-width: 32px;
    min-height: 32px;
    font-size: 12px;
}
.touch-device .dc-pos-btn {
    min-width: 30px;
    min-height: 30px;
    font-size: 10px;
}
.touch-device .dc-grp-btn {
    min-width: 28px;
    min-height: 28px;
    font-size: 10px;
}
.touch-device .dc-btn {
    min-height: 36px;
    padding: 8px 14px;
}
.touch-device .dc-sys-btn {
    min-height: 36px;
    padding: 6px 10px;
}
.touch-device .aar-btn,
.touch-device .aar-ctrl-btn {
    min-height: 36px;
    min-width: 36px;
}
.touch-device .sc-close {
    min-width: 36px;
    min-height: 36px;
}
.touch-device .sc-preset-btn {
    min-height: 56px;
    padding: 10px 8px;
}

/* Disable hover tooltips on touch (no mouse) */
.touch-device .drone-tooltip { display: none !important; }

/* ─── Mobile overlay (behind drawer panels) ─── */
.mob-overlay {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.mob-overlay.mob-overlay-active {
    opacity: 1;
    pointer-events: auto;
}

/* ─── Nav buttons (only shown on touch) ─── */
.mob-nav {
    display: none;
}
.touch-device .mob-nav {
    display: flex;
    gap: 4px;
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
}
.mob-nav-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.mob-nav-btn:active {
    background: rgba(0, 229, 255, 0.1);
    border-color: var(--cyan);
    color: var(--cyan);
}

/* ─── Drawer close handle (visual affordance) ─── */
.mob-drawer-handle {
    display: none;
}
.touch-device .mob-panel-open .mob-drawer-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    flex-shrink: 0;
    cursor: pointer;
}
.mob-drawer-handle::after {
    content: '';
    width: 32px;
    height: 4px;
    background: var(--border-accent);
    border-radius: 2px;
}

/* ─── Swipe hint ─── */
.mob-swipe-hint {
    position: fixed;
    bottom: 65px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 600;
    background: rgba(0, 229, 255, 0.15);
    border: 1px solid var(--cyan-dim);
    border-radius: 4px;
    color: var(--cyan);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    padding: 8px 20px;
    pointer-events: none;
    transition: opacity 0.5s;
}
.mob-hint-fade { opacity: 0; }


/* ═══════════════════════════════════════════
   TABLET — 768px to 1024px
   ═══════════════════════════════════════════ */

@media (max-width: 1024px) and (min-width: 768px) {

    /* Top bar: compact */
    .hud-top {
        height: 50px;
        padding-top: env(safe-area-inset-top, 0px);
    }
    .hud-title { font-size: 12px; }
    .hud-status-bar { gap: 12px; }
    .hud-status-item .label { font-size: 8px; }
    .hud-status-item .value { font-size: 11px; }

    /* Side panels: drawer mode (slide from edges)
       Width 250px, positioned at -250px, translate 250px → exact alignment */
    .hud-left {
        top: 0 !important;
        left: -250px !important;
        width: 250px !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: none !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-top: none !important;
        border-bottom: none !important;
        padding-top: 60px !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 95 !important;
        display: block !important;
    }
    .hud-left.mob-panel-open {
        transform: translateX(250px);
    }

    .hud-right {
        top: 0 !important;
        right: -250px !important;
        left: auto !important;
        width: 250px !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: none !important;
        border-radius: 0 !important;
        border-right: none !important;
        border-top: none !important;
        border-bottom: none !important;
        padding-top: 60px !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 95 !important;
        display: block !important;
    }
    .hud-right.mob-panel-open {
        transform: translateX(-250px);
    }

    /* Bottom bar: wrap controls */
    .hud-bottom {
        height: auto;
        min-height: 48px;
        padding: 6px 12px;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: center;
    }
    .hud-btn {
        font-size: 10px;
        padding: 6px 12px;
        letter-spacing: 0.08em;
    }
    .hud-separator { height: 20px; }

    /* Hide cursor coords (no mouse on tablet) */
    .touch-device .coord-info { display: none; }

    /* Bottom bar info items: compact */
    .target-info .label { font-size: 8px; }
    .target-info .value { font-size: 10px; }

    /* Drone tracker panel: full width at bottom */
    .dtp {
        width: calc(100% - 16px);
        left: 8px;
        transform: translateX(0) translateY(20px);
        bottom: 60px;
    }
    .dtp.dtp-visible {
        transform: translateX(0) translateY(0);
    }

    /* FPV feed: smaller, avoid right panel overlap */
    .fpv-container {
        width: 320px;
        right: 8px;
        top: 56px;
    }

    /* Configurator: wider on tablet */
    .sc-modal {
        width: 90vw;
        max-width: 560px;
    }

    /* Defense configurator: narrower on tablet */
    #defense-configurator {
        width: 280px;
    }
}


/* ═══════════════════════════════════════════
   PHONE — ≤ 767px
   ═══════════════════════════════════════════ */

@media (max-width: 767px) {

    /* Top bar: minimal, account for notch */
    .hud-top {
        height: 40px;
        padding-top: env(safe-area-inset-top, 0px);
    }
    .hud-title {
        font-size: 10px;
        letter-spacing: 0.08em;
    }
    .hud-title .hud-icon { display: none; }
    .hud-status-bar { gap: 8px; }
    .hud-status-item .label { font-size: 7px; }
    .hud-status-item .value { font-size: 10px; }

    /* Hide ФОРМАЦИЯ and ТАКТИКА on phone — not enough space */
    .hud-status-item:nth-child(5),
    .hud-status-item:nth-child(6) { display: none; }

    /* Side panels: full-height drawers
       Width 80vw, positioned at -80vw, translate 80vw → exact alignment */
    .hud-left {
        top: 0 !important;
        left: -80vw !important;
        width: 80vw !important;
        max-width: 300px !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: none !important;
        border-radius: 0 !important;
        border-left: none !important;
        padding-top: 48px !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 95 !important;
        display: block !important;
    }
    .hud-left.mob-panel-open {
        transform: translateX(80vw);
    }
    /* Cap at max-width */
    @supports (width: min(80vw, 300px)) {
        .hud-left {
            left: calc(-1 * min(80vw, 300px)) !important;
        }
        .hud-left.mob-panel-open {
            transform: translateX(min(80vw, 300px));
        }
    }

    .hud-right {
        top: 0 !important;
        right: -80vw !important;
        left: auto !important;
        width: 80vw !important;
        max-width: 300px !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: none !important;
        border-radius: 0 !important;
        border-right: none !important;
        padding-top: 48px !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 95 !important;
        display: block !important;
    }
    .hud-right.mob-panel-open {
        transform: translateX(-80vw);
    }
    @supports (width: min(80vw, 300px)) {
        .hud-right {
            right: calc(-1 * min(80vw, 300px)) !important;
        }
        .hud-right.mob-panel-open {
            transform: translateX(calc(-1 * min(80vw, 300px)));
        }
    }

    /* Bottom bar: two rows */
    .hud-bottom {
        height: auto;
        padding: 4px 8px;
        flex-wrap: wrap;
        gap: 4px;
        justify-content: center;
    }
    .hud-btn {
        font-size: 9px;
        padding: 6px 10px;
        letter-spacing: 0.05em;
    }
    .hud-btn .btn-icon { font-size: 12px; }

    .hud-separator { display: none; }

    /* Hide low-priority info */
    .touch-device .coord-info { display: none; }
    .touch-device .viewer-count-wrap { display: none; }
    .touch-device .target-info .label { display: none; }

    /* Drone tracker panel */
    .dtp {
        width: 100vw;
        left: 0;
        bottom: 52px;
        transform: translateX(0) translateY(20px);
        border-left: none;
        border-right: none;
    }
    .dtp.dtp-visible {
        transform: translateX(0) translateY(0);
    }
    .dtp-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px 8px;
    }
    .dtp-header { padding: 6px 10px; }
    .dtp-body { padding: 6px 10px; }
    .dtp-val { font-size: 11px; }
    .dtp-coords { display: none; }

    /* FPV feed: full width above bottom bar */
    .fpv-container {
        width: calc(100vw - 8px);
        right: 4px;
        top: auto;
        bottom: 56px;
        max-height: 50vh;
    }
    .fpv-viewport { aspect-ratio: 16 / 9; }

    /* Configurator: full screen on phone */
    .sc-modal {
        width: 100vw;
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        height: 100vh;
        height: 100dvh;
        border: none;
        border-radius: 0;
    }
    .sc-presets {
        grid-template-columns: repeat(2, 1fr);
    }
    .sc-target-row { flex-wrap: wrap; }
    .sc-defense-grid { grid-template-columns: 1fr; }

    /* Defense configurator: wider on phone */
    #defense-configurator {
        width: 85vw;
        max-width: 320px;
    }

    /* AAR viewer: wider on phone */
    #aar-viewer {
        width: 90vw;
        max-width: 340px;
    }
}


/* ═══════════════════════════════════════════
   VERY SMALL PHONE — ≤ 400px
   ═══════════════════════════════════════════ */

@media (max-width: 400px) {
    /* Icon-only buttons */
    .hud-btn { padding: 8px; font-size: 0; gap: 0; }
    .hud-btn .btn-icon { font-size: 16px; }

    /* Top bar: hide all but ФАЗА and WS */
    .hud-status-item:nth-child(n+3) { display: none; }

    .sc-presets { grid-template-columns: 1fr 1fr; gap: 4px; }
    .sc-slider-name { width: 70px; font-size: 8px; }
}


/* ═══════════════════════════════════════════
   Landscape phone (short height)
   ═══════════════════════════════════════════ */

@media (max-height: 500px) and (orientation: landscape) {
    .hud-top { height: 36px; }
    .hud-title { font-size: 9px; }
    .hud-status-bar { gap: 6px; }

    .hud-bottom {
        height: 36px;
        min-height: 36px;
        padding: 2px 8px;
    }
    .hud-btn {
        min-height: 32px;
        padding: 4px 8px;
        font-size: 9px;
    }

    .dtp { bottom: 38px; }
    .dtp-grid { grid-template-columns: repeat(4, 1fr); }

    /* Landscape: drawers narrower */
    .hud-left, .hud-right {
        width: 40vw !important;
        max-width: 240px !important;
    }

    /* FPV: smaller, side position */
    .fpv-container {
        width: 40vw;
        max-height: 80vh;
        right: 4px;
        top: 38px;
        bottom: auto;
    }
}


/* ═══════════════════════════════════════════
   Safe areas (notch, home indicator, Dynamic Island)
   ═══════════════════════════════════════════ */

@supports (padding: env(safe-area-inset-bottom)) {
    .hud-top {
        padding-top: max(0px, env(safe-area-inset-top));
    }
    .hud-bottom {
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }
    .hud-left {
        padding-left: max(12px, env(safe-area-inset-left));
    }
    .hud-right {
        padding-right: max(12px, env(safe-area-inset-right));
    }
    /* Modals: respect notch */
    .sc-modal,
    #defense-configurator,
    #aar-viewer {
        padding-top: env(safe-area-inset-top, 0px);
    }
}


/* ═══════════════════════════════════════════
   High-DPI screens
   ═══════════════════════════════════════════ */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .hud-panel {
        border-width: 0.5px;
    }
}


/* ═══════════════════════════════════════════
   Reduced motion preference
   ═══════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
    .hud-left, .hud-right,
    #defense-configurator, #aar-viewer,
    .fpv-container, .dtp, .sc-overlay {
        transition-duration: 0.01ms !important;
    }
    @keyframes blink { 0%, 100% { opacity: 1; } }
    @keyframes fpv-rec-blink { 0%, 100% { opacity: 1; } }
}
