/* HACCP Boucherie — tokens et structure (app tactile) */
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../fonts/plex-var.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ground: #f9fafb;
  --surface: #ffffff;
  --raised: #f9f9f9;
  --active: #eeeeee;
  --border: #e8e8e8;
  --rule: #f2f2f2;
  --control: #d1d5db;
  --text: #111111;
  --muted: #5f6368;
  --faint: #6b6b6b;
  --primary: #1d1f20;
  --negative: #c4242a;
  --pill-negative-bg: #ffedea;
  --pill-negative-ink: #831c1e;
  --positive: #247b50;
  --pill-positive-bg: #dcfae5;
  --pill-positive-ink: #04250e;
  --pill-warning-bg: #fffbeb;
  --pill-warning-ink: #92400e;
  --pill-warning-border: #fde68a;
  --radius-card: 8px;
  --radius-control: 6px;
  --gap: 16px;
  --pad: 24px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --fs-title: 24px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--ground);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 16px; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }

/* ---- coque ---- */
#app { display: flex; min-height: 100vh; }

#sidebar {
  width: 232px; flex: none;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  background: var(--ground);
}
.brand { display: flex; gap: 10px; align-items: center; padding: 20px 16px 14px; }
.brand-mark {
  width: 34px; height: 34px; flex: none; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-name { display: block; font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand-scope { display: block; font-size: 12px; color: var(--muted); }

#mainnav { padding: 4px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  height: 46px; padding: 0 12px; border-radius: 8px; font-size: 14px;
}
.nav-item svg { width: 18px; height: 18px; color: #454545; flex: none; }
.nav-item.active { background: var(--active); }
.nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--negative); color: #fff;
  font-size: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center;
}
#nav-user {
  margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--rule);
  font-size: 13px;
}
#nav-user-name { display: block; font-weight: 600; }
#nav-user-role { display: block; color: var(--muted); font-size: 12px; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  min-height: 60px; display: flex; align-items: center; gap: 12px;
  padding: 8px var(--pad);
}
#page-title { font-size: var(--fs-title); font-weight: 700; letter-spacing: -0.01em; }
#menu-btn {
  width: 44px; height: 44px; flex: none; border-radius: var(--radius-control);
  border: 1px solid var(--control); background: var(--surface);
  display: none; align-items: center; justify-content: center;
}
#menu-btn svg { width: 20px; height: 20px; }
#top-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
#top-date { font-size: 13px; color: var(--muted); }
#user-btn {
  height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--control); background: var(--surface);
  font-size: 14px; font-weight: 500;
}
#screen { padding: 4px var(--pad) 48px; flex: 1; min-width: 0; }

/* ---- blocs ---- */
.finding { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.finding strong { color: var(--text); font-weight: 600; }

.section-h { display: flex; align-items: baseline; gap: 10px; margin: 28px 0 10px; }
.section-h h2 { font-size: 16px; font-weight: 600; }
.section-h .count { color: var(--muted); font-size: 13px; }
.section-h .link {
  margin-left: auto; font-size: 13px; font-weight: 500; color: var(--text);
  background: none; border: none; padding: 4px 0;
}

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 4px 16px;
}
.card.pad { padding: 16px; }

.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 54px; border-bottom: 1px solid var(--rule); padding: 6px 0;
}
.row:last-child { border-bottom: none; }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 500; }
.row-title.done { color: var(--muted); text-decoration: line-through; }
.row-sub { color: var(--muted); font-size: 13px; }
.row-time { color: var(--muted); font-size: 13px; white-space: nowrap; }

.empty {
  border: 1px dashed var(--control); border-radius: 8px;
  padding: 18px 16px; color: var(--muted); font-size: 14px;
}
.empty a, .empty button.link { color: var(--text); font-weight: 500; }

/* ---- contrôles ---- */
.btn {
  height: 44px; padding: 0 18px; border-radius: var(--radius-control);
  border: 1px solid var(--control); background: var(--surface);
  font-size: 14px; font-weight: 500;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ghost { border-color: transparent; color: var(--text); padding: 0 10px; }
.btn.danger { color: var(--negative); border-color: var(--control); }
.btn.full { width: 100%; }
.btn.sm { height: 36px; padding: 0 14px; font-size: 13px; }
.btn:disabled { color: #cecece; background: #f4f4f4; border-color: #e8e8e8; }

.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; height: 46px; padding: 0 12px;
  border: 1px solid var(--control); border-radius: var(--radius-control);
  background: var(--surface); color: var(--text);
}
textarea.input { height: auto; min-height: 60px; padding: 10px 12px; resize: vertical; }
.frow { display: flex; gap: 12px; flex-wrap: wrap; }
.frow > .field { flex: 1; min-width: 140px; }
.form-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px; border-radius: 11px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.pill.ok { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pill.bad { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); border: 1px solid var(--pill-warning-border); }
.pill.mono { background: var(--raised); color: var(--muted); border: 1px solid var(--border); }

/* ---- accueil ---- */
.alerts { border-left: none; }
.alert-row .row-title.bad { color: var(--negative); }

/* ---- températures ---- */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--gap);
}
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 14px 16px;
}
.tile-name { font-weight: 600; font-size: 15px; }
.tile-seuil { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile-value {
  font-size: 30px; font-weight: 400; margin: 10px 0 8px;
  font-variant-numeric: tabular-nums;
}
.tile-value.bad { color: var(--negative); }
.tile-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile-foot .when { color: var(--muted); font-size: 12px; }

.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.numpad button {
  height: 60px; font-size: 22px; border-radius: var(--radius-control);
  border: 1px solid var(--control); background: var(--surface);
}
.numpad button:active { background: var(--active); }
.num-display {
  height: 56px; border: 1px solid var(--control); border-radius: var(--radius-control);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-variant-numeric: tabular-nums; background: var(--raised);
}

/* ---- réception : produits dynamiques ---- */
.prod-line { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.prod-line .input { flex: 1; min-width: 110px; }
.photo-prev { max-width: 180px; max-height: 140px; border-radius: 8px; border: 1px solid var(--border); }

/* ---- étiquettes ---- */
.label-line .pill { margin-left: 8px; }

/* ---- registre ---- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--control); background: var(--surface);
  font-size: 13px; font-weight: 500;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---- réglages ---- */
.settings-section { display: grid; grid-template-columns: minmax(220px, 420px) 1fr; gap: 24px; margin: 28px 0; }
.settings-copy h2 { font-size: 16px; font-weight: 600; }
.settings-copy p { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---- feuille modale ---- */
#sheet-root { position: fixed; inset: 0; z-index: 40; }
#sheet-root[hidden] { display: none; }
.overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); }
.sheet {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px));
  max-height: min(86vh, 760px); overflow: auto;
  background: var(--surface); border-radius: 12px; padding: 20px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
}
.sheet h2 { font-size: 18px; font-weight: 600; margin-bottom: 14px; }
.sheet-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---- nav mobile ---- */
#bottomnav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
#bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; height: 56px; font-size: 11px; color: var(--muted); position: relative;
}
#bottomnav a svg { width: 20px; height: 20px; }
#bottomnav a.active { color: var(--text); }
#bottomnav .nav-badge { position: absolute; top: 5px; right: calc(50% - 20px); }

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--primary); color: #fff; border-radius: 8px;
  padding: 11px 18px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; z-index: 60; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--negative); }

/* ---- impression étiquettes ---- */
#print-root { display: none; }
@media print {
  #app, #bottomnav, #toast, #sheet-root { display: none !important; }
  #print-root { display: block; }
  body { background: #fff; }
  .print-sheet { display: flex; flex-wrap: wrap; }
  .print-label {
    width: 70mm; height: 37mm; padding: 4mm 5mm;
    border: 1px dashed #999; overflow: hidden;
    display: flex; flex-direction: column; gap: 1mm;
  }
  .print-label .pl-name { font-weight: 700; font-size: 12pt; }
  .print-label .pl-meta { font-size: 7.5pt; color: #333; }
  .print-label .pl-dlc { font-weight: 700; font-size: 12pt; margin-top: auto; }
}

/* ---- responsive ---- */
@media (max-width: 899px) {
  :root { --pad: 16px; }
  #sidebar { display: none; }
  #menu-btn { display: flex; }
  #bottomnav { display: flex; }
  #screen { padding-bottom: 110px; }
  #page-title { font-size: 20px; }
  #top-date { display: none; }
  .settings-section { grid-template-columns: 1fr; gap: 10px; }
  .sheet { left: 16px; right: 16px; top: auto; bottom: 0; transform: none; width: auto; border-radius: 12px 12px 0 0; max-height: 88vh; }
  #toast { bottom: 72px; }
}
@media (min-width: 900px) {
  .numpad button { height: 56px; }
}
