:root {
    /* Restored Initial Premium Palette */
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --bg-gradient: linear-gradient(125deg, #E0EAFC 0%, #CFDEF3 100%);

    /* Elegant Crystal Sidebar */
    --sidebar-bg: rgba(255, 255, 255, 0.8);
    --sidebar-glow: rgba(99, 102, 241, 0.1);
    --sidebar-border: rgba(255, 255, 255, 0.6);
    --sidebar-text: #475569;
    --sidebar-text-bright: #1e293b;

    --glass-surface: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(255, 255, 255, 0.4);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.08);

    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;

    /* Initial Semantic Colors */
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --info: #60a5fa;

    /* Responsive Tokens */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--sidebar-text-bright);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
}

img {
    max-width: 100%;
    height: auto;
}

input,
select,
textarea {
    max-width: 100%;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 10px;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Premium Crystal Glass Sidebar (Light) */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 50;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.02);
}

.brand {
    padding: 0 1.5rem;
    margin-bottom: 2rem;
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--sidebar-text-bright);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    letter-spacing: -0.5px;
    line-height: 1.1;
}

.brand i {
    font-size: 1.75rem;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0 0.75rem;
    overflow-y: auto;
}

.nav-label {
    padding: 1.25rem 1.25rem 0.5rem;
    font-size: 0.65rem;
    font-weight: 700;
    color: #a3aebc;
    text-transform: uppercase;
    letter-spacing: 1.2px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.65rem 1rem;
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: 0.9rem;
    border-radius: 10px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
}

.nav-link:hover {
    background: rgba(99, 102, 241, 0.04);
    color: #6366f1;
    transform: translateX(3px);
}

.nav-link.active {
    background: #fff;
    color: #6366f1;
    font-weight: 600;
    border: 1px solid rgba(99, 102, 241, 0.08);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.06);
}

.nav-icon {
    font-size: 1.25rem;
    margin-right: 1rem;
    transition: transform 0.2s;
}

.nav-link.active .nav-icon {
    color: #6366f1;
    transform: scale(1.05);
}

/* Submenu Styles */
.nav-item.has-submenu {
    display: flex;
    flex-direction: column;
}

.submenu-toggle {
    cursor: pointer;
    justify-content: space-between;
}

.submenu-toggle::after {
    content: '\f105';
    /* Phosphor ph-caret-right */
    font-family: "Phosphor";
    font-size: 0.8rem;
    transition: transform 0.3s;
    margin-left: auto;
}

.nav-item.open .submenu-toggle::after {
    transform: rotate(90deg);
}

.submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(99, 102, 241, 0.02);
    margin: 0 0.5rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.nav-item.open .submenu {
    max-height: 500px;
    /* Large enough to hold all items */
    margin-bottom: 0.5rem;
}

.submenu .nav-link {
    padding-left: 2.75rem;
    font-size: 0.85rem;
    background: transparent;
    border: none;
    box-shadow: none;
}

.submenu .nav-link:hover {
    background: rgba(99, 102, 241, 0.05);
}

.submenu .nav-link.active {
    color: var(--primary);
    background: rgba(99, 102, 241, 0.08);
}

/* Custom Scrollbar for Sidebar */
.nav-menu::-webkit-scrollbar {
    width: 4px;
}

.nav-menu::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
}

.nav-menu:hover::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
}

/* Main Content */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.top-header {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 40;
}

#sidebar-toggle {
    display: none;
    background: var(--glass-surface);
    border: 1px solid var(--glass-border);
    width: 42px;
    height: 42px;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--primary);
    transition: all 0.2s;
}

#sidebar-toggle:hover {
    background: white;
    transform: scale(1.05);
}

.header-title {
    font-size: clamp(1rem, 4vw, 1.25rem);
    font-weight: 700;
    color: var(--sidebar-text-bright);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.user-profile {
    background: var(--glass-surface);
    backdrop-filter: blur(8px);
    padding: 0.5rem 1rem 0.5rem 0.5rem;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border: 1px solid var(--glass-border);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.2s;
}

.user-profile:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.avatar {
    width: 38px;
    height: 38px;
    background: var(--primary-gradient);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.main-content {
    padding: var(--spacing-lg);
    width: 100%;
}

section {
    width: 100%;
}

/* Glass Cards */
.card {
    background: var(--glass-surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--glass-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px 0 rgba(31, 38, 135, 0.12);
}

/* Stat Cards */
.stats-grid-4 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

/* Colorful accents for glass cards */
.glass-stat-card {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1.25rem;
    min-height: 100px;
}

.glass-stat-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.4) 0%, transparent 70%);
    opacity: 0.1;
    transform: rotate(30deg);
}

.glass-accent-green {
    border-bottom: 4px solid var(--success);
}

.glass-accent-blue {
    border-bottom: 4px solid var(--info);
}

.glass-accent-orange {
    border-bottom: 4px solid var(--warning);
}

.glass-accent-yellow {
    border-bottom: 4px solid #F59E0B;
}

.stat-icon-circle {
    width: 54px;
    height: 54px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: white;
    flex-shrink: 0;
}

.bg-grad-green {
    background: linear-gradient(135deg, #34d399 0%, #059669 100%);
}

.bg-grad-blue {
    background: linear-gradient(135deg, #60a5fa 0%, #2563eb 100%);
}

.bg-grad-orange {
    background: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
}

.bg-grad-yellow {
    background: linear-gradient(135deg, #f59e0b 0%, #b45309 100%);
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 800;
    color: #1e293b;
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* Modern Tables */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.table th {
    text-align: left;
    padding: 1.25rem 1rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.table td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    color: #1e293b;
    font-weight: 500;
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: rgba(255, 255, 255, 0.4);
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s;
    font-size: 0.95rem;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: #fff;
    color: #1e293b;
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* Forms */
.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.9);
    font-size: 1rem;
    transition: all 0.2s;
}

.form-control:focus {
    background: white;
    outline: none;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
    border-color: #6366f1;
}

.form-group {
    margin-bottom: var(--spacing-md);
    width: 100%;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--sidebar-text);
    font-size: 0.9rem;
}

.badge {
    padding: 0.35rem 0.75rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.025em;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

/* Utilities */
.section-title {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.text-right {
    text-align: right;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .top-header {
        padding: 0 var(--spacing-md);
    }

    .main-content {
        padding: var(--spacing-md);
    }
}

@media (max-width: 768px) {
    #sidebar-toggle {
        display: flex;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        width: 280px;
        z-index: 1000;
        background: var(--sidebar-bg);
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: 20px 0 60px rgba(0, 0, 0, 0.2);
    }

    #sidebar-overlay.active {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        z-index: 999;
    }

    .header-date {
        display: none;
    }

    .user-profile span {
        display: none;
    }

    .user-profile {
        padding: 0.25rem;
    }

    .stats-grid-4 {
        grid-template-columns: 1fr 1fr;
    }

    .section-title {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }

    .section-title .btn {
        width: 100%;
        justify-content: center;
    }

    .card {
        padding: var(--spacing-md);
        border-radius: var(--radius-md);
    }

    /* Responsive Tab Navigation */
    .tab-container,
    [style*="display: flex; gap: 2rem; border-bottom: 1px solid var(--glass-border)"],
    [style*="border-bottom: 1px solid var(--glass-border); display: flex; gap: 2rem;"] {
        display: flex !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
        gap: 1rem !important;
        padding-bottom: 0.25rem !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    [style*="display: flex; gap: 2rem; border-bottom: 1px solid var(--glass-border)"] a,
    [style*="border-bottom: 1px solid var(--glass-border); display: flex; gap: 2rem;"] a {
        flex: 0 0 auto;
    }

    /* Grid Stacking */
    [style*="grid-template-columns: 2fr 1fr"],
    [style*="grid-template-columns: 1fr 2fr"],
    [style*="grid-template-columns: 3fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"],
    .grid-stack-mobile {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto !important;
        gap: var(--spacing-md) !important;
    }

    /* Flex wrapping for common side-by-side elements */
    [style*="display: flex; gap: 2rem"],
    [style*="display: flex; gap: 1.5rem"] {
        flex-direction: column !important;
        gap: var(--spacing-md) !important;
    }

    [style*="display: flex; gap: 2rem; border-bottom"],
    .tab-container {
        flex-direction: row !important;
        /* Keep tabs horizontal */
    }

    .table-container {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: var(--spacing-sm);
        border-radius: var(--radius-sm);
        background: rgba(255, 255, 255, 0.4);
    }

    .table {
        min-width: 700px;
        /* Force scroll */
    }

    /* Calendar Grid to List */
    .calendar-grid {
        display: block !important;
        background: transparent !important;
        border: none !important;
    }

    .calendar-header {
        display: none;
    }

    .calendar-cell {
        min-height: auto !important;
        margin-bottom: 1rem;
        border: 1px solid var(--glass-border) !important;
        border-radius: var(--radius-md);
        box-shadow: var(--glass-shadow);
        background: var(--glass-surface);
        overflow: hidden;
    }

    .calendar-cell.other-month {
        display: none;
    }

    .day-number {
        padding: 0.75rem;
        background: rgba(255, 255, 255, 0.5);
        border-bottom: 1px solid var(--glass-border);
    }

    .event-item {
        margin: 0.5rem;
        padding: 0.75rem !important;
    }

    /* Free Times Grid */
    [style*="table-layout: fixed"] {
        table-layout: auto !important;
    }
}

@media (max-width: 480px) {
    :root {
        --spacing-lg: 1rem;
        --spacing-md: 0.75rem;
    }

    .stats-grid-4 {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: 1.75rem !important;
    }

    .stat-label {
        font-size: 0.8rem;
    }

    .glass-stat-card {
        min-height: 90px;
        padding: 0.75rem 1rem !important;
        gap: 0.75rem !important;
    }

    .stat-icon-circle {
        width: 44px;
        height: 44px;
        font-size: 1.25rem;
    }

    .top-header {
        height: 60px;
    }

    .header-title {
        font-size: 0.95rem;
    }

    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    form>div {
        flex: 1 1 100% !important;
    }
}

/* Ultra Small Devices (320px) */
@media (max-width: 340px) {
    .header-title {
        max-width: 140px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .card {
        padding: 0.75rem;
    }

    .btn {
        font-size: 0.85rem;
        gap: 0.25rem;
    }
}