:root {
    --bg: #f7f5f0;
    --card-bg: #ffffff;
    --ink: #23291f;
    --muted: #6b7264;
    --line: #e3e0d6;
    --primary: #2f6b4f;
    --primary-dark: #234f3a;
    --accent: #d97b3f;
    --danger: #b23a2e;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    padding-bottom: 40px;
}

.container {
    max-width: 560px;
    margin: 0 auto;
    padding: 12px 14px 32px;
}

/* ---------- Barre du haut ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--primary);
    color: #fff;
    padding: 14px 14px;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar h1 {
    font-size: 1.15rem;
    margin: 0;
    flex: 1;
}
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-link {
    color: #fff;
    text-decoration: none;
    font-size: 1.3rem;
    padding: 4px 8px;
}
button.icon-link {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    line-height: 1;
}

/* ---------- Cartes / sections ---------- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 16px;
}
h2 { font-size: 1rem; margin: 0 0 10px; color: var(--primary-dark); }
h3.aisle-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin: 18px 0 6px 4px;
}
.empty { color: var(--muted); text-align: center; padding: 20px 0; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 6px 0; }

/* ---------- Formulaires ---------- */
form { display: flex; flex-direction: column; gap: 8px; }
.inline-form { flex-direction: row; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { flex: 1; min-width: 120px; }
.form-row { display: flex; gap: 8px; }

input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 16px; /* évite le zoom auto sur iOS */
    background: #fff;
    color: var(--ink);
}
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.file-label {
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
}
.file-label input { margin-top: 6px; }

button { cursor: pointer; border: none; border-radius: 8px; font-size: 0.95rem; padding: 10px 14px; }
.btn-primary { background: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: #eef1ea; color: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-icon { background: transparent; font-size: 1.1rem; padding: 6px 8px; }
.full-width { width: 100%; }

/* ---------- Grille de listes (dashboard) ---------- */
.list-grid { display: grid; gap: 10px; }
.list-tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-left: 5px solid var(--primary);
    border-radius: var(--radius);
    padding: 14px;
    text-decoration: none;
    color: var(--ink);
}
.list-tile.shared { border-left-color: var(--accent); }
.list-tile-name { font-weight: 600; }

/* Coin haut-droit de la tuile : avancement "X/Y" + engrenage ⚙️ (propriétaire) */
.list-tile-wrap { position: relative; }
.list-tile-wrap .list-tile { padding-right: 72px; }
.list-corner {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.list-progress {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--bg);
    border-radius: 999px;
    padding: 2px 7px;
    white-space: nowrap;
}
.list-menu { position: relative; }
.list-menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.15rem;
    line-height: 1;
    padding: 6px;
    color: var(--muted);
}
.list-menu-pop {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 30;
    min-width: 180px;
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    padding: 4px;
    display: flex;
    flex-direction: column;
}
.list-menu-pop[hidden] { display: none; }
.list-menu-pop a,
.list-menu-pop button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    font: inherit;
    color: var(--ink);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
}
.list-menu-pop a:hover,
.list-menu-pop button:hover { background: var(--bg); }

/* Glisser-déposer des listes */
.tile-ghost { opacity: 0.35; }
.list-tile-wrap.sortable-chosen .list-tile { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); }
.badge { font-size: 0.75rem; color: var(--primary-dark); }
.badge.muted { color: var(--muted); }

.template-row { flex-direction: row; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }

/* ---------- Sélecteur de magasin ---------- */
.store-picker { margin-bottom: 10px; }
.store-picker select { background: var(--card-bg); }
.total-line { text-align: right; color: var(--primary-dark); margin: 4px 4px 14px; }

/* ---------- Items ---------- */
.item-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 8px;
}
.item-row.trashed { opacity: 0.75; }
.item-thumb { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.item-thumb.placeholder {
    display: flex; align-items: center; justify-content: center;
    background: #eef1ea; font-size: 1.2rem;
}
.item-info { flex: 1; min-width: 0; }
.item-name { font-weight: 600; }
.item-meta { font-size: 0.82rem; color: var(--muted); }
.price-per-100 { color: var(--muted); font-weight: normal; }
.item-note { font-size: 0.8rem; color: var(--accent); font-style: italic; }
.checkbox-btn {
    display: flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 6px;
    background: #eef1ea; border: 2px solid var(--primary-dark);
    flex-shrink: 0; cursor: pointer; padding: 0;
    transition: background 0.2s ease;
}
.checkbox-btn:hover { background: #dfe6da; }
.checkbox-btn .check-icon {
    width: 18px; height: 18px;
    fill: none; stroke: #fff; stroke-width: 3.5;
    stroke-linecap: round; stroke-linejoin: round;
    stroke-dasharray: 24; stroke-dashoffset: 24;
}
.checkbox-btn.checked { background: var(--primary-dark); animation: box-pop 0.3s ease; }
.checkbox-btn.checked .check-icon { animation: draw-check 0.45s ease 0.05s forwards; }
/* Case déjà cochée au chargement (section "déjà fait") : coche pleine, sans animation */
.checkbox-btn.checked-static { background: var(--primary-dark); }
.checkbox-btn.checked-static .check-icon { stroke-dashoffset: 0; }
@keyframes draw-check { to { stroke-dashoffset: 0; } }
@keyframes box-pop { 0% { transform: scale(1); } 45% { transform: scale(1.18); } 100% { transform: scale(1); } }
.item-check-form { margin: 0; }

/* Item coché : reste visible ~1 s avant de basculer dans les items cochés */
.item-row.checking {
    opacity: 0.45;
    transition: opacity 0.4s ease;
}
.item-row.checking .item-name { text-decoration: line-through; }

.trash-section summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.trash-actions { margin: 10px 0; }
.trash-item-actions { display: flex; gap: 4px; }

/* ---------- Menu / activité / partage ---------- */
details summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.activity-list { list-style: none; padding: 0; margin: 0; font-size: 0.85rem; }
.activity-list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.activity-time { color: var(--muted); float: right; }
.simple-list { list-style: none; padding: 0; margin: 8px 0; }
.simple-list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.share-link-row { display: flex; gap: 6px; align-items: center; margin: 6px 0; }
.share-link-row input { font-size: 0.8rem; background: #f1f0eb; }

/* ---------- Auth ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 26px 22px;
    width: 100%;
    max-width: 380px;
    border: 1px solid var(--line);
}
.auth-card h1 { text-align: center; color: var(--primary-dark); margin-top: 0; }
.error { color: var(--danger); font-size: 0.9rem; }
.switch-link { text-align: center; font-size: 0.9rem; margin-top: 14px; }
.switch-link a { color: var(--primary); }

/* ---------- Scanner ---------- */
.scan-modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.85);
    z-index: 100; display: flex; align-items: center; justify-content: center;
}
.scan-modal.hidden { display: none; }
#imgLightbox img { max-width: 92vw; max-height: 88vh; border-radius: 8px; cursor: zoom-out; }
.scan-modal-inner { background: #fff; border-radius: var(--radius); padding: 16px; width: 92%; max-width: 400px; text-align: center; }
.scan-modal-inner #closeScan,
.scan-modal-inner #closeEditItem { color: var(--ink); float: right; }
.edit-item-inner { text-align: left; max-height: 90vh; overflow-y: auto; }
.edit-item-inner h2 { margin: 4px 0 10px; }
#reader { width: 100%; margin-top: 10px; }
.scan-preview-img { max-width: 100px; border-radius: 8px; margin-top: 8px; }
.contribute-box { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 10px; text-align: left; }
.contribute-box input[type=file] { margin-bottom: 8px; }

/* ---------- Allées et photos de magasin ---------- */
.store-card-header { display: flex; justify-content: space-between; align-items: center; }
.aisle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 10px; margin: 10px 0; }
.aisle-card { text-align: center; }
.aisle-photo {
    width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px;
    border: 1px solid var(--line); display: block;
}
.aisle-photo.placeholder {
    display: flex; align-items: center; justify-content: center;
    background: #eef1ea; font-size: 1.4rem;
}
.aisle-card-name { font-size: 0.78rem; margin: 4px 0 2px; color: var(--muted); }
.aisle-form { margin-top: 8px; }

.aisle-header { display: flex; align-items: center; gap: 8px; margin: 18px 0 6px 4px; }
.aisle-header-photo { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.aisle-header .aisle-title { margin: 0; }

.store-info-edit {
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-top: none;
    border-radius: 0 0 10px 10px;
    padding: 4px 10px 10px;
    margin: -12px 0 8px;
    font-size: 0.85rem;
}
.store-info-edit summary { color: var(--muted); font-weight: 500; }
.store-info-form { margin-top: 8px; }

/* ---------- Responsive: écrans plus larges ---------- */
@media (min-width: 640px) {
    .list-grid { grid-template-columns: 1fr 1fr; }
}
