/* ============================================
   Layout Components – EnjazIMS v3.0
   ============================================ */

/* Hide navbar brand on desktop — logo lives in the sidebar */
@media (min-width: 993px) {
    .navbar-brand-wrap { display: none !important; }
    .navbar-shell      { justify-content: flex-end; }
    .navbar-start      { display: none; }
}

/* Sidebar backdrop overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1099;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ── Global Alerts ─────────────────────────── */
#global-alerts {
    position: fixed;
    top: 68px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    width: 90%;
    max-width: 560px;
    pointer-events: none;
}

#global-alerts .cx-toast {
    pointer-events: auto;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.75rem 0.9rem;
    background: var(--surface);
    color: var(--text-primary);
    transform: translateY(-10px);
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

#global-alerts .cx-toast.show {
    transform: translateY(0);
    opacity: 1;
}

#global-alerts .cx-toast.hide {
    transform: translateY(-8px);
    opacity: 0;
}

#global-alerts .cx-toast__icon {
    flex: 0 0 auto;
    font-size: 1rem;
}

#global-alerts .cx-toast__message {
    flex: 1;
    min-width: 0;
}

#global-alerts .cx-toast__close {
    border: 0;
    background: transparent;
    color: inherit;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    cursor: pointer;
}

#global-alerts .cx-toast__close:hover {
    background: rgba(0,0,0,0.06);
}

#global-alerts .cx-toast--success {
    border-color: var(--success, #22c55e);
}

#global-alerts .cx-toast--error {
    border-color: var(--danger, #ef4444);
}

#global-alerts .cx-toast--warning {
    border-color: var(--warning, #f59e0b);
}

#global-alerts .cx-toast--info {
    border-color: var(--info, #3b82f6);
}

.messages-container        { margin-bottom: 1rem; }
.messages-container .alert { border-radius: 12px; border: none; box-shadow: 0 2px 8px rgba(0,0,0,0.07); }

/* ── Shell ─────────────────────────── */
.dashboard-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.dashboard-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    margin-top: 50px;
    margin-right: 280px;
    padding: 0.875rem 1.25rem 1.25rem;
    gap: 0;
}

.dashboard-main {
    flex: 1;
    background: var(--bg-secondary);
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: 18px;
}

/* ── Page Header ─────────────────────────────── */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: var(--surface);
}

.page-head-title    { margin: 0; font-size: 1.25rem; font-weight: 700; color: var(--text-primary); }
.page-head-subtitle { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--text-secondary); }
.page-head-actions  { display: flex; gap: 0.4rem; }

/* ============================================
   Navbar
   ============================================ */
.navbar {
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    position: fixed;
    top: 0; left: 0; right: 280px;
    z-index: 1000;
    /* glass effect */
    backdrop-filter: blur(12px) saturate(1.4);
    -webkit-backdrop-filter: blur(12px) saturate(1.4);
    background: rgba(255,255,255,0.88);
}

[data-theme="dark"] .navbar {
    background: rgba(30,41,59,0.88);
}

.navbar-shell {
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: 100%;
}

/* Right group: hamburger + brand */
.navbar-start {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Brand */
.navbar-brand-wrap {
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-inline-end: 1.5rem;
    border-inline-end: 1px solid var(--border-color);
}

.navbar-brand-text {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.navbar-logo       { height: 28px; width: auto; display: block; }
.navbar-logo.logo-dark  { display: none; }
.navbar-logo.logo-light { display: block; }
[data-theme="dark"] .navbar-logo.logo-light { display: none;  }
[data-theme="dark"] .navbar-logo.logo-dark  { display: block; }

/* Actions group */
.navbar-actions {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* Icon buttons (theme toggle, notifications) */
.navbar-icon-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.78rem;
    transition: all 150ms ease;
    position: relative;
    text-decoration: none;
}

.navbar-icon-btn:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
    color: var(--primary);
}

/* Badge on icon button */
.navbar-badge {
    position: absolute;
    top: -4px;
    left: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--surface);
}

/* Divider between icon btns and dropdowns */
.navbar-sep {
    width: 1px;
    height: 22px;
    background: var(--border-color);
    margin: 0 0.25rem;
}

/* Dropdown trigger chips */
.navbar-menu-link {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-primary);
    text-decoration: none;
    padding: 0.3rem 0.5rem;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: all 150ms ease;
    font-size: 0.82rem;
    font-weight: 500;
}

.navbar-menu-link:hover,
.navbar-menu-link.show {
    background: var(--surface-hover);
    border-color: var(--border-color);
    color: var(--primary);
}

/* Avatar pill */
.navbar-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.navbar-label { font-size: 0.85rem; font-weight: 500; }

/* Dropdown menu polish */
.navbar .dropdown-menu {
    border-radius: 14px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
    padding: 0.3rem;
    min-width: 180px;
    margin-top: 6px !important;
}

.navbar .dropdown-item {
    border-radius: 9px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    transition: background 150ms ease;
}

.navbar .dropdown-item:hover { background: var(--surface-hover); color: var(--primary); }
.navbar .dropdown-divider    { border-color: var(--border-light); margin: 0.25rem 0; }

/* compat alias */
.theme-toggle {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 150ms ease;
    font-size: 0.85rem;
}
.theme-toggle:hover { background: var(--surface-hover); border-color: var(--primary); color: var(--primary); }

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    width: 280px;
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border-color);
    padding: 0 0.75rem 1rem;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 999;
    flex-shrink: 0;
    overflow-y: auto;
    scrollbar-width: none;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.sidebar::-webkit-scrollbar { display: none; }

/* Sidebar brand (logo at top) */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.9rem 0.7rem 0.75rem;
    margin-bottom: 0.25rem;
    text-decoration: none;
    flex-shrink: 0;
}

.sidebar-brand-text {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.sidebar-brand .navbar-logo       { height: 34px; width: auto; display: block; }
.sidebar-brand .navbar-logo.logo-dark  { display: none; }
.sidebar-brand .navbar-logo.logo-light { display: block; }
[data-theme="dark"] .sidebar-brand .navbar-logo.logo-light { display: none;  }
[data-theme="dark"] .sidebar-brand .navbar-logo.logo-dark  { display: block; }

/* Section separator */
.sidebar-separator {
    height: 1px;
    margin: 0.5rem 0.45rem;
    background: rgba(15, 23, 42, 0.10);
}

[data-theme="dark"] .sidebar-separator {
    background: rgba(148, 163, 184, 0.22);
}

.sidebar .nav {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Nav link */
.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.1rem 0.7rem;
    color: #1f2937;
    text-decoration: none;
    border-radius: 10px;
    transition: all 150ms ease;
    font-size: 0.875rem;
    font-weight: 600;
    position: relative;
}

[data-theme="dark"] .sidebar .nav-link {
    color: #e2e8f0;
}

.sidebar .nav-link:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

/* Active state */
.sidebar .nav-link.active {
    background: transparent;
    color: var(--primary);
    font-weight: 600;
    border-radius: 0;
}

.sidebar .nav-link.submenu-active {
    background: transparent;
    color: #4b5563;
    font-weight: 600;
}

[data-theme="dark"] .sidebar .nav-link.submenu-active {
    color: #cbd5e1;
}

[data-theme="dark"] .sidebar .nav-link.active {
    background: transparent;
}

[data-theme="dark"] .sidebar .nav-link.submenu-active {
    background: transparent;
}

.sidebar .nav-link.active::before {
    content: none;
    position: absolute;
    right: 0;
    top: 25%;
    bottom: 25%;
    width: 3px;
    border-radius: 4px;
    background: var(--primary);
}

/* Icon container */
.sidebar .nav-link .nav-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
    background: rgba(0,0,0,0.06);
    color: #374151;
    transition: background 150ms ease, color 150ms ease;
}

[data-theme="dark"] .sidebar .nav-link .nav-icon {
    background: rgba(255,255,255,0.08);
    color: #cbd5e1;
}

.sidebar .nav-link:hover .nav-icon { background: rgba(99,102,241,0.08); color: var(--primary); }
.sidebar .nav-link.active .nav-icon { background: rgba(99,102,241,0.14); color: var(--primary); }
.sidebar .nav-link.submenu-active .nav-icon { background: rgba(99,102,241,0.09); color: #6366f1; }

/* Muted / coming-soon links */
.sidebar-link-muted {
    opacity: 0.72;
    pointer-events: none;
}

.sidebar-link-muted small,
.nav-coming-soon {
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-tertiary);
    margin-right: auto;
    background: var(--bg-tertiary);
    border-radius: 20px;
    padding: 0.1rem 0.45rem;
}

.sidebar-divider {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 0.4rem 0;
}

/* ── Submenu ── */
.nav-link-toggle {
    cursor: pointer;
}

.nav-arrow {
    margin-right: auto;
    font-size: 0.65rem;
    color: var(--text-tertiary);
    transition: transform 200ms ease;
    display: flex;
    align-items: center;
}

.has-submenu.open > .nav-link-toggle .nav-arrow {
    transform: rotate(180deg);
}

.nav-submenu {
    list-style: none;
    padding: 0.12rem 0.35rem 0.12rem 0.9rem;
    margin: 0;
    overflow: hidden;
    max-height: 0;
    transition: max-height 250ms ease, opacity 200ms ease;
    opacity: 0;
}

.has-submenu.open > .nav-submenu {
    max-height: 300px;
    opacity: 1;
}

.nav-sublink {
    display: flex;
    align-items: center;
    padding: 0.3rem 1rem 0.2rem 0.45rem;
    font-size: 0.825rem;
    font-weight: 500;
    color: #374151;
    text-decoration: none;
    transition: background 150ms ease, color 150ms ease;
    border-right: 2px solid var(--border-light);
    margin-bottom: 1px;
    margin-right: 0.25rem;
}

[data-theme="dark"] .nav-sublink {
    color: #cbd5e1;
    border-right-color: var(--border-color);
}

.nav-sublink:hover {
    background: var(--surface-hover);
    color: var(--primary);
    border-right-color: var(--primary);
}

.nav-sublink.active {
    background: transparent;
    color: var(--primary);
    border-right-color: var(--border-light);
    font-weight: 700;
    position: relative;
    border-radius: 0;
}

.nav-sublink.active::before {
    content: none;
    position: absolute;
    left: 0.5rem;
    top: 50%;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    transform: translateY(-50%);
}

[data-theme="dark"] .nav-sublink.active {
    background: transparent;
    border-right-color: var(--border-color);
}

/* ── Sidebar footer (user info) ── */
.sidebar-footer {
    margin-top: auto;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.5rem 0;
}

.sidebar-footer-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-footer-name  { font-size: 0.8rem; font-weight: 600; color: var(--text-primary); line-height: 1.2; }
.sidebar-footer-role  { font-size: 0.7rem; color: var(--text-tertiary); }

/* ── Footer ─────────────────────────────────── */
.app-footer {
    background: transparent;
    border-top: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 0.5rem 1.25rem;
    text-align: center;
    font-size: 0.78rem;
}

.footer-subtitle { color: var(--text-secondary); font-size: 0.7rem; margin-top: 0.15rem; }

/* ── Content ─────────────────────────────────── */
.content { max-width: 100%; }

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 992px) {
    /* Navbar goes full width on mobile */
    .navbar { right: 0; }

    /* Show brand in navbar only on mobile (sidebar is hidden) */
    .navbar-brand-wrap { display: flex !important; }

    /* Remove body offset since sidebar is off-screen */
    .dashboard-body { margin-right: 0; }

    .sidebar {
        top: 0;
        right: -275px;
        height: 100vh;
        border-radius: 0;
        z-index: 1100;
        transition: right 0.25s ease;
        width: 275px;
    }

    .sidebar.show { right: 0; }

    .dashboard-body { padding: 0.75rem; gap: 0.75rem; }

    .dashboard-main { padding: 0 !important; }
}

@media (max-width: 768px) {
    .navbar-shell { padding: 0 0.875rem; }
    .navbar-label { display: none; }
    .navbar-sep   { display: none; }
    .dashboard-main { border-radius: 14px; padding: 0.75rem; }
    .page-head { flex-direction: column; align-items: flex-start; padding: 0.65rem 0.875rem; }
    .page-head-title    { font-size: 1.1rem; }
    .page-head-subtitle { font-size: 0.78rem; }
    .dashboard-body { padding: 0.5rem 0.6rem 0.6rem; }
}
