/* Marché de Noël — styles (mobile d'abord) */
:root {
  /* Charte inspirée du logo de l'École Saint-Bernard : bleu marine #124380 sur blanc */
  --bg: #F5F8FC;
  --surface: #FFFFFF;
  --surface-2: #EBF0F7;
  --line: #D9E2EE;
  --text: #0F1F38;
  --muted: #5B6B82;
  --primary: #124380;
  --primary-dark: #0C3263;
  --primary-ink: #FFFFFF;
  --primary-soft: #E6EEF8;
  --ink: #0B2447; /* bleu nuit : barre de total, éléments actifs */
  --fromage: #D9A21B;
  --charcuterie: #B23A3A;
  --epicerie: #2E7D5B;
  --danger: #B42318;
  --ok: #2F7A3F;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(18, 67, 128, .06), 0 4px 14px rgba(18, 67, 128, .07);
  --tabbar-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- Barre supérieure / navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px; background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  box-shadow: inset 0 -2px 0 var(--fromage);
}
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--text); font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand img { display: block; }
.user-chip { margin-left: auto; font-size: .85rem; color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); white-space: nowrap; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 7px; text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: 10px; font-weight: 550; font-size: .95rem; }
.nav a svg { width: 20px; height: 20px; flex: none; }
.nav a.active { color: var(--primary); background: var(--primary-soft); }
.nav a:hover { color: var(--text); }

@media (max-width: 760px) {
  /* backdrop-filter créerait un bloc conteneur : la barre d'onglets fixe resterait collée à l'en-tête */
  .topbar { backdrop-filter: none; background: var(--bg); }
  .brand span { font-size: .98rem; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; justify-content: space-around; gap: 0;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -2px 12px rgba(18, 67, 128, .07);
  }
  .nav a { flex: 1; flex-direction: column; gap: 2px; padding: 4px 2px; font-size: .7rem; border-radius: 10px; }
  .nav a svg { width: 22px; height: 22px; }
  .nav a.active { background: transparent; }
  body.has-tabbar .app { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px); }
}

/* ---------- Mise en page ---------- */
.app { max-width: 1180px; margin: 0 auto; padding: 16px 14px 32px; outline: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.card h2 { margin-bottom: 12px; }
.stack > * + * { margin-top: 12px; }
.grid-2 { display: grid; gap: 12px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600;
  text-decoration: none; color: var(--text); -webkit-tap-highlight-color: transparent; transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #F0C7C2; background: #FFF6F5; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-lg { min-height: 54px; font-size: 1.08rem; }
label.field { display: block; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  font-size: 16px; /* évite le zoom automatique sur iOS */
}
.input:focus, .btn:focus-visible, .chip:focus-visible, .product:focus-visible, .nav a:focus-visible { outline: 3px solid rgba(18, 67, 128, .28); outline-offset: 1px; border-color: var(--primary); }
.form-grid { display: grid; gap: 12px; }
@media (min-width: 640px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } }
.error-msg { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin: 6px 0 0; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); font-size: .9rem; min-height: 36px; }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

/* ---------- Connexion ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; }
.login .logo { display: block; margin: 0 auto 10px; }
.login h1 { text-align: center; font-size: 1.5rem; }
.login p.sub { text-align: center; margin: 4px 0 22px; color: var(--muted); }
.login .org { text-align: center; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--primary); font-weight: 650; margin: 0 0 4px; }
.login { border-top: 4px solid var(--primary); }

/* ---------- Saisie de vente ---------- */
.sale-layout { display: grid; gap: 14px; }
@media (min-width: 900px) { .sale-layout { grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); align-items: start; } .sale-layout .cart-col { position: sticky; top: 76px; } }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 99px; font-weight: 600; cursor: pointer; min-height: 40px; }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.product {
  text-align: left; border: 1px solid var(--line); border-left: 5px solid var(--cat, var(--line)); background: var(--surface);
  border-radius: 12px; padding: 12px; cursor: pointer; min-height: 76px; display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  box-shadow: var(--shadow); -webkit-tap-highlight-color: transparent;
}
.product:active { transform: scale(.98); }
.product .name { font-weight: 650; line-height: 1.2; }
.product .price { color: var(--muted); font-size: .88rem; }
.empty { text-align: center; color: var(--muted); padding: 26px 12px; }

.cart-lines { list-style: none; padding: 0; margin: 0; }
.cart-lines li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); cursor: pointer; }
.cart-lines li:last-child { border-bottom: 0; }
.cart-lines .l-name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.cart-lines .l-name i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.cart-lines .l-detail { color: var(--muted); font-size: .85rem; grid-column: 1; }
.cart-lines .l-total { font-weight: 650; grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.total-row { display: flex; align-items: baseline; justify-content: space-between; margin: 12px 0; padding-top: 12px; border-top: 2px solid var(--primary); }
.total-row .amount { font-size: 1.9rem; font-weight: 750; letter-spacing: -.02em; }
.pay { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.pay button { min-height: 42px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; font-weight: 600; cursor: pointer; }
.pay button.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* Barre de validation collante sur mobile */
@media (max-width: 899px) {
  .sticky-total {
    position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 10;
    display: flex; align-items: center; gap: 12px; background: var(--ink); color: #fff; border-radius: 16px; padding: 10px 10px 10px 16px;
    box-shadow: 0 8px 24px rgba(11, 36, 71, .3); margin-top: 14px;
  }
  .sticky-total .st-amount { font-size: 1.35rem; font-weight: 750; }
  .sticky-total .st-count { font-size: .8rem; opacity: .75; }
  .sticky-total .btn { margin-left: auto; background: #fff; color: var(--primary); border: 0; }
}
@media (min-width: 900px) { .sticky-total { display: none; } }

/* ---------- Feuille modale (saisie poids, formulaires) ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(11, 36, 71, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
.sheet {
  width: 100%; max-width: 520px; background: var(--surface); border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow-y: auto; animation: up .2s ease-out;
}
@media (min-width: 640px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 20px; } }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head .x { border: 0; background: var(--surface-2); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; line-height: 1; flex: none; }
.qty-input { font-size: 2rem !important; text-align: center; font-weight: 700; min-height: 64px !important; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.quick button { min-height: 42px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-weight: 600; cursor: pointer; }
.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 8px; }
.stepper button { font-size: 1.6rem; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; }
.line-preview { text-align: center; margin: 12px 0 16px; color: var(--muted); }
.line-preview b { color: var(--text); font-size: 1.3rem; }
.sheet-actions { display: flex; gap: 8px; }
.sheet-actions .btn { flex: 1; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Listes ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list .sub { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sale-item { cursor: pointer; }
.sale-item:hover .title { color: var(--primary); }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge.off { background: #FDECEA; color: var(--danger); }
.badge.admin { background: var(--primary-soft); color: var(--primary); }
.cat-title { display: flex; align-items: center; gap: 8px; margin: 4px 0 2px; }
.cat-title i { width: 12px; height: 12px; border-radius: 4px; }
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table td.r, .table th.r { text-align: right; }

/* ---------- Tableau de bord ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters select.input, .filters input.input { width: auto; min-height: 38px; padding: 6px 10px; font-size: .92rem; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(47, 122, 63, .18); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (min-width: 900px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi .k-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.kpi .k-value { font-size: 1.45rem; font-weight: 750; letter-spacing: -.02em; margin-top: 2px; }
.kpi.main { background: var(--primary); color: #fff; border-color: var(--primary); }
.kpi.main .k-label { color: rgba(255, 255, 255, .8); }
.dash-grid { display: grid; gap: 12px; }
@media (min-width: 900px) { .dash-grid { grid-template-columns: 1.6fr 1fr; } .dash-grid .wide { grid-column: 1 / -1; } }
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { font-size: 11px; fill: var(--muted); }
.chart .grid line { stroke: var(--line); }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; padding: 5px 9px; border-radius: 8px; font-size: .8rem; white-space: nowrap; transform: translate(-50%, -115%); box-shadow: var(--shadow); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: .88rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.donut-wrap { display: grid; grid-template-columns: minmax(130px, 170px) 1fr; gap: 16px; align-items: center; }
.donut-list { list-style: none; margin: 0; padding: 0; font-size: .92rem; }
.donut-list li { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.donut-list li:last-child { border: 0; }
.donut-list i { width: 12px; height: 12px; border-radius: 3px; }
.donut-list small { color: var(--muted); display: block; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; gap: 10px; align-items: center; font-size: .9rem; }
.bar-row .b-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .b-track { background: var(--surface-2); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-row .b-fill { height: 100%; border-radius: 6px; transition: width .5s ease-out; min-width: 2px; }
.bar-row .b-val { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }
@media (max-width: 480px) { .bar-row { grid-template-columns: 1fr auto; } .bar-row .b-track { grid-column: 1 / -1; grid-row: 2; } }

/* ---------- Notification ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 90px); transform: translate(-50%, 20px); z-index: 60;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
@media (min-width: 761px) { .toast { bottom: 28px; } }

.footer-note { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 28px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.footer-note img { opacity: .85; }
