/* Epicerie Orders: shared styles for the app screens.
   Labels are NOT styled here: they are server-generated PDFs (§3 rule 4). */

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --text: #1d1c1a;
  --muted: #6b6862;
  --line: #e2dfd8;
  --accent: #7a2e1f;        /* deep festive red */
  --accent-text: #ffffff;
  --ok: #2f6b3a;
  --ok-bg: #e8f2ea;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;       /* amber: "Low" rows (§9) */
  --bad: #9b1c1c;
  --bad-bg: #fbe6e6;
  --grey-bg: #eeece8;       /* greyed: sold out / closed */
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem;
  padding: .75rem 1rem; background: var(--accent); color: var(--accent-text);
}
.topbar a { color: inherit; text-decoration: none; }
.brand { font-weight: 700; font-size: 1.05rem; }
.brand span { font-weight: 400; opacity: .8; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .25rem; }
.topbar nav a { padding: .3rem .6rem; border-radius: var(--radius); }
.topbar nav a:hover, .topbar nav a[aria-current="page"] { background: rgba(255,255,255,.18); }
.who { margin-left: auto; font-size: .85rem; opacity: .85; }
.logout { margin: 0; }
.logout button { background: none; border: 1px solid rgba(255,255,255,.4); color: inherit; font: inherit; font-size: .85rem;
  padding: .2rem .6rem; border-radius: var(--radius); cursor: pointer; }
.logout button:hover { background: rgba(255,255,255,.18); }
main.login { max-width: 26rem; }
.shop-link { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.shop-link input { flex: 1 1 18rem; font-family: ui-monospace, monospace; font-size: .85rem; }
.password-once { font-family: ui-monospace, monospace; font-size: 1.25rem; letter-spacing: .05em; user-select: all; }

main { max-width: 72rem; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
h1 { font-size: 1.5rem; margin: .25rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }
p.lead { color: var(--muted); margin-top: -.5rem; }
a { color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.stat { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .85rem; }

/* Tables scroll inside their box on a phone, never the page */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .65rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #faf9f7; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.inactive td { color: var(--muted); background: var(--grey-bg); }

form.stack { display: grid; gap: .9rem; max-width: 38rem; }
.row { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input[type=text], input[type=number], input[type=date], input[type=datetime-local], input[type=search],
input[type=tel], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: .5rem .6rem; font: inherit; border: 1px solid #cfcbc2; border-radius: var(--radius); background-color: #fff;
}
/* One height for every one-line field, so a row of filters lines up in every
   browser. Safari ignores padding on a native drop-down and draws date fields
   taller, so the drop-down is drawn here, arrow included. */
input[type=text], input[type=number], input[type=date], input[type=datetime-local], input[type=search],
input[type=tel], input[type=email], input[type=password], select {
  height: 2.6rem; line-height: 1.2;
}
select {
  -webkit-appearance: none; appearance: none; padding-right: 2rem; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236b6459' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center; background-size: .7rem;
}
select[multiple] { height: auto; background-image: none; padding-right: .6rem; }
input[type=date]::-webkit-date-and-time-value, input[type=datetime-local]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type=date]::-webkit-datetime-edit, input[type=datetime-local]::-webkit-datetime-edit { padding: 0; }
textarea { min-height: 5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: .45rem; font-weight: 400; }
.check input { width: auto; }
.field-error { color: var(--bad); font-size: .85rem; margin: .25rem 0 0; }
/* The field a message is about, outlined in red: the error sits right after it. */
:is(input, select, textarea):has(+ .field-error) { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); background-color: var(--bad-bg); }

.btn { display: inline-block; padding: .5rem .9rem; border-radius: var(--radius); border: 1px solid var(--accent);
       background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn-secondary { background: #fff; color: var(--accent); }
.btn-danger { background: var(--bad); border-color: var(--bad); }
.btn-small { padding: .25rem .55rem; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
form.inline { display: inline; }

.flash { padding: .65rem .85rem; border-radius: var(--radius); margin: 0 0 1rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }
.flash-error { background: var(--bad-bg); color: var(--bad); }

.badge { display: inline-block; padding: .05rem .45rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--grey-bg); color: var(--muted); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
fieldset { border: 1px solid var(--line); }
legend { font-weight: 600; font-size: .9rem; padding: 0 .3rem; }

/* Import report (§8 dry run) */
.msg-list { margin: 0 0 1rem; padding: .5rem .75rem .5rem 1.75rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.msg-list li { margin: .3rem 0; overflow-wrap: anywhere; }
.msg-bad { border-color: var(--bad); background: var(--bad-bg); }
.msg-warn { border-color: #e6cf9c; background: var(--warn-bg); }
details.card > summary { cursor: pointer; }
details.card .table-wrap { margin-top: .75rem; }
input[type=file] { max-width: 100%; }

/* Event menu (publishing) */
.menu-table tr.group th { background: var(--grey-bg); color: var(--text); text-transform: none; letter-spacing: 0; font-size: .9rem; }
.num-input { width: 5.5rem !important; text-align: right; }
a.badge { text-decoration: none; }
tr.row-low td { background: var(--warn-bg); }   /* §9 amber "Low" */

/* Order entry (§9 display states, §6a covers, §11 allergens) */
.order-cat { margin-bottom: 1rem; }
/* Same column widths in every category, so prices and badges line up down
   the page however long the dish names are. The table still scrolls on a
   phone rather than squeezing the dish name. */
.order-cat table { table-layout: fixed; width: 100%; min-width: 40rem; }
.order-cat th:nth-child(2) { width: 9rem; }
.order-cat th:nth-child(3) { width: 13rem; }
.order-cat th:nth-child(4) { width: 7.5rem; }
/* A comment on one dish line: "no nuts", "extra truffle" */
.order-cat input.line-note { display: block; margin-top: .35rem; width: 100%; max-width: 26rem; padding: .3rem .5rem; font-size: .9rem; height: 2.1rem; }
em.line-note { color: var(--bad); font-weight: 600; }
.order-cat caption { text-align: left; font-weight: 700; padding: .6rem .65rem; background: var(--grey-bg); }
.avail .why { display: block; font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.avail .over-msg { display: block; font-size: .8rem; font-weight: 600; color: var(--bad); margin-top: .15rem; }
.avail .over-msg[hidden] { display: none; }
tr.row-over td { background: var(--bad-bg); }
tr.row-over input.pieces { border-color: var(--bad); color: var(--bad); font-weight: 600; }
.left-badge { transition: background-color .25s, color .25s; font-variant-numeric: tabular-nums; }
.left-badge.tick { animation: left-tick .35s ease-out; }
@keyframes left-tick { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .left-badge.tick { animation: none; } }
tr.inactive input { opacity: .5; }
/* "Printed on the box label": the client sees what is typed in Notes */
.label-warning { font-weight: 700; text-transform: uppercase; text-decoration: underline; text-underline-offset: 2px;
                 letter-spacing: .03em; font-size: .85em; color: var(--warn); }

/* Title drop-down in front of the client's name */
.name-field { display: flex; gap: .5rem; }
.name-field select { flex: 0 0 auto; width: 6.5rem; }
.name-field input { flex: 1 1 auto; min-width: 0; }
abbr.allergen { text-decoration: none; font-weight: 700; color: var(--warn); cursor: help; }
.legend { font-size: .85rem; }
.covers { margin: .25rem 0 .75rem; padding-left: 1.2rem; }
.order-summary .total { font-size: 1.15rem; margin: 0; }
.event-pick { text-decoration: none; color: inherit; display: block; }
.event-pick:hover { border-color: var(--accent); }
fieldset.card { margin: 0 0 1rem; display: grid; gap: .9rem; }
tfoot th, tfoot td { border-top: 2px solid var(--line); }
tfoot th.num { text-transform: none; }

[hidden] { display: none !important; }

/* Order list (§19 step 8) */
.filters .row { grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); }
.filters .actions { margin-top: .9rem; }
th a.sort { color: inherit; text-decoration: none; white-space: nowrap; }
th a.sort:hover { color: var(--accent); }
th[aria-sort] a.sort { color: var(--text); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: .75rem; }

.print-only { display: none; }
.pick h2 { margin-top: 0; }
.pick table td { padding: .2rem .5rem; border: 0; }

/* A printed list keeps the line saying which event it covers (§21) */
@media print {
  .topbar, .filters, .pager, .list-actions { display: none; }
  .table-wrap { overflow: visible; border: 0; }
  .pick { break-inside: avoid; }
  .print-only { display: inline; }
}

/* Order lifecycle (§10) */
.actions form { margin: 0; }
.cancel-order { margin-top: 1.5rem; }
.cancel-order summary { cursor: pointer; color: var(--bad); }
.history { margin: .25rem 0; padding-left: 1.2rem; }
.history ul { margin: .15rem 0 .5rem; padding-left: 1.1rem; color: var(--muted); }

/* Raw stock (§6, §21) */
tr.row-short td { background: var(--bad-bg); }
.unit-input { width: 5rem !important; display: inline-block; }
.inline-actions { display: flex; gap: .4rem; flex-wrap: wrap; margin: 0; }
.test-banner { background: #ffd23f; color: #3a2a00; text-align: center; padding: .4rem 1rem; font-size: .9rem;
  border-bottom: 2px solid #c79a00; }
@media print { .test-banner { display: none; } }
