:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --border: #e6e1d8;
  --text: #2b2622;
  --muted: #857c72;
  --primary: #c2410c;
  --primary-soft: #fde8dc;
  --success: #15803d;
  --success-soft: #dcf3e3;
  --warning: #b45309;
  --warning-soft: #fdf0d5;
  --danger: #b91c1c;
  --danger-soft: #fde2e2;
  --info: #1d4ed8;
  --info-soft: #dde7fd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(43, 38, 34, .06), 0 4px 12px rgba(43, 38, 34, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
h2, h3 { margin: 0; }
h3 { font-size: 16px; margin-bottom: 12px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.muted { color: var(--muted); font-size: 14px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 22px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tab {
  border: 0; background: none; padding: 8px 14px; border-radius: 8px;
  cursor: pointer; color: var(--muted); white-space: nowrap; position: relative;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.badge {
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 11px; padding: 1px 6px; margin-left: 4px; font-weight: 700;
}
.clock { color: var(--muted); font-variant-numeric: tabular-nums; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.view-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.view-head h2 { flex: 1; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Botones */
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  cursor: pointer; font-weight: 600; background: var(--surface-2);
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.success { background: var(--success); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn.danger.ghost { color: var(--danger); background: var(--surface); }
.btn.icon { padding: 4px 10px; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:not(:disabled):hover { filter: brightness(.95); }

/* Mesas */
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 14px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.dot.libre { background: var(--success); }
.dot.ocupada { background: var(--warning); }
.dot.listo { background: var(--info); }
.mesas-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.mesa {
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; text-align: left; box-shadow: var(--shadow);
  min-height: 120px; display: flex; flex-direction: column; gap: 4px;
  transition: transform .1s;
}
.mesa:hover { transform: translateY(-2px); }
.mesa .n { font-size: 22px; font-weight: 700; }
.mesa .estado { font-size: 13px; font-weight: 600; }
.mesa .info { font-size: 13px; color: var(--muted); margin-top: auto; }
.mesa.libre { border-color: #bfe5cb; }
.mesa.libre .estado { color: var(--success); }
.mesa.ocupada { border-color: #f2d19b; background: #fffaf0; }
.mesa.ocupada .estado { color: var(--warning); }
.mesa.listo { border-color: #a9c0f5; background: #f5f8ff; }
.mesa.listo .estado { color: var(--info); }
.mesa.llevar { border-style: dashed; }

/* Pedido */
.pedido-layout { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
.catalogo { display: flex; flex-direction: column; gap: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; cursor: pointer; font-size: 14px;
}
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }
.productos-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.producto {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 6px;
  min-height: 84px; box-shadow: var(--shadow);
}
.producto:hover { border-color: var(--primary); }
.producto .nombre { font-weight: 600; }
.producto .precio { color: var(--primary); font-weight: 700; margin-top: auto; }

.cuenta {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; position: sticky; top: 80px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 100px);
}
.cuenta-meta { display: grid; grid-template-columns: 1fr 90px; gap: 8px; }
.cuenta-meta label, .form label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.items { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; min-height: 80px; }
.items .vacio { color: var(--muted); text-align: center; padding: 24px 0; }
.item { padding: 10px 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; }
.item .top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.item .nombre { font-weight: 600; }
.item .nota { grid-column: 1 / -1; font-size: 13px; color: var(--muted); font-style: italic; }
.item .controles { display: flex; gap: 4px; align-items: center; }
.item .controles button { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.item .sub { font-weight: 600; }
.estado-tag {
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .02em;
}
.estado-tag.nuevo { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--border); }
.estado-tag.pendiente { background: var(--warning-soft); color: var(--warning); }
.estado-tag.preparando { background: var(--primary-soft); color: var(--primary); }
.estado-tag.listo { background: var(--info-soft); color: var(--info); }
.estado-tag.entregado { background: var(--success-soft); color: var(--success); }
.cuenta-total { display: flex; justify-content: space-between; font-size: 18px; padding-top: 4px; }
.cuenta-acciones { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cuenta-acciones .btn { padding: 12px; }

/* Cocina */
.comandas { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); align-items: start; }
.comanda {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border-top: 6px solid var(--warning); overflow: hidden;
}
.comanda.preparando { border-top-color: var(--primary); }
.comanda.listo { border-top-color: var(--info); }
.comanda-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; background: var(--surface-2); }
.comanda-head strong { font-size: 18px; }
.comanda-head .tiempo { font-size: 13px; font-weight: 600; color: var(--muted); }
.comanda-head .tiempo.tarde { color: var(--danger); }
.comanda ul { list-style: none; margin: 0; padding: 8px 14px; }
.comanda li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.comanda li:last-child { border-bottom: 0; }
.comanda li .cant { font-weight: 700; margin-right: 6px; }
.comanda li .nota { display: block; font-size: 13px; color: var(--danger); font-style: italic; }
.comanda-foot { padding: 10px 14px; display: flex; gap: 8px; }
.comanda-foot .btn { flex: 1; }
.vacio-grande { text-align: center; color: var(--muted); padding: 60px 20px; grid-column: 1 / -1; }

/* Tablas y tarjetas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.tabla { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.view > .tabla { border: 1px solid var(--border); box-shadow: var(--shadow); }
.tabla th, .tabla td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.tabla th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.tabla th.num, .tabla td.num { text-align: right; }
.tabla tr:last-child td { border-bottom: 0; }
.tabla .cat-row td { background: var(--surface-2); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.acciones-fila { display: flex; gap: 6px; justify-content: flex-end; }
.switch { position: relative; width: 40px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::before { transform: translateX(18px); }

.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .valor { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.reportes { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.barra { display: grid; grid-template-columns: 130px 1fr 110px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 14px; }
.barra .track { background: var(--surface-2); border-radius: 6px; height: 12px; overflow: hidden; }
.barra .fill { background: var(--primary); height: 100%; border-radius: 6px; }
.barra .v { text-align: right; font-variant-numeric: tabular-nums; }
.inline { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.inline input { width: auto; }

.form { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.form .btn { grid-column: 1 / -1; justify-self: start; }
.form .full { grid-column: 1 / -1; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 16, 12, .45); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal .form { grid-template-columns: 1fr; }
.modal .fila { display: flex; justify-content: space-between; padding: 6px 0; }
.modal .fila.total { font-size: 22px; font-weight: 700; border-top: 2px solid var(--text); margin-top: 6px; padding-top: 10px; }
.metodos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.metodo { border: 2px solid var(--border); border-radius: 8px; padding: 10px; cursor: pointer; background: var(--surface); font-weight: 600; }
.metodo.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.mesas-mini { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 8px; }
.mesas-mini button { padding: 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; }
.mesas-mini button:disabled { opacity: .35; cursor: not-allowed; }
.cambio { background: var(--success-soft); color: var(--success); padding: 10px; border-radius: 8px; font-weight: 700; text-align: center; }
.cambio.falta { background: var(--danger-soft); color: var(--danger); }

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

/* Recibo (solo impresión) */
.recibo { display: none; }
@media print {
  body > *:not(.recibo) { display: none !important; }
  .recibo { display: block; width: 72mm; font-family: "Courier New", monospace; font-size: 12px; color: #000; }
  .recibo h4 { text-align: center; margin: 0 0 4px; font-size: 15px; }
  .recibo .c { text-align: center; }
  .recibo .l { display: flex; justify-content: space-between; }
  .recibo hr { border: 0; border-top: 1px dashed #000; }
  @page { margin: 4mm; }
}

@media (max-width: 900px) {
  .pedido-layout { grid-template-columns: 1fr; }
  .cuenta { position: static; max-height: none; }
  .reportes, .form { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .clock { display: none; }
}
