/* StockControl — feuille de style unique, thème clair/sombre automatique. */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #14202e;
  --muted: #62748b;
  --border: #dde5ee;
  --brand: #1f6feb;
  --brand-ink: #ffffff;
  --ok: #17864b;
  --ok-bg: #e4f6ec;
  --warn: #a86400;
  --warn-bg: #fdf1dc;
  --danger: #c0273a;
  --danger-bg: #fdeaec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 32, 55, .06), 0 8px 24px rgba(16, 32, 55, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141b;
    --surface: #161d26;
    --surface-2: #1d262f;
    --text: #e6edf5;
    --muted: #90a1b5;
    --border: #28323e;
    --brand: #4c94ff;
    --brand-ink: #06121f;
    --ok: #4ade80;
    --ok-bg: #12301f;
    --warn: #fbbf5b;
    --warn-bg: #33260e;
    --danger: #ff7a8a;
    --danger-bg: #351319;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6rem; }
h1 { font-size: 1.6rem; letter-spacing: -.02em; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.strong { font-weight: 600; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: .5rem 1rem; z-index: 10; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 1rem; }

/* ---------------------------------------------------------------- Barre */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar .wrap { display: flex; align-items: center; gap: 1rem; min-height: 58px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: .15rem; flex: 1; flex-wrap: wrap; }
.nav-links a {
  padding: .45rem .7rem; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.nav-links a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-links a.active { background: var(--brand); color: var(--brand-ink); }
.user-chip { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.user-name { font-weight: 600; }

main { padding-top: 1.2rem; padding-bottom: 3rem; }
footer { padding: 1.2rem 1rem 2rem; }

/* --------------------------------------------------------------- Entête */
.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.page-head p { margin: 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- Cartes */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem; box-shadow: var(--shadow); margin-bottom: 1.1rem;
}
.grid { display: grid; gap: 1.1rem; }
.grid.two { grid-template-columns: 1fr 1fr; align-items: start; }
@media (max-width: 900px) { .grid.two { grid-template-columns: 1fr; } }

/* ----------------------------------------------------------------- KPIs */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: .8rem; margin-bottom: 1.1rem;
}
.kpis.compact { margin-bottom: .8rem; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; display: flex; flex-direction: column; gap: .15rem;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.kpi-hint { font-size: .78rem; color: var(--muted); }
.kpi.danger { border-color: var(--danger); }
.kpi.danger .kpi-value { color: var(--danger); }
.kpi.warn { border-color: var(--warn); }
.kpi.warn .kpi-value { color: var(--warn); }

/* --------------------------------------------------------------- Tables */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td {
  text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table thead th {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 600; white-space: nowrap;
}
.table tbody tr:hover { background: var(--surface-2); }
.table tfoot td { font-weight: 600; padding-top: .7rem; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.urgent td { background: var(--danger-bg); }
.table tr.inactive { opacity: .55; }
.sub { display: block; font-size: .76rem; color: var(--muted); }
.inline-tag { display: inline; background: var(--surface-2); padding: 0 .3rem; border-radius: 4px; }
/* Jamais de display:flex sur un <td> : la cellule sortirait du flux du tableau
   et sa bordure basse se décalerait par rapport aux autres colonnes. */
.actions { white-space: nowrap; }
.actions > * { vertical-align: middle; }
.actions > * + * { margin-left: .3rem; }
.spark-cell { width: 130px; color: var(--brand); }
.empty { color: var(--muted); text-align: center; padding: 1.6rem 0; }

@media (max-width: 720px) {
  .hide-s { display: none; }
  .table { font-size: .85rem; }
}

/* ------------------------------------------------------------- Éléments */
.badge {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.faible { background: var(--warn-bg); color: var(--warn); }
.badge.rupture { background: var(--danger-bg); color: var(--danger); }
.badge.archive { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.role {
  display: inline-block; padding: .1rem .45rem; border-radius: 6px; font-size: .72rem;
  font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.role-admin { color: var(--brand); border-color: var(--brand); }
.role-gestionnaire { color: var(--ok); border-color: var(--ok); }
.roles-help { margin: .9rem 0 0; padding-left: 1.1rem; }
.roles-help li { margin-bottom: .25rem; }

.trend { font-size: .78rem; font-weight: 600; }
.trend.up { color: var(--ok); }
.trend.down { color: var(--danger); }
.trend.flat { color: var(--muted); }

.gauge {
  display: inline-block; width: 54px; height: 6px; background: var(--surface-2);
  border-radius: 3px; overflow: hidden; vertical-align: middle; margin-right: .4rem;
}
.gauge span { display: block; height: 100%; background: var(--ok); }
.gauge.warn span { background: var(--warn); }
.gauge.danger span { background: var(--danger); }

.alert {
  display: flex; gap: .6rem; align-items: flex-start; padding: .7rem .9rem;
  border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid;
  background: var(--ok-bg); border-color: var(--ok); color: var(--ok);
}
.alert p { margin: 0; color: var(--text); }
.alert.error { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.alert.info { background: var(--surface-2); border-color: var(--border); color: var(--muted); }

.conseil {
  background: var(--surface-2); border-radius: 8px; padding: .6rem .8rem; font-size: .88rem;
}

/* ------------------------------------------------------------ Formulaires */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); }
label.wide { margin-bottom: .8rem; }
input, select, textarea {
  width: 100%; margin-top: .25rem; padding: .5rem .6rem; font: inherit;
  color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
.stack { display: flex; flex-direction: column; gap: .7rem; }
.stack + .stack { margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--border); }
.row { display: flex; gap: .7rem; flex-wrap: wrap; }
.row > label { flex: 1 1 180px; }
.row.end { justify-content: flex-end; align-items: center; }
.inline { display: inline-block; vertical-align: middle; }
.actions-card h3 { margin-top: 0; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .5rem .85rem; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--brand); text-decoration: none; }
button.primary, .button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.ghost, .button.ghost { background: transparent; }
button.small { padding: .3rem .55rem; font-size: .8rem; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.link {
  background: none; border: none; color: var(--brand); padding: 0; font-weight: 500;
  text-decoration: underline;
}

.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; color: var(--text); }
.check input { width: auto; margin: 0; }

.danger-zone { border-color: var(--danger); }
.danger-zone h2 { color: var(--danger); }

.filters {
  display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem;
}
.filters input, .filters select { width: auto; min-width: 150px; margin: 0; }
.filters input[type=search] { flex: 1 1 240px; }

.quick { display: inline-flex; gap: .25rem; align-items: center; vertical-align: middle; }
.quick input { width: 74px; margin: 0; padding: .3rem .4rem; }
.quick button { padding: .3rem .55rem; font-size: .8rem; }
.reset { display: inline-flex; gap: .25rem; vertical-align: middle; }
.reset input { min-width: 150px; margin: 0; padding: .3rem .5rem; font-size: .8rem; }

.switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.switch a { padding: .4rem .7rem; font-size: .85rem; color: var(--muted); }
.switch a:hover { background: var(--surface-2); text-decoration: none; }
.switch a.on { background: var(--brand); color: var(--brand-ink); }

.details { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem 1rem; margin: 0; }
.details div { min-width: 0; }
.details dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.details dd { margin: .1rem 0 0; font-weight: 500; }
.details .big { font-size: 1.3rem; }
@media (max-width: 560px) { .details { grid-template-columns: 1fr; } }

.stocktake input { max-width: 140px; margin: 0; }

/* --------------------------------------------------------- Graphiques */
.chart { position: relative; display: flex; align-items: flex-end; padding-top: 1.2rem; }
.chart-max { position: absolute; top: 0; left: 0; font-size: .74rem; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 2px; width: 100%; height: 100%; }
.bar-slot { display: flex; align-items: flex-end; justify-content: center; height: 100%; }
.bar {
  position: relative; width: 78%; min-height: 2px; border-radius: 3px 3px 0 0;
  background: var(--brand); opacity: .85;
}
.bar.is-zero { background: var(--border); height: 2px !important; }
.bar:hover { opacity: 1; }
.bar-tip {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); font-size: .74rem; padding: .2rem .45rem;
  border-radius: 5px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .1s;
  z-index: 2;
}
.bar:hover .bar-tip { opacity: 1; }
.chart-axis { display: flex; justify-content: space-between; font-size: .74rem; color: var(--muted); margin-top: .3rem; }

.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.hbars li { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr auto; gap: .6rem; align-items: center; font-size: .88rem; }
.hbar-track { background: var(--surface-2); border-radius: 4px; height: 10px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.hbar-value { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .82rem; }

.spark { display: block; }
.spark-empty { color: var(--muted); }
.spark-wrap { margin: .5rem 0; }

/* -------------------------------------------------------- Pages nues */
body.centered {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem;
}
.auth-card { width: 100%; max-width: 380px; margin: 0; }
.brand-big { text-align: center; font-size: 1.35rem; margin-bottom: 1.2rem; }
.auth-card button[type=submit] { width: 100%; margin-top: .3rem; }
