:root {
  /* Identidad Grupo BahíaPlaya */
  --brand-orange: #FFB400;
  --brand-yellow: #FFE40E;
  --brand-deep: #8A6200;
  --brand-ink: #3D2E05;
  --brand-tint: #FFF6DC;
  --brand-border: #F2DFA6;

  /* Estados funcionales (seguridad alimentaria) */
  --ok: #1f6f43;
  --ok-light: #eafaf1;
  --red: #c0392b;
  --red-light: #fdecea;
  --amber: #b8860b;
  --amber-light: #fdf3d9;

  --bg: #FAF7F0;
  --surface: #ffffff;
  --text: #2A2318;
  --text-dim: #6B5F4A;
  --border: #E8E1D3;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 84px;
}

header.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(100deg, var(--brand-orange) 0%, var(--brand-yellow) 100%);
  color: var(--brand-ink);
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow);
}

header.topbar h1 {
  font-size: 17px; margin: 0; font-weight: 700;
}

#operatorChip {
  background: rgba(61,46,5,0.12);
  border: 1px solid rgba(61,46,5,0.18);
  color: var(--brand-ink);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}

main { padding: 16px; flex: 1; }

section.view { display: none; }
section.view.active { display: block; }

h2.section-title {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  margin: 20px 0 10px;
}
h2.section-title:first-child { margin-top: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.zone-card { padding: 8px 0 4px; }
.zone-card h3 {
  font-size: 14px; margin: 6px 16px 8px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .03em;
}

.cp-row, .task-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.zone-card .task-row:first-of-type { border-top: none; }

.cp-name, .task-name { font-weight: 600; font-size: 15px; }
.cp-range { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.pill-group { display: flex; gap: 8px; }

.pill-btn {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  min-width: 68px;
  text-align: center;
}
.pill-btn.done {
  background: var(--ok-light);
  border-color: var(--ok);
  color: var(--ok);
}
.pill-btn.out {
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red);
}
.pill-btn.pending {
  background: var(--amber-light);
  border-color: var(--amber);
  color: var(--amber);
}

.check-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.check-btn.done {
  background: var(--ok);
  border-color: var(--ok);
  color: white;
}

nav.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 640px; margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
}
nav.tabbar button {
  flex: 1;
  background: none; border: none;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
}
nav.tabbar button .icon { font-size: 20px; }
nav.tabbar button.active { color: var(--brand-deep); }

button.primary {
  background: linear-gradient(100deg, var(--brand-orange), var(--brand-yellow));
  color: var(--brand-ink);
  border: none;
  padding: 13px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
  width: 100%;
}
button.secondary {
  background: var(--brand-tint);
  color: var(--brand-deep);
  border: 1.5px solid var(--brand-border);
  padding: 11px 16px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
}
button.link {
  background: none; border: none; color: var(--brand-deep);
  font-weight: 600; font-size: 14px; padding: 6px 0;
}

input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
  margin-bottom: 10px;
}
label { font-size: 13px; font-weight: 600; color: var(--text-dim); display: block; margin-bottom: 4px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface);
  width: 100%; max-width: 640px;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
}
.modal h3 { margin-top: 0; }

.badge {
  display: inline-block;
  font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 999px;
  background: var(--brand-tint); color: var(--brand-deep);
}
.badge.weekly { background: #eaf1fd; color: #1d4ed8; }

.history-item {
  padding: 10px 0; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.history-item:first-child { border-top: none; }
.history-meta { font-size: 12px; color: var(--text-dim); }
.history-value { font-weight: 700; font-size: 15px; }
.history-value.out { color: var(--red); }

.empty-state { text-align: center; color: var(--text-dim); padding: 30px 10px; font-size: 14px; }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--brand-ink); color: #FFE9A8; padding: 10px 18px;
  border-radius: 999px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow); z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast.error { background: var(--red); }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters select, .filters input { margin-bottom: 0; width: auto; flex: 1; min-width: 120px; }

@media print {
  header.topbar, nav.tabbar, .no-print { display: none !important; }
  body { background: white; }
}

/* ---------- Identidad de marca ---------- */
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  height: 38px; width: auto; display: block;
  background: rgba(255,255,255,0.92);
  border-radius: 9px; padding: 3px 5px;
}
header.topbar h1 { font-size: 16px; line-height: 1.15; }
.brand-sub {
  font-size: 11px; font-weight: 700; letter-spacing: .03em;
  color: rgba(61,46,5,0.72); margin-top: 1px;
}

/* ---------- Selector de área (Restaurante / Cafetería) ---------- */
.area-switch {
  position: sticky; top: 66px; z-index: 19;
  display: flex; gap: 6px; padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.area-switch button {
  flex: 1;
  border: 1.5px solid var(--brand-border);
  background: var(--surface);
  color: var(--text-dim);
  padding: 10px 8px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
}
.area-switch button.active {
  background: linear-gradient(100deg, var(--brand-orange), var(--brand-yellow));
  border-color: var(--brand-orange);
  color: var(--brand-ink);
}

/* ---------- Pantalla de acceso ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(160deg, var(--brand-orange) 0%, var(--brand-yellow) 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-screen.hidden { display: none; }
.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 22px calc(24px + env(safe-area-inset-bottom));
  width: 100%; max-width: 380px;
  box-shadow: 0 10px 40px rgba(61,46,5,0.22);
}
.login-logo { display: block; height: 64px; width: auto; margin: 0 auto 14px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.login-sub { font-size: 13px; color: var(--text-dim); text-align: center; margin: 0 0 20px; }
.login-error {
  color: var(--red); background: var(--red-light);
  border-radius: 9px; padding: 9px 12px; font-size: 13px; font-weight: 600;
  margin-bottom: 10px; display: none;
}
.login-error.show { display: block; }
.hidden-until-login { display: none; }

/* ---------- Informes ---------- */
.quick-ranges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.quick-ranges button {
  border: 1.5px solid var(--brand-border);
  background: var(--surface);
  color: var(--text-dim);
  padding: 8px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700;
}
.quick-ranges button.active {
  background: var(--brand-tint); border-color: var(--brand-orange); color: var(--brand-deep);
}

.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; text-align: center;
}
.kpi-value { font-size: 21px; font-weight: 800; line-height: 1.1; }
.kpi-value.good { color: var(--ok); }
.kpi-value.bad { color: var(--red); }
.kpi-label { font-size: 11px; color: var(--text-dim); font-weight: 600; margin-top: 3px; }

.bar-row { padding: 9px 0; border-top: 1px solid var(--border); }
.bar-row:first-child { border-top: none; }
.bar-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 5px; }
.bar-name { font-weight: 600; }
.bar-val { font-weight: 700; color: var(--text-dim); white-space: nowrap; }
.bar-track { height: 7px; background: var(--border); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--ok); }
.bar-fill.warn { background: var(--amber); }
.bar-fill.bad { background: var(--red); }

.send-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.send-actions button { width: 100%; }
.wa-btn {
  background: #25D366; color: #fff; border: none;
  padding: 13px 16px; border-radius: 12px; font-weight: 700; font-size: 14.5px; width: 100%;
}
.wa-btn:disabled { opacity: .5; }
.report-note { font-size: 12px; color: var(--text-dim); margin-top: 8px; line-height: 1.5; }
