:root {
    --primary: #1a1a2e;
    --secondary: #16213e;
    --accent: #e94560;
    --accent-hover: #c73652;
    --success: #0abf62;
    --warning: #f7b731;
    --info: #0fb9b1;
    --danger: #e74c3c;
    --text-light: #e8e8e8;
    --text-muted: #9aa0ac;
    --border: rgba(255,255,255,0.08);
    --card-bg: rgba(255, 255, 255, 0.04);
    --sidebar-width: 250px;
    --header-height: 64px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0,0,0,0.35);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--primary);
    color: var(--text-light);
    min-height: 100vh;
    line-height: 1.6;
}

/* ========================================
   LAYOUT PRINCIPAL
   ======================================== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-brand {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--accent), #ff6b6b);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 700;
    flex-shrink: 0;
}

.brand-name {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: var(--text-light);
}

.brand-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-section-title {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 1rem 1.25rem 0.5rem;
}

.nav-item {
    margin: 0.15rem 0.75rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.85rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-link:hover, .nav-link.active {
    color: var(--text-light);
    background: rgba(233, 69, 96, 0.12);
}

.nav-link.active {
    color: var(--accent);
    background: rgba(233, 69, 96, 0.15);
}

.nav-link .icon {
    font-size: 1rem;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--card-bg);
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), var(--info));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.user-name {
    font-size: 0.8rem;
    font-weight: 600;
}

.user-role {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ========================================
   MAIN CONTENT
   ======================================== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.page-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    background: rgba(22, 33, 62, 0.6);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-light);
}

.page-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.page-content {
    padding: 2rem;
    flex: 1;
}

/* ========================================
   CARDS
   ======================================== */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    transition: transform var(--transition), box-shadow var(--transition);
}

.card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
}

/* ========================================
   STAT CARDS
   ======================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all var(--transition);
}

.stat-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(233, 69, 96, 0.15);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-icon.red { background: rgba(233, 69, 96, 0.15); }
.stat-icon.green { background: rgba(10, 191, 98, 0.15); }
.stat-icon.blue { background: rgba(15, 185, 177, 0.15); }
.stat-icon.yellow { background: rgba(247, 183, 49, 0.15); }

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* ========================================
   TABLES
   ======================================== */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead tr {
    background: rgba(255,255,255,0.04);
}

th {
    padding: 0.875rem 1rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
}

td {
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr {
    transition: background var(--transition);
}

tbody tr:hover {
    background: rgba(255,255,255,0.03);
}

/* ========================================
   BADGES
   ======================================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.badge-success { background: rgba(10, 191, 98, 0.15); color: #0abf62; }
.badge-danger { background: rgba(231, 76, 60, 0.15); color: #e74c3c; }
.badge-warning { background: rgba(247, 183, 49, 0.15); color: #f7b731; }
.badge-info { background: rgba(15, 185, 177, 0.15); color: #0fb9b1; }
.badge-secondary { background: rgba(255,255,255,0.08); color: var(--text-muted); }

/* ========================================
   BOUTONS
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(233, 69, 96, 0.4);
    color: white;
    text-decoration: none;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #08a853;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(10, 191, 98, 0.4);
    color: white;
    text-decoration: none;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
    text-decoration: none;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
    color: white;
    text-decoration: none;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
}

.btn-lg {
    padding: 0.875rem 2rem;
    font-size: 1rem;
    border-radius: var(--radius);
}

.btn-xl {
    padding: 1.25rem 2.5rem;
    font-size: 1.2rem;
    border-radius: var(--radius);
    width: 100%;
}

/* ========================================
   FORMULAIRES
   ======================================== */
.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    letter-spacing: 0.03em;
}

.form-control {
    width: 100%;
    padding: 0.65rem 0.875rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-light);
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

select.form-control {
    cursor: pointer;
}

/* ========================================
   ALERTS & FLASH MESSAGES
   ======================================== */
.alert {
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius-sm);
    border: 1px solid;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-success {
    background: rgba(10, 191, 98, 0.1);
    border-color: rgba(10, 191, 98, 0.3);
    color: #0abf62;
}

.alert-error {
    background: rgba(231, 76, 60, 0.1);
    border-color: rgba(231, 76, 60, 0.3);
    color: #e74c3c;
}

.alert-warning {
    background: rgba(247, 183, 49, 0.1);
    border-color: rgba(247, 183, 49, 0.3);
    color: #f7b731;
}

.alert-info {
    background: rgba(15, 185, 177, 0.1);
    border-color: rgba(15, 185, 177, 0.3);
    color: #0fb9b1;
}

/* ========================================
   FILTRE PERIODE
   ======================================== */
.filtre-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1.25rem;
    margin-bottom: 1.5rem;
}

.filtre-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-right: 0.5rem;
}

.filtre-btn {
    padding: 0.35rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
}

.filtre-btn:hover, .filtre-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(233, 69, 96, 0.08);
    text-decoration: none;
}

.filtre-separator {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 0.25rem;
}

.filtre-dates {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.filtre-dates input[type="date"] {
    padding: 0.3rem 0.6rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-light);
    font-size: 0.78rem;
    cursor: pointer;
}

.filtre-dates input[type="date"]:focus {
    outline: none;
    border-color: var(--accent);
}

/* ========================================
   LIVREUR — INTERFACE MOBILE
   ======================================== */
.livreur-layout {
    background: var(--primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.livreur-header {
    background: var(--secondary);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.livreur-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
}

/* Compteur de recette livreur */
.recette-hero {
    background: linear-gradient(135deg, rgba(233, 69, 96, 0.15), rgba(15, 185, 177, 0.08));
    border: 1px solid rgba(233, 69, 96, 0.2);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    margin-bottom: 1.5rem;
}

.recette-montant {
    font-size: 3rem;
    font-weight: 800;
    color: var(--text-light);
    line-height: 1;
}

.recette-part {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--success);
    margin-top: 0.5rem;
}

.recette-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.recette-nb {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 1rem;
}

/* ========================================
   PIN KEYBOARD
   ======================================== */
.pin-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(ellipse at top, rgba(233, 69, 96, 0.12) 0%, var(--primary) 60%);
    padding: 1rem;
}

.pin-container {
    width: 100%;
    max-width: 380px;
}

.pin-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.pin-brand-name {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    color: var(--text-light);
}

.pin-brand-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.pin-display {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.pin-dot {
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition);
}

.pin-dot.filled {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.1);
}

.pin-keyboard {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.pin-key {
    aspect-ratio: 1;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.pin-key:hover {
    background: rgba(233, 69, 96, 0.15);
    border-color: var(--accent);
    transform: scale(0.97);
}

.pin-key:active {
    background: rgba(233, 69, 96, 0.25);
    transform: scale(0.93);
}

.pin-key.delete {
    font-size: 1.1rem;
    color: var(--text-muted);
}

.pin-key.empty {
    visibility: hidden;
    cursor: default;
}

.pin-key.validate {
    background: var(--accent);
    border-color: var(--accent);
    font-size: 1.1rem;
    color: white;
}

.pin-key.validate:hover {
    background: var(--accent-hover);
}

.pin-error {
    text-align: center;
    color: var(--danger);
    font-size: 0.85rem;
    padding: 0.75rem;
    background: rgba(231, 76, 60, 0.1);
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
}

/* ========================================
   SERVICES LISTE (LIVREUR)
   ======================================== */
.services-search {
    margin-bottom: 1rem;
}

.service-group {
    margin-bottom: 1rem;
}

.service-group-title {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.service-btn {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-light);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 0.4rem;
    transition: all var(--transition);
    text-align: left;
    -webkit-tap-highlight-color: transparent;
}

.service-btn:hover, .service-btn.selected {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
    color: var(--accent);
}

/* Montant keyboard */
.amount-display {
    text-align: center;
    font-size: 2.5rem;
    font-weight: 700;
    padding: 1.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
}

.amount-unit {
    font-size: 1rem;
    color: var(--text-muted);
    margin-left: 0.5rem;
}

/* ========================================
   CHARTS
   ======================================== */
.chart-container {
    position: relative;
    height: 280px;
}

/* ========================================
   MOBILE HAMBURGER
   ======================================== */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.5rem;
}

/* ========================================
   UTILITIES
   ======================================== */
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info { color: var(--info); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-bold { font-weight: 700; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

.w-100 { width: 100%; }
.hidden { display: none; }

/* ========================================
   ANIMATIONS
   ======================================== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.animate-fade { animation: fadeIn 0.4s ease forwards; }
.pulse { animation: pulse 2s infinite; }

.en-cours-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 2s infinite;
    margin-right: 0.4rem;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-toggle {
        display: block;
    }

    .page-content {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .grid-2, .grid-3 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Scrollbar custom */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
