/**
 * design-system.css — shared tokens (color/type/spacing), base element
 * styling, and reusable component classes for the whole restaurant-facing
 * front end. Loaded by templates/base.html on every page, before any
 * page-specific stylesheet (grid-common.css, per-page <style> blocks) so
 * those can consume these custom properties. Presentation only — never
 * encodes authorization or business logic.
 */

:root {
  /* Color tokens */
  --color-primary: #1a4d2e;
  --color-primary-dark: #123a23;
  --color-page: #f4f7f5;
  --color-surface: #ffffff;
  --color-border: #dce5df;
  --color-text: #18221b;
  --color-muted: #66736a;
  --color-success: #1f7a45;
  --color-warning: #b7791f;
  --color-danger: #b42318;

  /* Type scale */
  --fs-page-title: 1.3rem;
  --fs-section-heading: 1.05rem;
  --fs-body: 1rem;
  --fs-table: .85rem;
  --fs-status: .75rem;
  --fs-btn: 1rem;
  --fs-btn-compact: .9rem;

  /* Spacing scale */
  --space-1: .25rem;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  --radius: 10px;
  --radius-sm: 6px;
  --transition-fast: 140ms ease;

  color-scheme: light;
}

@media (prefers-reduced-motion: reduce) {
  :root { --transition-fast: 0ms; }
}

* { box-sizing: border-box; }

html, body { overflow-x: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Noto Sans SC", sans-serif;
  margin: 0; padding: 0;
  background: var(--color-page); color: var(--color-text);
  font-size: 18px; line-height: 1.4;
}

/* Visible keyboard focus everywhere — never removed, only ever restyled. */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-primary-dark);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- App shell ---------- */

header {
  background: var(--color-primary); color: #fff; padding: var(--space-4);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap;
}
header h1 { margin: 0; font-size: var(--fs-page-title); }

.lang-switch { display: flex; gap: .4rem; width: auto; margin: 0; }
.lang-switch .lang-link {
  display: inline-block; width: auto; margin: 0; padding: .3rem .6rem;
  font-size: var(--fs-status); font-weight: 600; min-height: 32px;
  background: transparent; color: #cfe8d8; border: 1px solid #cfe8d8;
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.lang-switch .lang-link.active { background: #cfe8d8; color: var(--color-primary); }
.lang-switch .lang-link:hover { color: #fff; border-color: #fff; }
.lang-switch .lang-link.active:hover { color: var(--color-primary); }

.user-context { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.user-context .user-name { font-size: var(--fs-status); color: #cfe8d8; }
.logout-form { margin: 0; width: auto; }
.logout-btn {
  width: auto; margin: 0; padding: .3rem .6rem; font-size: var(--fs-status);
  font-weight: 600; min-height: 32px;
  background: transparent; color: #cfe8d8; border: 1px solid #cfe8d8;
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.logout-btn:hover { color: #fff; border-color: #fff; }

/* Desktop nav — two visually distinct groups sharing one <nav>.
   .nav-group--ops (Receive/Recipes/Count): filled pill, higher visual
   weight — the day-to-day operational actions.
   .nav-group--mgmt (Suppliers/Ingredients/Global Ingredients): outlined,
   lighter weight — configuration/management, used less often. */
nav.nav-desktop {
  background: var(--color-primary-dark); padding: .5rem var(--space-4);
  display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap;
}
nav.nav-desktop .nav-group { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
nav.nav-desktop .nav-group-label {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
  color: #8fae9c; margin-right: .15rem; font-weight: 700;
}
nav.nav-desktop .nav-link {
  color: #cfe8d8; text-decoration: none; font-size: .88rem; font-weight: 600;
  padding: .4rem .7rem; border-radius: 999px; min-height: 32px;
  display: inline-flex; align-items: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}
nav.nav-desktop .nav-group--ops .nav-link { background: rgba(255,255,255,.06); }
nav.nav-desktop .nav-link:hover { color: #fff; background: rgba(255,255,255,.14); }
nav.nav-desktop .nav-link[aria-current="page"] {
  background: #cfe8d8; color: var(--color-primary-dark);
}
nav.nav-desktop .nav-link[aria-current="page"]:hover { background: #fff; }

main {
  padding: var(--space-4); max-width: 720px; margin: 0 auto;
  /* Leaves room for the fixed mobile bottom bar so content never sits
     underneath it — desktop overrides this back to 0 (see nav-mobile
     media query below, which only exists under the breakpoint). */
}
/* Opt-in per-page override for grid-heavy screens — a page overrides
   the main_class block to "main-wide"; everything else (forms, cards)
   keeps the default readable width. */
main.main-wide { max-width: 1400px; }

.card {
  background: var(--color-surface); border-radius: 12px; padding: var(--space-4);
  margin-bottom: var(--space-4); box-shadow: 0 1px 3px rgba(0,0,0,.1);
  border: 1px solid var(--color-border);
}

label { display: block; font-weight: 600; margin-bottom: .25rem; margin-top: var(--space-3); }
input, select, textarea {
  width: 100%; padding: .75rem; font-size: var(--fs-body);
  border: 1px solid #ccc; border-radius: 8px; min-height: 44px;
  font-family: inherit;
}
textarea { min-height: 88px; }

/* Reusable two-column field row (e.g. English/Chinese name pairs) — each
   direct child is one complete label+input group; balanced side-by-side on
   desktop, stacked (the default single-column form flow) below the
   breakpoint. */
.form-row-2col { display: grid; grid-template-columns: 1fr; gap: 0 var(--space-4); }
@media (min-width: 600px) {
  .form-row-2col { grid-template-columns: 1fr 1fr; }
}

/* Compact field grid — a denser alternative to the default full-width
   vertical stack, for forms with many short fields (e.g. a quick-create
   panel). Each field is its own label+input wrapper (.field) so related
   controls can sit beside each other on desktop; .field-grid-section
   headings visually divide groups of fields inside one <form> without a
   <fieldset>'s default browser chrome. Single column below the
   breakpoint — never horizontal scroll, never a forced multi-column
   layout on a narrow screen. */
.field-grid { display: grid; grid-template-columns: 1fr; gap: 0 var(--space-3); max-width: 640px; }
.field-grid .field { min-width: 0; }
.field-grid .field label { margin-top: var(--space-2); }
.field-grid .field-wide { grid-column: 1 / -1; }
.field-grid .field-grid-section {
  grid-column: 1 / -1; margin: var(--space-4) 0 .3rem;
  font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  color: var(--color-muted); border-bottom: 1px solid var(--color-border); padding-bottom: .3rem;
}
.field-grid .field-grid-section:first-child { margin-top: 0; }
@media (min-width: 600px) {
  .field-grid { grid-template-columns: 1fr 1fr; }
}
/* Purchase-package row: denser still on wide screens, since it's several
   short fields (supplier/package/qty/unit/price) that read naturally as
   one row rather than a 2-column stack. */
.field-grid .field-grid-dense { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr; gap: 0 var(--space-2); }
@media (min-width: 700px) {
  .field-grid .field-grid-dense { grid-template-columns: repeat(5, 1fr); }
  .field-grid .field-grid-dense .field label { font-size: .78rem; white-space: nowrap; }
}

button, .btn {
  display: inline-block; width: 100%; padding: 1rem; font-size: 1.1rem;
  font-weight: 700; min-height: 44px;
  background: var(--color-primary); color: #fff; border: none;
  border-radius: var(--radius); margin-top: var(--space-4);
  text-align: center; text-decoration: none; cursor: pointer;
  transition: background var(--transition-fast);
}
button:hover, .btn:hover { background: var(--color-primary-dark); }
button.secondary, .btn.secondary { background: #888; }
button.secondary:hover, .btn.secondary:hover { background: #6f6f6f; }

/* Compact variant — used wherever a button sits inline with other content
   (grid toolbars, table action cells, the mobile "More" sheet) rather than
   as a form's single full-width primary action. */
.btn-compact {
  display: inline-block; width: auto; padding: .5rem .9rem; font-size: var(--fs-btn-compact);
  font-weight: 700; min-height: 40px;
  background: var(--color-primary); color: #fff; border: none; border-radius: 8px;
  margin-top: 0; text-align: center; text-decoration: none; cursor: pointer;
  transition: background var(--transition-fast);
}
.btn-compact:hover { background: var(--color-primary-dark); }
.btn-compact.secondary { background: #888; }
.btn-compact.secondary:hover { background: #6f6f6f; }
.btn-compact.destructive { background: #fff; color: var(--color-danger); border: 1px solid var(--color-danger); }
.btn-compact.destructive:hover { background: #fbe4e1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .25rem; border-bottom: 1px solid #eee; font-size: var(--fs-table); }
.line-row input { width: 5.5rem; padding: .5rem; font-size: .95rem; }
.flag { color: var(--color-danger); font-weight: 600; }
.back-link { display: inline-block; color: var(--color-primary); font-weight: 600; text-decoration: none; font-size: .9rem; }
.back-link:hover { text-decoration: underline; }
.muted { color: var(--color-muted); font-size: .9rem; }
.messages { list-style: none; padding: 0; }
.messages li { background: #ffe9a8; padding: .5rem 1rem; border-radius: 8px; margin-bottom: .5rem; }

/* ---------- Status chips ---------- */
/* Text is always present and carries the meaning on its own — color is a
   secondary reinforcement, never the only signal. */
.status-chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .55rem; border-radius: 999px;
  font-size: var(--fs-status); font-weight: 700; line-height: 1.6;
  white-space: nowrap;
}
.status-chip--active { background: #e3f3e9; color: var(--color-success); }
.status-chip--archived, .status-chip--inactive { background: #eef0ee; color: var(--color-muted); }
.status-chip--warning { background: #fbf0dc; color: var(--color-warning); }
.status-chip--danger { background: #fbe4e1; color: var(--color-danger); }

/* ---------- Management-page header ---------- */
.mgmt-header { margin-bottom: var(--space-4); }
.mgmt-header .mgmt-header-top {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
  gap: var(--space-3);
}
.mgmt-header .mgmt-header-copy { flex: 1 1 20rem; }
.mgmt-header .mgmt-header-sentence { margin: 0 0 .2rem; color: var(--color-text); font-size: var(--fs-body); }
.mgmt-header .mgmt-header-count { margin: 0; color: var(--color-muted); font-size: .85rem; }
/* Standalone (not scoped to .mgmt-header) — also used inline within a
   compact form's own short permanently-visible explanation, e.g. the
   Ingredients quick-create panel. */
details.mgmt-help { margin-top: .35rem; }
details.mgmt-help summary {
  cursor: pointer; font-size: .82rem; color: var(--color-primary); font-weight: 600;
}
details.mgmt-help p { margin: .4rem 0 0; color: var(--color-muted); font-size: .85rem; }
/* flex-shrink:0 alone isn't enough once the "+ Add X" <details> is open —
   a flex item with flex-basis:auto still sizes to its unwrapped content's
   preferred width (here, an open create-form-panel's flex-wrap row of
   fixed-width inputs, which "prefers" to lay out on one very wide line)
   and refuses to shrink below that, so max-width:100% is needed as a hard
   clamp: it forces the item down to whatever width mgmt-header-top's own
   wrap actually gave it, which is what finally gives the form's own
   flex-wrap something narrow enough to wrap against instead of overflowing
   the viewport. */
.mgmt-header .mgmt-header-action { flex: 0 0 auto; max-width: 100%; }
.mgmt-header .mgmt-header-action .btn-compact { margin-top: 0; }
.mgmt-header details.mgmt-create { margin-top: var(--space-3); }
.mgmt-header details.mgmt-create > summary { list-style: none; display: inline-block; }
.mgmt-header details.mgmt-create > summary::-webkit-details-marker { display: none; }
.mgmt-header details.mgmt-create .create-form-panel {
  margin-top: var(--space-3); padding: var(--space-3); background: var(--color-page);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
}

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center; padding: var(--space-6) var(--space-4);
  background: var(--color-surface); border: 1px dashed var(--color-border);
  border-radius: 12px;
}
.empty-state .empty-state-icon {
  width: 40px; height: 40px; margin: 0 auto var(--space-3);
  color: var(--color-muted); opacity: .6;
}
.empty-state .empty-state-icon svg { width: 100%; height: 100%; }
.empty-state h2 { margin: 0 0 .35rem; font-size: var(--fs-section-heading); color: var(--color-text); }
.empty-state p { margin: 0 0 var(--space-3); color: var(--color-muted); font-size: .9rem; }
.empty-state .btn, .empty-state .btn-compact { display: inline-block; width: auto; }

/* ---------- Step indicator ---------- */
.step-indicator {
  display: flex; align-items: center; gap: .4rem; margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.step-indicator .step {
  display: flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--color-muted);
}
.step-indicator .step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; font-weight: 700; font-size: .75rem;
  background: var(--color-border); color: var(--color-muted); flex: 0 0 auto;
}
.step-indicator .step.is-current .step-num { background: var(--color-primary); color: #fff; }
.step-indicator .step.is-current .step-label { color: var(--color-text); font-weight: 700; }
.step-indicator .step.is-done .step-num { background: var(--color-success); color: #fff; }
.step-indicator .step-sep { color: var(--color-border); }

/* ---------- Mobile bottom nav ---------- */
.nav-mobile-bar { display: none; }

@media (max-width: 430px) {
  nav.nav-desktop { display: none; }

  main { padding-bottom: calc(64px + var(--space-4)); }

  .nav-mobile-bar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 500;
    background: var(--color-primary-dark); border-top: 1px solid rgba(255,255,255,.08);
  }
  .nav-mobile-bar .nav-mobile-item {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: .15rem; min-height: 56px; padding: .3rem;
    color: #cfe8d8; text-decoration: none; font-size: .68rem; font-weight: 600;
    background: none; border: none; cursor: pointer; font-family: inherit;
  }
  .nav-mobile-bar .nav-mobile-item[aria-current="page"] { color: #fff; background: rgba(255,255,255,.1); }
  .nav-mobile-bar .nav-mobile-item .nav-mobile-icon { width: 20px; height: 20px; }
  .nav-mobile-bar .nav-mobile-item .nav-mobile-icon svg { width: 100%; height: 100%; }

  /* The "More" sheet — a native <details> whose panel is fixed above the
     bar. No JS: <details> handles open/close and focus natively. */
  .nav-mobile-more { position: static; }
  .nav-mobile-more > summary {
    list-style: none;
  }
  .nav-mobile-more > summary::-webkit-details-marker { display: none; }
  .nav-mobile-more[open] > summary .nav-mobile-item { color: #fff; background: rgba(255,255,255,.1); }
  .nav-mobile-more-panel {
    position: fixed; left: 0; right: 0; bottom: 56px; z-index: 501;
    background: var(--color-surface); border-top: 1px solid var(--color-border);
    border-radius: 14px 14px 0 0; box-shadow: 0 -2px 12px rgba(0,0,0,.18);
    padding: var(--space-2) 0 var(--space-2);
    max-height: 60vh; overflow-y: auto;
  }
  .nav-mobile-more-panel .nav-mobile-more-link {
    display: flex; align-items: center; min-height: 48px; padding: 0 var(--space-4);
    color: var(--color-text); text-decoration: none; font-size: .95rem; font-weight: 600;
  }
  .nav-mobile-more-panel .nav-mobile-more-link[aria-current="page"] { color: var(--color-primary); }
  .nav-mobile-more-panel .nav-mobile-more-link:hover { background: var(--color-page); }
  .nav-mobile-more-panel .nav-mobile-more-section {
    padding: var(--space-3) var(--space-4) var(--space-1); display: flex; align-items: center;
    justify-content: space-between; gap: var(--space-2); flex-wrap: wrap;
  }
  .nav-mobile-more-panel hr { border: none; border-top: 1px solid var(--color-border); margin: .3rem var(--space-4); }
}

@media (min-width: 431px) {
  .nav-mobile-more-panel { display: none; }
}
