:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --ink: #2b2622;
  --muted: #8a7f72;
  --line: #e9e2d8;
  --soft: #f3ede4;
  --accent: #b3271e;
  --accent-dark: #8f1d16;
  --ok: #2e7d32;
  --warn: #a15c00;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(60, 40, 20, 0.07);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--accent); font-weight: 600; }

/* ---------- Encabezado y navegación ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  background: rgba(250, 247, 242, 0.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: 0.5px; }
.brand span { font-weight: 500; font-size: 13px; color: var(--muted); margin-left: 6px; }
.user-chip {
  background: var(--soft); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.user-chip small { color: var(--muted); font-weight: 500; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  flex: 1; background: none; border: none; cursor: pointer;
  padding: 8px 2px 10px; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 56px;
}
.bottom-nav button .nav-ico { font-size: 20px; line-height: 1; }
.bottom-nav button.active { color: var(--accent); font-weight: 700; }

main { padding: 16px 16px 96px; max-width: 860px; margin: 0 auto; }
.view-title { font-size: 24px; margin: 4px 0 12px; display: flex; align-items: center; gap: 10px; }
.section-title { font-size: 17px; margin: 22px 0 8px; }

/* ---------- Cajas centradas (login / setup) ---------- */
.center-box { max-width: 430px; margin: 6vh auto 0; }
.logo-big {
  font-size: 44px; font-weight: 800; letter-spacing: 2px; color: var(--accent);
  text-align: center; margin-bottom: 4px;
}
.center-box h1 { text-align: center; font-size: 22px; margin: 6px 0 14px; }

.people-list { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.person-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; font-size: 17px; font-weight: 600; text-align: left; cursor: pointer;
  box-shadow: var(--shadow); min-height: 60px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.person-btn small { color: var(--muted); font-weight: 500; font-size: 13px; text-align: right; }
.person-btn:disabled { opacity: 0.55; cursor: default; }

/* ---------- Campos y botones ---------- */
.field { display: block; margin: 12px 0; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 13px; font-size: 17px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.search {
  width: 100%; padding: 13px; font-size: 16px; margin: 4px 0 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
}

.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 12px; padding: 12px 16px; font-size: 15px; font-weight: 600;
  cursor: pointer; min-height: 48px;
}
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 2px 8px rgba(179, 39, 30, 0.25);
}
.btn-primary:active { background: var(--accent-dark); }
.btn-big { width: 100%; min-height: 58px; font-size: 17px; margin-top: 10px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); padding-left: 4px; }
.btn-small { min-height: 36px; padding: 6px 10px; font-size: 13px; }
.btn-danger { color: var(--accent); }

.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Tarjetas y listas ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin: 12px 0;
}
.card h2 { margin: 0 0 8px; font-size: 18px; }

.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.module-card { text-align: left; cursor: pointer; font: inherit; width: 100%; }
.module-card h3 { margin: 0 0 4px; font-size: 17px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.module-card p { margin: 0; color: var(--muted); font-size: 14px; }
.module-card.disabled { cursor: default; opacity: 0.85; }

.chip {
  display: inline-block; background: var(--soft); color: var(--ink);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; white-space: nowrap;
}
.chip-soft { background: #efe9df; color: var(--muted); }
.chip-ok { background: #e3f1e3; color: var(--ok); }
.chip-warn { background: #fbeecd; color: var(--warn); }
.chip-bad { background: #fbe3e1; color: var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip-btn {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 9px 14px; font-size: 14px; font-weight: 600; cursor: pointer; min-height: 42px;
}
.chip-btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.row-main { min-width: 0; }
.row-title { font-weight: 700; font-size: 16px; }
.row-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.row-actions { display: flex; gap: 8px; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
.empty { color: var(--muted); text-align: center; padding: 22px 0; }

/* ---------- Etiquetas ---------- */
.segmented {
  display: flex; background: var(--soft); border-radius: 12px; padding: 4px; margin-bottom: 14px;
}
.seg {
  flex: 1; border: none; background: transparent; padding: 11px; font-size: 15px;
  font-weight: 600; color: var(--muted); border-radius: 9px; cursor: pointer; min-height: 46px;
}
.seg.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 10px; }
.product-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; text-align: left; cursor: pointer;
  min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  font: inherit;
}
.product-btn .p-name { font-weight: 700; font-size: 16px; line-height: 1.25; }
.product-btn .p-life { font-size: 13px; color: var(--muted); }

.qty-row {
  display: flex; justify-content: space-between; align-items: center;
  margin: 14px 0 4px; font-weight: 600; font-size: 16px;
}
.stepper { display: flex; align-items: center; gap: 14px; }
.step-btn {
  width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--soft); font-size: 26px; cursor: pointer; line-height: 1;
}
.qty-value { font-size: 22px; font-weight: 800; min-width: 34px; text-align: center; }

/* Cara de la etiqueta: vista previa en pantalla y salida de impresión.
   El tamaño físico lo fijan las variables --lw / --lh (en pulgadas). */
.label-preview-wrap { display: flex; justify-content: center; padding: 10px 0 2px; }
.label-face {
  width: var(--lw, 2in); height: var(--lh, 2in);
  background: #fff; color: #000;
  border: 1.5px dashed #b9ac99;
  padding: calc(var(--lw, 2in) * 0.055);
  font-family: Arial, Helvetica, sans-serif;
  font-size: calc(var(--lw, 2in) * 0.072);
  line-height: 1.25;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.label-face .lf-name { font-weight: 700; font-size: 1.55em; line-height: 1.15; }
.label-face .lf-who { font-size: 0.95em; margin-top: 0.25em; }
.label-face .lf-date { font-size: 0.95em; }
.label-face .lf-use { font-size: 0.95em; margin-top: 0.55em; }
.label-face .lf-day { font-weight: 700; font-size: 1.5em; line-height: 1.15; }
.label-face .lf-exc { font-size: 0.9em; margin-top: 0.45em; font-weight: 600; }

/* ---------- Hoja modal ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(30, 22, 15, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}
.sheet h2 { margin: 0 0 6px; font-size: 19px; }
.total-big { font-size: 26px; font-weight: 800; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--ink); color: #fff; border-radius: 999px;
  padding: 12px 20px; font-size: 15px; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  max-width: 92vw; text-align: center;
}

/* ---------- Impresión ---------- */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  body { background: #fff; }
  #print-area { display: block; }
  .print-label {
    width: var(--lw); height: var(--lh);
    page-break-after: always; break-after: page;
    overflow: hidden;
  }
  .print-label:last-child { page-break-after: auto; break-after: auto; }
  .print-label .label-face { border: none; }
}
