/* sidebar.css — layout + chrome for the opt-in full-height sidebar.
 *
 * Safe to load unconditionally: every rule is either scoped to
 * body.sidebar-mode, or targets IDs that only exist in sidebar mode.
 */

/* ----- Push-layout: map makes room for the sidebar ---------------------- */

body.sidebar-mode #map {
    left: 0;
    right: var(--sidebar-width, 0);
    width: auto;
}

/* Keep the original floating #menu div out of the way in sidebar mode —
 * the layer menu renders inside #sidebar-layers-pane instead. */
body.sidebar-mode #menu {
    display: none;
}

/* ----- Sidebar container ------------------------------------------------- */

body.sidebar-mode #sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--sidebar-width, 420px);
    background: #f8f9fa;
    color: #1a1a2e;
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: -2px 0 6px rgba(0, 0, 0, 0.12);
    transition: transform 200ms ease;
    /* Sidebar chat uses solid background — override any glass blur coming
     * from chat.css that assumes a translucent floating container. */
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* ----- Resize handle on the left edge ----------------------------------- */

body.sidebar-mode .sidebar-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    background: transparent;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    transition: border-color 120ms ease, background 120ms ease;
    z-index: 2;
}

body.sidebar-mode .sidebar-resize-handle:hover {
    border-left-color: rgba(120, 170, 255, 0.8);
    background: rgba(120, 170, 255, 0.08);
}

/* ----- Header ------------------------------------------------------------ */

body.sidebar-mode #sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    flex: 0 0 auto;
}

body.sidebar-mode #sidebar-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

body.sidebar-mode #sidebar-hide {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 3px;
}

body.sidebar-mode #sidebar-hide:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* ----- Layers pane ------------------------------------------------------- */

body.sidebar-mode #sidebar-layers-pane {
    flex: 0 0 auto;
    max-height: 40%;
    overflow-y: auto;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

/* ----- Chat region — override a few chat.css rules that assume a
 *       translucent floating panel. ------------------------------------- */

body.sidebar-mode #chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 10px 12px;
}

body.sidebar-mode #chat-input-container {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

body.sidebar-mode #chat-input-container #chat-input {
    flex: 1;
}

/* ----- Footer ------------------------------------------------------------ */

body.sidebar-mode #sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 11px;
    flex: 0 0 auto;
}

body.sidebar-mode #sidebar-footer #chat-footer-right {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

body.sidebar-mode #sidebar-footer .footer-link {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    margin-right: 4px;
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    border-radius: 3px;
}

body.sidebar-mode #sidebar-footer .footer-link:hover {
    color: rgba(255, 255, 255, 1);
    background: rgba(255, 255, 255, 0.08);
}

/* ----- Collapse / show toggle ------------------------------------------- */

body.sidebar-mode.sidebar-collapsed {
    --sidebar-width: 0px;
}

body.sidebar-mode.sidebar-collapsed #sidebar {
    transform: translateX(100%);
}

#sidebar-show-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    display: none;  /* shown only while collapsed */
    background: rgba(255, 255, 255, 0.85);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 14px;
    cursor: pointer;
    z-index: 12;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

body.sidebar-mode.sidebar-collapsed #sidebar-show-btn {
    display: block;
}

/* ----- Z-index adjustments for floating map overlays in narrow map ----- */

body.sidebar-mode #legend,
body.sidebar-mode #h3-toggle,
body.sidebar-mode #h3-res-badge {
    z-index: 5;
}

/* ----- Narrow-viewport fallback: overlay instead of push --------------- */

@media (max-width: 700px) {
    body.sidebar-mode #map {
        right: 0;
        width: 100%;
    }
    body.sidebar-mode #sidebar {
        --sidebar-width: min(400px, 90vw);
        width: var(--sidebar-width);
        box-shadow: -4px 0 10px rgba(0, 0, 0, 0.35);
    }
    body.sidebar-mode .sidebar-resize-handle {
        /* Drag-resize disabled on narrow viewports. */
        pointer-events: none;
    }
}
