/* =========================================================
   site.css (FULL) — LLDK (CLEAN)
   - One mobile strategy only (no duplicates)
   - iOS sidebar scroll fixed
   - Requires: <div class="overlay" id="overlay"></div>
   - Requires: <div class="sidebar__scroll"> ... </div> inside #sidebar
========================================================= */

/* =========================
   Theme variables
========================= */
:root {
    --blue: #3f5fb8;
    --bg: #f2f4f8;
    --panel: #ffffff;
    --text: #1d2433;
    --muted: #6b7280;
    --line: #e5e7eb;
    --sidebar: #ffffff;
    --sidebarText: #111827;
    --shadow: 0 10px 28px rgba(0,0,0,.08);
    --radius: 10px;
    --topbar-h: 66px;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --panel: #111b33;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #1f2a44;
    --sidebar: #0f1a33;
    --sidebarText: #e5e7eb;
    --shadow: 0 12px 34px rgba(0,0,0,.35);
}

/* =========================
   Base / Reset
========================= */
* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
}

/* =========================
   Topbar
========================= */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--blue);
    color: #fff;
}

.topbar__left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand__title {
    font-weight: 700;
    font-size: 20px;
    letter-spacing: .2px;
}

.topbar__burger {
    display: none;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    font-size: 28px;
    line-height: 1;
}

.iconbtn {
    border: 0;
    background: transparent;
    color: inherit;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

    .iconbtn:hover {
        background: rgba(255,255,255,.14);
    }

.topbar__search {
    flex: 1;
    max-width: 560px;
    margin: 0 18px;
    position: relative;
}

.topbar__searchInput {
    width: 100%;
    height: 40px;
    border-radius: 999px;
    border: 0;
    padding: 0 44px 0 16px;
    outline: none;
}

.topbar__searchBtn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 999px;
    background: #fff;
    cursor: pointer;
}

.topbar__right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* =========================
   User menu (Topbar)
========================= */
.userMenu {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 12px;
    cursor: pointer;
}

    .userMenu:hover {
        background: rgba(255,255,255,.14);
    }

.userMenu__avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: rgba(255,255,255,.18);
    display: flex;
    align-items: center;
    justify-content: center;
}

.userMenu__meta {
    line-height: 1.05;
}

.userMenu__name {
    font-weight: 700;
    font-size: 13px;
}

.userMenu__role {
    font-size: 12px;
    opacity: .9;
}

.userMenu__caret {
    opacity: .9;
}

.userMenu__dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 48px;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 12px;
    min-width: 190px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

    .userMenu__dropdown.is-open {
        display: block;
    }

.userMenu__item {
    display: block;
    padding: 10px 12px;
    color: inherit;
    text-decoration: none;
    font-size: 14px;
}

    .userMenu__item:hover {
        background: rgba(0,0,0,.05);
    }

[data-theme="dark"] .userMenu__item:hover {
    background: rgba(255,255,255,.06);
}

.userMenu__sep {
    height: 1px;
    background: var(--line);
}

/* =========================
   Layout
========================= */
.layout {
    display: flex;
    min-height: calc(100vh - var(--topbar-h));
}

/* =========================
   Sidebar (desktop)
========================= */
.sidebar {
    width: 260px;
    transition: .3s;
}

    .sidebar.is-collapsed {
        width: 70px;
    }

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--sidebarText);
    padding: 10px 10px;
    border-radius: 12px;
    font-weight: 700;
}

    .sidebar__brand:hover {
        background: rgba(0,0,0,.04);
    }

[data-theme="dark"] .sidebar__brand:hover {
    background: rgba(255,255,255,.06);
}

.sidebar__brandIcon {
    font-size: 20px;
}

.sidebar__brandText {
    font-size: 14px;
}

.sidebar__bottom {
    padding: 12px 6px;
}

/* mobile user links (hidden on desktop) */
.mobileUserLinks {
    display: none;
}

/* =========================
   Nav
========================= */
.nav {
    margin-top: 8px;
}

.nav__sep {
    height: 1px;
    background: var(--line);
    margin: 10px 8px;
    border-radius: 999px;
}

.nav__link,
.nav__groupBtn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--sidebarText);
    background: transparent;
    border: 0;
    cursor: pointer;
    font-size: 14px;
}

.nav__icon {
    width: 22px;
    text-align: center;
}

.nav__text {
    flex: 1;
    text-align: left;
}

.nav__caret {
    opacity: .7;
}

.nav__badge {
    font-size: 11px;
    padding: 3px 7px;
    border-radius: 999px;
    background: #22c55e;
    color: #fff;
    font-weight: 700;
}

.nav__link:hover,
.nav__groupBtn:hover {
    background: rgba(0,0,0,.04);
}

[data-theme="dark"] .nav__link:hover,
[data-theme="dark"] .nav__groupBtn:hover {
    background: rgba(255,255,255,.06);
}

.nav__link.is-active {
    background: rgba(63,95,184,.14);
    font-weight: 700;
}

.nav__group {
    margin: 0 !important;
}

.nav__groupBody {
    display: none;
    padding-left: 10px;
}

    .nav__groupBody.is-open {
        display: block;
    }
    .nav__groupBody:not(.is-open) {
        display: none !important;
        height: 0 !important;
        overflow: hidden !important;
    }

.nav__sublink {
    display: block;
    padding: 8px 10px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--sidebarText);
    font-size: 13px;
    opacity: .92;
}

    .nav__sublink:hover {
        background: rgba(0,0,0,.04);
    }

    .nav__sublink.is-active {
        font-weight: 700;
        background: rgba(63,95,184,.12);
    }

/* =========================
   Main
========================= */
.main {
    transition: .3s;
}

.sidebar.is-collapsed ~ .main {
    margin-left: 70px;
    width: calc(100vw - 70px);
}

.main__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.crumbs {
    color: var(--muted);
    font-size: 13px;
}

.main__headerActions {
    display: flex;
    gap: 8px;
}

.main__content {
    max-width: 1050px;
}

/* Card */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 16px;
}

/* Forms */
.formGrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 18px;
}

.formRow {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.formRow--full {
    grid-column: 1 / -1;
}

.label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 700;
    letter-spacing: .2px;
}

.input {
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--line);
    padding: 8px 10px;
    background: transparent;
    color: inherit;
    outline: none;
}

    .input:focus {
        border-color: rgba(63,95,184,.55);
        box-shadow: 0 0 0 3px rgba(63,95,184,.15);
    }

.input--area {
    height: auto;
    resize: vertical;
}

.formActions {
    display: flex;
    justify-content: center;
    margin-top: 6px;
}

/* Buttons */
.btn {
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 700;
}

.btn--success {
    background: #22c55e;
    color: #fff;
    min-width: 140px;
}

    .btn--success:hover {
        filter: brightness(.95);
    }

.btn--ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: inherit;
}

    .btn--ghost:hover {
        background: rgba(0,0,0,.04);
    }

[data-theme="dark"] .btn--ghost:hover {
    background: rgba(255,255,255,.06);
}

.w100 {
    width: 100%;
}

/* Footer */
.footer__inner {
    color: var(--muted);
    font-size: 12px;
    padding: 10px 4px;
    text-align: right;
}

/* =========================
   Overlay (base)
========================= */
.overlay {
    display: none;
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0,0,0,.35);
    z-index: 9000;
    pointer-events: none;
}

    .overlay.is-open {
        display: block;
        pointer-events: auto;
    }

/* =========================================================
   MOBILE — single strategy (iOS scroll safe)
========================================================= */
@media (max-width:980px) {

    .topbar__burger {
        display: inline-flex;
    }

    .topbar__search {
        display: none;
    }

    .userMenu--top {
        display: none !important;
    }

    .mobileUserLinks {
        display: block;
    }

    /* optional body lock (activate with JS when open) */
    html.drawer-open,
    body.drawer-open {
        height: 100%;
        overflow: hidden;
    }

    /* Sidebar off-canvas using top+bottom (NOT height) */
    #sidebar.sidebar {
        position: fixed;
        top: var(--topbar-h);
        bottom: 0;
        left: -280px;
        width: 270px;
        z-index: 10000;
        transition: left .2s ease;
        background: var(--sidebar);
        border-right: 1px solid var(--line);
        padding: 14px 12px;
        display: flex;
        flex-direction: column;
        overflow: hidden; /* sidebar itself never scrolls */
    }

        #sidebar.sidebar.is-open {
            left: 0;
        }

        /* The ONLY scroll container */
        #sidebar.sidebar > .sidebar__scroll {
            flex: 1 1 auto;
            min-height: 0; /* CRITICAL for iOS */
            overflow-y: scroll; /* iOS prefers scroll */
            overflow-x: hidden;
            -webkit-overflow-scrolling: touch;
            overscroll-behavior: contain;
            touch-action: pan-y;
            padding-bottom: calc(28px + env(safe-area-inset-bottom));
        }

        /* ensure nav is not another scroller */
        #sidebar.sidebar .nav {
            overflow: visible;
        }

        /* bottom fixed by flex */
        #sidebar.sidebar > .sidebar__bottom {
            flex: 0 0 auto;
            border-top: 1px solid var(--line);
            background: var(--sidebar);
            padding: 12px 6px calc(12px + env(safe-area-inset-bottom));
        }

    .main {
        padding: 16px;
    }

    .formGrid {
        grid-template-columns: 1fr;
    }
}

/* Desktop explicit */
@media (min-width:981px) {
    .mobileUserLinks {
        display: none !important;
    }
}
/* =========================
   Sidebar final clean spacing
========================= */

.sidebar__scroll {
    display: block !important;
    line-height: normal !important;
}

    .sidebar__scroll .sidebar-nav {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
    }

        .sidebar__scroll .sidebar-nav > .nav__link,
        .sidebar__scroll .sidebar-nav > .nav__group {
            margin: 0 !important;
            padding: 0 !important;
        }

    .sidebar__scroll .nav__group {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .sidebar__scroll .nav__link,
    .sidebar__scroll .nav__groupBtn {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        width: 100% !important;
        height: auto !important;
        min-height: 40px !important;
        margin: 0 !important;
        padding: 9px 10px !important;
        line-height: 1.2 !important;
    }

    .sidebar__scroll .nav__groupBody {
        display: none !important;
        margin: 0 !important;
        padding: 0 0 0 24px !important;
    }

        .sidebar__scroll .nav__groupBody.is-open {
            display: block !important;
        }

    .sidebar__scroll .nav__sublink {
        display: block !important;
        margin: 0 !important;
        padding: 7px 10px !important;
        line-height: 1.2 !important;
    }
.userMenu__dropdown {
    min-width: 235px;
    border-radius: 14px;
}

.userMenu__roleBox {
    padding: 12px 14px;
    background: #ffffff;
}

.userMenu__roleLabel {
    display: block;
    font-size: 12px;
    font-weight: 900;
    color: #64748b;
    margin-bottom: 7px;
}

.userMenu__roleSelect {
    width: 100%;
    height: 38px;
    padding: 0 34px 0 12px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #f8fafc;
    color: #0f172a;
    font-size: 14px;
    font-weight: 800;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, #475569 50%), linear-gradient(135deg, #475569 50%, transparent 50%);
    background-position: calc(100% - 18px) 16px, calc(100% - 13px) 16px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

    .userMenu__roleSelect:hover {
        border-color: #94a3b8;
        background-color: #f1f5f9;
    }

    .userMenu__roleSelect:focus {
        border-color: #2563eb;
        background-color: #fff;
        box-shadow: 0 0 0 3px rgba(37,99,235,.14);
    }