:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #2b2420;
  --muted: #7a6f66;
  --line: #ece5dc;
  --brand: #c2410c;
  --brand-dark: #9a3412;
  --brand-soft: #fff1e6;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --warn: #b45309;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.wrap.wide { max-width: 1100px; }

header.top {
  background: var(--brand);
  color: #fff;
  padding: 18px 0 16px;
}
header.top h1 { font-size: 1.4rem; margin: 0; }
header.top .sub { opacity: .85; font-size: .9rem; }

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

.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--line); }
.btn.secondary:hover { background: var(--brand-soft); }
.btn.ghost { background: transparent; color: var(--brand); border-color: transparent; }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.danger { background: #fff; color: var(--danger); border-color: #f3c7c7; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ok { background: var(--ok); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: .875rem; }

label { display: block; font-weight: 600; font-size: .9rem; margin: 10px 0 4px; }
input, textarea, select {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid #d9d0c5;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 64px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.alert { padding: 12px 14px; border-radius: 10px; margin: 12px 0; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--brand-soft); color: var(--brand-dark); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }

.badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--line);
  color: var(--text);
  white-space: nowrap;
}
.badge.nuevo { background: #fde68a; color: #78350f; }
.badge.preparando { background: #bfdbfe; color: #1e3a8a; }
.badge.en_camino { background: #ddd6fe; color: #4c1d95; }
.badge.entregado { background: #bbf7d0; color: #14532d; }
.badge.cancelado { background: #fecaca; color: #7f1d1d; }
.badge.delivery { background: #e0f2fe; color: #075985; }
.badge.pickup { background: #fce7f3; color: #9d174d; }
.badge.soldout { background: #e5e7eb; color: #4b5563; }

/* ---------- Menú (vecinos) ---------- */
.category-title { margin: 22px 0 6px; font-size: 1.05rem; color: var(--brand-dark); }
.dish {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.dish:last-child { border-bottom: 0; }
.dish .info { flex: 1; min-width: 0; }
.dish .name { font-weight: 600; }
.dish .desc { color: var(--muted); font-size: .9rem; }
.dish .price { font-weight: 700; margin-top: 2px; }
.dish.out { opacity: .55; }

.qty { display: flex; align-items: center; gap: 6px; }
.qty button {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--brand);
  cursor: pointer;
}
.qty button.add { background: var(--brand); color: #fff; border-color: var(--brand); }
.qty span { min-width: 22px; text-align: center; font-weight: 700; }

.cart-bar {
  position: sticky;
  bottom: 0;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.summary-line { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.summary-line.total { font-weight: 700; font-size: 1.1rem; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }

.pay-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pay-options label {
  margin: 0;
  border: 1px solid #d9d0c5;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 500;
  cursor: pointer;
}
.pay-options input { width: auto; }
.pay-options label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.pay-options label:has(input:disabled) { opacity: .45; cursor: not-allowed; text-decoration: line-through; }

.steps { display: flex; gap: 4px; margin: 14px 0; }
.steps div { flex: 1; text-align: center; font-size: .75rem; color: var(--muted); }
.steps div::before {
  content: ""; display: block; height: 6px; border-radius: 3px; background: var(--line); margin-bottom: 6px;
}
.steps div.done { color: var(--text); font-weight: 600; }
.steps div.done::before { background: var(--brand); }

/* ---------- Admin ---------- */
nav.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 10px 0 0; }
nav.tabs button {
  border: 0; background: transparent; color: #fff; opacity: .8;
  font: inherit; font-weight: 600; padding: 10px 14px; border-radius: 10px 10px 0 0; cursor: pointer; white-space: nowrap;
}
nav.tabs button.active { background: var(--bg); color: var(--brand); opacity: 1; }
header.top.admin { padding-bottom: 0; }
.app-version { font-size: .75rem; font-weight: 500; opacity: .7; vertical-align: middle; }

.orders-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.order-card { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.order-card.nuevo { border-left: 5px solid #f59e0b; }
.order-card.cancelado, .order-card.entregado { opacity: .7; }
.order-card ul { margin: 0; padding-left: 18px; }
.ready-select { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; }
.ready-select select { width: auto; padding: 6px 10px; font-weight: 700; }
.ready-time { background: var(--brand-soft); color: var(--brand-dark); border-radius: 10px; padding: 8px 12px; margin: 10px 0; font-weight: 600; }
.order-card .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--line); }
table.list td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list input { padding: 7px 9px; }
table.list .price-input { max-width: 120px; }
@media (min-width: 701px) {
  table.list th:nth-child(1) { width: 1%; }
  table.list th:nth-child(2) { width: 26%; }
  table.list th:nth-child(3) { width: 16%; }
  table.list th:nth-child(5) { width: 120px; }
  table.list th:nth-child(6) { width: 1%; }
}

/* ---------- fotos ---------- */
.photo-cell { white-space: nowrap; }
.photo-cell.uploading { opacity: .5; pointer-events: none; }
.photo-thumb {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
  width: 52px; height: 52px; border-radius: 10px; overflow: hidden; margin: 0;
  background: var(--brand-soft); border: 1px dashed #e7c3a8; cursor: pointer; font-size: 1.3rem;
}
.photo-thumb:not(.empty) { border-style: solid; border-color: var(--line); }
span.photo-thumb { cursor: not-allowed; opacity: .5; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.menu-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex: none; }

.dish-img {
  flex: none; width: 76px; height: 76px; padding: 0; border: 0; border-radius: 12px; overflow: hidden;
  background: var(--line); cursor: zoom-in;
}
.dish-img img { width: 100%; height: 100%; object-fit: cover; display: block; }

dialog.zoom {
  border: 0; border-radius: var(--radius); padding: 0; max-width: min(92vw, 640px);
  background: var(--card); box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
dialog.zoom::backdrop { background: rgba(0,0,0,.6); }
dialog.zoom img { display: block; width: 100%; height: auto; max-height: 70vh; object-fit: contain; background: #000; }
dialog.zoom .zoom-info { padding: 12px 16px; display: flex; gap: 12px; align-items: center; }
@media (max-width: 700px) {
  table.list thead { display: none; }
  table.list tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.list td { border: 0; padding: 0; }
  table.list td.full { grid-column: 1 / -1; }
  table.list .price-input { max-width: none; }
}

.menu-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.menu-row:last-child { border-bottom: 0; }
.menu-row .grow { flex: 1; min-width: 0; }
.menu-row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; margin: 0; }
.switch input { width: 22px; height: 22px; accent-color: var(--ok); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chips button {
  border: 1px solid var(--line); background: var(--brand-soft); color: var(--brand-dark);
  font: inherit; font-size: .8rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; cursor: pointer;
}
.chips button:hover { border-color: var(--brand); }
.message-field { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.message-field textarea { min-height: 120px; }
.message-preview {
  white-space: pre-wrap; background: #e7f8dc; border-radius: 10px; padding: 10px 12px;
  font-size: .875rem; margin-top: 8px;
}
.message-preview.off { background: #f1efec; color: var(--muted); font-style: italic; }

/* ---------- catálogo (panel) ---------- */
dialog.catalog {
  border: 0; border-radius: var(--radius); padding: 0; width: min(96vw, 980px); max-height: 92vh;
  background: var(--bg); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.35);
  display: none; flex-direction: column;
}
dialog.catalog[open] { display: flex; }
dialog.catalog::backdrop { background: rgba(0,0,0,.5); }
.catalog-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px; }
.catalog-head h2 { flex: 1; }
.catalog-body { overflow: auto; padding: 4px 16px 16px; flex: 1; }
.catalog-foot { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--card); }
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.cat-item {
  background: var(--card); border: 2px solid var(--line); border-radius: 12px; overflow: hidden;
  display: flex; flex-direction: column; text-align: left; padding: 0; font: inherit; color: inherit;
}
.cat-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--line); }
.cat-item .cat-info { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.cat-item .cat-name { font-weight: 700; font-size: .92rem; }
.cat-item .cat-desc { color: var(--muted); font-size: .78rem; line-height: 1.3; }
.cat-item .cat-row { display: flex; align-items: center; gap: 6px; margin-top: auto; padding-top: 4px; }
.cat-item .cat-row input[type=number] { padding: 5px 8px; font-size: .85rem; }
.cat-item .cat-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.cat-item:has(input[type=checkbox]:checked) { border-color: var(--brand); }
.cat-item.exists { opacity: .55; }
button.cat-item { cursor: pointer; }
button.cat-item:hover { border-color: var(--brand); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 100; max-width: calc(100% - 32px);
}
