/* Courses Hermes — mobile d'abord, une colonne, thème clair. */
:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --text: #1b2420;
  --muted: #55615b;        /* 6,3:1 sur blanc */
  --border: #cfd8d3;
  --primary: #1f7a4d;      /* 5,4:1 avec du blanc */
  --primary-dark: #17603c;
  --primary-soft: #e3f2ea;
  --danger: #b3261e;       /* 6,1:1 avec du blanc */
  --danger-soft: #fbe9e8;
  --focus: #1a56db;
  --radius: 12px;
  --tap: 44px;
  color-scheme: light;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

[hidden] { display: none !important; }

a { color: var(--primary-dark); }

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

.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 {
  position: absolute; left: 8px; top: -100px;
  display: inline-flex; align-items: center; min-height: var(--tap);
  background: var(--surface); padding: 10px 14px; border-radius: 8px; z-index: 10;
}
.skip:focus { top: 8px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px;
  padding: 4px max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
  background: var(--primary);
  color: #fff;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 4px;
  color: #fff; font-weight: 700; text-decoration: none;
}
.topbar :focus-visible { outline-color: #fff; }

.offline {
  font-size: 0.875rem; font-weight: 600;
  background: #fff4ce; color: #5c4400;
  padding: 4px 10px; border-radius: 999px;
}

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 12px 32px;
  display: flex; flex-direction: column; gap: 16px;
}

#list-view { display: flex; flex-direction: column; gap: 16px; }

h1 { font-size: 1.5rem; line-height: 1.2; margin: 0 0 8px; overflow-wrap: anywhere; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }

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

.hint { color: var(--muted); margin: 0 0 12px; }
.empty { color: var(--muted); text-align: center; padding: 16px 8px; margin: 0; }
.optional { color: var(--muted); font-weight: 400; }

/* Formulaires */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { font-weight: 600; }

input[type=text], input[type=number], select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font: inherit;
  font-size: 16px; /* évite le zoom automatique d'iOS */
  color: var(--text);
  background: #fff;
  border: 1px solid #8a968f; /* 3:1 sur blanc */
  border-radius: 10px;
}
input[aria-invalid=true] { border-color: var(--danger); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }

.error { color: var(--danger); font-size: 0.9rem; margin: 0 0 8px; }
.error.full { flex-basis: 100%; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); min-width: var(--tap);
  padding: 8px 16px;
  font: inherit; font-weight: 600;
  border: 1px solid transparent; border-radius: 10px;
  cursor: pointer; text-decoration: none;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--primary-soft); color: var(--primary-dark); border-color: #b5d9c4; }
.btn-ghost { background: transparent; color: var(--primary-dark); border-color: var(--border); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #e3b4b0; }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-icon { padding: 0; width: var(--tap); background: transparent; color: var(--muted); font-size: 1.15rem; }
.btn-icon:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-icon-danger:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }

.form-actions { display: flex; gap: 8px; }
.form-actions .btn { flex: 1; }

/* Accueil : mes listes */
.recent { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding: 4px 0; }
.recent li:first-child { border-top: 0; }
.recent-link {
  flex: 1; min-width: 0;
  display: flex; align-items: center; min-height: var(--tap);
  font-weight: 600; overflow-wrap: anywhere;
}

/* Page liste */
.list-head { display: flex; flex-direction: column; gap: 10px; }
.title-row { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.title-row h1 { flex: 1; min-width: 0; margin: 6px 0 0; }
.title-row h1:focus { outline: none; }
#rename-form input { flex: 1 1 100%; }
#rename-form .btn { flex: 1; }

.aisle { margin-bottom: 16px; }
.aisle h3 {
  font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); margin: 0 0 6px 4px;
}
.items {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.item {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 4px 2px 0;
  border-top: 1px solid var(--border);
}
.item:first-child { border-top: 0; }
.item-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 6px 4px 6px 12px;
  font-weight: 400; cursor: pointer;
}
.item-main input[type=checkbox] {
  flex: none; width: 24px; height: 24px; margin: 0;
  accent-color: var(--primary);
}
.item-text { display: flex; flex-direction: column; min-width: 0; }
.item-name { overflow-wrap: anywhere; }
.item-qty { color: var(--muted); font-size: 0.9rem; }
.item-actions { display: flex; flex: none; }
.item.is-checked .item-name { text-decoration: line-through; color: var(--muted); }
.item.is-checked .item-qty { text-decoration: line-through; }
.item.is-pending { opacity: 0.6; }
.item.is-editing { display: block; padding: 12px; background: #fbfdfc; }

#share-fallback input { font-size: 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 24px);
  background: #1b2420; color: #fff;
  padding: 12px 16px; border-radius: 10px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.2);
  z-index: 20;
}

@media (min-width: 600px) {
  .page { padding-top: 24px; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .item { transition: background-color 0.15s, opacity 0.15s; }
}

.remaining { margin: 4px 0 12px; font-size: 1.125rem; font-weight: 600; }
