/*
 * Application styles. Keep all styling here: the Content Security Policy
 * blocks inline style attributes and inline scripts.
 *
 * Tokens are copied from the storefront's DESIGN.md section 12.1 (dark theme only for now, see A-69).
 * The fonts there are not loaded (the CSP has no external font host): system stacks stand in.
 */

:root {
  color-scheme: dark;
  /* base */
  --char: #191008; --soot: #251A0E; --soot-2: #2E2113;
  --roman: #E23D28; --roman-deep: #B92C1B; --ember: #FF6E4E;
  --cream: #F6EBDD; --crust: #E9A64F; --basil: #8FBF7F;
  /* roles */
  --surface: var(--char); --surface-raised: var(--soot); --surface-raised-2: var(--soot-2);
  --surface-sunken: var(--char); --scrim: rgba(10,6,3,.62);
  --text: var(--cream); --text-dim: #BDB2A6; --text-muted: #A89C8E;
  --text-on-accent: var(--cream); --text-on-gold: var(--char);
  --accent: var(--roman); --accent-fill: #C4321E; --accent-fill-hover: var(--roman-deep);
  --accent-text: var(--ember); --highlight: var(--crust);
  --success: var(--basil); --warning: var(--crust); --error: var(--ember); --info: var(--text-dim);
  --focus: var(--crust); --focus-on-red: var(--cream);
  --line: rgba(246,235,221,.14); --line-strong: rgba(246,235,221,.40);
  /* type */
  --font-display: 'Anton', 'Arial Narrow', Impact, sans-serif;
  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-body: 'Hanken Grotesk', 'Helvetica Neue', Arial, sans-serif;
  /* space */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px;
  --s-7: 32px; --s-8: 40px; --s-9: 48px; --s-10: 64px; --s-11: 96px;
  --gutter: clamp(20px, 4vw, 48px); --content-max: 1200px;
  /* radius */
  --r-xs: 6px; --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-pill: 999px; --r-check: 7px;
  /* motion */
  --ease-out: cubic-bezier(.2,.7,.2,1);
  --d-press: 120ms; --d-fast: 200ms; --d-mid: 250ms; --d-sheet: 320ms; --d-reveal: 700ms; --d-hero: 800ms;
  /* layers */
  --z-catbar: 40; --z-nav: 50; --z-scrim: 60; --z-sheet: 70; --z-toast: 80;
}
@media (prefers-contrast: more) {
  :root { --text-muted: var(--text-dim); --line: var(--line-strong); }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
}

main { max-width: var(--content-max); margin: var(--s-6) auto; padding: 0 var(--gutter); }
main.auth { max-width: 28rem; }

h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 var(--s-4); }
h2 { font-size: 1.25rem; margin: var(--s-6) 0 var(--s-3); }
h3 { font-size: 1.05rem; margin: var(--s-4) 0 var(--s-2); }
p { margin: 0 0 var(--s-3); }
a { color: var(--accent-text); }
.muted { color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.topbar :focus-visible, .button-primary:focus-visible { outline-color: var(--focus-on-red); }

/* Top bar and navigation */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-4);
  padding: var(--s-2) var(--gutter);
  background: var(--surface-raised);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 800; letter-spacing: .02em; }
.topbar form { margin: 0; }
.topbar .who { margin-left: auto; color: var(--text-dim); }

.admin-nav ul { display: flex; flex-wrap: wrap; gap: var(--s-1); list-style: none; margin: 0; padding: 0; }
.admin-nav a {
  display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; padding: 0 var(--s-3);
  border-radius: var(--r-sm); color: var(--text); text-decoration: none; border-bottom: 3px solid transparent;
}
.admin-nav a:hover { background: var(--surface-raised-2); }
.admin-nav a[aria-current="page"] { border-bottom-color: var(--accent); font-weight: 700; }

/* Buttons and controls */
button, .button, input[type="submit"], .link-button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; min-width: 44px; padding: 0 var(--s-4);
  font: inherit; font-weight: 600; color: var(--text); text-decoration: none; cursor: pointer;
  background: var(--surface-raised-2); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
}
button:hover, .button:hover, input[type="submit"]:hover { background: var(--soot); border-color: var(--text-dim); }
button[aria-pressed="true"] { background: var(--cream); color: var(--text-on-gold); border-color: var(--cream); }
button:disabled, button[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.button-primary, input[type="submit"].button-primary, button.button-primary {
  background: var(--accent-fill); border-color: var(--accent-fill); color: var(--text-on-accent);
}
.button-primary:hover { background: var(--accent-fill-hover); border-color: var(--accent-fill-hover); }
.link-button { background: none; border-color: currentcolor; }
.button_to { display: inline; margin: 0; }

label { display: block; font-weight: 600; margin-bottom: var(--s-1); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"],
input[type="time"], input[type="date"], input[type="datetime-local"], input[type="url"], select, textarea {
  width: 100%; min-height: 44px; padding: var(--s-2) var(--s-3); font: inherit; color: var(--text);
  background: var(--surface-raised-2); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
}
textarea { min-height: 6rem; }
.check { display: flex; align-items: center; gap: var(--s-2); min-height: 44px; font-weight: 500; margin: 0; }
.check input[type="checkbox"], .check input[type="radio"] { width: 24px; height: 24px; margin: 0; flex: none; accent-color: var(--accent-fill); }
fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); margin: 0 0 var(--s-4); }
legend { font-weight: 700; padding: 0 var(--s-2); }
.field { margin-bottom: var(--s-4); }
.hint { color: var(--text-muted); font-size: .9rem; margin: var(--s-1) 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin-top: var(--s-4); }

.stack { display: flex; flex-direction: column; gap: var(--s-2); }
.stack input[type="submit"] { margin-top: var(--s-2); background: var(--accent-fill); border-color: var(--accent-fill); color: var(--text-on-accent); }
.row { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.row > * { margin: 0; }
.spread { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; justify-content: space-between; }

/* Messages */
.flash { padding: var(--s-3) var(--gutter); border-bottom: 1px solid var(--line); }
.flash-notice { background: var(--surface-raised); color: var(--success); }
.flash-alert { background: var(--surface-raised); color: var(--error); }
.errors { border: 1px solid var(--error); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); margin-bottom: var(--s-4); color: var(--error); }
.errors ul { margin: 0; padding-left: var(--s-5); }
.badge {
  display: inline-block; padding: 2px var(--s-3); border-radius: var(--r-pill); font-size: .85rem; font-weight: 700;
  border: 1px solid var(--line-strong); color: var(--text-dim); white-space: nowrap;
}
.badge-warn { color: var(--warning); border-color: var(--warning); }
.badge-ok { color: var(--success); border-color: var(--success); }
.badge-off { color: var(--error); border-color: var(--error); }

/* Layout pieces */
.panel { background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-4); margin-bottom: var(--s-4); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: var(--s-4); margin-bottom: var(--s-4); }
.cards .panel { margin: 0; }
.big-number { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.area-list { display: flex; flex-wrap: wrap; gap: var(--s-2); list-style: none; padding: 0; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list > li { border-bottom: 1px solid var(--line); padding: var(--s-2) 0; }
.table-wrap { overflow-x: auto; }
/* A slip from the fake printer (M15): 42 characters wide, as a receipt printer would set it. */
.pos-slip { display: inline-block; min-width: 42ch; margin: 0 0 var(--s-4); padding: var(--s-3); background: var(--surface-raised); border: 1px dashed var(--line-strong); border-radius: var(--r-sm); font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9375rem; line-height: 1.4; white-space: pre; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--text-dim); font-weight: 700; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tabs { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: 0 0 var(--s-4); }
.tabs a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s-4); border: 1px solid var(--line-strong); border-radius: var(--r-pill); color: var(--text); text-decoration: none; }
.tabs a[aria-current="page"] { background: var(--cream); color: var(--text-on-gold); border-color: var(--cream); font-weight: 700; }
.search-form { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: flex-end; margin-bottom: var(--s-4); }
.search-form .field { margin: 0; flex: 1 1 14rem; }

/* Stock rows */
.stock-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-2) var(--s-4); align-items: center; padding: var(--s-3) 0; border-bottom: 1px solid var(--line); }
.stock-row .name { font-weight: 700; }
.stock-row .where { color: var(--text-muted); font-size: .9rem; }
.segmented { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.segmented form { margin: 0; }
.stock-live { min-height: 1.5rem; color: var(--text-dim); margin-bottom: var(--s-3); }

/* Editors */
.move-buttons { display: inline-flex; gap: var(--s-1); }
.rows-editor td input, .rows-editor td select { min-width: 6rem; }
.preview { border: 1px dashed var(--line-strong); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); }
.history { font-size: .95rem; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: var(--s-4); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (forced-colors: active) {
  button, .button, input, select, textarea { border: 1px solid ButtonText; }
  button[aria-pressed="true"] { border-width: 3px; }
}
