/* ── Estilo mobile-first para la app de comandas (Xiringuito Baradello) ── */
:root {
  --bg: #eef1ef;
  --bg-soft: #e6ebe8;
  --card: #ffffff;
  --ink: #1b2a2a;
  --muted: #6c7b7a;
  --accent: #0f4c4c;       /* teal profundo (cabecera) */
  --accent-2: #137a6e;     /* teal de acción */
  --accent-soft: #e7f1ee;  /* fondo de chips y suaves */
  --cta: #e8852f;          /* naranja chiringuito (cobrar) */
  --cta-press: #cf7322;
  --danger: #c0392b;
  --danger-soft: #fbeae8;
  --ok: #2e7d32;
  --border: #e1e7e5;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 40, .05), 0 6px 18px rgba(16, 40, 40, .06);
  --shadow-sm: 0 1px 2px rgba(16, 40, 40, .06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* ── Cabecera ── */
header {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(15, 76, 76, .25);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-size: 1.5rem;
  line-height: 1;
  background: rgba(255, 255, 255, .14);
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px;
}
header h1 { font-size: 1.05rem; margin: 0; letter-spacing: .5px; font-weight: 700; }
.brand-sub {
  font-size: .72rem; letter-spacing: 1.5px; text-transform: uppercase;
  color: rgba(255, 255, 255, .7);
}
.header-link {
  color: #fff;
  text-decoration: none;
  font-size: .85rem;
  background: rgba(255, 255, 255, .14);
  padding: 8px 12px;
  border-radius: 999px;
  white-space: nowrap;
  transition: background .15s;
}
.header-link:active { background: rgba(255, 255, 255, .28); }

main { padding: 16px; max-width: 760px; margin: 0 auto; }

.hidden { display: none !important; }

/* ── Botones ── */
button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  background: var(--accent-2);
  color: #fff;
  transition: transform .08s, filter .15s, background .15s;
}
button:active { transform: translateY(1px); filter: brightness(.95); }
button:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
button.secondary { background: var(--bg-soft); color: var(--ink); }
button.danger { background: var(--danger); }
button.ghost { background: transparent; color: var(--accent-2); padding: 6px 8px; font-weight: 600; }
button.small { padding: 7px 12px; font-size: .85rem; border-radius: 9px; }
button.cta { background: var(--cta); }
button.cta:active { background: var(--cta-press); }

input, select, textarea {
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 100%;
  background: #fff;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; }

/* ── Vista de mesas ── */
.open-table-row {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--card);
  padding: 10px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.open-table-row input { flex: 1; border: none; box-shadow: none; }
.open-table-row input:focus { box-shadow: none; }
.open-table-row button { white-space: nowrap; }

.tables-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.table-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform .1s, box-shadow .15s;
}
.table-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent-2), var(--cta));
}
.table-card:active { transform: scale(.98); }
@media (hover: hover) {
  .table-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
}
.table-card .name { font-weight: 700; font-size: 1.1rem; margin-top: 4px; }
.table-card .total { color: var(--accent-2); font-weight: 800; font-size: 1.15rem; }
.table-card .count {
  color: var(--muted); font-size: .8rem;
  display: inline-flex; align-items: center; gap: 5px;
}
.table-card .count::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok); display: inline-block;
}

.empty-msg {
  color: var(--muted);
  text-align: center;
  padding: 48px 20px;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Comanda ── */
.order-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}
.order-head h2 { margin: 0; font-size: 1.25rem; }

.section-title {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin: 18px 0 8px;
  font-weight: 700;
  display: block;
}

/* Líneas de la comanda */
.item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.item-top { display: flex; justify-content: space-between; gap: 8px; }
.item-name { font-weight: 600; }
.item-variant { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.item-subtotal { font-weight: 800; white-space: nowrap; color: var(--accent); }
.item-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.qty {
  display: flex; align-items: center; gap: 0;
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 3px;
}
.qty button {
  width: 36px; height: 36px; padding: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--accent);
  font-size: 1.2rem; font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.qty span { min-width: 32px; text-align: center; font-weight: 700; }
.item-controls .danger {
  margin-left: auto;
  background: var(--danger-soft) !important;
  color: var(--danger) !important;
}
.item .comment { margin-top: 10px; }

/* Pie fijo con total + acciones */
.order-footer {
  position: sticky;
  bottom: 0;
  margin: 16px -16px 0;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 18px rgba(16, 40, 40, .06);
}
.order-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 10px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.order-total #order-total-amount { color: var(--accent-2); }
.order-actions { display: flex; gap: 8px; }
.order-actions button { flex: 1; padding: 14px; font-size: 1rem; }
.order-actions #refresh-btn { flex: 0 0 auto; }

/* ── Menú (modal selección de productos) ── */
.menu-category { margin-bottom: 8px; }
.menu-category h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  color: var(--accent);
  padding: 8px 0 6px;
  border-bottom: 2px solid var(--accent-soft);
  position: sticky;
  top: 44px;
  background: var(--bg);
  z-index: 2;
}
.menu-subcategory {
  margin: 14px 0 4px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent-2);
}
.menu-product { padding: 10px 0; border-bottom: 1px solid var(--border); }
.menu-product .p-name { font-weight: 600; }
.menu-product .p-desc { color: var(--muted); font-size: .82rem; margin: 3px 0; }
.variant-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.variant-buttons button {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #d3e6e0;
  font-weight: 600;
  border-radius: 999px;
}
.variant-buttons button:active { background: #d8ebe5; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(12, 30, 30, .5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg);
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 0 16px 24px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
  animation: slideup .22s cubic-bezier(.2, .7, .3, 1);
}
@keyframes slideup { from { transform: translateY(24px); } to { transform: translateY(0); } }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; background: var(--bg);
  padding: 16px 0 10px; margin-bottom: 4px;
  z-index: 3;
}
.modal-head strong { font-size: 1.05rem; }
.modal::before {
  content: "";
  display: block;
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 8px auto 0;
}

/* ── Admin ── */
.admin-product {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.admin-product .row { display: flex; gap: 8px; align-items: center; margin-bottom: 9px; }
.admin-product .row label { font-size: .78rem; color: var(--muted); min-width: 72px; font-weight: 600; }
.admin-variant {
  display: flex; gap: 6px; align-items: center; margin-bottom: 6px;
  background: var(--bg-soft); padding: 6px; border-radius: var(--radius-sm);
}
.admin-variant input { background: #fff; }
.admin-variant input.label-in { flex: 2; }
.admin-variant input.price-in { flex: 1; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  opacity: 0; transition: opacity .2s, transform .2s; z-index: 100; font-size: .9rem;
  font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
