/* ============================================================
   css/components/layout.css
   
   FIXES:
   1. Sidebar toggle breakpoint unified to 992px throughout.
      Previously layout.css used 991.98px while navbar.css and
      Bootstrap's d-md-none used 768px — leaving a dead zone
      between 768px–991px where the toggle was invisible but the
      sidebar was already off-screen.
   2. Removed overflow-x:hidden from #wrapper. On mobile Safari
      this can interfere with touch scroll of inner elements.
   3. #page-content-wrapper: removed inline overflow definitions
      that competed with body scroll on Android WebView.
   4. Body overflow management for the sidebar backdrop is now
      handled exclusively in main-layout.component.js (the JS
      fix). The CSS no longer needs any body overflow rules.
   ============================================================ */

/* ── Wrapper ──────────────────────────────────────────────────── */
#wrapper {
    /* REMOVED: overflow-x: hidden — interferes with touch scroll
       on iOS/Android. The fixed sidebar handles its own overflow. */
    position: relative;
    padding-top: 70px; /* match .modern-navbar height */
}

/* ── Sidebar ──────────────────────────────────────────────────── */
#sidebar-wrapper {
    /*min-height: calc(100vh - 70px);*/
    height: calc(100vh - 70px);   /* was: min-height */
    width: 260px;
    position: fixed;
    top: 70px;
    left: 0;
    z-index: 1020;       /* below navbar (1030) */
    transition: transform 0.25s ease-out, width 0.25s ease-out;
    background-color: var(--bg-card);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    /* Enable momentum scrolling on iOS for the sidebar itself */
    -webkit-overflow-scrolling: touch;
}

/* ── Page content ─────────────────────────────────────────────── */
#page-content-wrapper {
    min-width: 0;
    width: 100%;
    background-color: var(--bg-body);
    padding-left: 260px;
    transition: padding-left 0.25s ease-out;
    /* CRITICAL: do NOT set overflow or height here.
       Doing so creates a scroll container that competes with
       the document scroll, causing the "can't scroll" bug on
       Android when body overflow is accidentally locked.       */
}

/* ── Desktop: sidebar collapse (toggled = sidebar hidden) ─────── */
#wrapper.toggled #sidebar-wrapper {
    width: 0;
    overflow: hidden;
}
#wrapper.toggled #page-content-wrapper {
    padding-left: 0;
}

/* ── Mobile: sidebar is off-screen by default ─────────────────── */
/* UNIFIED BREAKPOINT: 992px matches Bootstrap's lg breakpoint AND
   our JS checks (window.innerWidth < 992) in main-layout.          */
@media (max-width: 991.98px) {
    #sidebar-wrapper {
        transform: translateX(-260px);
        width: 260px;   /* keep width so animation works */
    }

    #page-content-wrapper {
        padding-left: 0;
    }

    /* When toggled on mobile: slide in, overlay content */
    #wrapper.toggled #sidebar-wrapper {
        transform: translateX(0);
        width: 260px;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* Content stays full width; sidebar overlays it */
    #wrapper.toggled #page-content-wrapper {
        padding-left: 0;
    }
}

/* ── Sidebar backdrop ─────────────────────────────────────────── */
#sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1019;  /* just below sidebar */
    cursor: pointer;
    /* Pointer events only when shown */
    pointer-events: none;
}
#sidebar-backdrop.show {
    display: block;
    pointer-events: auto;
}

/* ── Sidebar heading ──────────────────────────────────────────── */
#sidebar-wrapper .sidebar-heading {
    padding: 1rem 1.25rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
#sidebar-wrapper .sidebar-heading i {
    color: var(--primary-color);
    margin-right: 0.75rem;
    font-size: 1.5rem;
}

/* ── Sidebar nav ──────────────────────────────────────────────── */
.sidebar-nav {
    width: 260px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.sidebar-nav-item {
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    transition: all 0.2s ease;
    border-left: 4px solid transparent;
    /* Ensure touch target meets 44px minimum on mobile */
    min-height: 44px;
}
.sidebar-nav-item:hover {
    background-color: var(--bg-body);
    color: var(--text-primary);
    border-left-color: var(--primary-color);
}
.sidebar-nav-item.active {
    background-color: var(--bg-body);
    color: var(--primary-color);
    font-weight: 600;
    border-left-color: var(--primary-color);
}

.sidebar-nav-item .nav-icon {
    width: 30px;
    font-size: 0.95rem;
    margin-right: 0.75rem;
    text-align: center;
    color: var(--secondary-color);
    transition: color 0.2s ease;
}
.sidebar-nav-item:hover .nav-icon,
.sidebar-nav-item.active .nav-icon {
    color: var(--primary-color);
}

/* ── Dropdown toggle ──────────────────────────────────────────── */
.sidebar-nav-dropdown-toggle { position: relative; }
.sidebar-nav-dropdown-toggle::after {
    content: '\f078';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    position: absolute;
    right: 1.25rem;
    top: 50%;
    transform: translateY(-50%) rotate(0deg);
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}
.sidebar-nav-dropdown-toggle[aria-expanded="true"]::after {
    transform: translateY(-50%) rotate(-180deg);
    color: var(--primary-color);
}

.sidebar-nav-dropdown {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background-color: var(--bg-body);
    list-style: none;
    padding: 0;
    margin: 0;
}
.sidebar-nav-dropdown.show {
    max-height: 1000px;
    transition: max-height 0.5s ease-in;
}

.sidebar-nav-dropdown-item {
    display: flex;
    align-items: center;
    padding: 0.65rem 1.25rem 0.65rem 3.75rem;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.2s ease;
    border-left: 4px solid transparent;
    min-height: 44px;
}
.sidebar-nav-dropdown-item:hover {
    background-color: var(--bg-card);
    color: var(--text-primary);
    border-left-color: var(--info-color);
}
.sidebar-nav-dropdown-item.active {
    background-color: var(--bg-card);
    color: var(--primary-color);
    font-weight: 500;
    border-left-color: var(--primary-color);
}

/* ── Shared card/border utilities ─────────────────────────────── */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}
.card-header {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}
.card-body {
    color: var(--text-secondary);
}

.border-left-primary  { border-left: 0.25rem solid var(--primary-color)  !important; }
.border-left-success  { border-left: 0.25rem solid var(--success-color)  !important; }
.border-left-info     { border-left: 0.25rem solid var(--info-color)     !important; }
.border-left-warning  { border-left: 0.25rem solid var(--warning-color)  !important; }

.text-gray-800  { color: var(--text-primary)   !important; }
.text-gray-300  { color: #dddfeb               !important; }

/* ── Chart containers ─────────────────────────────────────────── */
.chart-area { position: relative; height: 10rem; width: 80vw; }
.chart-pie  { position: relative; height: 15rem; width: 80vw; }

@media (min-width: 768px) {
    .chart-area { height: 20rem; width: 100%; }
    .chart-pie  { height: 15rem; width: 100%; }
}