:root {
    --primary: #1E3A8A;
    --primary-light: #3B82F6;
    --secondary: #0D9488;
    --background: #F8FAFC;
    --surface: #FFFFFF;
    --text: #1F2937;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --danger: #EF4444;
    --success: #10B981;
    --warning: #F59E0B;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --table-header-bg: #F9FAFB;
    --table-hover-bg: #F9FAFB;
    --btn-secondary-hover: #D1D5DB;
    --card-selected-bg: #EFF6FF;
    
    /* Sidebar Light Theme */
    --sidebar-bg: #1E3A8A;
    --sidebar-color: white;
    --sidebar-link-color: rgba(255, 255, 255, 0.7);
    --sidebar-link-active-color: white;
    --sidebar-link-active-bg: rgba(255, 255, 255, 0.1);
}

html[data-theme='dark'] {
    --primary: #60A5FA;
    --primary-light: #93C5FD;
    --secondary: #14B8A6;
    --background: #0F172A;
    --surface: #1E293B;
    --text: #F8FAFC;
    --text-muted: #94A3B8;
    --border: #334155;
    --danger: #F87171;
    --success: #34D399;
    --warning: #FBBF24;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
    --table-header-bg: #1E293B;
    --table-hover-bg: #334155;
    --btn-secondary-hover: #475569;
    --card-selected-bg: #334155;
    
    /* Sidebar Dark Theme */
    --sidebar-bg: #0F172A;
    --sidebar-color: #F8FAFC;
    --sidebar-link-color: #94A3B8;
    --sidebar-link-active-color: #60A5FA;
    --sidebar-link-active-bg: rgba(96, 165, 250, 0.1);
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--background);
    color: var(--text);
    margin: 0;
    padding: 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
    transition: background-color 0.25s ease, color 0.25s ease;
}

* {
    box-sizing: border-box;
}

/* Core Layout styles */
.app-container {
    display: flex;
    min-height: 100dvh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Sidebar Styles */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-color);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    transition: var(--transition);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2.5rem;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    color: var(--sidebar-link-color);
    text-decoration: none;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    cursor: pointer;
}

.sidebar-link:hover, .sidebar-link.active {
    color: var(--sidebar-link-active-color);
    background-color: var(--sidebar-link-active-bg);
}

.sidebar-footer {
    margin-top: auto;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
    height: 100dvh;
    background-color: var(--background);
    transition: background-color 0.25s ease;
}

.topbar {
    height: 70px;
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.content-body {
    padding: 2rem;
    flex: 1;
}

/* Responsive Grids & Layouts */
.dashboard-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.studio-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
}

.form-row-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Responsive View Utilities (Desktop Default) */
.desktop-only-view {
    display: block !important;
}
.mobile-only-view {
    display: none !important;
}

/* Mobile Toggle Sidebar hamburger */
.btn-toggle-sidebar {
    display: none;
}

/* Responsive CSS */
@media (max-width: 768px) {
    .btn-toggle-sidebar {
        display: block !important;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px; /* Hide offscreen */
        height: 100dvh;
        z-index: 1500;
        box-shadow: 4px 0 15px rgba(0,0,0,0.25);
        width: 260px;
    }
    
    .sidebar.active {
        left: 0;
    }
    
    .topbar {
        padding: 0 0.5rem !important;
    }
    .topbar > div:first-child {
        gap: 0.5rem !important;
    }
    .topbar > div:last-child {
        gap: 0.4rem !important;
    }
    
    #notifications-dropdown {
        position: fixed !important;
        top: 60px !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-width: calc(100vw - 20px) !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }
    
    .content-body {
        padding: 1rem;
    }
    
    .dashboard-layout {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
    
    .studio-layout {
        grid-template-columns: 1fr !important;
        gap: 1.5rem;
        height: auto !important;
    }
    .studio-layout > div:first-child {
        border-right: none !important;
        border-bottom: 1px solid var(--border);
        padding-bottom: 1.5rem;
        padding-right: 0 !important;
    }
    
    .form-row-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }
    
    .topbar-user-text {
        display: none !important;
    }
    
    .desktop-only-view {
        display: none !important;
    }
    
    .mobile-only-view {
        display: block !important;
    }
    
    /* Modales Mobile */
    .modal-content {
        width: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        display: flex;
        flex-direction: column;
    }
    
    .modal-body {
        flex: 1;
        overflow-y: auto;
    }

    .modal-overlay {
        padding: 0 !important;
        align-items: flex-end !important;
    }

    /* Assistant Virtuel Plein Ecran */
    #assistant-window {
        width: 100vw !important;
        height: 100dvh !important;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0 !important;
        z-index: 10000 !important;
    }

    /* Tableaux Scrollables et UI Mobile */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .table-responsive .table {
        white-space: nowrap;
    }

    .hide-mobile {
        display: none !important;
    }

    .dashboard-grid, .grid-complex {
        grid-template-columns: 1fr !important;
    }

    /* Boutons d'action dans les tableaux plus faciles à toucher */
    .table .btn {
        min-height: 40px;
        min-width: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* Desktop Styles */
@media (min-width: 769px) {
    .btn-toggle-sidebar {
        display: block !important;
    }
    
    .sidebar {
        transition: width 0.25s ease, padding 0.25s ease;
    }
    
    .sidebar.collapsed {
        width: 85px;
        padding: 2rem 0.5rem;
        align-items: center;
    }
    
    .sidebar.collapsed .sidebar-logo {
        margin-bottom: 2.5rem;
    }
    
    .sidebar.collapsed .sidebar-logo img.full-logo {
        display: none !important;
    }
    
    .sidebar.collapsed .sidebar-logo img.icon-logo {
        display: block !important;
        max-height: 32px !important;
    }
    
    .sidebar.collapsed .sidebar-link span {
        display: none !important;
    }
    
    .sidebar.collapsed .sidebar-link {
        justify-content: center;
        padding: 0.85rem;
        width: 100%;
    }
    
    .sidebar.collapsed .sidebar-link i {
        margin: 0 !important;
        font-size: 1.25rem;
    }
}

/* RTL (Right to Left) Arabic Support Overrides */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .topbar-user-text {
    text-align: left !important;
}

[dir="rtl"] .sidebar-link i,
[dir="rtl"] .btn i,
[dir="rtl"] .card-header i,
[dir="rtl"] .form-group i,
[dir="rtl"] .badge i {
    margin-right: 0 !important;
    margin-left: 0.5rem !important;
}

[dir="rtl"] .sidebar-link i {
    margin-left: 0.75rem !important;
}

[dir="rtl"] #sidebar-toggle-icon {
    transform: scaleX(-1);
}

[dir="rtl"] select.form-control {
    background-position: left 0.75rem center !important;
    padding-left: 2rem !important;
    padding-right: 0.75rem !important;
}

/* Pulsing badge for pending notifications */
@keyframes pulse-badge {
    0%, 100% { transform: translateY(-50%) scale(1); opacity: 1; }
    50% { transform: translateY(-50%) scale(1.15); opacity: 0.85; }
}

/* iOS Safari Anti-Zoom Fix */
@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px !important;
    }
}


/* iOS Safari Anti-Zoom Fix & Apple HIG Native App Feel */
.card, .sidebar, .top-nav, .btn, button {
    -webkit-user-select: none;
    user-select: none;
}
input, textarea {
    -webkit-user-select: auto;
    user-select: auto;
}
@media (max-width: 768px) {
    .btn, button, .sidebar a, .nav-item, .nav-link, .menu-item {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}


/* Layout Mobile-First / Thumb Zone */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}
@media (max-width: 768px) {
    .p-desktop-grid, .grid, .row {
        display: flex;
        flex-direction: column !important;
        width: 100%;
    }
    .table-container, table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }
    .btn-action-primary {
        width: 100%;
        margin-top: 1rem;
    }
}

