:root {
  --bg: #fbf5f2;
  --card: #ffffff;
  --ink: #3a2a2e;
  --muted: #8a7479;
  --accent: #d9667b;
  --accent-soft: #f6e1e5;
  --line: #eadcd8;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(90, 40, 50, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding: env(safe-area-inset-top) 16px calc(32px + env(safe-area-inset-bottom));
  max-width: 900px;
  margin-inline: auto;
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* En-tête */
.top { text-align: center; padding: 28px 0 8px; }
.top h1 { margin: 0; font-size: 1.6rem; font-weight: 700; }
.top .name { color: var(--accent); }
.summary { margin: 6px 0 0; color: var(--muted); font-size: .95rem; }

/* Zone d'ajout */
.add {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin: 16px 0;
}
.field { display: flex; gap: 8px; }
input, select {
  font: inherit;
  font-size: 16px; /* évite le zoom auto sur iPhone */
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

button {
  font: inherit;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.primary {
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.primary:disabled { opacity: .6; }
.ghost {
  background: var(--accent-soft);
  color: var(--ink);
  padding: 0 14px;
  min-height: 44px;
}
.ghost.small { font-size: .9rem; padding: 0 12px; }
.hint { margin: 8px 2px 0; font-size: .85rem; color: var(--muted); min-height: 1em; }
.hint.error { color: #b3261e; }
.hint:empty, .sync:empty { display: none; }

/* Barre d'outils */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar select { flex: 1; padding: 10px 12px; }


/* Grille d'articles */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  animation: pop .25s ease-out;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } }

.card .thumb {
  aspect-ratio: 1;
  background: #f4eeec center / contain no-repeat;
  display: block;
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.card .thumb.noimg {
  display: grid;
  place-items: center;
  font-size: 2.4rem;
}
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card .title {
  font-size: .9rem;
  line-height: 1.25;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .price { font-weight: 700; color: var(--accent); font-size: 1.05rem; }
.card .price.unknown { color: var(--muted); font-weight: 400; font-size: .85rem; }
.price-input { display: flex; align-items: center; gap: 4px; }
.price-input input { padding: 7px 8px; border-radius: 8px; min-width: 0; flex: 1; }
.price-input span { color: var(--muted); }
.price-input button { background: var(--accent); color: #fff; padding: 8px 10px; border-radius: 8px; font-size: .8rem; font-weight: 600; }
.card .store { font-size: .75rem; color: var(--muted); }
.card .note { font-size: .8rem; color: var(--muted); font-style: italic; }
.card .actions { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; }
.card .actions a, .card .actions button {
  flex: 1;
  text-align: center;
  text-decoration: none;
  font-size: .85rem;
  padding: 9px 0;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--ink);
}
.card .actions a.go { background: var(--accent); color: #fff; font-weight: 600; flex: 2; }

.fav {
  position: absolute;
  top: 8px; right: 8px;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .9);
  font-size: 1.15rem;
  box-shadow: var(--shadow);
}

.card.loading .thumb { animation: shimmer 1.2s infinite linear; background: linear-gradient(90deg, #f4eeec 0%, #fbf7f6 50%, #f4eeec 100%); background-size: 200% 100%; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty { text-align: center; color: var(--muted); margin-top: 40px; }

/* Fenêtre d'édition */
dialog {
  border: 0;
  border-radius: 20px;
  padding: 20px;
  width: min(92vw, 420px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .2);
}
dialog::backdrop { background: rgba(58, 42, 46, .4); }
dialog h2 { margin: 0 0 12px; font-size: 1.15rem; }
dialog label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
dialog label input { margin-top: 4px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 6px; }
.dialog-actions button { flex: 1; margin: 0; min-height: 46px; }

/* Connexion */
.login {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin: 24px 0;
}
.login h2 { margin: 0 0 4px; font-size: 1.15rem; }
.login input { margin-top: 10px; }
.login label { display: block; }
body.locked .add,
body.locked .toolbar,
body.locked #list,
body.locked .empty { display: none; }
.sync { margin: 4px 0 0; font-size: .8rem; color: #b26a00; min-height: 0; }

/* Article déjà présent : la carte clignote */
.card.flash { animation: flash 1.2s ease-out 2; }
@keyframes flash { 0%, 100% { box-shadow: var(--shadow); } 30% { box-shadow: 0 0 0 4px var(--accent); } }
