/* =============================================================
   style.responsive.css  — Mobile / tablet responsive overrides
   ============================================================= */

/* ── Clip off-screen sidebar ── */
html, body { overflow-x: hidden; }

/* ── Desktop-only: hide mobile-only elements ── */
#btn_sidebar_toggle  { display: none; }
#btn_sidebar_close   { display: none; }
#sidebar_overlay     { display: none; }
#mobile_nav          { display: none; }
#mobile_top_title    { display: none; }
#map_gesture_hint    { display: none; }

/* =============================================================
   TABLET  769px – 1024px
   ============================================================= */
@media (max-width: 1024px) and (min-width: 769px) {
    #side_panel { width: 280px; }
    #map        { left: 285px; }
    #bottom_panel { left: 285px; }
    .history-view-control { left: 333px; }
}

/* =============================================================
   MOBILE  ≤768px
   ============================================================= */
@media (max-width: 768px) {

    /* ── Clip sidebar ── */
    #content { overflow-x: hidden; }

    /* ── Hide desktop menus entirely; hamburger replaces them ── */
    #top_panel .left-menu  { display: none !important; }
    #top_panel .right-menu { display: none !important; }

    /* ── Top panel: blue bar, flex row ── */
    #top_panel {
        display: flex;
        flex-direction: row;
        align-items: center;
        background-color: #2b82d4;
        height: 50px;
        padding: 0;
        overflow: hidden;
    }

    /* ── Hamburger: white bars on blue bg ── */
    #btn_sidebar_toggle {
        display: flex !important;
        flex: 0 0 50px;
        height: 50px;
        align-items: center;
        justify-content: center;
        float: none;
        cursor: pointer;
    }
    #btn_sidebar_toggle span,
    #btn_sidebar_toggle span::before,
    #btn_sidebar_toggle span::after {
        background: #ffffff;
    }
    #btn_sidebar_toggle span {
        display: block;
        width: 20px;
        height: 2px;
        position: relative;
        margin: 0 auto;
    }
    #btn_sidebar_toggle span::before,
    #btn_sidebar_toggle span::after {
        content: '';
        display: block;
        width: 20px;
        height: 2px;
        position: absolute;
        left: 0;
    }
    #btn_sidebar_toggle span::before { top: -7px; }
    #btn_sidebar_toggle span::after  { top:  7px; }

    /* ── Mobile title (current section label) ── */
    #mobile_top_title {
        display: block;
        flex: 1 1 auto;
        color: #ffffff;
        font-size: 16px;
        font-weight: 600;
        padding-left: 8px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* ── Map: push below the 50px top bar ── */
    #map {
        left: 0 !important;
        top: 50px !important;
    }
    #bottom_panel { left: 0 !important; }
    .history-view-control { left: 10px !important; top: 60px; }

    /* ── Map layer control: keep visible, just below top bar ── */
    .map-layer-control {
        display: block !important;
        top: 60px;
        right: 8px;
    }
    .map-layer-control select { min-width: 90px !important; font-size: 11px; }

    /* ── Sidebar: full-height slide-in overlay ── */
    #side_panel {
        top: 0 !important;
        width: 88% !important;
        max-width: 380px !important;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 300 !important;
        box-shadow: none;
    }
    body.sidebar-open #side_panel {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }

    /* ── Clip sidebar inner content to its width ── */
    #side_panel {
        overflow-x: hidden;
    }

    /* ── Force jqGrid tables to fit inside the sidebar ── */
    #side_panel .ui-jqgrid-view,
    #side_panel .ui-jqgrid-bdiv,
    #side_panel .ui-jqgrid-hdiv {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
        overflow-x: hidden !important;
    }
    #side_panel .ui-jqgrid-htable,
    #side_panel .ui-jqgrid-btable {
        width: 100% !important;
        max-width: 100% !important;
        table-layout: fixed !important;
        box-sizing: border-box;
    }
    /* Clip cells so text doesn't push columns wider */
    #side_panel .ui-jqgrid-htable th,
    #side_panel .ui-jqgrid-btable td {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        box-sizing: border-box;
    }

    /* ── Sidebar sub-panels: no overflow ── */
    #side_panel_objects,
    #side_panel_events,
    #side_panel_places,
    #side_panel_history,
    #side_panel_places_markers,
    #side_panel_places_routes,
    #side_panel_places_zones {
        overflow-x: hidden;
        width: 100%;
        box-sizing: border-box;
    }

    /* ── Sidebar tabs: fit width ── */
    #side_panel > .ui-tabs > ul,
    #side_panel > ul {
        width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }
    #side_panel > .ui-tabs > ul li a,
    #side_panel > ul li a {
        padding-left: 8px;
        padding-right: 8px;
        font-size: 12px;
    }

    /* ── Sidebar close button ── */
    #btn_sidebar_close {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        padding: 8px 12px 4px 12px;
        cursor: pointer;
        font-size: 18px;
        color: #808080;
    }

    /* ── Sidebar overlay backdrop ── */
    #sidebar_overlay {
        display: block;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.45);
        z-index: 299;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    body.sidebar-open #sidebar_overlay {
        opacity: 1;
        pointer-events: auto;
    }

    /* ── Mobile navigation overlay ── */
    #mobile_nav {
        display: none;        /* shown via .mobile-nav-open on body */
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: #f8f8f8;
        z-index: 400;
        overflow-y: auto;
        flex-direction: column;
    }
    body.mobile-nav-open #mobile_nav {
        display: flex;
    }

    /* Nav header */
    #mobile_nav_header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: #2b82d4;
        color: #ffffff;
        padding: 0 16px;
        height: 50px;
        flex-shrink: 0;
        font-size: 18px;
        font-weight: 600;
    }
    #mobile_nav_header a {
        color: #ffffff;
        font-size: 20px;
        text-decoration: none;
        line-height: 1;
        padding: 8px;
    }

    /* Nav tiles grid */
    #mobile_nav_tiles {
        list-style: none;
        padding: 16px;
        margin: 0;
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
        flex: 1 1 auto;
    }
    #mobile_nav_tiles li {
        width: calc(33.333% - 8px);
        box-sizing: border-box;
    }
    #mobile_nav_tiles li a {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 18px 8px;
        background: #ffffff;
        border-radius: 4px;
        box-shadow: 0 1px 4px rgba(0,0,0,0.12);
        color: #444444;
        font-size: 13px;
        text-align: center;
        text-decoration: none;
        gap: 10px;
    }
    #mobile_nav_tiles li a:active { opacity: 0.75; }
    #mobile_nav_tiles li a img {
        width: 32px;
        height: 32px;
        opacity: 0.6;
    }

    /* Nav footer (logout) */
    #mobile_nav_footer {
        padding: 16px;
        display: flex;
        justify-content: center;
        gap: 24px;
        flex-shrink: 0;
        border-top: 1px solid #eeeeee;
        margin-top: 8px;
    }
    #mobile_nav_footer a {
        display: flex;
        align-items: center;
        gap: 8px;
        color: #808080;
        font-size: 14px;
        text-decoration: none;
    }
    #mobile_nav_footer a img {
        width: 18px;
        height: 18px;
        opacity: 0.5;
    }

    /* ── Gesture hint overlay ── */
    #map_gesture_hint {
        display: none;          /* shown via JS */
        position: absolute;
        top: 50px; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.45);
        z-index: 150;
        align-items: center;
        justify-content: center;
        pointer-events: none;
    }
    #map_gesture_hint span {
        background: rgba(0,0,0,0.7);
        color: #ffffff;
        padding: 12px 20px;
        border-radius: 6px;
        font-size: 14px;
        text-align: center;
        max-width: 220px;
    }

    /* ── Login page ── */
    body#login .inner-wrapper {
        width: 88% !important;
        min-width: 0 !important;
        margin: 24px auto !important;
        box-sizing: border-box;
    }

    /* ── Dialogs: full width ── */
    .ui-dialog {
        max-width: 98vw !important;
        left: 1vw !important;
        box-sizing: border-box;
    }
    .ui-dialog-content {
        max-height: 70vh !important;
        overflow-y: auto !important;
    }
}

/* =============================================================
   Extra-small phones  ≤400px
   ============================================================= */
@media (max-width: 400px) {
    #mobile_nav_tiles li { width: calc(50% - 6px); }
    body#login .inner-wrapper { width: 94% !important; padding: 16px !important; }
}
