:root {
  --bg: #f5f3ec;
  --surface: #ffffff;
  --ink: #201a17;
  --muted: #78716c;
  --line: #e7e2d6;
  --accent: #9a3412;
  --accent-hover: #7c2d12;
  --accent-soft: #fbeedf;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(32, 26, 23, .06), 0 8px 24px -12px rgba(32, 26, 23, .18);
  --shadow-lg: 0 24px 64px -16px rgba(32, 26, 23, .35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: rgba(245, 243, 236, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: 1.45rem; font-weight: 800; letter-spacing: -0.02em; }

.collection-bar { display: flex; align-items: center; gap: 10px; flex: 1; flex-wrap: wrap; }
.collection-select {
  font-size: 1rem; font-weight: 600; color: var(--ink);
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); max-width: 280px; cursor: pointer;
}
.collection-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

/* ---------- language toggle ---------- */
.lang-toggle { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.lang-toggle button { font: inherit; font-size: .8rem; font-weight: 700; padding: 8px 12px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.lang-toggle button.active { background: var(--ink); color: var(--surface); }
.lang-toggle button + button { border-left: 1px solid var(--line); }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: .92rem; font-weight: 600;
  padding: 9px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 14px -6px rgba(154, 52, 18, .6); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger:hover { border-color: #b91c1c; color: #b91c1c; }
.btn-block { width: 100%; }

/* ---------- auth (Phase 2A) ---------- */
.auth-zone { display: flex; align-items: center; gap: 8px; }
.auth-zone[hidden] { display: none; }
.auth-email {
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: .85rem; font-weight: 600; color: var(--muted);
}
.auth-tabs {
  display: flex; width: max-content; margin-bottom: 18px;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface);
}
.auth-tabs button {
  font: inherit; font-size: .88rem; font-weight: 700; padding: 9px 18px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.auth-tabs button.active { background: var(--ink); color: var(--surface); }
.auth-tabs button + button { border-left: 1px solid var(--line); }
.auth-error {
  color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca;
  border-radius: 10px; padding: 10px 12px; font-size: .88rem; margin: 0 0 4px;
}
.auth-error[hidden] { display: none; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; gap: 10px; align-items: center;
  padding: 14px 20px 6px; flex-wrap: wrap;
}
.search-wrap {
  flex: 1; min-width: 200px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 0 12px;
}
.search-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-icon { color: var(--muted); }
#search { flex: 1; border: 0; outline: 0; font: inherit; padding: 11px 0; background: transparent; }
.sort-wrap select {
  font: inherit; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface); cursor: pointer;
}

/* ---------- letters ---------- */
.letters {
  display: flex; gap: 4px; padding: 10px 20px;
  overflow-x: auto; scrollbar-width: thin;
}
.letter {
  flex: 0 0 auto; min-width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; border: 1px solid transparent;
  font-weight: 700; font-size: .85rem; color: var(--muted);
  background: transparent; cursor: pointer; padding: 0 8px;
}
.letter:hover:not(:disabled) { background: var(--surface); color: var(--ink); }
.letter.active { background: var(--ink); color: #fff; }
.letter:disabled { opacity: .25; cursor: default; }

/* ---------- grid ---------- */
main { flex: 1; padding: 6px 20px 40px; max-width: 1280px; width: 100%; margin: 0 auto; }
.count { color: var(--muted); font-size: .9rem; margin: 8px 2px 14px; }

.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
}
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .12s ease, box-shadow .15s ease;
  display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.card-cover {
  aspect-ratio: 1; background: linear-gradient(135deg, var(--accent-soft), #efe6d4);
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem; overflow: hidden;
}
.card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body { padding: 12px 14px 14px; }
.card-body h3 { margin: 0 0 4px; font-size: .98rem; line-height: 1.3; }
.card-body p { margin: 0; color: var(--muted); font-size: .85rem; }

/* ---------- empty states ---------- */
.empty {
  text-align: center; padding: 72px 20px; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty .empty-icon { font-size: 3.2rem; display: block; margin-bottom: 12px; }
.empty h2 { color: var(--ink); margin: 0 0 8px; }
.empty p { margin: 0 0 18px; }

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(32, 26, 23, .5); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 18px; animation: fadeIn .15s ease;
}
.modal {
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  padding: 24px; position: relative; animation: popIn .18s ease;
}
.modal-wide { max-width: 880px; }
.modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: var(--bg); font-size: 1.2rem; cursor: pointer; color: var(--muted);
}
.modal-close:hover { color: var(--ink); background: var(--line); }
.modal h2 { margin: 0 0 6px; font-size: 1.3rem; }
.modal .modal-sub { color: var(--muted); margin: 0 0 18px; font-size: .92rem; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.field input[type="text"], .field input[type="number"], .field input[type="url"],
.field input[type="email"], .field input[type="password"],
.field textarea, .field select {
  width: 100%; font: inherit; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { min-height: 74px; resize: vertical; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* covers editor */
.covers-editor { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 4px; }
.cover-thumb {
  position: relative; width: 76px; height: 76px; border-radius: 10px; overflow: hidden;
  border: 2px solid var(--line); background: var(--bg); flex: 0 0 auto;
}
.cover-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-thumb.primary { border-color: var(--accent); }
.cover-thumb .cover-star, .cover-thumb .cover-del {
  position: absolute; border: 0; cursor: pointer; font-size: .8rem;
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.cover-thumb .cover-star { left: 4px; bottom: 4px; background: rgba(255,255,255,.92); }
.cover-thumb.primary .cover-star { background: var(--accent); color: #fff; }
.cover-thumb .cover-del { right: 4px; top: 4px; background: rgba(32,26,23,.72); color: #fff; }
.cover-add {
  width: 76px; height: 76px; border-radius: 10px; border: 2px dashed var(--line);
  background: transparent; cursor: pointer; font-size: 1.6rem; color: var(--muted);
}
.cover-add:hover { border-color: var(--accent); color: var(--accent); }

/* template picker */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.template-card {
  border: 2px solid var(--line); border-radius: 12px; padding: 14px 10px;
  text-align: center; cursor: pointer; background: #fff; font: inherit;
  transition: border-color .12s ease, background .12s ease;
}
.template-card .t-icon { font-size: 1.9rem; display: block; margin-bottom: 6px; }
.template-card .t-label { font-weight: 600; font-size: .9rem; }
.template-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.import-choice { display: grid; gap: 10px; }

/* ---------- detail view ---------- */
.detail-grid { display: grid; grid-template-columns: 300px 1fr; gap: 24px; }
.detail-gallery .main-img {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line);
}
.detail-gallery .thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.detail-gallery .thumbs img {
  width: 56px; height: 56px; object-fit: cover; border-radius: 8px; cursor: pointer;
  border: 2px solid transparent;
}
.detail-gallery .thumbs img.active { border-color: var(--accent); }
.detail-placeholder {
  width: 100%; aspect-ratio: 1; border-radius: 12px; font-size: 4rem;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent-soft), #efe6d4);
  border: 1px solid var(--line);
}
.detail-info h2 { margin: 0 0 4px; padding-right: 30px; }
.detail-info .subtitle { color: var(--muted); margin: 0 0 16px; }
.detail-fields { display: grid; gap: 10px; margin: 0 0 20px; }
.detail-fields .df { display: grid; grid-template-columns: 130px 1fr; gap: 10px; font-size: .93rem; }
.detail-fields .df dt { color: var(--muted); font-weight: 600; }
.detail-fields .df dd { margin: 0; word-break: break-word; }
.detail-fields .df dd a { color: var(--accent); }
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- toast / footer ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: .92rem; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 200; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 18px; border-top: 1px solid var(--line); }
.footer-links { margin: 6px 0 0; }
.footer a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.footer a:hover { color: var(--ink); }

/* ---------- bannière d'installation PWA ---------- */
.pwa-banner {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 20px 0; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.pwa-banner[hidden] { display: none; }
.pwa-banner-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pwa-banner-txt strong { font-size: .95rem; }
.pwa-banner-txt span { color: var(--muted); font-size: .85rem; }
.pwa-banner .btn { padding: 7px 12px; font-size: .85rem; flex-shrink: 0; }
#pwa-dismiss { padding: 7px 10px; }

/* ---------- cloud + partage public (Phase 2B) ---------- */
.cloud-actions { display: contents; }
.cloud-actions[hidden] { display: none; }
.migrate-progress { font-weight: 600; color: var(--muted); margin: 0 0 12px; }
.migrate-progress[hidden] { display: none; }
body.public-view .collection-bar,
body.public-view .toolbar,
body.public-view #letters,
body.public-view #pwa-banner,
body.public-view .auth-zone,
body.public-view .lang-toggle { display: none; }
.public-head { text-align: center; margin: 26px 0 10px; }
.public-kicker { color: var(--muted); font-weight: 600; font-size: .9rem; margin: 0 0 6px; }
.public-head h1 { margin: 0 0 4px; }
.public-head .btn { margin-top: 10px; }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .detail-grid { grid-template-columns: 1fr; }
  .collection-select { max-width: 100%; flex: 1; }
  .collection-bar { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  main { padding: 6px 12px 32px; }
  .toolbar, .letters { padding-left: 12px; padding-right: 12px; }
}
