/* =========================================
   KABINEO - Design Sobre & Professionnel
   ========================================= */

:root {
    --primary: #9ad3aa;
    --primary-dark: #11665f;
    --primary-darker: #0d4f49;
    --primary-light: #b8e0c4;
    
    --bg-app: #0a0e0d;
    --bg-card: #131917;
    --bg-sidebar: #0d1211;
    --bg-input: #1a1f1d;
    --bg-hover: rgba(154, 211, 170, 0.05);
    
    --text-primary: #e8f0ed;
    --text-secondary: #9fb3ab;
    --text-muted: #6b7b75;
    
    --border-light: #1f2926;
    --border-medium: #2d3935;
    
    /* NOUVEAU : Couleurs paiements */
    --especes: #9ad3aa;
    --cheque: #6eb3ff;
    --cb: #b695ff;
    --virement: #ffaa6e;
    --red: #ff6b6b;
    
    --transition: 0.2s ease;
}

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

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

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

.sidebar.collapsed {
    width: 70px;
}

/* Toggle button - Design sobre et professionnel */
.sidebar-toggle {
    position: absolute;
    right: -12px;
    top: 32px;
    width: 24px;
    height: 24px;
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.sidebar-toggle::before {
    content: '';
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-right: 6px solid var(--primary);
    transition: all var(--transition);
}

.sidebar.collapsed .sidebar-toggle::before {
    border-right: none;
    border-left: 6px solid var(--primary);
}

.sidebar-toggle:hover {
    background: var(--primary);
    border-color: var(--primary);
    transform: scale(1.1);
}

.sidebar-toggle:hover::before {
    border-right-color: var(--bg-card);
}

.sidebar.collapsed .sidebar-toggle:hover::before {
    border-right-color: transparent;
    border-left-color: var(--bg-card);
}

/* Sidebar header */
.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-light);
    transition: padding var(--transition);
}

.sidebar.collapsed .sidebar-header {
    padding: 24px 10px;
}

.sidebar-logo {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: contain;
    margin-bottom: 12px;
    transition: all var(--transition);
}

.sidebar.collapsed .sidebar-logo {
    width: 40px;
    height: 40px;
    margin: 0 auto 8px auto;
    display: block;
}

.sidebar-brand {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
    transition: opacity var(--transition);
}

.sidebar.collapsed .sidebar-brand {
    opacity: 0;
    height: 0;
    overflow: hidden;
}

.sidebar-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity var(--transition);
}

.sidebar.collapsed .sidebar-title {
    opacity: 0;
    height: 0;
    overflow: hidden;
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition);
    position: relative;
    white-space: nowrap;
}

.sidebar.collapsed .sidebar-nav a {
    padding: 12px 0;
    justify-content: center;
}

.sidebar-nav a::before {
    content: attr(data-icon);
    font-size: 20px;
    min-width: 20px;
    text-align: center;
}

.sidebar-nav a span {
    transition: opacity var(--transition);
    font-size: 14px;
    font-weight: 500;
}

.sidebar.collapsed .sidebar-nav a span {
    opacity: 0;
    position: absolute;
    pointer-events: none;
}

/* Tooltip au survol quand sidebar repliée */
.sidebar.collapsed .sidebar-nav a {
    position: relative;
}

.sidebar.collapsed .sidebar-nav a::after {
    content: attr(data-label);
    position: absolute;
    left: 70px;
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
    border: 1px solid var(--border-light);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.sidebar.collapsed .sidebar-nav a:hover::after {
    opacity: 1;
}

.sidebar-nav a:hover {
    color: var(--primary);
    background: var(--bg-hover);
}

.sidebar-nav a.active {
    color: var(--primary);
    background: rgba(154, 211, 170, 0.1);
    border-left: 3px solid var(--primary);
}

.sidebar.collapsed .sidebar-nav a.active {
    border-left: none;
    border-right: 3px solid var(--primary);
}

/* NOUVEAU : Bouton déconnexion avec hover rouge */
.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition);
}

.btn-logout::before {
    content: '⎋';
    font-size: 16px;
}

.btn-logout span {
    transition: opacity var(--transition);
}

/* Cacher le texte quand sidebar repliée */
.sidebar.collapsed .btn-logout span {
    opacity: 0;
    width: 0;
    overflow: hidden;
    position: absolute;
}

.btn-logout:hover {
    background: var(--red) !important;
    border-color: var(--red) !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.5);
    transform: translateY(-1px);
}

/* Sidebar footer */
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-light);
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    transition: opacity var(--transition);
}

.sidebar.collapsed .sidebar-footer {
    opacity: 0;
    height: 0;
    padding: 0;
    overflow: hidden;
}

/* ========== MAIN CONTENT ========== */
.main-content {
    margin-left: 260px;
    padding: 32px;
    transition: margin-left var(--transition);
    min-height: 100vh;
}

.sidebar.collapsed ~ .main-content {
    margin-left: 70px;
}

/* ========== TYPOGRAPHY ========== */
h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 24px 0 16px 0;
    color: var(--text-primary);
}

h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 16px 0 12px 0;
    color: var(--text-primary);
}

hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 24px 0;
}

.text-muted {
    color: var(--text-muted);
}

/* ========== CARDS ========== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.card-header {
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.card-header h2,
.card-header h3 {
    margin: 0;
}

/* ========== METRIC CARDS ========== */
.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 20px;
    transition: all var(--transition);
}

.metric-card:hover {
    border-color: var(--border-medium);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.metric-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.metric-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
}

/* ========== GRIDS ========== */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 20px; }

.mb-20 { margin-bottom: 20px; }

/* ========== FORMS ========== */
label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="tel"],
select,
textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition);
    margin-bottom: 16px;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(154, 211, 170, 0.1);
}

input:read-only,
input:disabled {
    background: var(--bg-hover);
    cursor: not-allowed;
    opacity: 0.6;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ad3aa' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    appearance: none;
    cursor: pointer;
}

textarea {
    resize: vertical;
    font-family: inherit;
}

.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.form-row > div {
    flex: 1;
}

/* ========== BUTTONS ========== */
button,
.btn-primary {
    padding: 10px 20px;
    background: var(--primary);
    color: var(--bg-app);
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

button:hover,
.btn-primary:hover {
    background: var(--primary-light);
    box-shadow: 0 2px 8px rgba(154, 211, 170, 0.3);
}

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

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: none;
}

/* ========== TABLES ========== */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}

thead {
    background: var(--bg-input);
}

th {
    padding: 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-light);
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--border-light);
}

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

tbody tr:hover {
    background: var(--bg-hover);
}

/* ========== TABS ========== */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 32px;
}

.tab {
    padding: 12px 24px;
    cursor: pointer;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ========== ENCAISSEMENTS ========== */
.encaissement-item {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
    transition: all var(--transition);
}

.encaissement-item:hover {
    border-color: var(--border-medium);
}

.encaissement-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    cursor: pointer;
    transition: background var(--transition);
}

.encaissement-header:hover {
    background: var(--bg-hover);
}

.encaissement-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.encaissement-content.open {
    max-height: 500px;
    border-top: 1px solid var(--border-light);
}

.encaissement-content form {
    padding: 20px;
}

/* NOUVEAU : Badges paiements avec couleurs */
.badge-paiement {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.badge-especes {
    background: rgba(154, 211, 170, 0.15);
    color: var(--especes);
    border: 1px solid var(--especes);
}

.badge-cheque {
    background: rgba(110, 179, 255, 0.15);
    color: var(--cheque);
    border: 1px solid var(--cheque);
}

.badge-cb {
    background: rgba(182, 149, 255, 0.15);
    color: var(--cb);
    border: 1px solid var(--cb);
}

.badge-virement {
    background: rgba(255, 170, 110, 0.15);
    color: var(--virement);
    border: 1px solid var(--virement);
}

/* ========== MESSAGES ========== */
.success {
    background: rgba(154, 211, 170, 0.1);
    border-left: 3px solid var(--primary);
    padding: 14px 18px;
    border-radius: 6px;
    color: var(--primary);
    font-size: 14px;
}

.warning {
    background: rgba(240, 173, 78, 0.1);
    border-left: 3px solid #f0ad4e;
    padding: 14px 18px;
    border-radius: 6px;
    color: #f0ad4e;
    font-size: 14px;
}

.error {
    background: rgba(217, 83, 79, 0.1);
    border-left: 3px solid #d9534f;
    padding: 14px 18px;
    border-radius: 6px;
    color: #d9534f;
    font-size: 14px;
}

/* ========== LOGIN ========== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-app);
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px auto;
    display: block;
    border-radius: 8px;
}

.login-title {
    text-align: center;
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 14px;
}

/* ========== AGENDA GRID ========== */
.agenda-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border-light);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    overflow: hidden;
}

.agenda-header {
    background: var(--bg-card);
    padding: 12px;
    text-align: center;
    font-weight: 600;
    font-size: 13px;
}

.agenda-slot {
    background: var(--bg-card);
    min-height: 45px;
    padding: 6px;
    font-size: 12px;
    transition: background var(--transition);
}

.agenda-slot.rdv {
    background: rgba(154, 211, 170, 0.1);
    border-left: 3px solid var(--primary);
    cursor: pointer;
    font-weight: 500;
}

.agenda-slot.rdv:hover {
    background: rgba(154, 211, 170, 0.2);
}

/* ========== RDV ITEMS ========== */
.rdv-item {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all var(--transition);
}

.rdv-item:hover {
    border-color: var(--primary);
    background: var(--bg-hover);
}

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

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-app);
}

::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* ==========================================
   RESPONSIVE (MOBILES, TABLETTES & PETITS ÉCRANS)
   ========================================== */

/* 1. COMPORTEMENT PAR DÉFAUT (PC) */
.mobile-menu-btn {
    display: none; /* Toujours caché sur PC */
}
.sidebar-overlay {
    display: none; /* Toujours caché sur PC */
}

/* 2. ÉCRANS MOYENS (Laptops / Petits écrans) */
@media (max-width: 1200px) {
    .grid-5 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 968px) {
    .grid-5, .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .main-content { padding: 24px; }
}

/* 3. MOBILES ET TABLETTES (Moins de 768px) */
@media (max-width: 768px) {
    
    /* --- La Sidebar --- */
    .sidebar {
        left: -280px;
        width: 280px !important; 
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 15px rgba(0,0,0,0.5);
        z-index: 1002 !important; /* <- CORRECTION : 1002 passe au-dessus du bouton (qui est à 1001) */
    }

    .sidebar.mobile-open {
        left: 0; /* Apparaît quand activée par JS */
    }

    /* On cache la flèche PC sur mobile */
    .sidebar-toggle {
        display: none !important; 
    }

    /* --- Le Bouton Hamburger --- */
    .mobile-menu-btn {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        position: fixed;
        top: 15px;
        left: 15px;
        width: 45px;
        height: 45px;
        background: var(--bg-card);
        border: 1px solid var(--border-light);
        border-radius: 8px;
        cursor: pointer;
        z-index: 1001; /* Au-dessus de l'overlay */
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
        padding: 0;
        transition: all var(--transition);
    }

    .mobile-menu-btn span {
        width: 22px;
        height: 2px;
        background: var(--primary);
        border-radius: 2px;
        transition: all 0.3s ease;
    }

    /* --- L'Overlay Sombre --- */
    .sidebar-overlay.active {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(3px);
        z-index: 999; /* Juste en dessous de la sidebar */
    }

    /* --- Le Contenu Principal --- */
    .main-content {
        margin-left: 0 !important; /* On annule la marge de la sidebar PC */
        padding: 80px 16px 24px 16px; /* Espace en haut pour le hamburger */
        width: 100%;
    }

    /* --- Ajustements Typo et Grilles --- */
    h1 { font-size: 24px; }
    h2 { font-size: 18px; }
    
    .grid-5, .grid-4, .grid-3, .grid-2 { 
        grid-template-columns: 1fr; /* Tout sur une seule colonne */
        gap: 16px;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .metric-value {
        font-size: 28px;
    }

    /* Rend les tableaux scrollables horizontalement pour ne pas casser le design */
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Zones tactiles plus grandes pour mobile */
    button, input, select, textarea {
        min-height: 44px;
    }
}

@media (max-width: 768px) {
    /* 1. Empêche le scroll du fond quand le menu est ouvert */
    body.no-scroll {
        overflow: hidden;
    }

    /* 2. Ajuste la boîte de connexion pour qu'elle ne touche pas les bords */
    .login-box {
        margin: 20px;
        padding: 24px !important;
        width: calc(100% - 40px) !important;
    }
}

@media (max-width: 768px) {
    .login-container {
        padding: 20px;
    }
    .login-box {
        width: 100% !important;
        margin: 0 !important;
        padding: 24px !important;
    }
}
@media (max-width: 768px) {
    /* 1. Bloque le scroll vertical sur la page de login */
    .login-container {
        height: 100dvh !important; /* dvh s'adapte à la vraie hauteur sans la barre d'adresse */
        min-height: unset;
        overflow: hidden;
    }
    
    /* 2. Empêche le rafraîchissement au tirage vers le bas (pull-to-refresh) */
    body {
        overscroll-behavior-y: none;
    }

    /* 3. Cache automatiquement le hamburger si la barre latérale est ouverte */
    body:has(.sidebar.mobile-open) .mobile-menu-btn {
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
}