/* Back-office de la caisse de cantine — mêmes couleurs que le prototype de caisse. */
:root {
    --bg: #E8E6E0;
    --panel: #F7F6F2;
    --surface: #FFFFFF;
    --ink: #1A1D1B;
    --muted: #5A605C;
    --line: #D9D6CE;
    --soft: #EFEDE7;
    --accent: #12302A;
    --accent-ink: #FFFFFF;
    --accent-soft: #DCE9E3;
    --red: #F9DEDA;
    --red-ink: #8E1F12;
    --ok: #DDF0E4;
    --ok-ink: #135A33;
    --amber: #FCE7C4;
    --amber-ink: #6B3B00;
    --radius: 14px;
    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121513;
        --panel: #1A1E1C;
        --surface: #202523;
        --ink: #ECEDEA;
        --muted: #A2A8A4;
        --line: #343A37;
        --soft: #262B29;
        --accent: #8FD1B4;
        --accent-ink: #0D201A;
        --accent-soft: #23372F;
        --red: #3E1F1B;
        --red-ink: #F4A497;
        --ok: #1D3527;
        --ok-ink: #93D9AE;
        --amber: #3D2E12;
        --amber-ink: #F6C977;
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.45;
}

h1 { margin: 0; font-size: 26px; letter-spacing: -0.01em; line-height: 1.15; }
a { color: var(--accent); }
.muted { color: var(--muted); margin: 0; }
.eyebrow { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Pages de connexion et d'erreur */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 12px;
    background: var(--accent); color: var(--accent-ink);
    display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.brand-name { display: block; font-weight: 700; }
.brand-sub { display: block; font-size: 13px; color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; }
.field input {
    min-height: 46px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    padding: 0 14px;
    font: inherit;
}
.field input:focus { border-color: var(--accent); outline: none; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 48px; padding: 0 20px; border-radius: 12px;
    font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border: none; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); align-self: flex-start; }

.alert { border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: 14px; }
.alert-error { background: var(--red); color: var(--red-ink); }
.alert-ok { background: var(--ok); color: var(--ok-ink); }

/* Back-office : barre latérale et contenu */
.shell { min-height: 100vh; display: grid; grid-template-columns: 240px 1fr; }
.sidebar {
    background: var(--panel); border-right: 1px solid var(--line);
    padding: 20px 16px; display: flex; flex-direction: column; gap: 24px;
    position: sticky; top: 0; height: 100vh;
}
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link { padding: 10px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 600; }
.nav-link:hover { background: var(--soft); }
.nav-link.is-active { background: var(--accent-soft); color: var(--ink); }
.who { margin-top: auto; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.who-name { font-weight: 700; color: var(--ink); text-decoration: none; }
.who-link { font-size: 13px; color: var(--accent); margin: 4px 0 6px; }
.who-link.is-active { font-weight: 700; }
.who-role { color: var(--muted); font-size: 13px; }
.link-button { background: none; border: 0; padding: 6px 0 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

.content { padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1100px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .muted { margin-top: 6px; max-width: 60ch; }
.eyebrow a { color: inherit; }
h2 { margin: 0 0 6px; font-size: 18px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.big { margin: 0; font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }

.form { max-width: 640px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
fieldset.field { border: 0; padding: 0; margin: 0; }
fieldset.field legend { font-size: 14px; font-weight: 600; margin-bottom: 6px; padding: 0; }
.check { display: flex; align-items: center; gap: 8px; min-height: 32px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.field-error { margin: 0; font-size: 13px; font-weight: 600; color: var(--red-ink); }
.field input[aria-invalid="true"] { border-color: var(--red-ink); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.form-actions .btn-ghost { align-self: auto; }
.inline-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; max-width: none; }
.grow { flex: 1 1 260px; }

.btn-small { min-height: 36px; padding: 0 14px; font-size: 14px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn-danger { color: var(--red-ink); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions form { display: inline; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--soft); font-size: 12px; font-weight: 600; }
.state { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.state-ok { background: var(--ok); color: var(--ok-ink); }
.state-off { background: var(--soft); color: var(--muted); }

.code-panel { border-color: var(--accent); background: var(--accent-soft); display: flex; flex-direction: column; gap: 8px; }
.code-panel p { margin: 0; }
.enroll-code { font-size: 40px; font-weight: 800; letter-spacing: .12em; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.plain { margin: 0; padding-left: 18px; }
.empty { text-align: center; }

@media (max-width: 800px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 16px; }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .who { margin-top: 0; margin-left: auto; }
    .content { padding: 20px 16px 40px; }
    .field-row { grid-template-columns: 1fr; }
}

/* Sprint 2 : montants alignés, ventes annulées, tableau dans un panneau */
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.num { text-align: right; }
.is-cancelled td { color: var(--muted); text-decoration: line-through; }
.is-cancelled td:first-child { text-decoration: none; }
.table-wrap.flat { border: 0; border-radius: 0; margin: 8px -20px -20px; }
.alert a { color: inherit; }
.error-code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

/* Sprint 3 : filtres, pagination, états des tickets, historique */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters .field { flex: 1 1 140px; }
.filters .field input, .filters .field select { min-height: 40px; }
.field select {
    min-height: 46px; border-radius: 12px; border: 1px solid var(--line);
    background: var(--surface); color: var(--ink); padding: 0 10px; font: inherit;
}
.filter-actions { display: flex; gap: 8px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; }
.state-valid { background: var(--accent-soft); color: var(--ink); }
.state-consumed { background: var(--ok); color: var(--ok-ink); }
.state-cancelled { background: var(--red); color: var(--red-ink); }
.state-expired { background: var(--amber); color: var(--amber-ink); }
.btn-danger-solid { background: var(--red-ink); color: #fff; border: none; }
.timeline { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.timeline-at { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 6px; }
.timeline-cancel, .timeline-warning { color: var(--red-ink); }
.timeline-consume { color: var(--ok-ink); font-weight: 600; }
.alert-warn { background: var(--amber); color: var(--amber-ink); }

/* Sprint 4 : journées, rapports, audit */
.shift-open { background: var(--accent-soft); color: var(--ink); }
.shift-waiting { background: var(--amber); color: var(--amber-ink); }
.shift-partial { background: var(--red); color: var(--red-ink); }
.shift-to_validate { background: var(--amber); color: var(--amber-ink); }
.shift-remitted { background: var(--ok); color: var(--ok-ink); }
.diff { color: var(--red-ink); font-weight: 700; }
.table.compact td { padding: 8px 0; }
.table tfoot th { border-top: 2px solid var(--line); border-bottom: 0; color: var(--ink); font-size: 14px; text-transform: none; letter-spacing: 0; }
.quiet td { color: var(--muted); }
.details { font-family: ui-monospace, Consolas, monospace; font-size: 12px; max-width: 360px; overflow-wrap: anywhere; }

/* Tableau de bord : liste « À faire » */
.todo { display: flex; flex-direction: column; gap: 12px; }
.todo-head { display: flex; align-items: center; gap: 10px; }
.todo-head h2 { margin: 0; }
.todo-count { display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 8px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 14px; }
.todo-empty { margin: 0; padding: 14px 16px; border-radius: 12px; background: var(--ok); color: var(--ok-ink); font-weight: 600; }
.todo-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.todo-item { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.todo-mark { width: 10px; align-self: stretch; border-radius: 6px; flex: none; background: var(--line); }
.todo-urgent .todo-mark { background: var(--red-ink); }
.todo-attention .todo-mark { background: #D08A00; }
.todo-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.todo-text .muted { font-size: 14px; }
.todo-item .btn { flex: none; }

/* Filtres : périodes rapides, mémorisation */
.date-shortcuts { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip.is-on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.filters-note { flex: 1 1 100%; margin: 0; font-size: 13px; color: var(--muted); }

/* Lignes cliquables et panneau latéral de détail */
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--soft); }
.drawer { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(10, 15, 12, .4); opacity: 0; transition: opacity .2s; }
.drawer-panel {
    position: absolute; top: 0; right: 0; bottom: 0; width: min(760px, 92vw); background: var(--bg);
    box-shadow: -12px 0 40px rgba(0, 0, 0, .2); transform: translateX(100%); transition: transform .2s ease;
    display: flex; flex-direction: column;
}
.drawer.is-open { pointer-events: auto; }
.drawer.is-open .drawer-backdrop { opacity: 1; }
.drawer.is-open .drawer-panel { transform: none; }
.drawer-bar { display: flex; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.drawer-body { flex: 1; overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; outline: none; }
body.has-drawer { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .drawer-panel, .drawer-backdrop { transition: none; } }
@media (max-width: 700px) { .todo-item { flex-wrap: wrap; } .todo-item .btn { width: 100%; } }

/* Historique des actions */
.history { display: flex; flex-direction: column; gap: 6px; }
.history-day { margin: 14px 0 4px; font-size: 15px; text-transform: capitalize; color: var(--muted); }
.history-day:first-child { margin-top: 0; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.history-item { display: flex; align-items: center; gap: 14px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.history-item:last-child { border-bottom: 0; }
.history-time { width: 46px; flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.history-text { flex: 1; min-width: 0; }
.history-item.is-warn .history-text strong::before { content: "⚠ "; color: var(--red-ink); }
.history-item .btn { flex: none; }
.technical { margin-top: 14px; font-size: 13px; color: var(--muted); }
.technical p { font-family: ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }
