/* ===================================================================
   PropManager — Design system  ·  "Émeraude / Immobilier"
   Un seul fichier de style pilote toute l'application.
   =================================================================== */
:root {
    /* — Marque (émeraude) — */
    --color-primary:      #0f766e;   /* émeraude profond */
    --color-primary-dark: #0b5d56;   /* survol */
    --color-primary-soft: #e2f2ef;   /* fond teinté */
    --color-accent:       #10b981;   /* accent vif (sidebar active, focus) */

    /* — Neutres chauds — */
    --color-bg:         #f6f5f2;      /* fond général chaud */
    --color-surface:    #ffffff;      /* cartes */
    --color-surface-2:  #fbfaf8;      /* survol de ligne */
    --color-border:     #e8e5df;      /* bordures chaudes */
    --color-text:       #1e2a27;      /* texte principal */
    --color-text-muted: #6c756f;      /* texte secondaire */

    /* — Sémantique — vert=entrée/payé · rouge=sortie/impayé · orange=partiel · bleu=info */
    --color-success: #15803d;  --color-success-bg: #e7f6ec;
    --color-danger:  #dc2626;  --color-danger-bg:  #fdeaea;
    --color-warning: #c2740c;  --color-warning-bg: #fdf1e0;
    --color-info:    #0369a1;  --color-info-bg:    #e4f1fb;

    /* — Sidebar sombre forêt — */
    --sidebar-bg:    #10201c;
    --sidebar-text:  #b7c6c0;
    --sidebar-muted: #6e847c;

    /* — Teintes dérivées (déclarées ici pour être basculées en mode sombre) — */
    --color-neutral-bg:   #eef1ef;   /* badge neutre, jauge calendrier, bouton fantôme */
    --color-topbar-bg:    rgba(255,255,255,.85);
    --color-placeholder:  #9aa39d;
    --color-danger-hover: #fbdcdc;
    --color-warning-hover:#fbe6c9;
    --color-success-brd:  #bfe4cb;
    --color-danger-brd:   #f3c9c9;
    --color-info-brd:     #c6e2f5;
    --color-warning-brd:  #f0d5a8;
    --color-purple-bg:    #f3e8ff;  --color-purple-text: #7c3aed;
    --color-blue-bg:      #e5edfb;  --color-blue-text:   #2f4fd6;
    --color-teal-bg:      #d6f3ee;
    --color-doc-bg:       #ffffff;   /* facture imprimable, carte de connexion */

    --color-primary-bg:   #ecfdf5;   /* survol des chiffres cliquables du tableau de bord */

    /* Texte posé SUR un aplat de couleur — doit contraster avec le fond, pas avec la page. */
    --color-on-primary:   #ffffff;
    --color-on-danger:    #ffffff;
    --color-danger-strong:#b91c1c;   /* survol du bouton rouge */

    /* — Formes & profondeur — */
    --sidebar-width: 250px;
    --radius-sm: 8px;
    --radius:    12px;
    --radius-lg: 18px;
    --shadow-xs: 0 1px 2px rgba(16, 32, 28, .06);
    --shadow:    0 2px 6px rgba(16, 32, 28, .06), 0 1px 2px rgba(16, 32, 28, .05);
    --shadow-md: 0 10px 25px rgba(16, 32, 28, .10);
    --shadow-lg: 0 24px 50px rgba(16, 32, 28, .16);
    --ring: 0 0 0 3px rgba(16, 185, 129, .28);
    --ease: .18s cubic-bezier(.4, 0, .2, 1);
}

/* ===================================================================
   MODE SOMBRE
   Seules les COULEURS changent ; formes, tailles et espacements restent
   identiques. Le thème s'applique via <html data-theme="dark">, posé par
   app.js avant l'affichage pour éviter tout clignotement blanc.
   =================================================================== */
:root[data-theme="dark"] {
    /* Marque : émeraude éclaircie — le vert profond devient illisible sur fond noir. */
    --color-primary:      #2dd4a7;
    --color-primary-dark: #5ee7c0;
    --color-primary-soft: #12312c;
    --color-accent:       #10b981;

    /* Neutres : gris-vert froids, jamais du noir pur (fatigant à lire). */
    --color-bg:         #0e1614;
    --color-surface:    #16211e;
    --color-surface-2:  #1d2a26;
    --color-border:     #2a3833;
    --color-text:       #e6ece9;
    --color-text-muted: #94a39d;

    /* Sémantique : texte vif + fond sourd, pour garder le contraste. */
    --color-success: #4ade80;  --color-success-bg: #12301f;
    --color-danger:  #f87171;  --color-danger-bg:  #3a1a1a;
    --color-warning: #fbbf24;  --color-warning-bg: #3a2a10;
    --color-info:    #60a5fa;  --color-info-bg:    #14283f;

    /* La sidebar est déjà sombre : on l'assombrit juste pour la détacher du fond. */
    --sidebar-bg:    #0a1412;
    --sidebar-text:  #b7c6c0;
    --sidebar-muted: #6e847c;

    /* Teintes dérivées */
    --color-neutral-bg:   #253330;
    --color-topbar-bg:    rgba(22,33,30,.85);
    --color-placeholder:  #6b7873;
    --color-danger-hover: #4a2020;
    --color-warning-hover:#4a3614;
    --color-success-brd:  #1f5136;
    --color-danger-brd:   #5c2a2a;
    --color-info-brd:     #24456b;
    --color-warning-brd:  #5c4418;
    --color-purple-bg:    #2c1f45;  --color-purple-text: #c4a5f8;
    --color-blue-bg:      #1a2749;  --color-blue-text:   #93b4fc;
    --color-teal-bg:      #12352f;
    --color-doc-bg:       #16211e;

    --color-primary-bg:   #12312c;

    /* En sombre, primary/danger sont des tons CLAIRS : le texte posé dessus
       doit être foncé, sinon le bouton devient illisible. */
    --color-on-primary:   #06211e;
    --color-on-danger:    #2a0d0d;
    --color-danger-strong:#fca5a5;

    /* Ombres plus denses : sur fond sombre, une ombre claire ne se voit pas. */
    --shadow-xs: 0 1px 2px rgba(0,0,0,.4);
    --shadow:    0 2px 6px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 10px 25px rgba(0,0,0,.5);
    --shadow-lg: 0 24px 50px rgba(0,0,0,.6);
}

/* Les documents imprimables restent blancs même en mode sombre :
   une facture doit sortir sur papier blanc, pas en noir. */
@media print {
    :root[data-theme="dark"] {
        --color-doc-bg: #ffffff;
        --color-surface: #ffffff;
        --color-bg: #ffffff;
        --color-text: #000000;
        --color-text-muted: #444444;
        --color-border: #dddddd;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Plus Jakarta Sans", "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.55rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 700; letter-spacing: -.01em; color: var(--color-text); }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

/* ---- App shell ---------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.1rem 0 2rem;
}

.sidebar-brand {
    font-size: 1.22rem;
    font-weight: 800;
    color: #fff;
    padding: 0 1.4rem 1.15rem;
    border-bottom: 1px solid rgba(255,255,255,.07);
    margin-bottom: .6rem;
    display: flex;
    align-items: center;
    gap: .6rem;
    letter-spacing: -.02em;
}
.sidebar-brand::before {
    content: "";
    width: 30px; height: 30px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--color-accent), var(--color-primary));
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(16,185,129,.35);
}

.sidebar-nav { display: flex; flex-direction: column; overflow-y: auto; }

/* Sur ordinateur : le menu occupe toute la hauteur de l'écran et reste collé en haut
   (sticky) quand on scrolle la page. Le contenu se pagine (1, 2, 3…) pour ne pas
   descendre à l'infini. */
@media (min-width: 901px) {
    .app-shell { align-items: stretch; }
    .sidebar {
        position: sticky;
        top: 0;
        /* Toujours toute la hauteur de l'écran, quel que soit le nombre de pages
           du rôle : un utilisateur avec 5 entrées voit le même menu plein qu'un
           administrateur. La liste défile si elle dépasse. */
        height: 100vh;
        overflow-y: auto;
    }
    /* Menu rétractable : masqué quand replié, le contenu prend toute la largeur. */
    body.sidebar-collapsed .sidebar { display: none; }
}

.sidebar-nav a {
    color: var(--sidebar-text);
    padding: .62rem 1.4rem;
    text-decoration: none;
    border-left: 3px solid transparent;
    font-size: .92rem;
    font-weight: 500;
    transition: background var(--ease), color var(--ease);
}
.sidebar-nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar-nav a.active {
    background: linear-gradient(90deg, rgba(16,185,129,.20), rgba(16,185,129,.02));
    border-left-color: var(--color-accent);
    color: #fff;
    font-weight: 700;
}

.sidebar-section {
    margin-top: 1.1rem;
    padding: 0 1.4rem .35rem;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--sidebar-muted);
    font-weight: 700;
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: .62rem; left: .62rem;
    z-index: 50;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    width: 42px; height: 42px;
    font-size: 1.15rem;
    box-shadow: var(--shadow);
    cursor: pointer;
}

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Bouton pour replier/déplier le menu (visible sur ordinateur uniquement). */
.sidebar-collapse-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex-shrink: 0;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 9px; font-size: 1.1rem; cursor: pointer; color: var(--color-text);
    transition: background var(--ease);
}
.sidebar-collapse-btn:hover { background: var(--color-surface-2); border-color: var(--color-primary); }

/* ---- Topbar --------------------------------------------------------- */
.topbar {
    background: var(--color-topbar-bg);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--color-border);
    padding: .7rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar-title { font-weight: 700; font-size: 1.02rem; letter-spacing: -.01em; }
.topbar-right { display: flex; align-items: center; gap: 1rem; margin-left: auto; }

.topbar-search { display: flex; align-items: center; flex: 1; max-width: 380px; }
.topbar-search input {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    border-right: none;
    background: var(--color-surface);
}
.topbar-search button {
    border: 1px solid var(--color-border);
    border-left: none;
    background: var(--color-primary-soft);
    color: var(--color-primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 0 .85rem;
    cursor: pointer;
    font-size: .95rem;
    height: 40px;
    transition: background var(--ease);
}
.topbar-search button:hover { background: var(--color-primary); color: var(--color-on-primary); }

.lang-switch a { color: var(--color-text-muted); font-weight: 700; font-size: .82rem; }
.lang-switch a.active { color: var(--color-primary); }

/* Bascule clair / sombre — même gabarit que le bouton de repli du menu. */
.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; flex-shrink: 0;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 9px; font-size: 1rem; cursor: pointer; line-height: 1;
    transition: background var(--ease), border-color var(--ease), transform var(--ease);
}
.theme-toggle:hover { background: var(--color-surface-2); border-color: var(--color-primary); transform: translateY(-1px); }

.user-info { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.user-name { font-weight: 700; font-size: .86rem; }
.user-role { font-size: .72rem; }

.content { padding: 1.6rem; max-width: 1240px; width: 100%; margin: 0 auto; }
@media (min-width: 1400px){ .content { max-width: 1340px; } }

/* ---- Avatar (topbar profile) --------------------------------------- */
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: #fff; font-weight: 800; font-size: .9rem;
    display: grid; place-items: center; flex-shrink: 0;
}

/* ---- Notification bell --------------------------------------------- */
.notif { position: relative; z-index: 200; }
.notif-btn {
    width: 40px; height: 40px; border-radius: 10px;
    border: 1px solid var(--color-border); background: var(--color-surface);
    cursor: pointer; font-size: 1.1rem; position: relative;
    display: grid; place-items: center; transition: background var(--ease);
}
.notif-btn:hover { background: var(--color-primary-soft); }
.notif-count {
    position: absolute; top: -6px; right: -6px;
    min-width: 18px; height: 18px; padding: 0 5px;
    background: var(--color-danger); color: var(--color-on-danger);
    border-radius: 999px; font-size: .68rem; font-weight: 800;
    display: grid; place-items: center; border: 2px solid var(--color-surface);
}
.notif-panel {
    position: absolute; right: 0; top: calc(100% + 8px); width: 340px; max-width: 90vw;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    z-index: 200; overflow: hidden; display: none;
    max-height: 70vh; overflow-y: auto;
}
.notif-panel.open { display: block; animation: pop .14s var(--ease); }
.notif-panel h4 { margin: 0; padding: .85rem 1rem; border-bottom: 1px solid var(--color-border); font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-muted); }
.notif-item { display: flex; gap: .7rem; align-items: flex-start; padding: .75rem 1rem; border-bottom: 1px solid var(--color-border); text-decoration: none; color: var(--color-text); transition: background var(--ease); }
.notif-item:hover { background: var(--color-surface-2); text-decoration: none; }
.notif-item .ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; font-size: 1rem; }
.notif-item .tx { font-size: .86rem; line-height: 1.35; }
.notif-item .tx b { display: block; font-weight: 700; }
.notif-item .tx span { color: var(--color-text-muted); font-size: .8rem; }
.notif-empty { padding: 1.6rem 1rem; text-align: center; color: var(--color-text-muted); font-size: .88rem; }

@keyframes pop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Badges --------------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .22rem .6rem;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 700;
    background: var(--color-neutral-bg);
    color: var(--color-text-muted);
    line-height: 1.4;
}
.badge.role-admin        { background: var(--color-purple-bg); color: var(--color-purple-text); }
.badge.role-manager      { background: var(--color-blue-bg); color: var(--color-blue-text); }
.badge.role-receptionist { background: var(--color-success-bg); color: var(--color-success); }
.badge.role-accountant   { background: var(--color-info-bg); color: var(--color-info); }
.badge.role-technician   { background: var(--color-teal-bg); color: var(--color-primary); }
.badge.role-cleaner      { background: var(--color-warning-bg); color: var(--color-warning); }
.badge.type-expense  { background: var(--color-success-bg); color: var(--color-success); }
.badge.type-purchase { background: var(--color-warning-bg); color: var(--color-warning); }

/* Statuts — vert=ok/payé · orange=en cours/partiel · rouge=impayé/annulé · bleu=réservé */
.status-available, .status-paid, .status-resolved, .status-checked_out, .status-active {
    background: var(--color-success-bg); color: var(--color-success);
}
.status-occupied, .status-checked_in, .status-partial, .status-in_progress {
    background: var(--color-warning-bg); color: var(--color-warning);
}
.status-maintenance, .status-unpaid, .status-pending, .status-cancelled, .status-terminated {
    background: var(--color-danger-bg); color: var(--color-danger);
}
.status-reserved { background: var(--color-info-bg); color: var(--color-info); }

/* ---- KPI cards ------------------------------------------------------ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.kpi-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.15rem 1.25rem;
    box-shadow: var(--shadow);
    position: relative;
    transition: transform var(--ease), box-shadow var(--ease);
}
a.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); text-decoration: none; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: .55rem; }
.kpi-label { font-size: .78rem; color: var(--color-text-muted); font-weight: 600; margin-bottom: .45rem; }
.kpi-top .kpi-label { margin-bottom: 0; }
.kpi-ic {
    width: 34px; height: 34px; border-radius: 10px;
    display: grid; place-items: center; font-size: 1.05rem;
    background: var(--color-primary-soft); color: var(--color-primary);
}
.kpi-value { font-size: 1.65rem; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.kpi-value.positive { color: var(--color-success); }
.kpi-value.negative { color: var(--color-danger); }
.kpi-sub { font-size: .76rem; color: var(--color-text-muted); margin-top: .35rem; }

/* ---- Cards ---------------------------------------------------------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.35rem;
    margin-bottom: 1.5rem;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.1rem; flex-wrap: wrap; gap: .75rem;
}
.card-header h1, .card-header h2, .card-header h3 { margin: 0; }

/* ---- Tables --------------------------------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th, .data-table td {
    padding: .72rem .8rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    white-space: nowrap;
}
.data-table thead th {
    color: var(--color-text-muted);
    font-weight: 700;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: var(--color-surface-2);
    position: sticky; top: 0;
}
.data-table tbody tr { transition: background var(--ease); }
.data-table tbody tr:hover { background: var(--color-surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.row-alert { background: var(--color-danger-bg); }
.data-table tbody tr.row-alert:hover { background: var(--color-danger-hover); }
.data-table tbody tr.row-warn { background: var(--color-warning-bg); }
.data-table tbody tr.row-warn:hover { background: var(--color-warning-hover); }

/* Ligne secondaire sous la valeur principale d'une cellule (n° de pièce, date d'encaissement…) */
.cell-sub { font-size: .78rem; color: var(--color-text-muted); margin-top: .15rem; }

/* Encaissement direct depuis le tableau (caution) */
.inline-pay { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.inline-pay input { padding: .35rem .5rem; font-size: .82rem; width: 8.5rem; }
.inline-pay select { padding: .35rem .5rem; font-size: .82rem; width: auto; }

/* ---- Comptabilité ---------------------------------------------------- */
.section-title {
    margin: 2.2rem 0 1rem;
    padding-top: 1.4rem;
    border-top: 2px solid var(--color-border);
    font-size: 1.3rem; font-weight: 700; color: var(--color-text);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.muted-note { color: var(--color-text-muted); font-size: .82rem; margin: -.35rem 0 .8rem; }

/* Barre récapitulative (page Factures) : facturé / payé / reste dû sur une ligne. */
.summary-bar { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem; font-size: .95rem; margin: .2rem 0 .3rem; }
.summary-bar .sep { color: var(--color-text-muted); }
.summary-bar .pos, .pos { color: var(--color-success); }
.summary-bar .neg, .neg { color: var(--color-danger); }

/* Liens de forage depuis la carte Revenu vers les pages de détail. */
.kpi-drill { color: var(--color-text-muted); text-decoration: none; border-radius: 6px; padding: .15rem .3rem; margin: 0 -.3rem; transition: background .15s, color .15s; }
.kpi-drill:hover { background: var(--color-primary-bg, rgba(0,0,0,.05)); color: var(--color-primary); }

/* Sous-totaux et résultat du compte de résultat / bilan */
.data-table tr.row-total td { border-top: 1px solid var(--color-border); background: var(--color-surface-2); }
.data-table tr.row-result td {
    border-top: 2px solid var(--color-primary);
    background: var(--color-primary-bg, #ecfdf5);
    font-size: 1.02rem;
}
.data-table td.num, .data-table th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* La caisse totale : le chiffre que le patron regarde en premier */
.kpi-card.kpi-strong { border-color: var(--color-primary); box-shadow: 0 0 0 1px var(--color-primary) inset; }

/* ---- Pagination ------------------------------------------------------ */
.pagination-bar {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: .8rem; margin-top: 1rem;
}
.pagination-summary { color: var(--color-text-muted); font-size: .85rem; }
.pagination { display: flex; flex-wrap: wrap; gap: .3rem; }
.pagination .page-link {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 2.2rem; height: 2.2rem; padding: 0 .6rem;
    border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    background: var(--color-surface); color: var(--color-text);
    font-size: .9rem; font-weight: 600; text-decoration: none;
    transition: background var(--ease), border-color var(--ease);
}
.pagination .page-link:hover { background: var(--color-surface-2); border-color: var(--color-primary); }
.pagination .page-link.current {
    background: var(--color-primary); border-color: var(--color-primary); color: var(--color-on-primary); cursor: default;
}
.pagination .page-link.disabled { color: var(--color-text-muted); opacity: .5; pointer-events: none; }
.pagination .page-gap { display: inline-flex; align-items: center; padding: 0 .3rem; color: var(--color-text-muted); }
@media (max-width: 640px) {
    .pagination-bar { justify-content: center; }
    .pagination .page-link { min-width: 2.6rem; height: 2.6rem; } /* cibles tactiles plus grandes */
}

/* ---- Buttons -------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .58rem 1.05rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: .88rem; font-weight: 700; font-family: inherit;
    cursor: pointer; text-decoration: none;
    background: var(--color-neutral-bg); color: var(--color-text);
    transition: background var(--ease), box-shadow var(--ease), transform var(--ease), filter var(--ease);
    white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.98); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { box-shadow: var(--ring); }
.btn-primary { background: var(--color-primary); color: var(--color-on-primary); box-shadow: 0 3px 10px rgba(15,118,110,.25); }
.btn-primary:hover { background: var(--color-primary-dark); filter: none; }
.btn-danger { background: var(--color-danger); color: var(--color-on-danger); }
.btn-danger:hover { background: var(--color-danger-strong); filter: none; }
.btn-ghost { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-ghost:hover { background: var(--color-surface-2); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; border-radius: 7px; }
.btn-block { width: 100%; }
.btn:disabled, .btn.is-loading { opacity: .6; cursor: not-allowed; pointer-events: none; }
.btn.is-loading::after {
    content: ""; width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid currentColor; border-top-color: transparent;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-group { display: flex; gap: .45rem; flex-wrap: wrap; }

/* ---- Forms ---------------------------------------------------------- */
.form-group { margin-bottom: 1.05rem; }
.form-group label { display: block; font-weight: 700; font-size: .84rem; margin-bottom: .4rem; color: var(--color-text); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }

input, select, textarea {
    width: 100%;
    padding: .62rem .8rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: .9rem;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--ease), box-shadow var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--color-placeholder); }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: var(--ring);
}
input[readonly] { background: var(--color-surface-2); color: var(--color-text-muted); }
.field-error input, .field-error select, .field-error textarea { border-color: var(--color-danger); }
.field-msg { font-size: .78rem; color: var(--color-danger); margin-top: .3rem; }

/* ---- Alerts / toasts ----------------------------------------------- */
.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .9rem; font-weight: 600; border: 1px solid transparent; }
.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success-brd); }
.alert-danger  { background: var(--color-danger-bg);  color: var(--color-danger);  border-color: var(--color-danger-brd); }
.alert-info    { background: var(--color-info-bg);    color: var(--color-info);     border-color: var(--color-info-brd); }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning);  border-color: var(--color-warning-brd); }

.toast-wrap {
    position: fixed; top: 16px; right: 16px; z-index: 200;
    display: flex; flex-direction: column; gap: .6rem; max-width: 360px;
}
.toast {
    display: flex; align-items: flex-start; gap: .7rem;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-primary);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
    padding: .8rem .95rem; font-size: .9rem; font-weight: 600;
    animation: toastIn .25s var(--ease);
}
.toast.success { border-left-color: var(--color-success); }
.toast.danger  { border-left-color: var(--color-danger); }
.toast.info    { border-left-color: var(--color-info); }
.toast.warning { border-left-color: var(--color-warning); }
.toast .ic { font-size: 1.1rem; line-height: 1.2; }
.toast.hide { animation: toastOut .25s var(--ease) forwards; }
@keyframes toastIn  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* ---- Modal (confirmations) ----------------------------------------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(16,32,28,.5);
    display: none; align-items: center; justify-content: center; z-index: 300; padding: 1rem;
}
.modal-backdrop.open { display: flex; animation: fade .15s var(--ease); }
.modal {
    background: var(--color-surface); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); max-width: 420px; width: 100%;
    padding: 1.5rem; animation: pop .18s var(--ease);
}
.modal h3 { margin-bottom: .5rem; }
.modal p { color: var(--color-text-muted); margin-bottom: 1.3rem; line-height: 1.5; }
.modal .btn-group { justify-content: flex-end; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---- Empty state ---------------------------------------------------- */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--color-text-muted); }
.empty-state h1 { font-size: 3rem; color: var(--color-primary); }

/* ---- Filter bar ----------------------------------------------------- */
.filter-bar { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.filter-bar .form-group { margin-bottom: 0; min-width: 150px; }

/* ---- Calendar (réservations) --------------------------------------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .dow { text-align: center; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-muted); padding: .3rem 0; }
.cal .day {
    min-height: 74px; border: 1px solid var(--color-border); border-radius: 10px;
    padding: .4rem .45rem; background: var(--color-surface); position: relative; font-size: .8rem;
}
.cal .day.out { background: var(--color-surface-2); opacity: .5; }
.cal .day .num { font-weight: 700; font-size: .8rem; }
.cal .day.today { border-color: var(--color-accent); box-shadow: inset 0 0 0 1px var(--color-accent); }
.cal .day .occ { position: absolute; left: .45rem; right: .45rem; bottom: .4rem; height: 6px; border-radius: 4px; background: var(--color-neutral-bg); overflow: hidden; }
.cal .day .occ i { display: block; height: 100%; background: linear-gradient(90deg, var(--color-primary), var(--color-accent)); }
.cal .day .badge-occ { position: absolute; top: .35rem; right: .4rem; font-size: .66rem; font-weight: 800; color: var(--color-primary); }

/* Chaque jour est un lien vers le détail de la journée : on neutralise le style
   par défaut des liens et on ajoute un retour visuel au survol. */
a.cal .day, .cal a.day { display: block; text-decoration: none; color: inherit; transition: border-color var(--ease), transform var(--ease); }
.cal a.day:hover { text-decoration: none; border-color: var(--color-primary); transform: translateY(-1px); box-shadow: var(--shadow); }

/* Pastilles d'agenda : arrivées, départs, pannes, rappels. */
.cal .cal-dots { position: absolute; left: .4rem; bottom: 1.1rem; display: flex; gap: .18rem; flex-wrap: wrap; }
.cal .cal-dot { font-size: .62rem; line-height: 1; padding: .1rem .18rem; border-radius: 4px; font-weight: 800; }
.cal .cal-dot.in { background: var(--color-success-bg); color: var(--color-success); }
.cal .cal-dot.out { background: var(--color-info-bg); color: var(--color-info); }
.cal .cal-dot.mt { background: var(--color-warning-bg); color: var(--color-warning); }
.cal .cal-dot.rm { background: var(--color-purple-bg); color: var(--color-purple-text); }

.cal-legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; font-size: .82rem; color: var(--color-text-muted); }

/* ---- Login ---------------------------------------------------------- */
.login-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1000px 600px at 20% -10%, #0f766e 0%, #0b3d38 45%, #06211e 100%);
    padding: 1.5rem;
}
.login-lang { position: absolute; top: 1.5rem; right: 1.5rem; color: #fff; font-weight: 700; font-size: .85rem; }
.login-lang a { color: rgba(255,255,255,.7); }
.login-lang a.active { color: #fff; }
.login-card {
    background: var(--color-surface); border-radius: var(--radius-lg); padding: 2.6rem;
    width: 100%; max-width: 400px; box-shadow: var(--shadow-lg);
}
.login-title { font-size: 1.5rem; display: flex; align-items: center; gap: .6rem; }
.login-title::before { content: ""; width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--color-accent), var(--color-primary)); box-shadow: 0 6px 16px rgba(16,185,129,.35); }
.login-subtitle { color: var(--color-text-muted); margin-bottom: 1.6rem; }

/* ---- Invoice / print ------------------------------------------------ */
.invoice-doc { background: var(--color-doc-bg); padding: 2rem; max-width: 800px; margin: 0 auto; }
.invoice-doc-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 2rem; }

@media print {
    .sidebar, .topbar, .sidebar-toggle, .no-print, .toast-wrap, .sidebar-backdrop { display: none !important; }
    .main-area { width: 100%; }
    .content { padding: 0; max-width: none; }
    body { background: #fff; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ---- Responsive (téléphone) ---------------------------------------- */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(16,32,28,.45); z-index: 35; }

@media (max-width: 900px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0;
        width: min(280px, 82vw);
        transform: translateX(-100%);
        transition: transform .22s ease;
        z-index: 40; overflow-y: auto; -webkit-overflow-scrolling: touch;
    }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.35); }
    .sidebar.open ~ .sidebar-backdrop, body.nav-open .sidebar-backdrop { display: block; }
    .sidebar-nav a { padding: .9rem 1.4rem; font-size: 1rem; }
    .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
    .sidebar-collapse-btn { display: none; } /* sur mobile c'est le menu tiroir (hamburger) qui gère */

    .topbar { padding: .55rem .75rem .55rem 3.5rem; flex-wrap: wrap; row-gap: .5rem; }
    .topbar-title { display: none; }
    .topbar-search { order: 3; width: 100%; max-width: none; flex-basis: 100%; }
    .topbar-right { gap: .6rem; }
    .user-info { display: none; }

    .content { padding: .9rem; }
    .btn { min-height: 44px; }
    .btn-sm { min-height: 38px; }
    input, select, textarea { min-height: 44px; font-size: 16px; }

    .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
    .kpi-card { padding: .85rem .9rem; }
    .kpi-value { font-size: 1.25rem; }
    .card { padding: 1rem; margin-bottom: 1rem; }

    .form-row { grid-template-columns: 1fr; gap: .6rem; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .form-group { min-width: 0; }
    .filter-bar .btn { width: 100%; }
    form .btn-group { flex-direction: column; }
    form .btn-group .btn { width: 100%; }

    .card-header { flex-direction: column; align-items: stretch; }
    .card-header .btn-group { flex-direction: row; }
    .card-header .btn { flex: 1; }

    .table-wrap {
        overflow-x: auto; -webkit-overflow-scrolling: touch;
        background:
            linear-gradient(to right, var(--color-surface) 30%, transparent),
            linear-gradient(to left, var(--color-surface) 30%, transparent) 100% 0,
            radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.12), transparent),
            radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.12), transparent) 100% 0;
        background-repeat: no-repeat;
        background-size: 42px 100%, 42px 100%, 16px 100%, 16px 100%;
        background-attachment: local, local, scroll, scroll;
    }
    .data-table th, .data-table td { padding: .58rem .62rem; }
    .data-table .btn-group { flex-wrap: nowrap; }
    .notif-panel { position: fixed; top: 60px; right: 8px; left: 8px; width: auto; }
    .cal .day { min-height: 56px; }
}

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

/* ---- Bloc-notes (post-it) ------------------------------------------- */
/* Les couleurs sont définies deux fois : claires par défaut, assombries en
   mode sombre pour rester lisibles sans éblouir. */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.note {
    border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
    border: 1px solid var(--color-border); display: flex; flex-direction: column;
    min-height: 140px; transition: transform var(--ease), box-shadow var(--ease);
}
.note:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.note-head h3 { margin: 0 0 .5rem; font-size: 1rem; }
.note-body { flex: 1; font-size: .9rem; line-height: 1.5; white-space: normal; word-break: break-word; }
.note-foot {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    margin-top: .8rem; padding-top: .6rem; border-top: 1px solid rgba(0,0,0,.08);
    font-size: .74rem; color: var(--color-text-muted); flex-wrap: wrap;
}
.note-yellow { background: #fef9c3; }
.note-green  { background: #dcfce7; }
.note-blue   { background: #dbeafe; }
.note-pink   { background: #fce7f3; }
.note-grey   { background: #eef1ef; }
.note-yellow, .note-green, .note-blue, .note-pink, .note-grey { color: #1e2a27; }

:root[data-theme="dark"] .note-yellow { background: #3d3411; }
:root[data-theme="dark"] .note-green  { background: #14331f; }
:root[data-theme="dark"] .note-blue   { background: #16273f; }
:root[data-theme="dark"] .note-pink   { background: #3a1c2c; }
:root[data-theme="dark"] .note-grey   { background: #253330; }
:root[data-theme="dark"] .note-yellow,
:root[data-theme="dark"] .note-green,
:root[data-theme="dark"] .note-blue,
:root[data-theme="dark"] .note-pink,
:root[data-theme="dark"] .note-grey { color: var(--color-text); }
:root[data-theme="dark"] .note-foot { border-top-color: rgba(255,255,255,.12); }

/* Sélecteur de couleur du formulaire */
.note-color-pick {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .4rem .7rem; border-radius: var(--radius-sm);
    border: 1px solid var(--color-border); cursor: pointer; font-size: .85rem;
}
