/* ============================================
   SIDEBAR & LAYOUT STYLES

   Theme is loaded separately via base.html:
   <link rel="stylesheet" href="{% static 'ambient-theme.css' %}">
   ============================================ */

:root {
    --sidebar-collapsed-width: 60px;
    --sidebar-expanded-width: 240px;
    --link-container-margin: 16px;
    --icon-size: 20px;
}

/* ---- Prevent document-level overscroll in PWA standalone mode ---- */

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

/* ---- Main layout ---- */

.main-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    background: #ffffff;
}

.general-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: #ffffff;
    min-width: 0;
}

/* ---- Sidebar shell (reserves space in flex layout) ---- */

.sidebar {
    position: relative;
    overflow: visible; /* Allow toggle button and hover overlay to extend outside */
    width: var(--sidebar-collapsed-width);
    height: 100vh;
    flex-shrink: 0;
    z-index: 10;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.sidebar-expanded {
    width: var(--sidebar-expanded-width);
}

/* ---- Sidebar visual panel (absolutely positioned so hover can overlay without reflow) ---- */

.sidebar-sticky {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--sidebar-collapsed-width);
    background-color: #f8f9fa;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: visible; /* Must be visible so toggle button extends past the panel edge */
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s;
    /* Above the top-bar (z-index: 100) so backdrop-filter on top-bar doesn't blur sidebar content */
    z-index: 110;
}

.sidebar.sidebar-expanded .sidebar-sticky {
    width: var(--sidebar-expanded-width);
}

/* Inner wrapper clips nav content during width transition without clipping the toggle button */
.sidebar-inner {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* ---- Logo area ---- */

.sidebar-logo-area {
    padding: 16px;
    flex-shrink: 0;
    margin-bottom: 8px;
}

.sidebar-logo-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    white-space: nowrap;
}

.sidebar-logo-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-wordmark {
    display: none;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 18px;
    color: var(--ambient-text-dark, #2d3748);
}

.sidebar.sidebar-expanded .sidebar-wordmark {
    display: block;
}

/* ---- Nav list ---- */

.sidebar ul.nav {
    padding: 0;
    margin: 0;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar li.nav-item {
    padding: 0;
    margin: 0;
    list-style: none;
}

/* ---- Nav links ---- */

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 var(--link-container-margin);
    height: 40px;
    margin: 4px 0;
    color: var(--ambient-text-dark, #2d3748) !important;
    text-decoration: none;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 500;
    /* Transparent border-left reserves space so icon doesn't shift on active */
    border-left: 3px solid transparent;
    border-radius: 0 8px 8px 0;
    transition: background 100ms ease, border-color 100ms ease;
    box-sizing: border-box;
}

.sidebar .nav-link:hover {
    background: rgba(0, 0, 0, 0.04);
    border-radius: 8px;
    border-left-color: transparent;
}

.sidebar .nav-link.active {
    background: rgba(120, 119, 198, 0.08);
    border-left: 3px solid #7877c6;
    border-radius: 0 8px 8px 0;
    color: var(--ambient-primary-dark, #6366f1) !important;
    font-weight: 600;
}

.sidebar .nav-link:focus-visible {
    outline: 2px solid var(--ambient-primary, #7877c6);
    outline-offset: 2px;
}

/* Lucide icons inside nav links */
.sidebar .nav-link svg.lucide {
    width: var(--icon-size);
    height: var(--icon-size);
    flex-shrink: 0;
    stroke-width: 1.5;
}

/* SVG image icons (e.g. auto_cal.svg) — match Lucide icon sizing */
.sidebar .nav-link .nav-svg-icon {
    width: var(--icon-size);
    height: var(--icon-size);
    flex-shrink: 0;
    display: block;
}

/* ---- Sidebar labels ---- */

.sidebar-label {
    display: none;
    font-size: 14px;
    font-weight: inherit;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.sidebar-expanded .sidebar-label {
    display: block;
}

/* ---- Nav group dividers ---- */

.nav-group-divider {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 8px 0;
    padding: 0;
    list-style: none;
}

.group-divider {
    width: 40px;
    height: 1px;
    background: rgba(0, 0, 0, 0.1);
}

/* ---- Nav spacer (pushes utility group to bottom) ---- */

.nav-spacer {
    flex-grow: 1;
    list-style: none;
}

/* ---- Edge toggle button ---- */

.sidebar-toggle-edge {
    position: absolute;
    right: -14px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.12);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    color: #718096;
    padding: 0;
    transition: background 100ms ease, box-shadow 100ms ease, color 100ms ease;
}

.sidebar-toggle-edge:hover {
    background: #f7fafc;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    color: #2d3748;
}

.sidebar-toggle-edge:focus-visible {
    outline: 2px solid var(--ambient-primary, #7877c6);
    outline-offset: 2px;
}

.sidebar-toggle-edge svg.lucide {
    width: 16px;
    height: 16px;
    stroke-width: 1.5;
    transition: transform 200ms ease;
}

/* Chevron rotation: collapsed = points right (rotate 180°), expanded = points left */
.sidebar:not(.sidebar-expanded) .sidebar-toggle-edge svg.lucide {
    transform: rotate(180deg);
}

.sidebar.sidebar-expanded .sidebar-toggle-edge svg.lucide {
    transform: rotate(0deg);
}

/* ---- Desktop hover overlay (collapsed sidebar only) ---- */
/* Driven by JS: class .sidebar-hover-expanded is added on mouseover
   (excluding the toggle button) and removed on mouseleave.            */

@media (min-width: 769px) {
    .sidebar.sidebar-hover-expanded {
        z-index: 200;
    }

    .sidebar.sidebar-hover-expanded .sidebar-sticky {
        width: var(--sidebar-expanded-width);
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.08);
    }

    .sidebar.sidebar-hover-expanded .sidebar-label,
    .sidebar.sidebar-hover-expanded .sidebar-wordmark {
        display: block;
    }

    .sidebar.sidebar-hover-expanded .sidebar-toggle-edge {
        display: none;
    }
}

/* ---- Top bar ---- */

.top-bar {
    width: 100%;
    height: 56px;
    flex-shrink: 0;
    z-index: 100;
    background-color: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.top-bar .navbar {
    height: 100%;
    padding-top: 0;
    padding-bottom: 0;
}

.navbar-title {
    color: white;
    font-size: 1.25rem;
    font-weight: 500;
}

/* ---- Body content ---- */

.body-content {
    flex-grow: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #ffffff;
}

.body-content .container-fluid {
    padding: 0.5rem;
}

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

footer.footer {
    flex-shrink: 0;
    background-color: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

/* ---- Mobile sidebar toggle button ---- */

.sidebar-toggle-btn {
    display: none;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    margin-right: 15px;
}

.sidebar-toggle-btn img {
    height: 20px;
}

/* ---- Sidebar overlay for mobile ---- */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

/* ---- Mobile responsive ---- */

@media (max-width: 768px) {
    .sidebar-toggle-btn {
        display: block;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        width: max-content; /* Size to widest nav item — equal padding on both sides of content */
        transition: left 0.3s ease-in-out;
        z-index: 1000;
    }

    /* Reset sidebar-sticky to normal flow on mobile */
    .sidebar-sticky {
        position: relative;
        width: 100%;
        height: 100%;
        box-shadow: none !important;
    }

    .sidebar.mobile-open {
        left: 0;
    }

    .sidebar.mobile-open .sidebar-label,
    .sidebar.mobile-open .sidebar-wordmark {
        display: block;
    }

    /* Hide desktop edge toggle on mobile */
    .sidebar-toggle-edge {
        display: none;
    }
}
