/* =========================================================================
   LaboStock — feuille de style
   ========================================================================= */

/* ---------- Design tokens ---------- */
:root {
    /* Palette claire */
    --bg:            #f4f6fb;
    --bg-soft:       #eef1f7;
    --card:          #ffffff;
    --card-alt:      #fafbfd;
    --text:          #0f172a;
    --text-soft:     #334155;
    --muted:         #64748b;
    --line:          #e2e8f0;
    --line-strong:   #cbd5e1;

    --accent:        #2563eb;
    --accent-soft:   #dbeafe;
    --accent-dark:   #1d4ed8;

    --ok:            #047857;
    --ok-soft:       #d1fae5;
    --warn:          #b45309;
    --warn-soft:     #fef3c7;
    --danger:        #b91c1c;
    --danger-soft:   #fee2e2;
    --info:          #0e7490;
    --info-soft:     #cffafe;

    /* Espacements */
    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 24px;
    --s-6: 32px;
    --s-7: 48px;

    /* Rayons */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 22px;
    --r-pill: 999px;

    /* Ombres */
    --shadow-1: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
    --shadow-2: 0 4px 12px rgba(15, 23, 42, .06), 0 2px 4px rgba(15, 23, 42, .04);
    --shadow-3: 0 12px 28px rgba(15, 23, 42, .08), 0 4px 12px rgba(15, 23, 42, .06);

    /* Transitions */
    --t-fast: .12s ease;
    --t-base: .2s ease;
}

/* ---------- Mode sombre automatique ---------- */
@media (prefers-color-scheme: dark) {
    :root {
        --bg:            #0b1220;
        --bg-soft:       #111a2e;
        --card:          #131c2f;
        --card-alt:      #18223a;
        --text:          #e2e8f0;
        --text-soft:     #cbd5e1;
        --muted:         #94a3b8;
        --line:          #1f2a44;
        --line-strong:   #2d3a5b;

        --accent:        #60a5fa;
        --accent-soft:   #1e3a8a40;
        --accent-dark:   #93c5fd;

        --ok:            #34d399;
        --ok-soft:       #064e3b66;
        --warn:          #fbbf24;
        --warn-soft:     #78350f66;
        --danger:        #f87171;
        --danger-soft:   #7f1d1d66;
        --info:          #67e8f9;
        --info-soft:     #155e7566;

        --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-2: 0 4px 12px rgba(0, 0, 0, .35);
        --shadow-3: 0 12px 28px rgba(0, 0, 0, .45);
    }
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
                 Arial, "Noto Sans", "Liberation Sans", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 var(--s-3); color: var(--text); letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.2rem; font-weight: 750; }
h3 { font-size: 1.05rem; font-weight: 700; }
p  { margin: 0 0 var(--s-3); }
small { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-5) 0; }

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--t-fast);
}
a:hover { color: var(--accent-dark); text-decoration: underline; }

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
    border-radius: 6px;
}

::selection { background: var(--accent-soft); color: var(--text); }

/* Accessibilité : visible only for screen readers */
.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0);
    white-space: nowrap; border: 0;
}

/* ---------- Skip link (accessibilité) ---------- */
.skip-link {
    position: absolute;
    top: -40px; left: 8px;
    background: var(--accent);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    z-index: 100;
    transition: top var(--t-base);
}
.skip-link:focus { top: 8px; color: #fff; text-decoration: none; }

/* ---------- Topbar / Navigation ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-1);
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: var(--s-4);
    padding: 10px var(--s-5);
    flex-wrap: wrap;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    font-weight: 800;
    font-size: 1.05rem;
    color: var(--text);
    white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--text); }
.brand .logo {
    display: inline-grid;
    place-items: center;
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    color: #fff;
    border-radius: 10px;
    font-size: 1rem;
}

.topbar nav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: wrap;
}
.topbar nav a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-soft);
    padding: 8px 12px;
    border-radius: 10px;
    font-size: .95rem;
    font-weight: 600;
    transition: background var(--t-fast), color var(--t-fast);
}
.topbar nav a:hover {
    background: var(--bg-soft);
    color: var(--text);
    text-decoration: none;
}
.topbar nav a.active {
    background: var(--accent-soft);
    color: var(--accent-dark);
}
.topbar nav svg { width: 16px; height: 16px; }

.topbar-spacer { flex: 1; }

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: 6px 10px 6px 6px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    font-size: .9rem;
    color: var(--text-soft);
}
.user-chip .avatar {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: #fff;
    display: inline-grid;
    place-items: center;
    font-size: .8rem;
    font-weight: 700;
}
.user-chip .role {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    margin-left: 4px;
}

.menu-btn {
    display: none;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 10px;
    color: var(--text);
    cursor: pointer;
}

/* ---------- Container / Layout ---------- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--s-5);
}

.footer {
    text-align: center;
    color: var(--muted);
    padding: var(--s-6) var(--s-5);
    font-size: .9rem;
}

/* ---------- Cards & grids ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: var(--s-5);
    box-shadow: var(--shadow-1);
}
.card + .card,
section + section { margin-top: var(--s-4); }

.grid { display: grid; gap: var(--s-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.row.tight { gap: var(--s-2); }
.space-between { justify-content: space-between; }
.muted { color: var(--muted); }
.text-soft { color: var(--text-soft); }

/* ---------- Hero ---------- */
.hero {
    position: relative;
    background: linear-gradient(135deg, #1e3a8a, #2563eb 50%, #6366f1);
    color: #fff;
    border: 0;
    overflow: hidden;
}
.hero::after {
    content: "";
    position: absolute; right: -40px; top: -40px;
    width: 220px; height: 220px;
    background: radial-gradient(circle, rgba(255,255,255,.18), transparent 60%);
    pointer-events: none;
}
.hero h1 { color: #fff; font-size: 1.8rem; font-weight: 800; }
.hero p { color: #dbeafe; max-width: 60ch; }
.hero .searchbar input {
    background: #ffffffea; color: var(--text);
}

/* ---------- Stats ---------- */
.stat {
    display: flex;
    align-items: center;
    gap: var(--s-4);
    transition: transform var(--t-base), box-shadow var(--t-base);
}
a.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); text-decoration: none; }
.stat .stat-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    display: grid; place-items: center;
    background: var(--accent-soft);
    color: var(--accent-dark);
    flex-shrink: 0;
}
.stat .stat-icon svg { width: 22px; height: 22px; }
.stat .stat-icon.warn  { background: var(--warn-soft);   color: var(--warn); }
.stat .stat-icon.danger{ background: var(--danger-soft); color: var(--danger); }
.stat .stat-icon.ok    { background: var(--ok-soft);     color: var(--ok); }
.stat .stat-body { display: flex; flex-direction: column; }
.stat .stat-body strong { font-size: 1.7rem; font-weight: 800; line-height: 1.1; color: var(--text); }
.stat .stat-body span   { color: var(--muted); font-size: .9rem; }

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    padding: 10px 16px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    min-height: 42px;
    transition: background var(--t-fast), border-color var(--t-fast),
                box-shadow var(--t-fast), transform var(--t-fast);
    text-decoration: none;
}
.btn:hover { background: var(--accent-dark); color: #fff; text-decoration: none; box-shadow: var(--shadow-1); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] {
    opacity: .55; cursor: not-allowed; transform: none; box-shadow: none;
}
.btn.secondary {
    background: var(--bg-soft);
    color: var(--text);
    border-color: var(--line);
}
.btn.secondary:hover { background: var(--line); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #991b1b; }
.btn.ghost {
    background: transparent;
    color: var(--text-soft);
    border-color: var(--line);
}
.btn.ghost:hover { background: var(--bg-soft); }
.btn.small { padding: 6px 10px; min-height: 32px; font-size: .9rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn svg { width: 16px; height: 16px; }

/* ---------- Searchbar ---------- */
.searchbar {
    display: flex;
    gap: var(--s-2);
    align-items: stretch;
}
.searchbar input,
.searchbar select {
    flex: 1;
    font-size: 1rem;
    min-height: 44px;
}
.searchbar .btn { white-space: nowrap; }

/* ---------- Formulaires ---------- */
label {
    display: block;
    font-weight: 600;
    font-size: .9rem;
    margin-bottom: 4px;
    color: var(--text-soft);
}
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--card);
    color: var(--text);
    font: inherit;
    transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
input:hover, select:hover, textarea:hover { border-color: var(--accent); }
input:focus, select:focus, textarea:focus {
    outline: 0;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 110px; resize: vertical; }
input[type="file"] { padding: 6px; cursor: pointer; }
input::placeholder, textarea::placeholder { color: var(--muted); }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s-4);
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid p { margin: 0; }

fieldset {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: var(--s-4);
}
legend { padding: 0 8px; font-weight: 700; color: var(--text-soft); }

/* ---------- Tableaux ---------- */
.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--card);
}
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
}
th, td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}
th {
    background: var(--bg-soft);
    font-size: .8rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 700;
    position: sticky; top: 0;
}
tbody tr:nth-child(even) td { background: var(--card-alt); }
tbody tr:hover td { background: var(--accent-soft); }
tr:last-child td { border-bottom: 0; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--r-pill);
    font-size: .78rem;
    font-weight: 700;
    line-height: 1.4;
    border: 1px solid transparent;
}
.badge::before {
    content: "";
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: currentColor;
}
.badge.ok      { background: var(--ok-soft);     color: var(--ok); }
.badge.warn    { background: var(--warn-soft);   color: var(--warn); }
.badge.danger  { background: var(--danger-soft); color: var(--danger); }
.badge.neutral { background: var(--bg-soft);     color: var(--text-soft); border-color: var(--line); }
.badge.info    { background: var(--info-soft);   color: var(--info); }

/* ---------- Alertes / flashes ---------- */
.alert {
    position: relative;
    padding: 12px 40px 12px 14px;
    border-radius: var(--r-md);
    margin-bottom: var(--s-3);
    border: 1px solid transparent;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: fadeIn .25s ease;
}
.alert::before {
    content: "";
    width: 4px;
    align-self: stretch;
    border-radius: 4px;
    background: currentColor;
    opacity: .8;
}
.alert .alert-close {
    position: absolute;
    top: 6px; right: 8px;
    background: transparent; border: 0; color: inherit;
    font-size: 1.1rem; cursor: pointer; opacity: .6;
}
.alert .alert-close:hover { opacity: 1; }
.alert-success { background: var(--ok-soft);     color: var(--ok); }
.alert-error   { background: var(--danger-soft); color: var(--danger); }
.alert-info    { background: var(--accent-soft); color: var(--accent-dark); }
.alert-warn    { background: var(--warn-soft);   color: var(--warn); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- Login ---------- */
.login {
    max-width: 460px;
    margin: 8vh auto;
    padding: var(--s-6);
}
.login h1 {
    display: flex; align-items: center; gap: var(--s-2);
    font-size: 1.4rem;
}

/* ---------- Item / cartes spécifiques ---------- */
.item-card { display: grid; gap: 8px; }
.item-title { font-weight: 800; font-size: 1.1rem; color: var(--text); }
.photo {
    max-width: 220px;
    max-height: 160px;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    object-fit: cover;
}

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv > dt { color: var(--muted); font-weight: 600; }
.kv > dd { margin: 0; }

/* Quick actions list (page d'accueil) */
.quick-actions { display: grid; gap: var(--s-2); grid-template-columns: 1fr 1fr; }
.quick-actions .btn { justify-content: flex-start; min-height: 48px; }

/* ---------- Affichages mobiles vs desktop ---------- */
.mobile-cards { display: none; }
.desktop-table { display: block; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
    .container { padding: var(--s-4); }
    h1 { font-size: 1.35rem; }
    .hero h1 { font-size: 1.45rem; }
    .grid-2, .grid-3, .grid-4, .form-grid, .quick-actions { grid-template-columns: 1fr; }
    .desktop-table { display: none; }
    .mobile-cards { display: grid; }
    .searchbar { flex-direction: column; }
    .searchbar .btn { width: 100%; }

    .menu-btn { display: inline-flex; }
    .topbar nav {
        order: 99;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        padding: var(--s-2) 0;
        border-top: 1px solid var(--line);
        margin-top: var(--s-2);
        display: none;
    }
    body.nav-open .topbar nav { display: flex; }
    .topbar nav a { padding: 12px var(--s-3); }

    .user-chip .role { display: none; }
    .kv { grid-template-columns: 1fr; }
    .kv > dt { margin-top: var(--s-2); }
}

/* Touch : agrandir les cibles */
@media (pointer: coarse) {
    .btn { min-height: 46px; }
    .topbar nav a { padding: 10px 14px; }
}

/* Print : version imprimable propre */
@media print {
    .topbar, .footer, .menu-btn, .btn, .alert { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}

/* LABOSTOCK_BULK_CSS : tri d'en-t\u00eate + s\u00e9lection en masse */
.sort-link {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font: inherit;
}
.sort-link:hover { color: var(--accent); text-decoration: none; }
.sort-link .sort-arrow { font-size: .9em; opacity: .8; }

/* Colonne case \u00e0 cocher */
.check-col { width: 36px; text-align: center; }
.row-check, #select-all {
    width: 18px; height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* Barre d'action en masse */
.bulk-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: var(--r-md);
    margin-top: 12px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-1);
}
.bulk-bar strong { color: var(--accent-dark); }

/* Panneau d'\u00e9dition en masse */
.bulk-panel {
    border-color: var(--accent);
    border-left-width: 4px;
}
.bulk-panel h3 { color: var(--accent-dark); margin-top: 0; }
.bulk-panel .check-row {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 6px; font-weight: 700;
}
.bulk-panel .check-row input[type="checkbox"] { width: 16px; height: 16px; }

/* Actions sur ligne (compactes) */
.row-actions { white-space: nowrap; }
.row-actions .btn { margin-right: 4px; }
.row-actions .btn:last-child { margin-right: 0; }

/* Surligner la ligne quand coch\u00e9e */
tbody tr:has(.row-check:checked) td { background: var(--accent-soft) !important; }

@media (max-width: 820px) {
    .bulk-bar { flex-direction: column; align-items: stretch; }
    .bulk-bar .btn { width: 100%; }
    .row-actions { display: flex; flex-direction: column; gap: 4px; }
    .row-actions .btn { width: 100%; margin: 0; }
}

/* LABOSTOCK_DANGER_ZONE */
.danger-zone {
    border-color: var(--danger);
    border-left-width: 4px;
    background: linear-gradient(to right, var(--danger-soft) 0%, var(--card) 30%);
}

/* LABOSTOCK_RESERVATIONS_CSS */
/* Tableau "matériel" du formulaire de réservation */
.matos-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.matos-table th, .matos-table td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.matos-table th { background: var(--bg-soft); font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.matos-table input { min-height: 36px; }
.matos-table tr.matos-warn td { background: var(--danger-soft); }
.matos-table .matos-flag { color: var(--danger); font-weight: 700; font-size: .85rem; }
.matos-table .matos-ok   { color: var(--ok); font-size: .85rem; }

/* Calendrier mensuel */
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-top: 12px;
}
.cal-head {
    text-align: center;
    font-weight: 700;
    color: var(--muted);
    font-size: .85rem;
    text-transform: uppercase;
    padding: 6px 0;
}
.cal-day {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 110px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
}
.cal-empty { background: transparent; border-color: transparent; }
.cal-today { border: 2px solid var(--accent); background: var(--accent-soft); }
.cal-num { font-weight: 700; color: var(--text-soft); font-size: .9rem; }
.cal-event {
    font-size: .8rem;
    padding: 2px 6px;
    border-radius: 6px;
    text-decoration: none;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}
.cal-event:hover { text-decoration: none; opacity: .85; }
.cal-event.badge::before { display: none; }

@media (max-width: 720px) {
    .cal-grid { grid-template-columns: repeat(7, 1fr); gap: 2px; }
    .cal-day { min-height: 70px; padding: 3px; font-size: .85rem; }
    .cal-event { font-size: .7rem; padding: 1px 4px; }
}

/* Item view : ligne stock insuffisant */
tbody tr.matos-warn td { background: var(--danger-soft) !important; }

/* LABOSTOCK_NAV_BADGE : pastille compteur sur les liens de la nav */
.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--danger);
    color: #fff;
    border-radius: 999px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: .75rem;
    font-weight: 700;
    margin-left: 4px;
    line-height: 1;
}

/* LABOSTOCK_BELL_CSS : cloche notifications dans la nav */
.bell-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border-radius: 10px;
    color: var(--text-soft);
    background: var(--bg-soft);
    border: 1px solid var(--line);
}
.bell-link:hover { background: var(--accent-soft); color: var(--accent-dark); text-decoration: none; }
.bell-link .nav-badge {
    position: absolute;
    top: -6px; right: -6px;
    margin: 0;
}
.notif-item.unread strong { color: var(--accent-dark); }

/* LABOSTOCK_BLOCK_CTA : appel à action large dans le hero */
.btn.block-cta {
    display: inline-flex;
    background: #ffffff;
    color: var(--accent-dark);
    border: 2px solid #ffffff;
    font-size: 1.05rem;
    font-weight: 700;
    padding: 14px 22px;
    border-radius: 14px;
    box-shadow: 0 6px 16px rgba(0,0,0,.18);
    transition: transform .15s ease, box-shadow .2s ease;
}
.btn.block-cta:hover {
    background: #ffffff;
    color: var(--accent-dark);
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(0,0,0,.22);
}
@media (max-width: 600px) {
    .btn.block-cta { width: 100%; justify-content: center; }
}
