/* HADOTECH GESTION v1.4.1 — CSS auto-suffisant sans modif des vues */

*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px; line-height: 1.5;
    color: #1e293b; background: #f1f5f9;
    -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; }
h1, h2, h3 { margin: 0 0 .75rem 0; font-weight: 600; color: #0f172a; }
h1 { font-size: 1.5rem; }
a { color: #2E4EB8; text-decoration: none; }
a:hover { color: #1E3A8A; }
code { font-family: monospace; background: #f1f5f9; padding: .1em .35em; border-radius: 4px; color: #b91c1c; font-size: .88em; }
small { font-size: .82em; color: #64748b; }
.text-muted { color: #64748b; }
.right { text-align: right; }
.center { text-align: center; }

/* ===== LAYOUT ===== */
.app { min-height: 100vh; }
.sidebar {
    position: fixed; top: 0; left: 0;
    width: 260px; height: 100vh;
    background: linear-gradient(180deg, #0153A7 0%, #014488 55%, #013569 100%); color: #e6f0fb;
    overflow-y: auto; z-index: 100;
    display: flex; flex-direction: column;
    box-shadow: 2px 0 12px rgba(1,53,105,.25);
}
.brand { padding: 1rem 1.25rem; background: #fff; border-bottom: 3px solid #DC2027; }
.brand-logo { max-height: 48px; margin: 0 auto; display: block; }
.menu { flex: 1; padding: .5rem 0 1rem 0; }
.menu-sep {
    padding: .75rem 1.25rem .35rem 1.25rem;
    font-size: .68rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .08em;
    color: #9cc6f2;
}
.menu-item {
    display: block; padding: .55rem 1.25rem;
    color: #eaf3fd; font-size: .88rem; font-weight: 500;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all .15s ease;
}
.menu-item:hover { background: rgba(255,255,255,.12); color: #fff; border-left-color: #fff; }
.menu-item.active, .menu-item[data-active="1"] {
    background: #fff; color: #0153A7;
    border-left-color: #DC2027; font-weight: 700;
}
.sidebar-footer { padding: 1rem; text-align: center; color: #9cc6f2; font-size: .72rem; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.3); border-radius: 3px; }
/* « Caisse tactile » : bouton rouge du logo, lisible sur le fond bleu */
/* ===== Menu hiérarchique (modules déroulants) ===== */
.menu-top { font-weight: 600; }
.menu-group { margin: 1px 0; }
.menu-group-btn {
    width: 100%; display: flex; align-items: center; gap: .6rem;
    padding: .62rem 1rem .62rem 1.25rem; background: none; border: 0; border-left: 3px solid transparent;
    color: #fff; font: inherit; font-size: .9rem; font-weight: 600; text-align: left; cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
}
.menu-group-btn:hover { background: rgba(255,255,255,.1); }
.menu-group-btn:focus-visible, .menu-item:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.mg-icon { width: 1.3rem; text-align: center; flex: 0 0 auto; }
.mg-label { flex: 1; }
.mg-chevron { flex: 0 0 auto; opacity: .85; transition: transform .2s ease; }
.menu-group.open > .menu-group-btn .mg-chevron { transform: rotate(90deg); }
.menu-group.open > .menu-group-btn { background: rgba(0,0,0,.14); }
.menu-group.has-active > .menu-group-btn { border-left-color: #DC2027; color: #fff; }
.menu-group.has-active > .menu-group-btn .mg-label::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: .45rem; border-radius: 50%; background: #DC2027; vertical-align: middle; }
/* Ouverture / fermeture animée (hauteur automatique, sans JavaScript de mesure) */
.menu-sub { display: grid; grid-template-rows: 0fr; visibility: hidden; transition: grid-template-rows .2s ease, visibility 0s linear .2s; }
.menu-group.open > .menu-sub { grid-template-rows: 1fr; visibility: visible; transition: grid-template-rows .2s ease, visibility 0s; }
.menu-sub-inner { overflow: hidden; background: rgba(0,0,0,.14); }
.menu-subitem { padding: .45rem 1rem .45rem 2.9rem; font-size: .85rem; position: relative; }
.menu-subitem::before { content: ""; position: absolute; left: 1.95rem; top: 50%; width: 5px; height: 5px; margin-top: -2.5px; border-radius: 50%; background: rgba(255,255,255,.45); }
.menu-subitem.active::before { background: #DC2027; }
.menu.no-anim .menu-sub, .menu.no-anim .mg-chevron { transition: none !important; }
@media (prefers-reduced-motion: reduce) { .menu-sub, .mg-chevron { transition: none !important; } }
@media (hover: none) { .menu-group-btn, .menu-item { padding-top: .7rem; padding-bottom: .7rem; } } /* cibles tactiles */
.sidebar a.menu-item[href="/pos"] { color: #fff !important; background: #DC2027; margin: .2rem .9rem; border-radius: 8px; border-left: 0; text-align: center; font-weight: 700; box-shadow: 0 3px 8px rgba(0,0,0,.18); }
.sidebar a.menu-item[href="/pos"]:hover { background: #b9151c; }
.sidebar a.menu-item[href="/pos"].active, .sidebar a.menu-item[href="/pos"][data-active="1"] { background: #fff; color: #DC2027 !important; }

.topbar {
    position: fixed; top: 0; left: 260px; right: 0; height: 58px;
    background: #fff; border-bottom: 1px solid #e2e8f0;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.5rem; z-index: 90;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: .75rem; }
.chip {
    display: inline-flex; align-items: center;
    padding: .3rem .75rem; background: #eef2ff; color: #1E3A8A;
    border-radius: 999px; font-size: .82rem; font-weight: 600;
    border: 1px solid #e0e7ff;
}
.chip-super { background: #fef2f2; color: #B01820; border-color: #fecaca; }
.chip-branch { background: #dcfce7; color: #14532d; border-color: #bbf7d0; }
.user { font-weight: 600; color: #334155; font-size: .9rem; }

.main {
    margin-left: 260px;
    padding: calc(58px + 1.5rem) 1.5rem 2rem 1.5rem;
    min-height: 100vh;
}
.main-guest { margin-left: 0; padding: 0; }

/* ===== FORMULAIRES ENVELOPPÉS AUTOMATIQUEMENT ===== */
/* Cible toutes les pages Nouvelle X / Modifier X (formulaires principaux) */
.main > form {
    background: #fff;
    border-radius: 10px;
    padding: 1.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    border: 1px solid #e2e8f0;
    margin-bottom: 1.25rem;
}

/* Le .card existant / nouveau */
.card {
    background: #fff;
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    border: 1px solid #e2e8f0;
    margin-bottom: 1.25rem;
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 1rem; flex-wrap: wrap;
    margin-bottom: 1.5rem; padding-bottom: 1.25rem;
    border-bottom: 1px solid #e2e8f0;
}
.page-header h1 { margin: 0 0 .35rem 0; font-size: 1.6rem; font-weight: 700; color: #0f172a; }
.page-subtitle { color: #64748b; font-size: .92rem; margin: 0; }

/* ===== BOUTONS ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: .4rem; padding: .6rem 1.15rem;
    border-radius: 8px; font-weight: 600; font-size: .88rem;
    text-decoration: none; border: 1px solid transparent;
    cursor: pointer; transition: all .15s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 6px rgba(0,0,0,.08); }
.btn-primary { background: #2E4EB8; color: #fff; border-color: #2E4EB8; }
.btn-primary:hover { background: #1E3A8A; color: #fff; }
.btn-secondary { background: #fff; color: #334155; border-color: #cbd5e1; }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: #DC2027; color: #fff; border-color: #DC2027; }
.btn-danger:hover { background: #B01820; color: #fff; }
.btn-success { background: #10b981; color: #fff; border-color: #10b981; }
.btn-outline { background: transparent; color: #475569; border-color: #cbd5e1; }
.btn-sm { padding: .35rem .7rem; font-size: .78rem; border-radius: 6px; }

/* ===== FORMULAIRES ===== */
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="datetime-local"],
input[type="tel"], input[type="url"], input[type="search"],
select, textarea, .form-input {
    width: 100%;
    padding: .55rem .75rem;
    font-size: .92rem;
    font-family: inherit;
    color: #0f172a;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
    appearance: none;
}
input:focus, select:focus, textarea:focus, .form-input:focus {
    outline: none;
    border-color: #2E4EB8;
    box-shadow: 0 0 0 3px rgba(46, 78, 184, .15);
}
select {
    padding-right: 2.25rem; cursor: pointer;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12'><path d='M3 5l3 3 3-3' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
    background-repeat: no-repeat; background-position: right .75rem center;
    background-size: 12px;
}
textarea { min-height: 80px; resize: vertical; }

label {
    display: block; font-size: .85rem; font-weight: 600;
    color: #334155; margin-bottom: .35rem;
}

/* Formulaire disposé en grille (labels + inputs pas côte à côte) */
.form-group { margin-bottom: 1.15rem; }

/* --- Auto-layout pour les vieux formulaires sans .form-group --- */
/* Force chaque paire label+input sur sa propre ligne */
form label + input, form label + select, form label + textarea {
    display: block; margin-top: .35rem;
}

/* Grilles */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.15rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.15rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.15rem; }

input[type="checkbox"], input[type="radio"] {
    width: 1.05rem; height: 1.05rem; accent-color: #2E4EB8; cursor: pointer;
}

.form-actions {
    display: flex; gap: .75rem; padding-top: 1.25rem;
    border-top: 1px solid #e2e8f0; margin-top: 1.5rem;
}

/* ===== TABLEAUX ===== */
.table {
    width: 100%; border-collapse: separate; border-spacing: 0;
    background: #fff;
}
.table thead th {
    background: #f8fafc; color: #475569;
    font-size: .74rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .05em;
    padding: .7rem .85rem; text-align: left;
    border-bottom: 1px solid #e2e8f0;
}
.table tbody td {
    padding: .7rem .85rem;
    border-bottom: 1px solid #e2e8f0;
    color: #334155; font-size: .88rem;
}
.table tbody tr:hover td { background: #f8fafc; }
.table .right { text-align: right; }
.table .center { text-align: center; }

/* ===== BADGES ===== */
.badge {
    display: inline-flex; align-items: center;
    padding: .18rem .55rem; border-radius: 999px;
    font-size: .72rem; font-weight: 600;
    background: #e2e8f0; color: #475569;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }
.badge-info    { background: #dbeafe; color: #1e40af; }

/* ===== ALERTES ===== */
.alert {
    padding: .85rem 1.15rem; border-radius: 8px;
    margin-bottom: 1.25rem; border-left: 4px solid transparent;
    font-size: .9rem;
}
.alert ul { margin: 0; padding-left: 1.2em; }
.alert-success { background: #dcfce7; border-color: #10b981; color: #14532d; }
.alert-error   { background: #fee2e2; border-color: #DC2027; color: #7f1d1d; }
.alert-info    { background: #dbeafe; border-color: #0ea5e9; color: #1e3a8a; }
.alert-warning { background: #fef3c7; border-color: #f59e0b; color: #78350f; }

/* ===== STAT CARDS ===== */
.stat-label { font-size: .78rem; color: #64748b; text-transform: uppercase; font-weight: 600; }

/* ===== FILTRES ===== */
.filter-bar {
    display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
    padding: 1rem 1.25rem; background: #fff; border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 1.25rem;
    border: 1px solid #e2e8f0;
}
.filter-bar input, .filter-bar select { min-width: 140px; }

/* ===== LOGIN ===== */
.auth-wrap {
    min-height: 100vh;
    background: linear-gradient(135deg, #1E3A8A 0%, #2E4EB8 100%);
    display: flex; align-items: center; justify-content: center;
    padding: 2rem 1rem;
}
.auth-wrap .auth-card {
    background: #fff; border-radius: 14px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,.35);
    padding: 2.5rem 2rem; max-width: 420px; width: 100%;
    border-top: 4px solid #DC2027;
}
.auth-brand { text-align: center; margin-bottom: 1.75rem; }
.auth-logo { max-height: 60px; margin: 0 auto; }
.auth-sub { color: #1E3A8A; font-size: .9rem; letter-spacing: .12em; font-weight: 600; margin-top: .75rem; text-transform: uppercase; }
.auth-form .field { display: block; margin-bottom: 1rem; }
.auth-form .field > span { display: block; font-size: .85rem; font-weight: 600; color: #334155; margin-bottom: .35rem; }
.auth-form .field-row { display: flex; justify-content: space-between; align-items: center; margin: 1rem 0 1.5rem 0; font-size: .85rem; }
.auth-form .check { display: flex; align-items: center; gap: .4rem; }
.auth-form .link { color: #2E4EB8; font-weight: 500; }
.auth-form .btn-primary { width: 100%; padding: .7rem; }

/* ===== MOBILE ===== */
.sidebar-toggle {
    display: none;
    position: fixed; top: 10px; left: 10px; z-index: 1001;
    background: #2E4EB8; color: #fff; border: 0; border-radius: 8px;
    width: 40px; height: 40px; font-size: 1.35rem; cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,.08);
}
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 999; }
.sidebar-backdrop.show { display: block; }

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
    .sidebar { left: -100%; width: 280px; transition: left .3s ease; z-index: 1000; } /* au-dessus du voile (999) : menu cliquable sur téléphone */
    .sidebar.open { left: 0; }
    .topbar { left: 0; padding: 0 .75rem 0 60px; flex-wrap: nowrap; gap: .5rem; }
    /* Barre du haut sur téléphone : rien ne dépasse de l'écran */
    .topbar-left { min-width: 0; flex: 1 1 auto; }
    .topbar-left .chip { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topbar .chip-branch, .topbar .user { display: none; }
    .topbar-right { gap: .4rem; flex: 0 0 auto; }
    .topbar-right .notif-bell { margin-right: 0 !important; }
    .topbar-right .btn { padding: .4rem .65rem; font-size: .8rem; }
    .main { min-width: 0; overflow-x: hidden; }
    .main { margin-left: 0; padding: calc(58px + 1rem) 1rem 1.5rem 1rem; }
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    input, select, textarea { font-size: 16px !important; }
    .table { min-width: 500px; font-size: .82rem; }
    .card, .main > form { overflow-x: auto; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { justify-content: center; }
}

@media print {
    .sidebar, .topbar, .sidebar-toggle, .btn, form:not(.print-visible) { display: none !important; }
    .main { margin-left: 0 !important; padding: 0 !important; }
    body { background: #fff !important; }
}