/* ============================================
   LAYOUT CSS - Global Layout Structure
   Professional Admin Dashboard Layout
   ============================================ */

/* ===== SIDEBAR ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--sidebar-bg-start) 0%, var(--sidebar-bg-end) 100%);
    color: var(--white);
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    transition: var(--transition-slow);
    -webkit-overflow-scrolling: touch;
}

.sidebar::-webkit-scrollbar {
    width: 5px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.15);
    border-radius: 5px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.25);
}

/* Sidebar Brand */
.sidebar .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    text-decoration: none;
}

.sidebar .sidebar-brand img {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.sidebar .sidebar-brand span {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--white);
    white-space: nowrap;
    letter-spacing: -0.01em;
}

/* Sidebar Navigation */
.sidebar .sidebar-nav {
    flex: 1;
    padding: 1rem 0;
}

.sidebar .sidebar-nav .nav-section {
    padding: 0.625rem 1.5rem;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255, 255, 255, 0.35);
    font-weight: 700;
    margin-top: 0.75rem;
}

.sidebar .sidebar-nav .nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: rgba(255, 255, 255, 0.65);
    text-decoration: none;
    transition: var(--transition);
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: 400;
    border-left: 3px solid transparent;
    position: relative;
}

.sidebar .sidebar-nav .nav-item:hover {
    background-color: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
}

.sidebar .sidebar-nav .nav-item.active {
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--white);
    border-left-color: var(--sidebar-active-border);
    font-weight: 500;
}

.sidebar .sidebar-nav .nav-item .nav-icon {
    width: 22px;
    text-align: center;
    flex-shrink: 0;
    font-size: 1.1rem;
    opacity: 0.7;
}

.sidebar .sidebar-nav .nav-item.active .nav-icon {
    opacity: 1;
}

/* Submenu */
.sidebar .sidebar-nav .nav-item-parent {
    cursor: pointer;
}

.sidebar .sidebar-nav .nav-item-parent .nav-arrow {
    margin-left: auto;
    font-size: 0.6rem;
    transition: var(--transition);
    opacity: 0.5;
}

.sidebar .sidebar-nav .nav-item-parent.expanded .nav-arrow {
    transform: rotate(180deg);
}

.sidebar .sidebar-nav .nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
}

.sidebar .sidebar-nav .nav-submenu.expanded {
    max-height: 500px;
}

.sidebar .sidebar-nav .nav-sub-item {
    padding-left: 3.75rem !important;
    font-size: var(--font-size-xs) !important;
}

/* Sidebar Footer */
.sidebar .sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.sidebar .sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.sidebar .sidebar-user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

.sidebar .sidebar-user-detail {
    flex: 1;
    min-width: 0;
}

.sidebar .sidebar-user-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--white);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar .sidebar-user-role {
    font-size: var(--font-size-xs);
    color: rgba(255, 255, 255, 0.5);
    display: block;
}

.sidebar .sidebar-logout-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.625rem;
    background-color: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--border-radius);
    cursor: pointer;
    font-family: var(--font-family);
    font-size: var(--font-size-xs);
    transition: var(--transition);
    text-align: left;
}

.sidebar .sidebar-logout-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--white);
}

/* ===== SIDEBAR COLLAPSED STATE ===== */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-arrow,
.sidebar.collapsed .sidebar-user-detail,
.sidebar.collapsed .sidebar-logout-btn span,
.sidebar.collapsed .sidebar-user-info {
    display: none !important;
}

.sidebar.collapsed .sidebar-brand {
    justify-content: center;
    padding: 1.25rem 0.5rem;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0.75rem 0.5rem !important;
}

.sidebar.collapsed .nav-submenu {
    display: none !important;
}

.sidebar.collapsed .sidebar-footer {
    text-align: center;
    padding: 0.75rem 0.5rem;
}

.sidebar.collapsed .sidebar-logout-btn {
    justify-content: center;
    padding: 0.5rem;
}

/* Ketika sidebar collapsed, header & main ikut mengecil */
.sidebar.collapsed ~ .header,
body:has(.sidebar.collapsed) .header {
    left: var(--sidebar-collapsed-width);
}

.sidebar.collapsed ~ .main-content,
body:has(.sidebar.collapsed) .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

/* Sidebar Collapse Button */
.sidebar-collapse-btn {
    margin-left: auto;
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.6);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

.sidebar.collapsed .sidebar-collapse-btn i {
    transform: rotate(180deg);
}

/* Di mobile, collapsed tetap full overlay */
@media (max-width: 768px) {
    .sidebar.collapsed ~ .header,
    body:has(.sidebar.collapsed) .header {
        left: 0;
    }

    .sidebar.collapsed ~ .main-content,
    body:has(.sidebar.collapsed) .main-content {
        margin-left: 0;
    }
}

/* ===== HEADER ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color-light);
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    transition: var(--transition-slow);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.header .header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header .header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Sidebar Toggle */
.header .sidebar-toggle {
    background: none;
    border: 1px solid var(--border-color);
    cursor: pointer;
    padding: 0.5rem;
    color: var(--gray-600);
    font-size: 1.25rem;
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.header .sidebar-toggle:hover {
    background-color: var(--gray-100);
    color: var(--gray-900);
}

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--font-size-sm);
    color: var(--gray-500);
}

.breadcrumb-item {
    color: var(--gray-500);
    text-decoration: none;
}

.breadcrumb-item:last-child {
    color: var(--gray-800);
    font-weight: 500;
}

/* User Dropdown */
.header-user-dropdown {
    position: relative;
}

.user-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    cursor: pointer;
    padding: 0.375rem 0.5rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
    border: none;
    background: none;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    color: var(--gray-700);
}

.user-dropdown-toggle:hover {
    background-color: var(--gray-100);
}

.user-dropdown-toggle .user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

.user-dropdown-toggle .user-name {
    font-weight: 500;
}

.user-dropdown-toggle .dropdown-arrow {
    font-size: 0.6rem;
    color: var(--gray-400);
    transition: var(--transition);
}

.profile-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 220px;
    background-color: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 1050;
    overflow: hidden;
}

.profile-dropdown-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    font-size: var(--font-size-sm);
    color: var(--gray-700);
    text-decoration: none;
    transition: background-color 0.15s ease;
    border: none;
    background: none;
    width: 100%;
    cursor: pointer;
    font-family: var(--font-family);
    text-align: left;
}

.profile-dropdown-menu .dropdown-item:hover {
    background-color: var(--gray-50);
}

.profile-dropdown-menu .dropdown-item-danger {
    color: var(--danger);
}

.profile-dropdown-menu .dropdown-item-danger:hover {
    background-color: var(--danger-light);
}

.profile-dropdown-menu .dropdown-divider {
    height: 1px;
    background-color: var(--border-color-light);
    margin: 0.25rem 0;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: 0;
    margin-top: 0;
    padding: 1rem;
    min-height: 100vh;
    min-height: 100dvh;
    transition: var(--transition-slow);
    background-color: #0a0e14;
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.75rem;
}

.page-header .page-title {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--gray-900);
    margin: 0;
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.page-header .page-breadcrumb {
    font-size: var(--font-size-xs);
    color: var(--gray-500);
    margin-top: 0.125rem;
}

.page-header .page-actions {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
    width: 100%;
}

.page-header .page-actions .btn {
    flex: none;
}

/* ===== STAT CARDS GRID ===== */
.content-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    margin-bottom: 1rem;
}

/* ===== STAT CARD ===== */
.stat-card {
    background-color: var(--white);
    border-radius: var(--border-radius-xl);
    padding: 1.2rem;
    border: 1px solid var(--border-color-light);
    box-shadow: var(--shadow-xs);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    min-height: 130px;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 80px;
    height: 80px;
    background: radial-gradient(circle, var(--primary-light) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card:hover::after {
    opacity: 0.5;
}

.stat-card .stat-icon {
    width: 50px;
    height: 50px;
    border-radius: var(--border-radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
    align-self: center;
}

.stat-icon-primary { background-color: var(--primary-light); color: var(--primary); }
.stat-icon-success { background-color: var(--success-light); color: var(--success); }
.stat-icon-warning { background-color: var(--warning-light); color: #856404; }
.stat-icon-info { background-color: var(--info-light); color: var(--info); }

.stat-card .stat-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    min-height: 100px;
}

.stat-card .stat-info .stat-label {
    font-size: var(--font-size-xs);
    color: var(--gray-500);
    margin-bottom: 0;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    align-self: flex-start;
}

.stat-card .stat-info .stat-value {
    font-size: var(--font-size-2xl);
    font-weight: 600;
    color: var(--gray-900);
    line-height: 1.2;
    letter-spacing: -0.01em;
    margin: auto 0;
    align-self: flex-start;
}

.stat-card .stat-info .stat-sub {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--gray-500);
    margin-top: 0;
    align-self: flex-start;
}

/* ===== FOOTER ===== */
.footer {
    margin-left: 0;
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: var(--font-size-xs);
    color: var(--gray-500);
    border-top: 1px solid var(--border-color-light);
    background-color: var(--white);
}

/* ===== MOBILE BOTTOM NAVIGATION ===== */
.bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background-color: #1a2530;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 1030;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.2);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav .bottom-nav-inner {
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
}

.bottom-nav .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.6rem;
    font-weight: 500;
    transition: var(--transition);
    cursor: pointer;
    padding: 0.375rem;
    border: none;
    background: none;
    font-family: var(--font-family);
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav .bottom-nav-item .nav-icon {
    font-size: 1.3rem;
}

.bottom-nav .bottom-nav-item.active {
    color: #ffffff;
}

.bottom-nav .bottom-nav-item:active {
    color: var(--portal-primary);
    transform: scale(0.94);
}

/* ===== MOBILE SIDEBAR OVERLAY ===== */
.mobile-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1035;
    backdrop-filter: blur(2px);
}

.mobile-sidebar-overlay.show {
    display: block;
}

/* ===== MOBILE SUBMENU ===== */
.mobile-submenu-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 1050;
    display: flex;
    align-items: flex-end;
}

.mobile-submenu-sheet {
    width: 100%;
    background-color: var(--white);
    border-radius: var(--border-radius-xl) var(--border-radius-xl) 0 0;
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.mobile-submenu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color-light);
}

.mobile-submenu-title {
    font-weight: 700;
    font-size: var(--font-size-base);
    color: var(--gray-900);
}

.mobile-submenu-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-500);
    padding: 0.25rem;
}

.mobile-submenu-body {
    padding: 0.75rem;
}

.mobile-submenu-item {
    display: block;
    padding: 1rem 1.25rem;
    font-size: var(--font-size-base);
    color: var(--gray-800);
    text-decoration: none;
    border-radius: var(--border-radius);
    transition: background-color 0.15s ease;
}

.mobile-submenu-item:active {
    background-color: var(--gray-100);
}

/* ===== RESPONSIVE ===== */

/* Tablet & Desktop */
@media (min-width: 769px) {
    .sidebar {
        transform: translateX(0) !important;
    }
    
    .header {
        left: var(--sidebar-width);
    }
    
    .main-content {
        margin-left: var(--sidebar-width);
    }
    
    .footer {
        margin-left: var(--sidebar-width);
    }
    
    .bottom-nav {
        display: none !important;
    }
    
    .mobile-sidebar-overlay {
        display: none !important;
    }
    
    .page-header {
        flex-direction: row;
        align-items: flex-end;
        justify-content: space-between;
    }
    
    .page-header .page-actions {
        width: auto;
    }
    
    .content-grid { grid-template-columns: repeat(2, 1fr); }
    .content-grid-2 { grid-template-columns: repeat(2, 1fr); }
    .content-grid-3 { grid-template-columns: repeat(3, 1fr); }
    .content-grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* Mobile */
@media (max-width: 768px) {
    html {
        overflow-y: auto;
        overflow-x: hidden;
        height: 100%;
    }

    body {
        overflow-y: auto;
        overflow-x: hidden;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 30px rgba(0, 0, 0, 0.3);
    }
    
    .header {
        left: 0;
        padding: 0 1rem;
    }
    
    .main-content {
        margin-left: 0;
        padding: 0;
        padding-top: calc(56px + 0.5rem);
        padding-bottom: calc(var(--bottom-nav-height) + 0.5rem + env(safe-area-inset-bottom, 0));
        padding-left: 1rem;
        padding-right: 1rem;
        min-height: auto;
        box-sizing: border-box;
    }
    
    .footer {
        margin-left: 0;
        margin-bottom: var(--bottom-nav-height);
    }
    
    .content-grid,
    .content-grid-2,
    .content-grid-3,
    .content-grid-4 {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
    
    .stat-card {
        padding: 1.25rem;
    }
    
    .card-header {
        padding: 1rem 1.25rem;
    }
    
    .card-body {
        padding: 1.25rem;
    }
    
    .page-header .page-title {
        font-size: var(--font-size-xl);
    }
}

/* Small Mobile */
@media (max-width: 400px) {
    :root {
        --header-height: 56px;
        --bottom-nav-height: 56px;
    }
    
    .header {
        padding: 0 0.75rem;
    }
    
    .main-content {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        padding-top: calc(56px + 0.5rem);
        padding-bottom: calc(var(--bottom-nav-height) + 0.5rem + env(safe-area-inset-bottom, 0));
        min-height: auto;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .stat-card .stat-icon {
        width: 42px;
        height: 42px;
        font-size: 1.25rem;
    }
    
    .stat-card .stat-info .stat-value {
        font-size: var(--font-size-xl);
    }
}