/* StockIO — feuille de style unique, sans dépendance externe. */

:root {
    --bg: #f4f5f2;
    --surface: #ffffff;
    --ink: #1d2320;
    --ink-soft: #5a635e;
    --line: #dde1dc;
    --line-strong: #c3c9c3;
    --field-border: #7d867f; /* 3,76:1 sur blanc (WCAG 1.4.11) */
    --accent: #1f6f5c;
    --accent-ink: #ffffff;
    --accent-soft: #e3f0ec;
    --danger: #b3261e;
    --danger-soft: #fbe9e7;
    --warn: #8a5a00;
    --warn-soft: #fdf3dc;
    --success: #1e7a3c;
    --success-soft: #e5f4ea;
    --info-soft: #e8eef7;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(20, 30, 25, .06);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    color-scheme: light;
}

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

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

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid #2b8a73; outline-offset: 2px; border-radius: 3px; }

h1 { font-size: 1.55rem; line-height: 1.25; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.08rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
code { font-family: var(--mono); font-size: .9em; background: #eef0ec; padding: .05em .3em; border-radius: 4px; word-break: break-all; }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: .5rem 1rem; z-index: 10; }
.skip-link:focus { left: .5rem; top: .5rem; }

.visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- En-tête ---------- */

.topbar { background: #16201c; color: #e8ece9; position: sticky; top: 0; z-index: 5; }
.topbar-inner {
    max-width: 1200px; margin: 0 auto; padding: .6rem 1rem;
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; font-weight: 700; }
.brand-mark {
    display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 6px;
    background: var(--accent); color: #fff; font-weight: 800;
}
.brand-center { justify-content: center; display: flex; margin: 2rem 0 1rem; font-size: 1.2rem; }
.scan-form { flex: 1 1 260px; display: flex; gap: .4rem; }
.scan-form input {
    flex: 1; min-width: 0; padding: .5rem .7rem; border-radius: 6px; border: 1px solid #39463f;
    background: #233029; color: #fff; font-size: 1rem;
}
.scan-form input::placeholder { color: #9fb0a7; }
.user-menu { position: relative; font-size: .9rem; }
.user-name {
    list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem;
    min-height: 2.4rem; padding: 0 .7rem; border-radius: 6px; color: #e8ece9; border: 1px solid #39463f;
}
.user-name::-webkit-details-marker { display: none; }
.user-name::after { content: ""; width: .45rem; height: .45rem; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); }
.user-menu[open] > .user-name::after { transform: translateY(1px) rotate(-135deg); }
.user-name:hover, .user-menu[open] > .user-name { background: #233029; }
.user-name-text { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-panel {
    position: absolute; right: 0; top: calc(100% + .35rem); z-index: 20; min-width: 12.5rem;
    background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--radius);
    box-shadow: 0 6px 18px rgba(20, 30, 25, .18); padding: .3rem; display: flex; flex-direction: column;
}
.menu-panel form { margin: 0; }
.menu-panel a, .menu-panel button {
    display: flex; align-items: center; width: 100%; min-height: 2.75rem; padding: 0 .75rem; border: 0; border-radius: 6px;
    background: none; color: var(--ink); font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.menu-panel a:hover, .menu-panel button:hover { background: #f1f3f0; }
.menu-panel a[aria-current="page"] { font-weight: 700; background: var(--accent-soft); }
.menu-panel form { border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .3rem; }

.mainnav { border-top: 1px solid #26332d; }
.mainnav ul {
    list-style: none; margin: 0 auto; padding: 0 .5rem; max-width: 1200px;
    display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: thin;
}
.mainnav a {
    display: block; padding: .6rem .75rem; color: #c8d3cd; text-decoration: none; white-space: nowrap;
    border-bottom: 3px solid transparent; font-size: .93rem;
}
.mainnav a:hover { color: #fff; }
.mainnav a[aria-current="page"] { color: #fff; border-bottom-color: #4fb79c; font-weight: 600; }

/* ---------- Mise en page ---------- */

.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem; }
.container.narrow { max-width: 560px; }
.footer { color: var(--ink-soft); font-size: .8rem; padding-top: 0; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.breadcrumb { margin: 0 0 .2rem; font-size: .88rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 0; }

.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow: hidden; }
.card .pad, .card.flush > .pad { padding: 1rem; margin: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.card-warn { border-color: #e6c66f; }
.danger-zone { border-style: dashed; }
.empty { text-align: center; padding: 2rem 1rem; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 1rem; }

/* ---------- Indicateurs ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: .9rem 1rem; display: flex; flex-direction: column; gap: .15rem; box-shadow: var(--shadow);
}
.stat-label { color: var(--ink-soft); font-size: .85rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .82rem; color: var(--ink-soft); }
/* État porté par la surface entière (fond teinté + bordure de 1 px), jamais par un filet latéral. */
.stat-alert { background: var(--danger-soft); border-color: var(--danger); order: -1; }
.stat-alert .stat-value { color: var(--danger); font-size: 2.1rem; line-height: 1.1; }
.stat-alert .stat-sub { color: var(--ink); }
.stat-warn { background: var(--warn-soft); border-color: var(--warn); }
.stat-ok { background: var(--success-soft); border-color: var(--success); }
.stat-ok .stat-value { color: var(--success); }
.stat-ok .stat-sub { color: var(--ink); }
.stat-verdict { font-size: .95rem; }
.stat-link, .row-link { display: inline-flex; align-items: center; min-height: 1.75rem; }
/* Cartes de listes : hauteur propre à chaque carte, la garantie occupe toute la largeur sur grand écran. */
.dash-lists { align-items: start; }
.dash-warranty { grid-column: 1 / -1; }
#stock-bas, #lots-prix-inconnu { scroll-margin-top: 1rem; }

/* ---------- Tableaux ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th, .table td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { font-size: .8rem; font-weight: 600; color: var(--ink-soft); background: #f8f9f7; white-space: nowrap; }
.table thead th a { color: inherit; text-decoration: none; }
.table thead th a:hover { color: var(--accent); }
.table tbody tr:hover { background: #fafbf9; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.archived td { color: var(--ink-soft); background: #f7f7f5; }
.table tr.muted td { color: var(--ink-soft); }
.row-actions { white-space: nowrap; }
.row-actions > * { margin-right: .6rem; }
.nowrap { white-space: nowrap; }

.tree .depth-1 { padding-left: 1.8rem; }
.tree .depth-2 { padding-left: 3rem; }
.tree .depth-3 { padding-left: 4.2rem; }
.tree .depth-4 { padding-left: 5.4rem; }
.tree .depth-5, .tree .depth-6 { padding-left: 6.6rem; }
.tree [class^="depth-"]:not(.depth-0)::before { content: "└ "; color: var(--line-strong); }

.location-totals { list-style: none; margin: 0; padding: 0; }
.location-totals li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.location-totals li:last-child { border-bottom: 0; }

/* ---------- Formulaires ---------- */

.form .field, .filters .field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; min-width: 0; }
label, .label { font-weight: 600; font-size: .9rem; }
.req { color: var(--danger); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"],
input[type="date"], input[type="tel"], input[type="url"], input:not([type]), select, textarea {
    width: 100%; padding: .55rem .65rem; font: inherit; font-size: 1rem; color: var(--ink);
    background: #fff; border: 1px solid var(--field-border); border-radius: 6px; min-height: 2.6rem;
}
textarea { resize: vertical; min-height: 4rem; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); background: #fffafa; }
.scan-form input { min-height: 2.4rem; }
.hint { font-size: .82rem; color: var(--ink-soft); margin: 0; }
.field-error { color: var(--danger); font-size: .85rem; margin: 0; font-weight: 600; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; margin: 0 0 .9rem; }
legend { font-weight: 700; padding: 0 .3rem; }
.radio-row { display: flex; gap: 1.25rem; margin-bottom: .6rem; flex-wrap: wrap; }
.radio-row label, .checkbox { font-weight: 500; display: inline-flex; gap: .4rem; align-items: center; }
.mono { font-family: var(--mono); }
input[type="checkbox"], input[type="radio"] { width: 1.15rem; height: 1.15rem; flex: none; accent-color: var(--accent); }
.checkbox { padding: .35rem 0; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0 1rem; }
.field-wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }
.form-inline { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.form-inline .field { flex: 1 1 220px; margin-bottom: 0; }
.form-inline.compact { align-items: center; display: inline-flex; flex-wrap: nowrap; }
.form-inline.compact input { min-height: 2.1rem; padding: .3rem .5rem; max-width: 16rem; }
form.inline { display: inline; margin: 0; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 .8rem; align-items: end; }
.filters .field-wide { grid-column: 1 / -1; }
.filter-actions { display: flex; gap: .5rem; margin-bottom: .9rem; }

.qty-input { max-width: 7rem; text-align: right; margin-left: auto; }
.inventory-table td { vertical-align: middle; }

/* ---------- Boutons ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    padding: .5rem .9rem; min-height: 2.5rem; border-radius: 6px; border: 1px solid var(--line-strong);
    background: #fff; color: var(--ink); font: inherit; font-weight: 600; font-size: .92rem;
    text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f1f3f0; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #185b4b; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #8f1e18; }
.btn-small { min-height: 2.1rem; padding: .3rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Messages et badges ---------- */

.alert { padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); border-color: #b9dfc6; color: #134d27; }
.alert-error { background: var(--danger-soft); border-color: #f0c2bd; color: #7d1a14; }
.alert-warning { background: var(--warn-soft); border-color: #f0d79a; color: #6a4500; }
.alert-info { background: var(--info-soft); border-color: #c9d6ea; color: #1f3a63; }

.badge {
    display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .45rem; border-radius: 999px;
    background: #eceee9; color: #4b544f; vertical-align: middle; white-space: nowrap;
}
.badge-in { background: var(--success-soft); color: var(--success); }
.badge-out { background: var(--danger-soft); color: var(--danger); }
.badge-transfer { background: var(--info-soft); color: #234b84; }
.badge-adjust { background: var(--warn-soft); color: var(--warn); }
.badge-ok { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-error { background: var(--danger-soft); color: var(--danger); }
.badge-cond-new { background: var(--success-soft); color: var(--success); }
.badge-cond-to_repair { background: var(--warn-soft); color: var(--warn); }
.badge-cond-out_of_service { background: var(--danger-soft); color: var(--danger); }

.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }
.text-success { color: var(--success); }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.big { font-size: 1.35rem; }
.pre { white-space: pre-line; }

.details { display: grid; grid-template-columns: minmax(130px, 34%) 1fr; gap: .45rem 1rem; margin: 0; }
.details dt { color: var(--ink-soft); font-size: .88rem; }
.details dd { margin: 0; overflow-wrap: anywhere; }
.details.compact { gap: .3rem 1rem; }

.pagination { display: flex; gap: 1rem; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin: .5rem 0 1rem; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--ink-soft); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.price-calc [data-price-output] { font-weight: 600; color: var(--ink); }

.error-page { text-align: center; padding: 2.5rem 1rem; }

/* ---------- Petits écrans ---------- */

@media (max-width: 720px) {
    body { font-size: 15px; }
    h1 { font-size: 1.3rem; }
    .container { padding: 1rem .7rem; }
    .topbar-inner { gap: .5rem; }
    .scan-form { order: 3; flex-basis: 100%; }
    .user-menu { margin-left: auto; }
    .user-name-text { max-width: 7rem; }
    .hide-sm { display: none; }
    .stats { grid-template-columns: repeat(2, 1fr); gap: .5rem; }
    .stat { padding: .75rem; }
    .btn { min-height: 2.75rem; }
    /* Alerte : une ligne compacte (chiffre à gauche, consigne et lien à droite) pour laisser voir les lignes à traiter. */
    .stat-alert, .stat-ok {
        grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 1rem;
        grid-template-areas: "label label" "value sub";
    }
    .stat-alert .stat-label, .stat-ok .stat-label { grid-area: label; }
    .stat-alert .stat-value, .stat-ok .stat-value { grid-area: value; }
    .stat-alert .stat-sub, .stat-ok .stat-sub { grid-area: sub; }
    .stat-link, .row-link { min-height: 2.75rem; }

    /* Tableaux empilés : une ligne = une fiche de deux ou trois lignes, aucune colonne rognée. */
    .table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .table-stack tbody tr {
        display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .75rem; align-items: center;
        grid-template-areas: "item qty" "meta act" "extra extra"; padding: .35rem 0; border-bottom: 1px solid var(--line);
    }
    .table-stack tbody tr:last-child { border-bottom: 0; }
    .table-stack { table-layout: fixed; }
    /* Plus de défilement latéral ; la zone tactile agrandie dépasse la ligne sans créer de barre de défilement. */
    .table-wrap:has(> .table-stack) { overflow: visible; }
    .table.table-stack td.nowrap { white-space: normal; }
    .table.table-stack td { display: block; border: 0; padding: .05rem 0; min-width: 0; }
    .table-stack .a-item { grid-area: item; font-weight: 600; }
    .table-stack .a-qty { grid-area: qty; text-align: right; }
    .table-stack .a-meta { grid-area: meta; font-size: .85rem; color: var(--ink-soft); }
    .table-stack .a-act { grid-area: act; text-align: right; }
    .table-stack .a-extra { grid-area: extra; font-size: .85rem; color: var(--ink-soft); }
    .table-stack td[data-label]::before { content: attr(data-label) " "; color: var(--ink-soft); font-weight: 400; }
    .table-stack td.num { text-align: right; }
    .table-stack td.hide-sm { display: none; }
    .table-stack tbody tr.hide-sm { display: none; }
    /* Cible de 44 px sans gonfler la fiche : le padding agrandit la zone tactile, la marge négative rend l'espace. */
    .table-stack .row-link { min-height: 0; padding: .75rem 0; margin: -.75rem 0; }
    .dash-lists { grid-template-columns: 1fr; }
    .dash-warranty { order: 2; }
    .dash-lots { order: 3; }
    .brand { min-height: 2.75rem; }
    .card-head { align-items: center; }
    .table th, .table td { padding: .5rem .5rem; }
    .details { grid-template-columns: 1fr; gap: .1rem; }
    .details dd { margin-bottom: .45rem; }
    .page-head .actions { width: 100%; }
    .page-head .actions .btn { flex: 1 1 auto; }
    .row-actions { white-space: normal; }
    .row-actions > * { display: inline-block; margin: .1rem .5rem .1rem 0; }
    .card { padding: .85rem; }
    /* En-tête de trois rangées : trop haut pour rester collé sur un petit écran. */
    .topbar { position: static; }
    .link-button { display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0 .5rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; }
}

@media print {
    .topbar, .footer, .actions, .filters, .danger-zone, .row-actions { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; border: 0; }
}

/* Phase 2 : numéros de série, import */
.badge-info { background: var(--info-soft); color: #234b84; }
.serial-picker { border: 1px solid var(--line-strong); border-radius: 8px; padding: .75rem 1rem; margin: 0; }
.serial-picker legend { font-weight: 600; font-size: .9rem; padding: 0 .25rem; }
.serial-list { list-style: none; margin: .25rem 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .25rem .75rem; max-height: 18rem; overflow-y: auto; }
.import-row-error td { background: var(--danger-soft); }
.error-summary { margin-bottom: 1rem; }
.error-summary:focus { outline: 3px solid #2b8a73; outline-offset: 2px; }
.error-summary ul { margin: .35rem 0 0; padding-left: 1.1rem; }
.import-messages { margin: 0; padding-left: 1.1rem; }
.columns-table td:first-child { white-space: nowrap; }

/* Journal des versions */
.changes { margin: 0; padding-left: 1.2rem; }
.changes li { margin-bottom: .25rem; }
