:root {
    --brown: #3A261D;
    --pink: #E0BCB1;
    --beige: #F5F0EB;
    --gold: #C9A96E;
    --white: #ffffff;
    --text: #2b211d;
    --muted: #7c6d66;
    --border: #e7ddd7;
    --danger: #b3261e;
    --warning: #a76500;
    --ok: #227a44;
    --shadow: 0 10px 30px rgba(58, 38, 29, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Open Sans", Calibri, Arial, sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, var(--beige) 0%, #fff 45%);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 16px 22px;
    background: rgba(255,255,255,.92);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
}

.brand {
    font-family: Georgia, "Times New Roman", serif;
    color: var(--brown);
    font-size: 25px;
    font-weight: 700;
    letter-spacing: .2px;
}

.subtitle {
    color: var(--muted);
    font-size: 13px;
    margin-top: 2px;
}

.nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav a {
    color: var(--brown);
    text-decoration: none;
    padding: 9px 13px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: transparent;
    font-weight: 600;
    font-size: 14px;
}

.nav a.active, .nav a:hover {
    border-color: var(--pink);
    background: var(--beige);
}

.container {
    width: min(1180px, calc(100% - 28px));
    margin: 22px auto 70px;
}

.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 18px;
}

.card.tight { padding: 15px; }

h1, h2, h3 {
    font-family: Georgia, "Times New Roman", serif;
    color: var(--brown);
    margin: 0 0 14px;
}

h1 { font-size: 31px; }
h2 { font-size: 23px; }
h3 { font-size: 18px; }

.small { font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }

.toolbar {
    display: flex;
    align-items: end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 170px;
}

label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 700;
}

input, select, textarea, button {
    font: inherit;
}

input[type="text"], input[type="date"], input[type="number"], select, textarea, input[type="password"] {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 13px;
    background: #fff;
    color: var(--text);
    outline: none;
}

textarea { min-height: 86px; resize: vertical; }

input:focus, select:focus, textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 4px rgba(201,169,110,.18);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--brown);
    background: var(--brown);
    color: white;
    padding: 12px 16px;
    border-radius: 14px;
    cursor: pointer;
    text-decoration: none;
    font-weight: 700;
    min-height: 45px;
}

.btn.secondary {
    background: #fff;
    color: var(--brown);
    border-color: var(--border);
}

.btn.pink {
    background: var(--pink);
    color: var(--brown);
    border-color: var(--pink);
}

.btn.danger {
    background: #fff;
    color: var(--danger);
    border-color: #f1cbc7;
}

.btn.small-btn { padding: 8px 11px; min-height: 36px; border-radius: 12px; font-size: 13px; }

.hidden-form { display: none; }

.btn:active { transform: translateY(1px); }

.notice {
    padding: 13px 15px;
    border-radius: 16px;
    margin-bottom: 16px;
    background: #fff7ea;
    border: 1px solid #f0d5a7;
    color: #654313;
}

.notice.success {
    background: #edf9f2;
    border-color: #bee8cf;
    color: #195b32;
}

.notice.danger {
    background: #fff0ef;
    border-color: #f3c3bf;
    color: var(--danger);
}

.sheet-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 10px 0 18px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    background: var(--beige);
    color: var(--brown);
    border: 1px solid var(--border);
}

.badge.validated, .badge.ok { background: #eaf7ee; color: var(--ok); border-color: #bee8cf; }
.badge.draft, .badge.warning { background: #fff5e5; color: var(--warning); border-color: #efcf9a; }
.badge.danger { background: #ffedeb; color: var(--danger); border-color: #f2beb9; }

.category-block {
    margin: 0 0 22px;
}

.category-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 18px 0 10px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.grid-header, .product-row {
    display: grid;
    grid-template-columns: minmax(190px, 1.5fr) 170px 170px minmax(180px, 1fr);
    gap: 10px;
    align-items: center;
}

.grid-header {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    padding: 0 12px 7px;
}

.product-row {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 10px 12px;
    margin-bottom: 8px;
}

.product-name {
    font-weight: 800;
    color: var(--brown);
}

.product-unit {
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
}

.qty-control {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    gap: 6px;
}

.qty-control button {
    height: 46px;
    border: 1px solid var(--border);
    background: var(--beige);
    border-radius: 13px;
    color: var(--brown);
    font-weight: 900;
    font-size: 20px;
    cursor: pointer;
}

.qty-control input {
    text-align: center;
    font-weight: 800;
    font-size: 18px;
    padding: 8px 6px;
}

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
}

th, td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1.4fr;
    gap: 18px;
    align-items: start;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.form-grid .full { grid-column: 1 / -1; }

.checkbox-line {
    display: flex;
    gap: 8px;
    align-items: center;
    padding-top: 28px;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(430px, 100%);
}

.export-box {
    width: 100%;
    min-height: 360px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre-wrap;
}

@media (max-width: 900px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .nav { justify-content: flex-start; width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
    .grid-header { display: none; }
    .product-row { grid-template-columns: 1fr; }
    .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .container { width: min(100% - 18px, 1180px); margin-top: 12px; }
    .card { padding: 16px; border-radius: 18px; }
    h1 { font-size: 25px; }
    .form-grid { grid-template-columns: 1fr; }
    .toolbar { align-items: stretch; }
    .toolbar .field, .toolbar .btn { width: 100%; }
}

/* V3 - Saisie compacte en grille */
.rest-entry-card {
    padding-top: 18px;
}

.saisie-tools {
    position: sticky;
    top: 76px;
    z-index: 12;
    display: grid;
    grid-template-columns: minmax(220px, 330px) 1fr auto;
    gap: 14px;
    align-items: end;
    padding: 14px;
    margin: -2px 0 20px;
    background: rgba(255,255,255,.96);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 8px 24px rgba(58, 38, 29, .06);
    backdrop-filter: blur(10px);
}

.category-filter {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.filter-chip {
    white-space: nowrap;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--brown);
    border-radius: 999px;
    padding: 9px 12px;
    font-weight: 800;
    cursor: pointer;
}

.filter-chip.active,
.filter-chip:hover {
    background: var(--beige);
    border-color: var(--pink);
}

.saisie-actions {
    display: flex;
    flex-direction: column;
    gap: 7px;
    align-items: flex-end;
    justify-content: flex-end;
    min-width: 135px;
}

.compact-category {
    margin: 0 0 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: #fffdfc;
    overflow: hidden;
}

.compact-category[hidden] { display: none; }

.compact-summary {
    cursor: pointer;
    margin: 0;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #fff, var(--beige));
    list-style: none;
}

.compact-summary::-webkit-details-marker { display: none; }

.compact-summary h2 {
    margin-bottom: 2px;
}

.summary-arrow {
    font-size: 22px;
    font-weight: 900;
    color: var(--brown);
    transition: transform .15s ease;
}

.compact-category:not([open]) .summary-arrow {
    transform: rotate(-90deg);
}

.product-compact-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    padding: 12px;
}

.product-card-compact {
    border: 1px solid var(--border);
    border-radius: 17px;
    background: #fff;
    padding: 10px;
    min-width: 0;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.product-card-compact.has-qty {
    border-color: var(--gold);
    background: #fffaf2;
    box-shadow: 0 6px 18px rgba(201,169,110,.13);
}

.product-card-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 132px;
    gap: 9px;
    align-items: center;
}

.product-info-compact {
    min-width: 0;
}

.product-info-compact .product-name {
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.compact-qty {
    grid-template-columns: 34px 1fr 34px;
    gap: 4px;
}

.compact-qty button {
    height: 39px;
    border-radius: 11px;
    font-size: 18px;
}

.compact-qty input {
    height: 39px;
    min-width: 0;
    border-radius: 11px;
    padding: 6px 3px;
    font-size: 17px;
}

.product-extra {
    display: grid;
    grid-template-columns: 42px 1fr;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.product-extra label {
    font-size: 12px;
}

.product-extra input[type="date"] {
    padding: 9px 10px;
    border-radius: 12px;
}

.mini-note {
    margin-top: 6px;
}

.mini-note summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    list-style: none;
    user-select: none;
}

.mini-note summary::-webkit-details-marker { display: none; }

.mini-note summary::before {
    content: "+ ";
    color: var(--gold);
}

.mini-note[open] summary::before {
    content: "− ";
}

.mini-note input {
    margin-top: 6px;
    padding: 9px 10px;
    border-radius: 12px;
}

.save-bar {
    position: sticky;
    bottom: 12px;
    z-index: 11;
    align-items: end;
    padding: 12px;
    margin: 18px -4px 0;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255,255,255,.96);
    box-shadow: 0 -8px 24px rgba(58, 38, 29, .08);
    backdrop-filter: blur(10px);
}

.validated-field {
    min-width: 230px;
}

@media (max-width: 1160px) {
    .product-compact-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .saisie-tools {
        top: 116px;
        grid-template-columns: 1fr;
        align-items: stretch;
    }
    .saisie-actions { align-items: stretch; }
    .product-compact-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 650px) {
    .saisie-tools { position: static; }
    .product-compact-grid { grid-template-columns: 1fr; padding: 9px; }
    .product-card-main { grid-template-columns: 1fr; }
    .compact-qty { grid-template-columns: 44px 1fr 44px; }
    .compact-qty button, .compact-qty input { height: 44px; }
    .save-bar { position: static; }
}

/* V4 - Saisie optimisée iPad + production récap */
.container {
    width: min(1400px, calc(100% - 24px));
}

.saisie-tools.no-search {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
}

.saisie-tools.no-search .category-filter-field {
    min-width: 0;
}

.saisie-tools.no-search .category-filter {
    max-width: 100%;
}

.edit-hint {
    color: var(--warning);
    font-weight: 700;
}

.product-compact-grid {
    grid-template-columns: repeat(auto-fit, minmax(245px, 1fr));
    gap: clamp(8px, 1vw, 14px);
}

.product-card-compact {
    min-height: 92px;
}

.product-card-main {
    grid-template-columns: minmax(0, 1fr) minmax(128px, 142px);
}

.compact-qty button,
.compact-qty input {
    min-height: 42px;
}

.save-bar .btn {
    white-space: nowrap;
}

.production-category-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 9px;
}

.production-category-title h2 {
    margin: 0;
}

.production-count {
    background: var(--beige);
}

.production-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px;
}

.production-item {
    border: 1px solid var(--border);
    border-radius: 17px;
    padding: 13px;
    background: #fff;
}

.production-item-main {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.production-item-main strong {
    color: var(--brown);
    overflow-wrap: anywhere;
}

.production-qty {
    flex: 0 0 auto;
    border-radius: 999px;
    background: var(--beige);
    color: var(--brown);
    border: 1px solid var(--border);
    padding: 5px 9px;
    font-weight: 900;
    font-size: 14px;
}

.production-detail,
.production-note {
    margin-top: 9px;
    color: var(--muted);
    font-size: 13px;
}

.production-detail {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

@media (min-width: 1180px) {
    .product-compact-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
    .production-summary-grid {
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    }
}

@media (min-width: 760px) and (max-width: 1180px) {
    .topbar {
        padding: 12px 16px;
        gap: 12px;
    }
    .brand { font-size: 22px; }
    .container {
        width: min(100% - 20px, 1120px);
        margin-top: 14px;
    }
    .card {
        padding: 17px;
        border-radius: 20px;
    }
    .saisie-tools {
        top: 68px;
    }
    .saisie-tools.no-search {
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 11px;
    }
    .saisie-actions {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    .product-compact-grid {
        grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
        padding: 10px;
    }
    .product-card-main {
        grid-template-columns: minmax(0, 1fr) 132px;
    }
    .save-bar {
        bottom: 8px;
        display: grid;
        grid-template-columns: auto minmax(190px, 1fr) auto auto;
        gap: 8px;
        align-items: end;
    }
    .save-bar .btn {
        padding-left: 12px;
        padding-right: 12px;
    }
}

@media (max-width: 760px) {
    .saisie-tools.no-search {
        grid-template-columns: 1fr;
    }
    .saisie-actions {
        align-items: stretch;
    }
    .product-compact-grid {
        grid-template-columns: 1fr;
    }
    .product-card-main {
        grid-template-columns: 1fr;
    }
    .production-summary-grid {
        grid-template-columns: 1fr;
    }
}

/* V7 - Production : quantité collée au nom du produit */
.production-item-main {
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.production-qty {
    margin-left: 0;
}

/* V8 - Produits : liste regroupée par catégories */
.admin-section-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.admin-section-title h2 {
    margin-bottom: 4px;
}

.admin-category-block {
    border: 1px solid var(--border);
    border-radius: 20px;
    background: #fff;
    margin: 0 0 14px;
    overflow: hidden;
}

.admin-category-block[open] {
    box-shadow: 0 8px 18px rgba(58, 38, 29, .04);
}

.admin-category-summary {
    margin: 0;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    background: rgba(245, 240, 235, .45);
}

.admin-category-summary h3 {
    margin: 0;
    font-size: 22px;
}

.admin-product-list {
    display: grid;
    gap: 10px;
    padding: 12px;
}

.admin-product-card {
    display: grid;
    grid-template-columns: minmax(240px, 1.4fr) minmax(190px, 1fr) minmax(95px, .45fr) auto auto auto;
    gap: 10px;
    align-items: end;
    border: 1px solid var(--border);
    border-radius: 17px;
    padding: 12px;
    background: #fff;
}

.admin-product-card .field label {
    font-size: 10px;
}

.admin-product-name input {
    font-weight: 800;
}

.admin-product-card .small-field input {
    min-width: 78px;
}

.admin-check {
    padding-top: 0;
    align-self: center;
    white-space: nowrap;
    font-weight: 800;
    color: var(--brown);
}

.admin-delete-cell {
    align-self: center;
}

.admin-save-bar {
    position: sticky;
    bottom: 12px;
    z-index: 20;
    justify-content: flex-end;
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 10px;
    margin-top: 14px;
}

@media (max-width: 1150px) {
    .admin-product-card {
        grid-template-columns: minmax(220px, 1.3fr) minmax(180px, 1fr) minmax(90px, .45fr);
    }
    .admin-check,
    .admin-delete-cell {
        align-self: end;
    }
}

@media (max-width: 760px) {
    .admin-section-title {
        flex-direction: column;
        align-items: stretch;
    }
    .admin-product-card {
        grid-template-columns: 1fr;
    }
    .admin-check,
    .admin-delete-cell {
        align-self: stretch;
    }
    .admin-delete-cell .btn {
        width: 100%;
    }
}

/* V10 - Catégorie Sélection / onglet À faire */
.selection-category .compact-summary {
    background: linear-gradient(180deg, #fffaf7, #f8eee9);
}

.selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
    padding: 12px;
}

.selection-card {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 17px;
    background: #fff;
    padding: 14px;
    cursor: pointer;
    min-height: 58px;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}

.selection-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.selection-box {
    width: 28px;
    height: 28px;
    border-radius: 9px;
    border: 2px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    font-weight: 900;
    flex: 0 0 auto;
    background: #fff;
}

.selection-name {
    color: var(--brown);
    font-weight: 900;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.selection-card.is-selected {
    border-color: var(--gold);
    background: #fffaf2;
    box-shadow: 0 6px 18px rgba(201,169,110,.13);
}

.selection-card.is-selected .selection-box {
    background: var(--brown);
    border-color: var(--brown);
    color: #fff;
}

.todo-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px;
}

.todo-item {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 17px;
    background: #fffaf2;
    padding: 14px;
}

.todo-check {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--brown);
    color: #fff;
    font-weight: 900;
    flex: 0 0 auto;
}

.todo-item strong {
    color: var(--brown);
    overflow-wrap: anywhere;
}

@media (min-width: 760px) and (max-width: 1180px) {
    .selection-grid,
    .todo-list {
        grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    }
}

@media (max-width: 760px) {
    .selection-grid,
    .todo-list {
        grid-template-columns: 1fr;
    }
}

/* V12 - Sélection en bas de saisie + clic direct + commentaire */
.selection-bottom {
    margin-top: 18px;
    border: 2px solid rgba(201,169,110,.35);
}

.selection-card {
    position: relative;
    min-height: 66px;
    padding: 16px;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.selection-card:focus-visible {
    outline: 3px solid rgba(201,169,110,.45);
    outline-offset: 3px;
}

.selection-card input {
    width: 1px;
    height: 1px;
}

.selection-comment-field {
    border-top: 1px solid var(--border);
    padding: 14px 16px 16px;
    display: grid;
    gap: 7px;
}

.selection-comment-field label {
    font-weight: 900;
    color: var(--brown);
}

.selection-comment-field textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px 14px;
    font: inherit;
    color: var(--text);
    background: #fff;
    resize: vertical;
    min-height: 78px;
}

.selection-comment-field textarea:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201,169,110,.18);
}

.todo-comment-item {
    align-items: flex-start;
}

.todo-comment-text {
    margin-top: 4px;
    color: var(--text);
    line-height: 1.35;
    overflow-wrap: anywhere;
}

/* V14 - Ordre manuel des catégories */
.category-sort-list {
    display: grid;
    gap: 10px;
}

.category-sort-row {
    display: grid;
    grid-template-columns: auto minmax(180px, 1fr) auto auto;
    gap: 10px;
    align-items: end;
    border: 1px solid var(--border);
    border-radius: 17px;
    background: #fff;
    padding: 10px;
    transition: box-shadow .15s ease, transform .15s ease, opacity .15s ease;
}

.category-sort-row.is-dragging {
    opacity: .82;
    box-shadow: 0 14px 32px rgba(58, 38, 29, .16);
    transform: scale(.995);
    z-index: 40;
}

.drag-handle {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--beige);
    color: var(--brown);
    cursor: grab;
    font-weight: 900;
    font-size: 20px;
    touch-action: none;
    align-self: center;
}

.drag-handle:active {
    cursor: grabbing;
}

.category-sort-name label {
    font-size: 10px;
}

.category-sort-active {
    padding-top: 0;
    align-self: center;
    white-space: nowrap;
    font-weight: 800;
}

@media (max-width: 760px) {
    .category-sort-row {
        grid-template-columns: auto 1fr;
        align-items: center;
    }

    .category-sort-name,
    .category-sort-row .btn {
        grid-column: 1 / -1;
    }

    .category-sort-active {
        justify-content: flex-start;
    }
}

/* V15 - Saisie : barre de validation plus compacte */
.save-bar {
    padding: 8px 10px;
    margin-top: 12px;
    border-radius: 15px;
    gap: 8px;
}

.validated-field-compact {
    min-width: 170px;
}

.validated-field-compact select {
    padding: 9px 11px;
    border-radius: 12px;
    min-height: 40px;
}

.validated-field-compact .small {
    display: none;
}

.save-bar .btn {
    min-height: 40px;
    padding-top: 9px;
    padding-bottom: 9px;
}

@media (min-width: 760px) and (max-width: 1180px) {
    .save-bar {
        grid-template-columns: auto minmax(160px, 220px) auto auto;
        align-items: center;
        padding: 8px 9px;
    }
}

@media (max-width: 760px) {
    .save-bar {
        padding: 10px;
    }
    .validated-field-compact {
        min-width: 0;
    }
}

/* V16 - Produit terminé aujourd'hui + réaffichage */
.hidden-today-card {
    scroll-margin-top: 96px;
}

.hidden-today-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    list-style: none;
}

.hidden-today-summary::-webkit-details-marker {
    display: none;
}

.hidden-today-summary::after {
    content: "⌄";
    color: var(--brown);
    font-size: 20px;
    font-weight: 900;
}

.hidden-today-card:not([open]) .hidden-today-summary::after {
    transform: rotate(-90deg);
}

.restore-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 10px;
    margin: 12px 0;
}

.restore-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: #fff;
    cursor: pointer;
}

.restore-item input {
    width: 18px;
    height: 18px;
    accent-color: var(--brown);
}

.restore-item span {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.restore-item small {
    color: var(--muted);
}

.product-card-compact {
    position: relative;
    padding-bottom: 25px;
}

.finished-today-toggle {
    position: absolute;
    right: 9px;
    bottom: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--beige);
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    user-select: none;
}

.finished-today-toggle input {
    width: 11px;
    height: 11px;
    margin: 0;
    accent-color: var(--brown);
}

.product-card-compact.is-finished-today {
    opacity: .68;
    border-style: dashed;
    background: #fbf7f4;
}

.product-card-compact.is-finished-today .finished-today-toggle {
    color: var(--brown);
    border-color: var(--pink);
    background: #fff;
}

@media (max-width: 650px) {
    .product-card-compact {
        padding-bottom: 28px;
    }

    .finished-today-toggle {
        bottom: 10px;
        font-size: 10px;
        padding: 3px 6px;
    }
}


/* V18 - ajuste la case Finis aujourd'hui dans Saisie */


/* V20 - Remarque sous la case Finis aujourd'hui */
.product-card-compact {
    padding-bottom: 10px;
}

.product-card-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    margin-top: 6px;
}

.product-card-actions .finished-today-toggle {
    position: static;
    right: auto;
    bottom: auto;
    align-self: flex-end;
    width: fit-content;
}

.product-card-actions .mini-note {
    margin-top: 0;
    align-self: flex-end;
    width: auto;
}

.product-card-actions .mini-note summary {
    text-align: right;
}

.product-card-actions .mini-note[open] {
    align-self: stretch;
    width: 100%;
}

.product-card-actions .mini-note[open] summary {
    text-align: right;
}

.product-card-actions .mini-note input {
    width: 100%;
}

@media (max-width: 650px) {
    .product-card-compact {
        padding-bottom: 10px;
    }
}

/* V21 - Finis aujourd'hui à gauche et Remarque à droite sur la même ligne */
.product-card-actions {
    display: grid;
    grid-template-columns: auto auto;
    align-items: center;
    justify-content: space-between;
    column-gap: 8px;
    row-gap: 4px;
    margin-top: 6px;
}

.product-card-actions .finished-today-toggle {
    position: static;
    right: auto;
    bottom: auto;
    grid-column: 1;
    justify-self: start;
    align-self: center;
    width: fit-content;
}

.product-card-actions .mini-note {
    grid-column: 2;
    justify-self: end;
    align-self: center;
    width: auto;
    margin-top: 0;
}

.product-card-actions .mini-note summary {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    min-height: 24px;
    text-align: right;
}

.product-card-actions .mini-note[open] {
    grid-column: 1 / -1;
    justify-self: stretch;
    align-self: stretch;
    width: 100%;
}

.product-card-actions .mini-note[open] summary {
    justify-content: flex-end;
    width: 100%;
}

.product-card-actions .mini-note input {
    width: 100%;
}

/* V22 - Optimisation hauteur des cartes produit dans Saisie */
.product-card-compact {
    min-height: 0;
    padding: 8px 10px 8px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.product-card-main {
    align-items: start;
}

.product-info-compact .product-name {
    margin-bottom: 2px;
}

.compact-qty button,
.compact-qty input {
    min-height: 38px;
    height: 38px;
}

.product-card-actions {
    margin-top: 5px;
    line-height: 1;
}

.product-card-actions .finished-today-toggle {
    padding: 2px 5px;
    font-size: 9px;
}

.product-card-actions .finished-today-toggle input {
    width: 10px;
    height: 10px;
}

.product-card-actions .mini-note summary {
    min-height: 18px;
    font-size: 11px;
}

.product-card-actions .mini-note input {
    margin-top: 5px;
    padding: 8px 9px;
}

.product-extra {
    margin-top: 5px;
}

@media (max-width: 650px) {
    .product-card-compact {
        padding: 8px 9px;
    }

    .compact-qty button,
    .compact-qty input {
        min-height: 38px;
        height: 38px;
    }
}

/* PATCH V24 - Filtre catégorie dans Produits */
.admin-filter-bar {
    align-items: flex-end;
    justify-content: flex-start;
    gap: 12px;
    margin: 0 0 16px;
}

.admin-filter-bar .field {
    min-width: 280px;
    max-width: 420px;
    margin: 0;
}

.admin-filter-bar select {
    width: 100%;
}

@media (max-width: 640px) {
    .admin-filter-bar .field {
        min-width: 100%;
        max-width: none;
    }
}

/* Patch V25 - Historique / plats */
.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    align-items: center;
}
.inline-form {
    display: inline-flex;
    margin: 0;
}
.history-complete-group {
    padding: 12px 0 16px;
    border-top: 1px solid var(--border);
}
.history-complete-group:first-of-type {
    border-top: 0;
    padding-top: 0;
}
.history-complete-group h3 {
    margin: 0 0 10px;
    font-size: 18px;
}
.dish-card .production-detail {
    margin-top: 8px;
}
@media (max-width: 760px) {
    .table-actions .btn,
    .table-actions .inline-form {
        width: 100%;
    }
    .table-actions .inline-form .btn {
        width: 100%;
    }
}

/* PATCH V27 - Optimisation responsive iPad / smartphone / PC */
:root {
    --page-x: clamp(10px, 1.8vw, 26px);
    --card-radius-responsive: clamp(15px, 2vw, 22px);
    --sticky-offset: 84px;
    --touch-size: 42px;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100svh;
}

.topbar {
    padding: clamp(8px, 1.5vw, 16px) var(--page-x);
}

.nav {
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.nav::-webkit-scrollbar,
.category-filter::-webkit-scrollbar {
    display: none;
}

.nav a,
.filter-chip,
.btn,
.qty-control button,
.selection-card,
.restore-item,
.drag-handle {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.container {
    width: min(1600px, calc(100% - (var(--page-x) * 2)));
    margin-top: clamp(10px, 1.7vw, 22px);
    margin-bottom: calc(80px + env(safe-area-inset-bottom));
}

.card {
    border-radius: var(--card-radius-responsive);
    padding: clamp(14px, 1.8vw, 22px);
}

.saisie-tools {
    top: calc(var(--sticky-offset) + 8px);
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
}

.category-filter {
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
}

.filter-chip {
    scroll-snap-align: start;
}

.compact-category,
.hidden-today-card {
    scroll-margin-top: calc(var(--sticky-offset) + 78px);
}

.product-compact-grid,
.production-summary-grid,
.selection-grid,
.todo-list,
.restore-grid {
    grid-template-columns: repeat(auto-fill, minmax(var(--grid-card-min, 260px), 1fr));
}

.product-card-compact,
.production-item,
.selection-card,
.todo-item,
.restore-item {
    min-width: 0;
}

.product-card-main {
    grid-template-columns: minmax(0, 1fr) minmax(118px, 138px);
    gap: 8px;
}

.product-info-compact .product-name,
.production-item-main strong,
.selection-name,
.todo-item strong {
    word-break: normal;
    overflow-wrap: anywhere;
    hyphens: auto;
}

.save-bar {
    bottom: calc(10px + env(safe-area-inset-bottom));
}

.table-wrap {
    -webkit-overflow-scrolling: touch;
}

/* PC large : plus d’espace, plus de colonnes, navigation sur une seule ligne */
@media (min-width: 1280px) {
    :root {
        --grid-card-min: 280px;
        --touch-size: 40px;
    }

    .topbar {
        flex-direction: row;
        align-items: center;
    }

    .nav {
        flex-wrap: wrap;
        justify-content: flex-end;
        overflow: visible;
    }

    .product-compact-grid {
        gap: 12px;
    }

    .compact-qty button,
    .compact-qty input {
        height: 38px;
        min-height: 38px;
    }

    .save-bar {
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
}

/* iPad paysage / petites machines : 3 colonnes confortables */
@media (min-width: 1024px) and (max-width: 1279px) {
    :root {
        --grid-card-min: 300px;
        --touch-size: 44px;
    }

    .topbar {
        gap: 12px;
    }

    .brand {
        font-size: 22px;
    }

    .nav a {
        padding: 8px 11px;
        font-size: 13px;
    }

    .saisie-tools.no-search {
        grid-template-columns: 1fr auto;
        padding: 10px;
    }

    .product-card-main {
        grid-template-columns: minmax(0, 1fr) 128px;
    }

    .compact-qty {
        grid-template-columns: 34px 1fr 34px;
    }

    .compact-qty button,
    .compact-qty input {
        height: 40px;
        min-height: 40px;
    }

    .save-bar {
        display: grid;
        grid-template-columns: auto minmax(170px, 230px) auto auto;
        gap: 8px;
        align-items: center;
    }
}

/* iPad portrait : 2 colonnes, menus faciles au doigt */
@media (min-width: 700px) and (max-width: 1023px) {
    :root {
        --grid-card-min: 310px;
        --touch-size: 46px;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .brand {
        font-size: 22px;
    }

    .subtitle {
        font-size: 12px;
    }

    .nav {
        width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
        padding-bottom: 2px;
    }

    .nav a {
        flex: 0 0 auto;
        padding: 9px 12px;
    }

    .container {
        width: calc(100% - 20px);
    }

    .saisie-tools,
    .saisie-tools.no-search {
        top: calc(var(--sticky-offset) + 6px);
        grid-template-columns: 1fr;
        gap: 9px;
        padding: 10px;
    }

    .saisie-actions {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .product-card-main {
        grid-template-columns: minmax(0, 1fr) 132px;
    }

    .compact-qty button,
    .compact-qty input {
        height: var(--touch-size);
        min-height: var(--touch-size);
    }

    .save-bar {
        display: grid;
        grid-template-columns: auto minmax(150px, 220px) auto auto;
        gap: 7px;
        align-items: center;
        padding: 8px;
    }

    .save-bar .btn {
        padding-left: 10px;
        padding-right: 10px;
    }

    .admin-grid {
        grid-template-columns: 1fr;
    }
}

/* Smartphone : une seule colonne, barre d’action utilisable au pouce */
@media (max-width: 699px) {
    :root {
        --grid-card-min: 100%;
        --touch-size: 46px;
        --page-x: 9px;
    }

    .topbar {
        position: sticky;
        flex-direction: column;
        align-items: stretch;
        gap: 7px;
        padding-top: calc(7px + env(safe-area-inset-top));
        padding-bottom: 7px;
    }

    .brand {
        font-size: 20px;
        line-height: 1.05;
    }

    .subtitle {
        display: none;
    }

    .nav {
        width: 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
        gap: 6px;
        padding-bottom: 1px;
    }

    .nav a {
        flex: 0 0 auto;
        padding: 8px 10px;
        font-size: 13px;
        min-height: 36px;
    }

    .container {
        width: calc(100% - 14px);
        margin-top: 9px;
        margin-bottom: calc(18px + env(safe-area-inset-bottom));
    }

    .card {
        padding: 12px;
        margin-bottom: 12px;
        border-radius: 16px;
    }

    h1 { font-size: 23px; }
    h2 { font-size: 19px; }
    h3 { font-size: 17px; }

    .toolbar {
        gap: 8px;
        align-items: stretch;
    }

    .toolbar .field,
    .toolbar .btn,
    .toolbar a.btn {
        width: 100%;
    }

    input[type="text"],
    input[type="date"],
    input[type="number"],
    select,
    textarea,
    input[type="password"] {
        min-height: var(--touch-size);
        padding: 10px 11px;
        border-radius: 12px;
        font-size: 16px; /* évite le zoom iPhone */
    }

    .saisie-tools,
    .saisie-tools.no-search {
        position: sticky;
        top: calc(var(--sticky-offset) + 5px);
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 8px;
        border-radius: 14px;
        margin-bottom: 12px;
    }

    .filter-chip {
        padding: 8px 10px;
        font-size: 13px;
    }

    .saisie-actions {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }

    .compact-summary {
        padding: 11px 12px;
    }

    .product-compact-grid {
        padding: 8px;
        gap: 8px;
    }

    .product-card-main {
        grid-template-columns: minmax(0, 1fr) minmax(128px, 42%);
        align-items: center;
    }

    .compact-qty {
        grid-template-columns: 40px 1fr 40px;
    }

    .compact-qty button,
    .compact-qty input {
        height: var(--touch-size);
        min-height: var(--touch-size);
    }

    .product-extra {
        grid-template-columns: 34px 1fr;
    }

    .product-card-actions {
        margin-top: 6px;
    }

    .finished-today-toggle {
        font-size: 10px;
        padding: 3px 6px;
    }

    .selection-grid,
    .todo-list,
    .restore-grid,
    .production-summary-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .selection-card,
    .todo-item,
    .restore-item,
    .production-item {
        padding: 11px 12px;
        border-radius: 15px;
    }

    .save-bar {
        position: sticky;
        bottom: calc(6px + env(safe-area-inset-bottom));
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 7px;
        padding: 8px;
        margin: 12px -2px 0;
        border-radius: 15px;
        z-index: 30;
    }

    .save-bar .validated-field-compact {
        grid-column: 1 / -1;
        order: 1;
        min-width: 0;
    }

    .save-bar button[name="action"][value="save"] {
        order: 2;
    }

    .save-bar button[name="action"][value="validate"] {
        order: 3;
    }

    .save-bar a.btn {
        grid-column: 1 / -1;
        order: 4;
    }

    .save-bar .btn {
        width: 100%;
        min-height: 40px;
        padding: 8px 9px;
        font-size: 13px;
        white-space: normal;
    }

    .admin-product-card,
    .category-sort-row,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .admin-filter-bar .field {
        min-width: 0;
    }

    .table-wrap {
        margin-left: -4px;
        margin-right: -4px;
    }

    th,
    td {
        padding: 10px 8px;
    }
}

/* Très petits téléphones */
@media (max-width: 420px) {
    .product-card-main {
        grid-template-columns: 1fr;
        gap: 7px;
    }

    .compact-qty {
        grid-template-columns: 42px 1fr 42px;
    }

    .product-name {
        font-size: 14px;
    }

    .save-bar {
        grid-template-columns: 1fr;
    }

    .save-bar .validated-field-compact,
    .save-bar a.btn {
        grid-column: auto;
    }
}

/* Optimisation des appareils tactiles */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .filter-chip,
    .nav a {
        min-height: 40px;
    }

    .qty-control button,
    .selection-card,
    .restore-item,
    .drag-handle {
        min-height: 44px;
    }

    details > summary {
        touch-action: manipulation;
    }
}

/* Impression éventuelle depuis PC : évite les barres collantes */
@media print {
    .topbar,
    .saisie-tools,
    .save-bar,
    .toolbar,
    .btn {
        display: none !important;
    }

    .container {
        width: 100%;
        margin: 0;
    }

    .card,
    .compact-category,
    .production-item {
        box-shadow: none;
        break-inside: avoid;
    }
}
