:root {
    --bg: #f6f1ea;
    --surface: #ffffff;
    --surface-2: #efe7db;
    --text: #26201a;
    --muted: #6a5e50;
    --border: rgba(38, 32, 26, 0.10);
    --border-strong: rgba(38, 32, 26, 0.20);
    --primary: #b5451e;
    --primary-hover: #96391a;
    --primary-contrast: #fdf6ef;
    --success: #4c6f47;
    --success-bg: rgba(76, 111, 71, 0.13);
    --error: #a63a26;
    --error-bg: rgba(166, 58, 38, 0.11);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --radius-pill: 980px;
    --shadow-sm: 0 1px 2px rgba(38, 32, 26, 0.06), 0 1px 1px rgba(38, 32, 26, 0.04);
    --shadow-md: 0 12px 32px rgba(38, 32, 26, 0.10), 0 2px 8px rgba(38, 32, 26, 0.06);
    --ease: cubic-bezier(0.25, 1, 0.5, 1);
    --font-display: "Fraunces", Georgia, "Times New Roman", serif;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    /* Spacing scale — mobile-first: this is the base rhythm, bumped up on
       wider screens further down, never squeezed down for mobile. */
    --space-1: 6px;
    --space-2: 10px;
    --space-3: 16px;
    --space-4: 24px;
    --space-5: 32px;
    --space-6: 44px;
    --space-7: 56px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17130f;
        --surface: #221c16;
        --surface-2: #2c2419;
        --text: #f4ece0;
        --muted: #a99c8a;
        --border: rgba(255, 255, 255, 0.11);
        --border-strong: rgba(255, 255, 255, 0.20);
        --primary: #e37a45;
        --primary-hover: #ec8c5c;
        --primary-contrast: #1b140e;
        --success: #8ebd84;
        --success-bg: rgba(142, 189, 132, 0.16);
        --error: #e2735f;
        --error-bg: rgba(226, 115, 95, 0.16);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.5);
    }
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; }

body {
    margin: 0;
    font-family: var(--font-body);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    background-color: var(--bg);
    background-image:
        radial-gradient(1100px 550px at 10% -12%, color-mix(in srgb, var(--primary) 8%, transparent), transparent 60%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.035 0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: no-repeat, repeat;
    background-attachment: fixed, fixed;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: opacity 0.15s var(--ease);
}
a:hover { opacity: 0.75; }

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--primary);
    color: var(--primary-contrast);
    padding: 12px 18px;
    border-radius: 0 0 var(--radius-sm) 0;
    z-index: 50;
    font-size: 0.9rem;
}
.skip-link:focus { left: 0; }

/* Mobile-first layout: base padding is for small screens, widened below. */
.container {
    max-width: 980px;
    margin: 0 auto;
    padding: var(--space-5) var(--space-3) var(--space-6);
    position: relative;
}

@media (min-width: 700px) {
    .container { padding: var(--space-7) var(--space-4) 96px; }
}

/* Masthead (replaces the old nav bar — this app is a single page) */
.masthead {
    margin-bottom: var(--space-5);
}
.wordmark {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 500;
    font-size: 1rem;
    color: var(--primary);
    letter-spacing: 0.01em;
    margin: 0 0 10px;
}
.masthead h1 {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(1.6rem, 1.3rem + 3vw, 2.75rem);
    line-height: 1.18;
    letter-spacing: -0.01em;
    color: var(--text);
    margin: 0;
    max-width: 22ch;
    text-wrap: balance;
}

@media (min-width: 700px) {
    .masthead { margin-bottom: var(--space-6); }
}

/* Typography */
h2 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--text);
    margin: 0;
}

/* Alerts */
.alert {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-4);
    font-size: 0.9rem;
    animation: alert-in 0.4s var(--ease);
}
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--error-bg); color: var(--error); }

@keyframes alert-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fade-up {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Stat tiles */
.stats {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}
@media (min-width: 480px) {
    .stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-3); }
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-sm);
}
.stat-card--primary {
    background: var(--primary);
    border-color: transparent;
}
.stat-card--primary .stat-label,
.stat-card--primary .stat-value { color: var(--primary-contrast); }
.stat-label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.stat-value {
    display: block;
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

/* Filters */
.filters {
    display: flex;
    gap: var(--space-2);
    align-items: stretch;
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}
.filters select { flex: 1 1 160px; }

/* Section headings (Items) */
.section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    margin: var(--space-7) 0 var(--space-3);
    scroll-margin-top: 24px;
}
.section-heading h2 { margin: 0; }
.section-count { font-size: 0.85rem; color: var(--muted); }

.category-title {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--primary);
    margin: var(--space-5) 0 var(--space-2);
}
.category-title:first-of-type { margin-top: var(--space-1); }

/* Item list (per category) */
.item-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: var(--space-4);
}

.item-row {
    border-bottom: 1px solid var(--border);
    animation: fade-up 0.5s var(--ease) backwards;
    animation-delay: calc(var(--stagger, 0) * 35ms);
}
.item-row:last-of-type { border-bottom: none; }

.item-row > summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.12s var(--ease);
    scroll-margin-top: 24px;
}
.item-row > summary::-webkit-details-marker { display: none; }
.item-row > summary:hover { background: var(--surface-2); }
.item-row[open] > summary { background: var(--surface-2); border-bottom: 1px solid var(--border); }

.item-summary-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px var(--space-2);
    flex: 1 1 auto;
    min-width: 0;
}

.item-row .item-name { font-weight: 500; flex: 1 1 100%; min-width: 140px; }
.item-row .item-meta { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.item-row .item-price { white-space: nowrap; font-weight: 500; }
.item-row .item-price .item-enseigne { color: var(--muted); font-weight: 400; margin-left: 4px; }
.item-row .item-price.is-empty { color: var(--muted); font-weight: 400; }

@media (min-width: 560px) {
    .item-row .item-name { flex: 1 1 auto; min-width: 120px; }
}

.chevron {
    width: 9px;
    height: 9px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: rotate(-45deg);
    transition: transform 0.25s var(--ease), border-color 0.15s var(--ease);
    flex: none;
    margin-left: var(--space-1);
}
.item-row[open] .chevron { transform: rotate(45deg); border-color: var(--primary); }

.item-panel {
    padding: var(--space-4) var(--space-3) var(--space-5);
    background: var(--surface-2);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.item-panel > div + div {
    border-top: 1px solid var(--border);
    padding-top: var(--space-5);
}

.item-panel h3 {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin: 0 0 var(--space-3);
}

.subheading {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin: var(--space-4) 0 var(--space-2);
}

/* Field grid used by the item-edit and add-price forms: one column on
   mobile, several on wider screens so related fields sit side by side
   without ever cramming them into a single unreadable row. */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
}
@media (min-width: 560px) {
    .form-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
.form-row-grow { grid-column: 1 / -1; }

.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-3);
}

.item-edit-form textarea { min-height: 44px; }

.item-panel-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px dashed var(--border);
}

/* Admin disclosure panels (Catégories / Enseignes) */
.admin-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-3);
    overflow: hidden;
}
.admin-panel:first-of-type { margin-top: var(--space-6); }
.admin-panel > summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    transition: background 0.12s var(--ease);
}
.admin-panel > summary::-webkit-details-marker { display: none; }
.admin-panel > summary:hover { background: var(--surface-2); }
.admin-panel[open] > summary { border-bottom: 1px solid var(--border); }
.admin-panel .section-count { font-family: var(--font-body); }
.admin-panel-body { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.admin-panel-body .card-form { margin-bottom: 0; box-shadow: none; padding: 0; border: none; }
.admin-panel-body .notes { margin: 0; }

/* Form controls — 16px min font-size prevents iOS Safari's auto-zoom-on-focus */
select, input[type=text], input[type=number], input[type=password],
input[type=url], input[type=date], textarea {
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
    width: 100%;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

select:focus, input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent);
}

::placeholder { color: var(--muted); opacity: 1; }

textarea { min-height: 76px; }

/* Buttons */
button, .button, input[type=submit] {
    padding: 12px 22px;
    border: none;
    border-radius: var(--radius-pill);
    background: var(--primary);
    color: var(--primary-contrast);
    font-size: 0.95rem;
    font-weight: 500;
    font-family: var(--font-body);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.3;
    width: 100%;
    transition: background 0.15s var(--ease), transform 0.15s var(--ease);
}

@media (min-width: 480px) {
    button, .button, input[type=submit] { width: auto; }
}

button:hover, .button:hover { background: var(--primary-hover); opacity: 1; }
button:active, .button:active { transform: scale(0.97); }

/* Secondary action "chips" — Modifier / Supprimer / Marquer acheté ici / Annuler.
   Real buttons with a visible boundary and a comfortable tap target, instead of
   bare inline text that's hard to read and hard to tap on a phone. */
.link-button,
.card-form > a,
.items-table td:last-child a,
.item-panel-footer > a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: auto;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text);
    cursor: pointer;
    padding: 8px 14px;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    transition: color 0.15s var(--ease), border-color 0.15s var(--ease), background 0.15s var(--ease);
    white-space: nowrap;
}
.link-button:hover,
.card-form > a:hover,
.items-table td:last-child a:hover,
.item-panel-footer > a:hover {
    opacity: 1;
    border-color: var(--primary);
    color: var(--primary);
    background: var(--surface-2);
}
.link-button.is-danger:hover { border-color: var(--error); color: var(--error); background: var(--error-bg); }

.inline-form { display: inline-flex; }

/* Cards / forms */
.card-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: flex-end;
    box-shadow: var(--shadow-sm);
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1 1 160px;
}

.form-row label { font-size: 0.85rem; color: var(--muted); }

.checkbox-row { flex-direction: row; align-items: center; gap: var(--space-2); flex: 1 1 auto; }
.checkbox-row label { display: flex; align-items: center; gap: var(--space-2); font-size: 0.95rem; color: var(--text); }
.checkbox-row input[type=checkbox] { accent-color: var(--primary); width: 18px; height: 18px; flex: none; }

/* Tables */
/* Wrapper handles the horizontal scroll + card chrome; the <table> itself
   keeps its native table layout so it actually stretches to fill the
   wrapper (display:block on a <table> breaks that and left a dead gap). */
.table-scroll {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th, .items-table td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 0.9rem;
    white-space: nowrap;
}

.items-table th {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.8rem;
    background: var(--surface-2);
}
.items-table tr:last-child td { border-bottom: none; }
.items-table tbody tr { transition: background 0.12s var(--ease); }
.items-table tbody tr:hover { background: var(--surface-2); }
.items-table tr.row-best { background: var(--success-bg); }
.items-table tr.row-best:hover { background: color-mix(in srgb, var(--success-bg) 80%, var(--surface-2)); }

.items-table td a { color: var(--text); text-decoration: none; font-weight: 500; }

.items-table td:last-child {
    white-space: normal;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-2);
    align-items: center;
}
.items-table td:last-child .inline-form { margin-left: 0; }

.price-table td { white-space: normal; vertical-align: top; }
.price-main { font-weight: 500; }
.price-meta { color: var(--muted); font-size: 0.82rem; margin-top: 3px; }

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.78rem;
    font-weight: 500;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    white-space: nowrap;
    flex: none;
}
.badge-success { background: var(--success-bg); color: var(--success); border-color: transparent; }

.notes { color: var(--muted); white-space: pre-line; }

/* Back-to-top */
.to-top {
    position: fixed;
    right: var(--space-3);
    bottom: var(--space-3);
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--text);
    color: var(--bg);
    font-size: 1.1rem;
    line-height: 1;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 0.2s var(--ease), transform 0.2s var(--ease), background 0.15s var(--ease);
    z-index: 30;
}
.to-top.is-visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.to-top:hover { background: var(--primary); opacity: 1; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}
