/* Tokens del sistema visual. Ningún color, radio o sombra se escribe fuera de
   aquí: los componentes solo referencian estas variables. */
:root {
  color-scheme: light;

  --brand: #1d6b5e;
  --brand-strong: #144f45;
  --brand-soft: #e4f1ee;
  --brand-line: #bcdcd4;
  --accent: #b8512f;
  --accent-soft: #fbece6;

  --ink: #14201e;
  --ink-2: #465552;
  --ink-3: #74827e;
  --line: #e2e8e6;
  --line-strong: #cbd5d2;

  --surface: #ffffff;
  --surface-2: #f5f8f7;
  --bg: #eef2f1;

  --ok: #1d7a45;
  --ok-soft: #e5f4ea;
  --warn: #8f5c08;
  --warn-soft: #fcf2df;
  --danger: #ad241d;
  --danger-soft: #fcecea;
  --info: #1e5b93;
  --info-soft: #e7f0f9;

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 22px;
  --shadow-1: 0 1px 2px rgb(16 40 36 / 6%), 0 2px 6px rgb(16 40 36 / 6%);
  --shadow-2: 0 18px 44px rgb(16 40 36 / 18%), 0 3px 8px rgb(16 40 36 / 8%);
  --focus: 0 0 0 3px rgb(29 107 94 / 30%);

  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-md: 0.9375rem;
  --fs-lg: 1.0625rem;
  --fs-xl: 1.3125rem;
  --fs-2xl: 1.625rem;
  --fs-3xl: 2.125rem;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --header-h: 60px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --toast-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.015em; line-height: 1.15; }
h2 { font-size: var(--fs-lg); font-weight: 650; }
h3 { font-size: var(--fs-sm); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
small { font-size: var(--fs-sm); color: var(--ink-2); }
a { color: var(--brand-strong); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

/* ------------------------------- Botón --------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: var(--fs-md);
  line-height: 1;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  transition: background 120ms ease, transform 80ms ease, border-color 120ms ease;
}
.btn svg { flex: 0 0 auto; }
.btn:hover { background: var(--brand-strong); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--brand-strong); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.danger { background: var(--danger); }
.btn.danger-ghost { background: transparent; color: var(--danger); }
.btn.danger-ghost:hover { background: var(--danger-soft); }
/* Acciones de fila que se leen sin gritar: el color solo aparece al pasar el
   cursor, para que una lista de platos no parezca llena de alertas. */
.btn.danger-quiet { background: transparent; color: var(--ink-2); }
.btn.danger-quiet:hover { background: var(--danger-soft); color: var(--danger); }
.btn.ok-quiet { background: transparent; color: var(--ok); }
.btn.ok-quiet:hover { background: var(--ok-soft); color: var(--ok); }
.btn.block { width: 100%; }
.btn.lg { min-height: 52px; font-size: var(--fs-lg); border-radius: var(--radius); }
.btn.sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--fs-sm); }
.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ------------------------------- Campos -------------------------------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field > .label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); box-shadow: var(--focus); outline: none; }
.field .error { font-size: var(--fs-xs); color: var(--danger); font-weight: 600; min-height: 0; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
@media (max-width: 640px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* ------------------------------ Primitivas ----------------------------- */
/* Una rejilla nunca debe crecer más que su contenedor: si una celda calcula un
   ancho enorme (por una fuente, un icono o un texto largo), se queda dentro del
   área desplazable en vez de estirar la página entera. */
.view, .stack, .grid-2, .section, .metrics, .table-grid, .product-grid, .order-list, .week-grid { min-width: 0; max-width: 100%; }
.view > *, .stack > *, .grid-2 > *, .metrics > *, .table-grid > *, .product-grid > *, .order-list > *, .section > * { min-width: 0; }
.view-head > * { min-width: 0; flex-shrink: 1; }
/* `fit-content` deja que estos contenedores se encojan con su contenido en vez
   de estirar la columna de la rejilla donde viven. */
.row { width: fit-content; max-width: 100%; }
.segmented { width: fit-content; max-width: 100%; }
.tabs { max-width: 100%; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1); }
.card.pad { padding: var(--space-4); }
.stack { display: grid; gap: var(--space-3); }
.stack.tight { gap: var(--space-2); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--ink-2); }
.tiny { font-size: var(--fs-xs); color: var(--ink-3); }
.numeric { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strong { font-weight: 700; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--fs-xs);
  font-weight: 650;
  white-space: nowrap;
}
.pill[data-tone="ok"] { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill[data-tone="warn"] { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill[data-tone="danger"] { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill[data-tone="info"] { background: var(--info-soft); color: var(--info); border-color: transparent; }
.pill[data-tone="brand"] { background: var(--brand-soft); color: var(--brand-strong); border-color: transparent; }

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background 140ms ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-1);
  transition: transform 140ms ease;
}
.switch[aria-checked="true"] { background: var(--brand); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
}
.segmented button {
  min-height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* Desplegable discreto: la acción poco frecuente queda a la vista pero plegada. */
.disclosure { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.disclosure > summary {
  padding: 12px var(--space-4);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before { content: "+"; font-weight: 700; color: var(--ink-3); }
.disclosure[open] > summary::before { content: "−"; }
.disclosure > .stack { padding: 0 var(--space-4) var(--space-4); }

/* Token del agente de impresión: se lee y se copia sin errores. */
.token-box {
  display: block;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font: 12px/1.4 ui-monospace, monospace;
  word-break: break-all;
  user-select: all;
}

.tabs { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ------------------------------ Avisos --------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: var(--toast-bottom);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 500;
  box-shadow: var(--shadow-2);
  transform: translateX(-50%);
  animation: toast-in 160ms ease-out;
}
.toast[data-tone="danger"] { background: var(--danger); }
.toast[data-tone="ok"] { background: var(--ok); }
.toast .btn { background: rgb(255 255 255 / 18%); color: #fff; border-color: transparent; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* --------------------------- Carga y vacíos ---------------------------- */
.skeleton {
  min-height: 64px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #e9efed, #f7faf9, #e9efed);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.empty { padding: var(--space-8) var(--space-4); text-align: center; color: var(--ink-2); display: grid; gap: 4px; }
.empty strong { color: var(--ink); font-size: var(--fs-lg); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
