/**
 * ============================================================
 * 📊 DASHBOARD CSS V9 - TAILLE OPTIMISÉE, BANDEAU PRÉSERVÉ
 * ============================================================
 */

:root {
    --theme-primary: #2563eb;
    --theme-secondary: #64748b;
    --theme-background: #ffffff;
    --theme-surface: #fafbfc;
    --theme-text: #1a1a2e;
    --theme-text-secondary: #6b7280;
    --theme-border: #eef2f6;
    --theme-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
    --theme-base-size: 16px;
    --theme-border-radius: 0.5rem;
    
    --spacing-xs: 0.5rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.25rem;
    --spacing-xl: 1.75rem;
    --spacing-2xl: 2rem;
    
    --text-xs: 0.8rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.02);
    --shadow-md: 0 2px 4px rgba(0,0,0,0.02);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.04);
    
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.625rem;
    --radius-xl: 0.75rem;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--theme-font-family);
    font-size: var(--theme-base-size);
    color: var(--theme-text);
    background: var(--theme-background);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.dashboard-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================================
   HEADER - BANDEAU SUPÉRIEUR (NON MODIFIÉ)
   ============================================================ */

.main-header {
    background: var(--theme-surface);
    border-bottom: 1px solid var(--theme-border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    background: rgba(250, 251, 252, 0.85);
}

.header-container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0.625rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.logo-img {
    height: 30px;
    width: auto;
}

.platform-name {
    font-size: 1.0625rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    background: linear-gradient(135deg, var(--theme-primary) 0%, #4f46e5 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-nav {
    display: flex;
    gap: 0.375rem;
    align-items: center;
}

.user-greeting {
    font-size: var(--text-sm);
    color: var(--theme-text-secondary);
    padding: 0.25rem 0.5rem;
    font-weight: 450;
}

.btn-auth, .btn-icon {
    padding: 0.4rem 0.75rem;
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
    font-weight: 450;
    text-decoration: none;
    border: none;
    cursor: pointer;
    background: transparent;
    color: var(--theme-text);
    transition: all 0.12s ease;
    letter-spacing: -0.01em;
}

.btn-icon {
    padding: 0.4rem 0.6rem;
    font-size: 1rem;
}

.btn-auth:hover, .btn-icon:hover {
    background: var(--theme-background);
}

.btn-active {
    background: var(--theme-primary);
    color: white;
}

.btn-active:hover {
    background: var(--theme-primary);
    opacity: 0.88;
}

.btn-logout {
    color: var(--theme-text-secondary);
}

.btn-logout:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.06);
}

.layout-toggle {
    display: flex;
    gap: 2px;
    background: var(--theme-background);
    padding: 3px;
    border-radius: var(--radius-md);
    border: 1px solid var(--theme-border);
}

.layout-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.9rem;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--theme-text-secondary);
    transition: all 0.12s ease;
}

.layout-btn:hover {
    background: var(--theme-surface);
}

.layout-btn.active {
    background: var(--theme-primary);
    color: white;
}

.mode-toggle-btn {
    background: transparent;
    border: 1px solid var(--theme-border);
    border-radius: var(--radius-md);
    padding: 0.4rem 0.6rem;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.12s ease;
}

.mode-toggle-btn:hover {
    background: var(--theme-surface);
    border-color: var(--theme-primary);
}

/* ============================================================
   DROPDOWN THÈME - RAFFINÉ
   ============================================================ */

.theme-selector {
    position: relative;
}

.theme-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: var(--theme-background);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(0,0,0,0.06);
    min-width: 280px;
    z-index: 2000;
    border: 1px solid var(--theme-border);
    overflow: hidden;
}

.theme-dropdown.active {
    display: block;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.theme-dropdown-header {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--theme-border);
}

.theme-dropdown-header h4 {
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--theme-text-secondary);
    margin: 0;
}

.theme-options-container {
    max-height: 320px;
    overflow-y: auto;
    padding: 0.5rem;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.875rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--text-sm);
    transition: background 0.1s ease;
}

.theme-option:hover {
    background: var(--theme-surface);
}

.theme-option.active {
    background: var(--theme-primary);
    color: white;
}

.theme-option-preview {
    display: flex;
    gap: 4px;
}

.theme-color-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.4);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.theme-option-info {
    flex: 1;
}

.theme-option-info strong {
    font-weight: 500;
}

.badge-personalized {
    font-size: 0.65rem;
    background: rgba(0,0,0,0.04);
    padding: 0.15rem 0.4rem;
    border-radius: 12px;
    margin-left: 0.5rem;
    font-weight: 450;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.theme-option.active .badge-personalized {
    background: rgba(255,255,255,0.15);
}

.theme-active-check {
    font-weight: 500;
    opacity: 0.9;
}

.theme-dropdown-divider {
    height: 1px;
    background: var(--theme-border);
    margin: 0.25rem 0;
}

.theme-dropdown-actions {
    padding: 0.625rem;
    display: flex;
    gap: 0.5rem;
}

.theme-action-item {
    flex: 1;
    text-align: center;
    padding: 0.625rem 0.25rem;
    font-size: 0.8rem;
    font-weight: 450;
    border-radius: var(--radius-md);
    cursor: pointer;
    background: var(--theme-surface);
    transition: all 0.12s ease;
    letter-spacing: -0.01em;
}

.theme-action-item:hover {
    background: var(--theme-primary);
    color: white;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */

.dashboard-main {
    flex: 1;
    padding: 2rem 1.5rem;
}

.dashboard-container {
    max-width: 1280px;
    margin: 0 auto;
}

/* ============================================================
   HERO SECTION - LÉGER
   ============================================================ */

.welcome-dashboard {
    background: linear-gradient(135deg, var(--theme-primary) 0%, #4f46e5 100%);
    border-radius: var(--radius-xl);
    padding: 1.5rem 1.75rem;
    margin-bottom: 2rem;
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
}

.welcome-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.welcome-info h1 {
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    letter-spacing: -0.02em;
}

.last-login {
    font-size: 0.8rem;
    opacity: 0.8;
    font-weight: 400;
}

.welcome-actions {
    display: flex;
    gap: 0.625rem;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    border-radius: var(--radius-md);
    background: white;
    color: var(--theme-primary);
    text-decoration: none;
    font-weight: 450;
    transition: all 0.12s ease;
    letter-spacing: -0.01em;
}

.btn-sm:hover {
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.btn-outline {
    background: transparent;
    color: white;
    border: 1px solid rgba(255,255,255,0.25);
}

.btn-outline:hover {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.4);
}

/* ============================================================
   STATS GRID - ÉPURÉ
   ============================================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--theme-surface);
    border-radius: var(--radius-lg);
    padding: 1.125rem 1rem;
    text-align: center;
    border: 1px solid var(--theme-border);
    transition: all 0.12s ease;
}

.stat-card:hover {
    border-color: var(--theme-primary);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.04);
}

.stat-value {
    font-size: 1.875rem;
    font-weight: 500;
    color: var(--theme-primary);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--theme-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 450;
}

/* ============================================================
   SECTIONS - MINIMALISTES
   ============================================================ */

.dashboard-section {
    background: var(--theme-surface);
    border-radius: var(--radius-lg);
    padding: 0;
    margin-bottom: 1.125rem;
    border: 1px solid var(--theme-border);
    overflow: hidden;
    transition: border-color 0.12s ease;
}

.dashboard-section:hover {
    border-color: rgba(37, 99, 235, 0.15);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.875rem 1.25rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s ease;
}

.section-header:hover {
    background: rgba(0,0,0,0.01);
}

.collapsible-section[data-collapsed="false"] .section-header {
    border-bottom: 1px solid var(--theme-border);
}

.toggle-icon {
    font-size: 0.7rem;
    color: var(--theme-text-secondary);
    width: 18px;
    opacity: 0.6;
}

.section-header h2 {
    font-size: 1.0625rem;
    font-weight: 500;
    flex: 1;
    margin: 0;
    letter-spacing: -0.01em;
    color: var(--theme-text);
}

.section-badge {
    font-size: 0.75rem;
    background: var(--theme-background);
    padding: 0.2rem 0.5rem;
    border-radius: 20px;
    color: var(--theme-text-secondary);
    font-weight: 450;
    border: 1px solid var(--theme-border);
}

.section-content {
    padding: 1.25rem;
}

/* ============================================================
   APP CARDS - RAFFINÉES
   ============================================================ */

.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 1.125rem;
}

.apps-grid.list-view {
    grid-template-columns: 1fr;
}

.apps-grid--compact {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.app-card {
    background: var(--theme-background);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--theme-border);
    text-decoration: none;
    transition: all 0.15s ease;
}

.app-card:hover {
    border-color: var(--theme-primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.04);
}

.app-card--compact .app-card__logo {
    padding: 1rem 0.75rem 0.5rem;
    text-align: center;
    background: linear-gradient(135deg, var(--theme-surface) 0%, var(--theme-background) 100%);
    border-bottom: 1px solid var(--theme-border);
}

.app-card--compact .app-card__logo img {
    width: 60px;
    height: 60px;
    object-fit: contain;
}

.app-card--compact .app-card__content {
    padding: 0.875rem 0.875rem;
    flex: 1;
}

.app-card--compact .app-card__content h3 {
    font-size: 0.9375rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--theme-text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: -0.01em;
}

.default-badge {
    font-size: 0.75rem;
    opacity: 0.75;
}

.app-card--compact .app-card__content p {
    color: var(--theme-text-secondary);
    font-size: 0.8125rem;
    line-height: 1.45;
    margin-bottom: 0.25rem;
}

.app-card--compact .app-card__footer {
    padding: 0.625rem 0.875rem;
    border-top: 1px solid var(--theme-border);
    background: var(--theme-surface);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.radio-label-compact {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--theme-text-secondary);
    font-size: 0.8125rem;
    font-weight: 450;
    cursor: pointer;
}

.radio-label-compact input {
    width: 15px;
    height: 15px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--theme-primary);
}

.app-card__link {
    color: var(--theme-primary);
    font-weight: 450;
    font-size: 0.875rem;
    text-decoration: none;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: background 0.12s ease;
}

.app-card__link:hover {
    background: rgba(37, 99, 235, 0.06);
}

/* Liste view */
.apps-grid.list-view .app-card {
    display: grid;
    grid-template-columns: 85px 1fr auto;
    align-items: center;
}

.apps-grid.list-view .app-card__logo {
    padding: 0.625rem;
    border-bottom: none;
    border-right: 1px solid var(--theme-border);
}

.apps-grid.list-view .app-card__logo img {
    width: 50px;
    height: 50px;
}

.apps-grid.list-view .app-card__content {
    padding: 0.625rem 1rem;
}

.apps-grid.list-view .app-card__footer {
    border-top: none;
    border-left: 1px solid var(--theme-border);
    padding: 0.625rem 1rem;
}

/* ============================================================
   ACTIVITY LIST - LÉGER
   ============================================================ */

.activity-list {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--theme-border);
    font-size: 0.875rem;
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-icon {
    width: 24px;
    text-align: center;
    font-size: 0.9375rem;
    opacity: 0.7;
}

.activity-action {
    flex: 1;
    color: var(--theme-text);
    font-weight: 450;
}

.activity-time {
    font-size: 0.75rem;
    color: var(--theme-text-secondary);
    font-weight: 400;
}

.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--theme-text-secondary);
    font-size: 0.875rem;
    font-weight: 450;
}

/* ============================================================
   MODALS - ÉPURÉS
   ============================================================ */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.2);
    backdrop-filter: blur(4px);
    z-index: 3000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--theme-background);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0,0,0,0.08);
    border: 1px solid var(--theme-border);
}

.modal-content--sm {
    max-width: 400px;
}

.modal-content--lg {
    max-width: 650px;
}

.modal-content h3 {
    font-size: 1.1875rem;
    font-weight: 500;
    margin-bottom: 1.25rem;
    letter-spacing: -0.01em;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.375rem;
    font-weight: 450;
    color: var(--theme-text);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--theme-border);
    border-radius: var(--radius-md);
    background: var(--theme-background);
    font-size: 0.9375rem;
    color: var(--theme-text);
    transition: border-color 0.12s ease;
    font-family: var(--theme-font-family);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--theme-primary);
}

.form-group input[type="color"] {
    height: 44px;
    padding: 4px;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.625rem;
}

.modal-buttons {
    display: flex;
    gap: 0.625rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.btn-primary {
    background: var(--theme-primary);
    color: white;
    border: none;
}

.btn-primary:hover {
    opacity: 0.88;
}

/* ============================================================
   NOTIFICATIONS
   ============================================================ */

.theme-notification {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: #10b981;
    color: white;
    padding: 0.75rem 1.125rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.15);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    font-weight: 450;
    transition: opacity 0.25s, transform 0.25s;
    border: 1px solid rgba(255,255,255,0.1);
}

.notification-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    border-radius: var(--radius-sm);
}

.notification-close:hover {
    opacity: 1;
    background: rgba(255,255,255,0.1);
}

.tiny-notification {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--theme-background);
    color: var(--theme-text);
    padding: 0.625rem 1.25rem;
    border-radius: 40px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.06);
    z-index: 10000;
    font-size: 0.875rem;
    font-weight: 450;
    border: 1px solid var(--theme-border);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    letter-spacing: -0.01em;
}

.tiny-notification--success {
    background: #10b981;
    color: white;
    border-color: #059669;
}

.tiny-notification--error {
    background: #ef4444;
    color: white;
    border-color: #dc2626;
}

.tiny-notification--info {
    background: var(--theme-primary);
    color: white;
}

/* ============================================================
   SUPPRESSION DES FLASHES
   ============================================================ */

input[type="radio"] {
    transition: none !important;
    animation: none !important;
}

.app-card,
.app-card * {
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.12s ease !important;
    transform: none !important;
}

/* ============================================================
   FOOTER - DISCRET
   ============================================================ */

.main-footer {
    padding: 1rem 1.5rem;
    text-align: center;
    border-top: 1px solid var(--theme-border);
    font-size: 0.8125rem;
    color: var(--theme-text-secondary);
    font-weight: 400;
    letter-spacing: -0.01em;
    background: var(--theme-surface);
}

/* ============================================================
   DARK MODE - ÉLÉGANT
   ============================================================ */

[data-mode="dark"] {
    --theme-background: #0a0a0f;
    --theme-surface: #12121a;
    --theme-text: #ecedee;
    --theme-text-secondary: #8e8e9a;
    --theme-border: #252530;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 2px 4px rgba(0,0,0,0.2);
    --shadow-lg: 0 8px 20px rgba(0,0,0,0.3);
}

[data-mode="dark"] .main-header {
    background: rgba(18, 18, 26, 0.85);
}

[data-mode="dark"] .theme-dropdown {
    background: var(--theme-surface);
    border-color: var(--theme-border);
}

[data-mode="dark"] .theme-option:hover {
    background: rgba(255,255,255,0.04);
}

[data-mode="dark"] .modal-content {
    background: var(--theme-surface);
    border-color: var(--theme-border);
}

[data-mode="dark"] .welcome-dashboard {
    background: linear-gradient(135deg, #1a1a3e 0%, #2d1f4e 100%);
}

[data-mode="dark"] .btn-auth:hover,
[data-mode="dark"] .btn-icon:hover {
    background: rgba(255,255,255,0.04);
}

/* ============================================================
   RESPONSIVE - ADAPTATIF
   ============================================================ */

@media (max-width: 900px) {
    .dashboard-container {
        padding: 0;
    }
    
    .stats-grid {
        gap: 0.875rem;
    }
}

@media (max-width: 768px) {
    .header-container {
        flex-direction: column;
        align-items: stretch;
    }
    
    .auth-nav {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .apps-grid,
    .apps-grid--compact {
        grid-template-columns: 1fr;
    }
    
    .color-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .theme-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 20px 20px 0 0;
    }
    
    .dashboard-main {
        padding: 1.25rem 1rem;
    }
    
    .welcome-dashboard {
        padding: 1.25rem 1.25rem;
    }
    
    .section-header {
        padding: 0.75rem 1rem;
    }
    
    .section-content {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .welcome-content {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .welcome-actions {
        width: 100%;
    }
    
    .welcome-actions .btn-sm {
        flex: 1;
        text-align: center;
    }
    
    .welcome-info h1 {
        font-size: 1.25rem;
    }
}