/* ============================================
   RESET & BASE
============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #0A2463;
    --primary-light: #1A3A6B;
    --secondary: #1E88E5;
    --success: #00C853;
    --warning: #FFB300;
    --danger: #E53935;
    --bg: #F5F7FA;
    --white: #FFFFFF;
    --text: #1A2332;
    --text-light: #64748B;
    --border: #E2E8F0;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --radius: 12px;
    --sidebar-width: 250px;
    --header-height: 70px;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* ============================================
   SPLASH SCREEN
============================================ */
#splash-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.6s ease, visibility 0.6s ease;
}

#splash-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.splash-content {
    text-align: center;
    color: var(--white);
}

.splash-logo {
    font-size: 80px;
    margin-bottom: 10px;
}

.splash-content h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: 2px;
}

.splash-content p {
    font-size: 16px;
    opacity: 0.8;
    margin-top: 4px;
}

.splash-spinner {
    width: 40px;
    height: 40px;
    margin: 30px auto 10px;
    border: 4px solid rgba(255,255,255,0.2);
    border-top: 4px solid var(--white);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.splash-version {
    display: block;
    font-size: 13px;
    opacity: 0.5;
    margin-top: 8px;
}

/* ============================================
   APPLICATION
============================================ */
#app {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

.screen {
    display: none;
    height: 100%;
    width: 100%;
}

.screen.active {
    display: flex;
}

/* ============================================
   LOGIN SCREEN
============================================ */
#login-screen, #register-screen {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, #1a3a6b 100%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 40px 30px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center;
}

.login-logo {
    font-size: 60px;
    display: block;
    margin-bottom: 5px;
}

.login-card h1 {
    font-size: 26px;
    color: var(--primary);
    font-weight: 700;
}

.login-subtitle {
    color: var(--text-light);
    font-size: 14px;
    margin-bottom: 25px;
}

.login-form {
    text-align: left;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #F8F9FA;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.15);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.error-message {
    color: var(--danger);
    font-size: 13px;
    margin: 8px 0;
    min-height: 20px;
}

.login-divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

.login-version {
    color: var(--text-light);
    font-size: 12px;
    margin-top: 20px;
}

/* ============================================
   BOUTONS
============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    font-family: inherit;
    gap: 8px;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}
.btn-primary:hover { background: var(--primary-light); }

.btn-secondary {
    background: var(--text-light);
    color: var(--white);
}
.btn-secondary:hover { background: #4a5568; }

.btn-success {
    background: var(--success);
    color: var(--white);
}
.btn-success:hover { background: #00b748; }

.btn-danger {
    background: var(--danger);
    color: var(--white);
}
.btn-danger:hover { background: #c62828; }

.btn-warning {
    background: var(--warning);
    color: var(--white);
}
.btn-warning:hover { background: #e6a800; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: var(--white); }

.btn-block {
    width: 100%;
    display: flex;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}
.btn-lg {
    padding: 16px 32px;
    font-size: 18px;
}

/* ============================================
   DASHBOARD - SIDEBAR
============================================ */
#dashboard-screen {
    flex-direction: row;
}

#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--primary);
    color: var(--white);
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px 16px;
    text-align: center;
}

.sidebar-logo {
    font-size: 48px;
    display: block;
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 700;
    margin-top: 2px;
}

.sidebar-header span {
    font-size: 12px;
    opacity: 0.7;
}

.sidebar-divider {
    height: 1px;
    background: rgba(255,255,255,0.15);
    margin: 0 16px;
}

.sidebar-nav {
    list-style: none;
    padding: 12px 8px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
    font-size: 15px;
}

.nav-item:hover {
    background: rgba(255,255,255,0.08);
}

.nav-item.active {
    background: rgba(255,255,255,0.15);
    font-weight: 600;
}

.nav-icon {
    font-size: 20px;
    width: 28px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    font-size: 36px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.user-name {
    font-weight: 600;
    font-size: 15px;
}

.btn-logout {
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    font-size: 13px;
    padding: 0;
    font-family: inherit;
    transition: color 0.2s;
}

.btn-logout:hover {
    color: var(--white);
}

/* ============================================
   MAIN CONTENT
============================================ */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

#app-header {
    height: var(--header-height);
    background: var(--white);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}

#app-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-right .header-profile {
    font-size: 28px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

#headerDate {
    color: var(--text-light);
    font-size: 14px;
}

#page-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ============================================
   CARTES & STATS
============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    text-align: center;
    border: 1px solid var(--border);
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text);
}

/* ============================================
   TABLEAUX
============================================ */
.table-container {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table th {
    background: var(--primary);
    color: var(--white);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

table tr:last-child td {
    border-bottom: none;
}

table tr:hover td {
    background: #F8FAFC;
}

table .status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.pending { background: #FFF3E0; color: #E65100; }
.status-badge.sent { background: #E3F2FD; color: #0D47A1; }
.status-badge.approved { background: #E8F5E9; color: #1B5E20; }

.table-actions {
    display: flex;
    gap: 6px;
}

.table-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 4px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}

.table-actions button:hover {
    background: var(--bg);
}

/* ============================================
   FORMULAIRE DEVIS
============================================ */
.invoice-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 900px) {
    .invoice-form-grid {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.invoice-items-container {
    max-height: 300px;
    overflow-y: auto;
}

.invoice-item-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 40px;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    align-items: center;
    font-size: 14px;
}

.invoice-item-row .item-remove {
    color: var(--danger);
    cursor: pointer;
    font-size: 18px;
    text-align: center;
}

.invoice-total-box {
    background: #FFF5F5;
    border: 2px solid var(--danger);
    border-radius: 8px;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
}

.invoice-total-box .total-label {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.invoice-total-box .total-amount {
    font-size: 24px;
    font-weight: 700;
    color: var(--danger);
}

/* ============================================
   MODALE
============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
    display: flex;
}

.modal-container {
    background: var(--white);
    border-radius: var(--radius);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 80px rgba(0,0,0,0.3);
    animation: slideUp 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-light);
    padding: 0 4px;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ============================================
   RESPONSIVE
============================================ */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
        width: 280px;
        z-index: 200;
        box-shadow: 4px 0 20px rgba(0,0,0,0.2);
    }

    #sidebar.open {
        transform: translateX(0);
    }

    #sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 150;
        display: none;
    }

    #sidebar-overlay.active {
        display: block;
    }

    .menu-toggle {
        display: block;
    }

    #app-header h1 {
        font-size: 17px;
    }

    #page-content {
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-card .stat-value {
        font-size: 22px;
    }

    .login-container {
        padding: 12px;
    }

    .login-card {
        padding: 28px 20px;
    }

    .modal-container {
        margin: 12px;
        max-height: 95vh;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-card .stat-value {
        font-size: 20px;
    }

    table {
        font-size: 13px;
    }

    table th, table td {
        padding: 8px 10px;
    }
}

/* ============================================
   UTILITAIRES
============================================ */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-col { display: flex; flex-direction: column; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* Scrollbar personnalisée */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}
/* Ajouter ceci à la fin du fichier pour gérer les icônes manquantes */

/* Fallback pour les icônes */
.sidebar-logo, #loginLogo {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-logo img, #loginLogo img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

/* Masquer les erreurs d'icônes */
img[src=""], img:not([src]) {
    opacity: 0;
}