:root {
    --bg: #f4f6f2;
    --card: #ffffff;
    --text: #22302a;
    --muted: #6d7a70;
    --line: #d9e0d8;
    --primary: #4f6b57;
    --primary-dark: #3a5140;
    --danger: #a3453b;
    --soft: #e9efe8;
    --shadow: 0 10px 30px rgba(34, 48, 42, 0.08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(1.4rem, 4vw, 2rem); }
h2 { font-size: clamp(1.15rem, 3vw, 1.45rem); }
h3 { font-size: 1rem; }
p { margin: .35rem 0 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem clamp(1rem, 4vw, 2rem);
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}
.topbar h1::first-letter { text-transform: uppercase; }
.topbar-actions { display: flex; align-items: center; gap: .6rem; flex: 0 0 auto; }

.lock-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255, 255, 255, .45);
    border-radius: 999px;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    cursor: pointer;
}
.lock-button:hover { background: rgba(255, 255, 255, .24); }
.lock-button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.container {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: 1rem;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: clamp(1rem, 3vw, 1.4rem);
    margin-bottom: 1rem;
}

.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}
.section-head.compact { align-items: center; margin-top: 1rem; }

.muted { color: var(--muted); }
.hidden { display: none !important; }

.button {
    appearance: none;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    border-radius: 999px;
    padding: .7rem 1rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 44px;
}
.button:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.button.secondary { background: var(--soft); color: var(--primary); }
.button.secondary:hover { background: #dbe6d9; }
.button.ghost { background: #fff; color: var(--primary); }
.button.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.button.danger:hover { background: #fdf3f2; }
.button:disabled { opacity: .55; cursor: not-allowed; }

.tabbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, .94);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
.tabs {
    display: flex;
    gap: .5rem;
    overflow-x: auto;
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: .6rem 1rem;
    scrollbar-width: thin;
}
.tab {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    border-radius: 999px;
    padding: .7rem 1rem;
    min-height: 44px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
.tab.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.admin-tab { display: none; }
.admin-tab.active { display: block; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin: 1rem 0;
}
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: 1fr 1fr auto; align-items: end; }

label { display: grid; gap: .35rem; font-weight: 700; }
input, select, textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: .65rem .75rem;
    font: inherit;
    background: #fff;
    color: var(--text);
}
textarea { resize: vertical; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.inline-actions { margin-bottom: 0; align-self: end; }
.sticky-actions {
    position: sticky;
    bottom: -1px;
    z-index: 5;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 -6px 18px rgba(34, 48, 42, .08);
    padding: .75rem;
    margin-top: 1rem;
}

.notice {
    border: 1px solid #f3ce73;
    background: #fff7df;
    color: #6b4e00;
    border-radius: 12px;
    padding: .8rem;
}

.list {
    display: grid;
    gap: .75rem;
}
.item-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: .85rem;
    display: grid;
    gap: .55rem;
    background: #fff;
}
.item-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}
.item-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: .2rem .55rem;
    font-size: .85rem;
    font-weight: 700;
    background: var(--soft);
    color: var(--primary);
}

.tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    margin-left: .35rem;
    padding: 0 .35rem;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: .78rem;
}
.tab.active .tab-count { background: #fff; color: var(--primary); }

.stock-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: .8rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--soft);
    margin-bottom: 1rem;
}
.stock-bar p { margin: 0; }

.stock-groups { display: grid; gap: 1.4rem; }
.stock-group .list { margin-top: .6rem; }
.group-title {
    padding-bottom: .35rem;
    border-bottom: 2px solid var(--line);
}
.group-title .muted { font-weight: 600; font-size: .9rem; }

.item-card.is-empty {
    border-color: #e3bcb6;
    background: #fdf7f6;
}

.stock-toggle {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 999px;
    overflow: hidden;
    background: #fff;
}
.stock-btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 700;
    padding: .55rem .9rem;
    min-height: 44px;
    cursor: pointer;
}
.stock-btn + .stock-btn { border-left: 1px solid var(--line); }
.stock-btn:hover { background: var(--soft); }
.stock-btn.ok[aria-pressed="true"] { background: #dfeee2; color: #33613f; }
.stock-btn.out[aria-pressed="true"] { background: #f7e2df; color: var(--danger); }

.checkbox-row {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .7rem .8rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--soft);
}
.checkbox-row input { width: 22px; min-height: 22px; height: 22px; margin: 0; flex: 0 0 auto; }

.shopping-block-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: 1.4rem;
}

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 650px; }
.data-table th, .data-table td { border-bottom: 1px solid var(--line); padding: .55rem; text-align: left; vertical-align: top; }
.data-table th { color: var(--muted); font-size: .9rem; }
.data-table input { min-width: 110px; }
.data-table .small-input { max-width: 120px; }
.ing-table { min-width: 820px; }
.ing-table select { min-width: 160px; }


/* ---- Accueil : le repas du jour, puis la semaine ---- */

.today-panel { margin-bottom: 1.6rem; }

.today-card {
    border: 1px solid var(--line);
    border-top: 5px solid var(--day, var(--primary));
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
}
.today-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    padding: .9rem 1.1rem;
    background: #fafbf9;
    background: color-mix(in srgb, var(--day, var(--primary)) 8%, #fff);
    border-bottom: 1px solid var(--line);
}
.today-head h3 { font-size: 1.15rem; }
.today-head h3::first-letter { text-transform: uppercase; }
.today-chip {
    display: inline-flex;
    align-items: center;
    height: 26px;
    padding: 0 .6rem;
    border-radius: 999px;
    background: var(--day, var(--primary));
    color: #fff;
    font-size: .8rem;
    font-weight: 700;
}

.today-slots { display: grid; grid-template-columns: 1fr 1fr; }
.today-slot { padding: 1.1rem; }
.today-slot + .today-slot { border-left: 1px solid var(--line); }
.today-meal {
    margin: .3rem 0 0;
    font-size: 1.2rem;
    font-weight: 800;
    line-height: 1.25;
}
.today-side { margin: .15rem 0 0; color: var(--day, var(--primary)); font-weight: 600; }
.today-people { margin: .45rem 0 0; color: var(--muted); font-size: .9rem; }

.week-head { margin-bottom: .8rem; }
.week-head h3 { font-size: 1rem; }
.week-head p { margin: .15rem 0 0; font-size: .9rem; }

.empty-note {
    margin: 0;
    padding: 1.1rem;
    border: 1px dashed var(--line);
    border-radius: 14px;
    background: #fbfcfa;
    color: var(--muted);
}

.week-agenda { display: grid; gap: .55rem; }

.agenda-row {
    display: grid;
    grid-template-columns: 168px 1fr 1fr;
    border: 1px solid var(--line);
    border-left: 5px solid var(--day, var(--line));
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
}
.agenda-row.today {
    border-color: var(--day, var(--primary));
    box-shadow: 0 0 0 2px var(--day, var(--primary));
}
.agenda-day {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: .1rem;
    padding: .75rem .9rem;
    background: #fafbf9;
    background: color-mix(in srgb, var(--day, var(--primary)) 7%, #fff);
}
.day-name { font-weight: 800; color: var(--day, var(--text)); text-transform: capitalize; }
.day-date { color: var(--muted); font-size: .85rem; }

.agenda-slot {
    display: grid;
    align-content: center;
    gap: .1rem;
    padding: .75rem .9rem;
    border-left: 1px solid var(--line);
}
.agenda-slot.empty .slot-meal { color: var(--muted); font-weight: 500; }
.slot-title { color: var(--muted); font-weight: 700; font-size: .78rem; }
.slot-meal { font-weight: 700; }
.slot-side { color: var(--day, var(--primary)); font-size: .9rem; }
.slot-people { color: var(--muted); font-size: .85rem; }

/* ---- Éditeur de menu : même agenda que l'accueil ---- */

.editor-row .agenda-slot { gap: .45rem; align-content: start; }
.editor-row .slot-title { margin-bottom: .1rem; }
.editor-row select,
.editor-row input {
    min-height: 42px;
    padding: .45rem .6rem;
    border-radius: 10px;
}
.editor-row .week-side { background: var(--soft); }
.slot-pair { display: grid; grid-template-columns: 1fr 78px; gap: .45rem; }
.slot-pair input { text-align: center; }

.shopping-table { margin-top: 1rem; }
.shopping-meta { margin-top: .75rem; }
.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    max-width: min(420px, calc(100vw - 2rem));
    background: #111827;
    color: #fff;
    border-radius: 14px;
    padding: .85rem 1rem;
    box-shadow: var(--shadow);
    z-index: 30;
}

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

.icon-button {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    border-radius: 999px;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}
.icon-button:hover { background: var(--soft); color: var(--text); }

.modal {
    width: min(760px, calc(100vw - 2rem));
    max-width: none;
    max-height: min(90vh, 920px);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--card);
    color: var(--text);
    box-shadow: 0 24px 60px rgba(15, 23, 42, .25);
    overflow: hidden;
}
.modal.narrow { width: min(520px, calc(100vw - 2rem)); }
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(15, 23, 42, .55); }
body:has(.modal[open]) { overflow: hidden; }

.modal-shell {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
}
.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: clamp(1rem, 3vw, 1.3rem);
    border-bottom: 1px solid var(--line);
}
.modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 clamp(1rem, 3vw, 1.3rem) clamp(1rem, 3vw, 1.3rem);
}
.modal-foot {
    display: flex;
    gap: .6rem;
    justify-content: flex-end;
    flex-wrap: wrap;
    padding: clamp(.8rem, 3vw, 1.1rem) clamp(1rem, 3vw, 1.3rem);
    border-top: 1px solid var(--line);
    background: var(--soft);
}

@media (max-width: 760px) {
    .modal {
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        margin: 0;
        border: none;
        border-radius: 0;
    }
    .modal-foot .button { flex: 1 1 auto; }

    .ing-table { min-width: 0; }
    .ing-table select { min-width: 0; }
    .ing-table thead { display: none; }
    .ing-table, .ing-table tbody, .ing-table tr, .ing-table td { display: block; }
    .ing-table tr {
        border: 1px solid var(--line);
        border-radius: 14px;
        padding: .75rem;
        margin-bottom: .75rem;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: .6rem;
    }
    .ing-table td { border: none; padding: 0; }
    .ing-table td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: .25rem;
        font-size: .8rem;
        font-weight: 700;
        color: var(--muted);
    }
    .ing-table td:nth-child(1),
    .ing-table td:nth-child(4),
    .ing-table td:nth-child(5),
    .ing-table td:nth-child(6) { grid-column: 1 / -1; }
    .ing-table .small-input { max-width: none; }
    .ing-table input { min-width: 0; }
}

@media (max-width: 760px) {
    .topbar { align-items: flex-start; }
    .section-head { flex-direction: column; align-items: stretch; }
    .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
    .inline-actions { align-self: stretch; }
    .inline-actions .button, .form-actions .button { flex: 1 1 auto; }
    .item-row { flex-direction: column; }
    .stock-bar { flex-direction: column; align-items: stretch; }
    .stock-toggle { width: 100%; }
    .stock-btn { flex: 1 1 0; }
    .item-actions { justify-content: flex-start; width: 100%; }
    .today-slots { grid-template-columns: 1fr; }
    .today-slot + .today-slot { border-left: 0; border-top: 1px solid var(--line); }
    .agenda-row { grid-template-columns: 1fr; }
    .agenda-day { flex-direction: row; align-items: baseline; justify-content: flex-start; gap: .4rem; }
    .agenda-slot { border-left: 0; border-top: 1px solid var(--line); }
}

@media print {
    body { background: #fff; }
    .topbar, #authPanel, #homeSection, .tabbar, .tabs, #mealsTab, #sidesTab, #stockTab, #menuTab, #logoutBtn, .form-grid, .button, .toast, dialog { display: none !important; }
    #adminPanel, #shoppingTab { display: block !important; }
    .card { box-shadow: none; border: none; padding: 0; }
}
