/* Floating draggable panel groups (Lagebild HUD).
   Each .ms-pgroup is an absolutely-positioned, collapsible container that
   floats over the map. Drag position + collapsed state persist in
   localStorage (see wwwroot/js/ms-panels.js). Panels are grouped by theme:
   tracks, weather, radar, missions. */

/* The Lagebild shell switches from the legacy 3-column grid to a relative
   block so the map can fill it and the groups can float on top. */
.ms-lagebild--floating {
    display: block;
    position: relative;
    overflow: hidden;
}

.ms-lagebild-map {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: var(--ms-water);
    /* side borders come from the nested .ms-mapview (inset:0) — don't double them */
}

/* ---- the floating group ---- */

.ms-pgroup {
    position: absolute;
    z-index: 6; /* above the map HUD filters (z 5); operator can drag to reveal */
    width: 330px;
    max-width: calc(100% - 24px);
    max-height: calc(100% - 24px);
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--ms-panel);
    border: 1px solid var(--ms-panel-border);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

/* Default anchors per theme group — a starting layout the operator can
   drag away from. inset-inline-* flips automatically in RTL. Saved
   localStorage positions override these on the next load. */
.ms-pgroup[data-pgroup-key="tracks"]   { inset-block-start: 12px; inset-inline-start: 12px; width: 320px; }
.ms-pgroup[data-pgroup-key="weather"]  { inset-block-start: 12px; inset-inline-end: 12px; }
.ms-pgroup[data-pgroup-key="radar"]    { inset-block-end: 44px;  inset-inline-start: 12px; }
.ms-pgroup[data-pgroup-key="missions"] { inset-block-end: 12px;  inset-inline-end: 12px; }

/* ---- drag bar / header ---- */

.ms-pgroup-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px 7px 10px;
    flex-shrink: 0;
    background: var(--ms-panel-header);
    border-bottom: 1px solid var(--ms-panel-border);
    cursor: grab;
    user-select: none;
    touch-action: none; /* let pointermove drag instead of scrolling on touch */
}
.ms-pgroup.is-dragging .ms-pgroup-bar { cursor: grabbing; }
.ms-pgroup.is-dragging { box-shadow: 0 10px 34px rgba(0, 0, 0, 0.55); }

.ms-pgroup-glyph {
    color: var(--ms-accent);
    font-size: 13px;
    line-height: 1;
}
.ms-pgroup-grip {
    color: var(--ms-text-mute);
    font-size: 12px;
    line-height: 1;
    letter-spacing: -1px;
}
.ms-pgroup-title {
    flex: 1;
    font-family: var(--ms-font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ms-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ms-pgroup-collapse {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--ms-panel-border);
    border-radius: 3px;
    color: var(--ms-text-dim);
    cursor: var(--ms-cursor-pointer);
    font-size: 10px;
    line-height: 1;
    transition: transform 120ms ease-out, color 100ms ease-out, border-color 100ms ease-out;
}
.ms-pgroup-collapse:hover {
    color: var(--ms-text);
    border-color: var(--ms-text-dim);
}
.ms-pgroup.is-collapsed .ms-pgroup-collapse { transform: rotate(-90deg); }

/* ---- body ---- */

.ms-pgroup-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}
.ms-pgroup.is-collapsed .ms-pgroup-body { display: none; }

.ms-pgroup-body::-webkit-scrollbar { width: 6px; }
.ms-pgroup-body::-webkit-scrollbar-thumb { background: var(--ms-panel-border); }
.ms-pgroup-body::-webkit-scrollbar-track { background: transparent; }

/* Inner panels size to content and stack flush — the group provides the
   outer frame, so the panels drop their own side borders. */
.ms-pgroup-body > .ms-panel {
    flex: 0 0 auto;
    border-inline: none;
    border-top: none;
}
.ms-pgroup-body > .ms-panel:first-child { border-top: none; }

/* The group wrapper is layout-transparent on desktop: display:contents means
   it generates no box, so each .ms-pgroup still positions absolutely against
   the .ms-lagebild shell and the drag controller's offsetParent math is
   unchanged. On tablet it morphs into the drawer (below). */
.ms-hud-groups { display: contents; }

/* The backdrop + FABs are desktop-hidden; the tablet media block reveals
   them. Declared here (outside the query) so the default state is explicit. */
.ms-panels-backdrop { display: none; }
.ms-map-fab-panels { display: none; }

/* ---- tablet (≤1024px): off-canvas HUD drawer ----
   The floating absolute HUD steals the space the map needs on a tablet, so at
   tablet width the map keeps the full viewport and the four panel groups
   collapse into a single off-canvas drawer that slides in from the inline-end
   edge over the map. A floating button (.ms-map-fab-panels) toggles it;
   .ms-panels-drawer-open on the shell slides it in and shows the backdrop.
   Desktop (>1024px) is untouched — this whole block is gated. */
@media (max-width: 1024px) {
    /* Drawer container — a fixed, scrollable column pinned to the inline-end
       edge between the top bar and status bar, translated off-screen until
       opened. */
    .ms-hud-groups {
        display: flex;
        flex-direction: column;
        gap: 10px;
        position: fixed;
        inset-block-start: 52px;   /* below the top bar */
        inset-block-end: 28px;     /* above the status bar */
        inset-inline-end: 0;
        width: min(360px, 90vw);
        padding: 10px;
        overflow-y: auto;
        z-index: 60;
        background: var(--ms-bg2);
        border-inline-start: 1px solid var(--ms-panel-border);
        box-shadow: -8px 0 28px rgba(0, 0, 0, 0.5);
        transform: translateX(110%);
        transition: transform 220ms ease-out;
    }
    .ms-panels-drawer-open .ms-hud-groups { transform: translateX(0); }

    /* Inside the drawer the groups flow as static, full-width, sized-to-
       content blocks. !important neutralises the per-group default insets
       and any inline left/top the drag controller persisted. */
    .ms-pgroup {
        position: static !important;
        inset: auto !important;
        left: auto !important;
        top: auto !important;
        width: 100% !important;
        max-width: none !important;
        max-height: none !important;
        flex: 0 0 auto;
        box-shadow: none;
    }
    /* Drag is meaningless once a group is a static drawer block. */
    .ms-pgroup-bar { cursor: default; }
    .ms-pgroup-grip { display: none; }

    /* Backdrop behind the open drawer — tap to dismiss. */
    .ms-panels-backdrop {
        display: block;
        position: fixed;
        inset: 52px 0 28px 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 55;
        opacity: 0;
        visibility: hidden;
        transition: opacity 200ms ease-out, visibility 200ms;
    }
    .ms-panels-drawer-open .ms-panels-backdrop {
        opacity: 1;
        visibility: visible;
    }

    /* Floating toggle button — bottom inline-end corner, above the drawer. */
    .ms-map-fab-panels {
        display: inline-flex;
    }
}
