/* 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 16px;
    /* Divider line lives on .sidebar-splitter when the splitter is visible. */
}

/* Once the user drags the splitter, switch to fixed-pixel sizing.
 * Skipped when either pane is collapsed (other rules below take over). */
body.sidebar-mode.layers-pane-resized:not(.chat-collapsed)
    #sidebar-layers-pane:not(.collapsed) {
    flex: 0 0 var(--layers-pane-height, 200px);
    max-height: none;
}

/* When chat is collapsed, layers pane fills the available height. */
body.sidebar-mode.chat-collapsed #sidebar-layers-pane {
    flex: 1 1 auto;
    max-height: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

/* Layers pane keeps a visible divider when its own splitter is hidden
 * (which happens when the layers pane itself is collapsed). */
body.sidebar-mode #sidebar-layers-pane.collapsed {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

/* Collapse behavior — mirror the floating-mode #menu rules in style.css
 * (#menu only matches in floating mode, so sidebar needs its own copies). */
body.sidebar-mode #sidebar-layers-pane.collapsed #menu-body {
    display: none;
}

body.sidebar-mode #sidebar-layers-pane:not(.collapsed) .menu-header .section-title {
    display: none;
}

body.sidebar-mode #sidebar-layers-pane:not(.collapsed) .menu-header {
    justify-content: flex-end;
    margin-bottom: 4px;
}

/* ----- Splitter between layers pane and chat ---------------------------- */

body.sidebar-mode .sidebar-splitter {
    flex: 0 0 5px;
    background: transparent;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    cursor: row-resize;
    transition: background 120ms ease, border-color 120ms ease;
    z-index: 1;
}

body.sidebar-mode .sidebar-splitter:hover {
    background: rgba(120, 170, 255, 0.12);
    border-bottom-color: rgba(120, 170, 255, 0.8);
}

/* Hide the splitter when either side is fully collapsed — nothing to drag. */
body.sidebar-mode.chat-collapsed .sidebar-splitter,
body.sidebar-mode #sidebar-layers-pane.collapsed + .sidebar-splitter {
    display: none;
}

/* ----- Chat section header (collapse toggle bar) ------------------------ */

body.sidebar-mode #chat-section-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 4px 8px;
    font-size: 11px;
    color: rgba(0, 0, 0, 0.55);
    letter-spacing: 0.4px;
    text-transform: uppercase;
}

body.sidebar-mode #chat-section-header .section-title {
    margin: 0;
    font-weight: 600;
    /* Mirror layers menu-header: only show the title while collapsed. */
    display: none;
}

body.sidebar-mode.chat-collapsed #chat-section-header {
    justify-content: space-between;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

body.sidebar-mode.chat-collapsed #chat-section-header .section-title {
    display: inline;
}

/* Opt-in via sidebar.chat_title: show the heading persistently (not just
 * while collapsed), mirroring the always-visible layers "Overlays" label. */
body.sidebar-mode #chat-section-header.has-chat-title {
    justify-content: space-between;
}

body.sidebar-mode #chat-section-header.has-chat-title .section-title {
    display: inline;
}

body.sidebar-mode #chat-section-toggle {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
    border-radius: 3px;
}

body.sidebar-mode #chat-section-toggle:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* Hide chat content when collapsed; layers pane fills the gap. */
body.sidebar-mode.chat-collapsed #chat-messages,
body.sidebar-mode.chat-collapsed #chat-input-container {
    display: none;
}

/* ----- 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: 18px 12px 10px;
}

body.sidebar-mode #chat-input-container {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    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(0, 0, 0, 0.55);
    text-decoration: none;
    border-radius: 3px;
}

body.sidebar-mode #sidebar-footer .footer-link:hover {
    color: rgba(0, 0, 0, 0.85);
    background: rgba(0, 0, 0, 0.06);
}

body.sidebar-mode #sidebar-footer .footer-link.carbon-link,
body.sidebar-mode #sidebar-footer .footer-link.carbon-link:hover {
    color: #2e7d32;
}

/* ----- 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,
    body.sidebar-mode .sidebar-splitter {
        /* Drag-resize disabled on narrow viewports. */
        pointer-events: none;
    }
}
