:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #c2410c;
  --accent-soft: #fff1e8;
  --ok: #15803d;
  --danger: #b91c1c;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: .95rem; margin: 18px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: #1f2937; color: #fff;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; padding: 12px 0; white-space: nowrap; }
#nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
#nav::-webkit-scrollbar { display: none; }
#nav a { color: #d1d5db; text-decoration: none; padding: 14px 10px; white-space: nowrap; border-bottom: 3px solid transparent; }
#nav a.active { color: #fff; border-bottom-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 80px; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 16px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.spacer { flex: 1; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }

/* Controles */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px;
  border: 1px solid var(--line); background: #fff; color: var(--text); text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: #cbd5e1; background: #f9fafb; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #9a3412; }
button.danger { color: var(--danger); }
button.whatsapp { background: #16a34a; border-color: #16a34a; color: #fff; }
button.icon { padding: 4px 9px; line-height: 1.2; }
button.link { border: none; background: none; color: var(--accent); padding: 2px 4px; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit; color: inherit; padding: 7px 9px; border: 1px solid #d1d5db; border-radius: 7px; background: #fff; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #fdba74; border-color: var(--accent); }
input.qty { width: 90px; text-align: right; }
input.mine { background: var(--accent-soft); border-color: #fdba74; }
input.edited { background: #fef9c3; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { color: var(--text); font-size: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }

/* Tablas */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; }
tr.cat-row td { background: #f3f4f6; font-weight: 700; font-size: .85rem; color: #374151; padding-top: 8px; }
tfoot td { font-weight: 700; border-bottom: none; }
.table-wrap { overflow-x: auto; }

/* Chips */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: #f3f4f6; font-size: .85rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: #e5e7eb; }
.badge.open { background: #fef3c7; color: #92400e; }
.badge.done { background: #dcfce7; color: var(--ok); }

/* Calendario */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal-h { font-size: .75rem; color: var(--muted); padding: 6px; text-align: center; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fafafa; }
.cal-d { min-height: 96px; padding: 4px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fff; cursor: pointer; overflow: hidden; }
.cal-d.other { background: #fafafa; color: #9ca3af; }
.cal-d.today .cal-n { background: var(--accent); color: #fff; }
.cal-n { font-size: .8rem; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; }
.ev {
  display: block; width: 100%; text-align: left; margin-top: 3px; padding: 2px 6px; border-radius: 5px; border: none;
  font-size: .75rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ev:hover { filter: brightness(1.1); background-color: inherit; }

.ev-list .item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ev-list .item:last-child { border-bottom: none; }
.ev-date { width: 54px; text-align: center; flex: none; }
.ev-date b { display: block; font-size: 1.3rem; line-height: 1; }

/* Listas de compra (pensadas para el celular) */
.check-row { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.check-row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--ok); flex: none; }
.check-row .name { flex: 1; min-width: 0; }
.check-row.checked .name { text-decoration: line-through; color: var(--muted); }
.check-row .extra { display: flex; gap: 6px; align-items: center; }
.progress { height: 6px; background: #e5e7eb; border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--ok); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; white-space: nowrap; }
.tabs button.active { border-bottom-color: var(--accent); font-weight: 600; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.menu-card { cursor: pointer; margin: 0; }
.menu-card:hover { border-color: #fdba74; }
.menu-card p { white-space: pre-line; max-height: 4.4em; overflow: hidden; margin: 6px 0; }

.stat { font-size: 1.5rem; font-weight: 700; }

/* Modal */
dialog { border: none; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(17,24,39,.45); }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; }
#toast.error { background: var(--danger); }

@media (max-width: 700px) {
  main { padding: 14px 10px 80px; }
  .brand { display: none; }
  .cal-d { min-height: 62px; padding: 2px; }
  .ev { font-size: 0; height: 8px; padding: 0; margin-top: 2px; }
  .hide-sm { display: none; }
  th, td { padding: 6px 4px; }
  input.qty { width: 72px; }
  .check-row { flex-wrap: wrap; }
  .check-row .extra { width: 100%; padding-left: 32px; }
}
