:root {
    --bg: #f6f4ef;
    --surface: #ffffff;
    --text: #1d2422;
    --muted: #5d6865;
    --primary: #1f5f5b;
    --primary-text: #ffffff;
    --primary-soft: #e3efed;
    --danger: #b3261e;
    --danger-soft: #fbe9e7;
    --success: #1e7b45;
    --border: #d9d5cc;
    --radius: 12px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121614;
        --surface: #1c2220;
        --text: #e9ecea;
        --muted: #a3ada9;
        --primary: #5fb3ac;
        --primary-text: #0d1312;
        --primary-soft: #23312f;
        --danger: #f2b8b5;
        --danger-soft: #3a2220;
        --success: #8fd6a8;
        --border: #313a37;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
    padding: max(12px, env(safe-area-inset-top)) 16px 12px;
    background: var(--primary);
    color: var(--primary-text);
}

.brand { font-weight: 700; font-size: 1.1rem; color: inherit; text-decoration: none; }

.page {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
    display: grid;
    gap: 16px;
}

h1 { font-size: 1.4rem; margin: 0; line-height: 1.25; }
p { margin: 0; }
a { color: var(--primary); }

.muted { color: var(--muted); font-weight: 400; }
.danger { color: var(--danger); font-weight: 600; }
.success { color: var(--success); }
.back { text-decoration: none; font-weight: 600; }

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

.stack { display: grid; gap: 12px; }

label { font-weight: 600; }

input, select {
    font: inherit;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    width: 100%;
    min-height: 52px;
}

.button {
    display: flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-weight: 600;
    min-height: 56px;
    width: 100%;
    padding: 12px 20px;
    border: 0;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--primary-text);
    text-decoration: none;
    cursor: pointer;
}

.button:disabled { opacity: 0.6; }

.button-secondary {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--border);
}

.button-inline { width: auto; flex: none; }

.error { color: var(--danger); margin: 0; font-weight: 600; }

.alert {
    background: var(--danger-soft);
    color: var(--text);
    border-left: 4px solid var(--danger);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.alert ul, .summary { margin: 0; padding-left: 20px; }

/* Grands choix (accueil, logements, objets) */
.choices { display: grid; gap: 12px; }

.choice {
    display: grid;
    gap: 2px;
    padding: 18px 20px;
    min-height: 64px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
}

.choice:active { background: var(--primary-soft); }
.choice-title { font-weight: 700; font-size: 1.1rem; }
.choice-hint { color: var(--muted); font-size: 0.95rem; }
.choice-primary { border-left: 6px solid var(--primary); }

/* Lignes de saisie : nom à gauche, quantité à droite */
.lines { display: grid; gap: 8px; }

.line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.line.below { border-color: var(--danger); background: var(--danger-soft); }
.line.below .line-name { color: var(--danger); }
.line-label { display: grid; min-width: 0; }
.line-name { font-weight: 600; overflow-wrap: anywhere; }
.line-meta { color: var(--muted); font-size: 0.9rem; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.badge {
    background: var(--primary-soft);
    color: var(--primary);
    border-radius: 999px;
    padding: 0 8px;
    font-size: 0.8rem;
    font-weight: 600;
}

.stepper { display: flex; align-items: center; gap: 4px; flex: none; }

.stepper input {
    width: 64px;
    min-height: 48px;
    padding: 8px 4px;
    text-align: center;
    font-weight: 700;
    -moz-appearance: textfield;
}

.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.step {
    width: 48px;
    height: 48px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font: inherit;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.add { display: flex; gap: 8px; }
.add select { flex: 1; min-width: 0; }

.author { display: grid; gap: 6px; }
.author label { font-size: 0.95rem; }

/* Bouton de validation toujours visible en bas de l'écran */
.submit-bar {
    position: sticky;
    bottom: 0;
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(transparent, var(--bg) 30%);
}

.radios { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.radios legend { font-weight: 700; margin-bottom: 8px; padding: 0; }

.radio {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    min-height: 56px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-weight: 600;
}

.radio:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.radio input { width: 22px; height: 22px; min-height: 0; margin: 0; flex: none; accent-color: var(--primary); }
.radio .muted { margin-left: auto; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.table th:not(:first-child), .table td:not(:first-child) { text-align: right; }
.table tr.below td { color: var(--danger); font-weight: 600; }

h2 { font-size: 1.15rem; margin: 0; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 1rem; margin: 8px 0 0; }

.count {
    background: var(--primary-soft);
    color: var(--primary);
    border-radius: 999px;
    padding: 0 10px;
    font-size: 0.9rem;
}

.notice {
    background: var(--primary-soft);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.links { display: flex; flex-wrap: wrap; gap: 8px 16px; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.actions .button { flex: 1 1 140px; width: auto; }

/* Onglets de gestion, défilables sur téléphone */
.tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    margin: -4px -16px 0;
    padding: 0 16px 4px;
    scrollbar-width: none;
}

.tabs a {
    flex: none;
    padding: 8px 14px;
    border-radius: 999px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    border: 1px solid var(--border);
    background: var(--surface);
}

.tabs a[aria-current="page"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

/* Saisie de quantités en liste (achat, inventaire) */
fieldset.card { margin: 0; }
fieldset.card legend { font-weight: 700; padding: 0 4px; }

.entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-weight: 400;
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}

.entry:last-child { border-bottom: 0; }
.entry > span { display: grid; min-width: 0; }
.entry input { width: 96px; flex: none; text-align: center; font-weight: 700; min-height: 48px; padding: 8px; }

/* Journal */
.summary-toggle { font-weight: 700; cursor: pointer; }
details[open] .summary-toggle { margin-bottom: 12px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.filters label { display: grid; gap: 4px; font-size: 0.9rem; }
.filters-actions { display: flex; gap: 8px; align-items: end; grid-column: 1 / -1; }

.entries { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.entry-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    display: grid;
    gap: 2px;
}

.entry-row.cancelled { opacity: 0.6; }
.entry-row.cancelled .entry-main { text-decoration: line-through; }
.entry-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 0.9rem; }
.entry-main { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; }
.entry-meta { color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }

.link-button {
    background: none;
    border: 0;
    padding: 8px 0 0;
    color: var(--danger);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.table tfoot th { border-bottom: 0; }
.table tr.changed td { font-weight: 600; }

/* Référentiels */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-head .button { min-height: 44px; }
.rows li { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--border); }
.rows li:last-child { border-bottom: 0; }
.rows li a { font-weight: 600; }
.rows li.archived a { color: var(--muted); }
.button-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.allocation { display: grid; grid-template-columns: 1fr 72px 72px; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--border); }
.allocation:last-child { border-bottom: 0; }
.allocation-head { font-size: 0.85rem; font-weight: 600; }
.allocation > span { display: grid; min-width: 0; }
.allocation input { min-height: 48px; padding: 8px; text-align: center; font-weight: 700; }

.summary { list-style: none; padding: 0; }
.summary li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.summary li:last-child { border-bottom: 0; }
