* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #b8860b;
  --primary-dark: #8b6508;
  --bg: #f3efe4;
  --card: #ffffff;
  --text: #2b2b2b;
  --muted: #8a8a8a;
  --green: #2e7d32;
  --red: #c62828;
  --border: #e4dcc9;
}

html { font-size: 16px; }

body {
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: 40px;
}

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.topbar-inner { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.topbar h1 { font-size: 1.15rem; font-weight: 700; }
.badge {
  background: rgba(255,255,255,.22);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: .72rem;
  vertical-align: middle;
}
.badge-dark { background: #3a3a3a; color: #fff; }
.caja-info { font-size: .8rem; background: rgba(0,0,0,.18); padding: 4px 10px; border-radius: 20px; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.btn-qr {
  border: 1px solid rgba(255,255,255,.45);
  background: rgba(255,255,255,.18);
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-qr:active { background: rgba(255,255,255,.32); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 51px;
  z-index: 40;
}
.tab {
  flex: 1;
  padding: 13px 4px;
  border: none;
  background: transparent;
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab.active {
  color: var(--primary-dark);
  border-bottom-color: var(--primary);
}

/* ---------- Panels ---------- */
.tab-panel { display: none; padding: 14px; }
.tab-panel.active { display: block; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.card-title { font-size: 1rem; margin-bottom: 10px; color: var(--primary-dark); }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field span { font-size: .75rem; color: var(--muted); font-weight: 600; }
.field input, .field select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  background: #fff;
  width: 100%;
}
.field input:focus, .field select:focus { outline: 2px solid var(--primary); border-color: transparent; }
.row-cliente { display: flex; gap: 10px; align-items: flex-end; }
.grow { flex: 1; }
.grow .field { margin: 0; }

.input-big {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 1.02rem;
  margin-bottom: 10px;
  background: #fff;
}
.input-big:focus { outline: 2px solid var(--primary); }

.search-wrap { position: relative; }
.sugerencias {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 60;
  box-shadow: 0 6px 18px rgba(0,0,0,.15);
}
.sugerencia {
  padding: 10px 12px;
  border-bottom: 1px solid #f1ecdf;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.sugerencia:active { background: #fbf6e8; }
.sugerencia .s-nombre { font-size: .88rem; }
.sugerencia .s-precio { font-weight: 700; color: var(--green); white-space: nowrap; }
.sugerencia .s-stock { font-size: .7rem; color: var(--muted); }

/* ---------- Tabla carrito ---------- */
.empty { color: var(--muted); text-align: center; padding: 18px 0; font-size: .9rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th { text-align: left; color: var(--muted); font-size: .72rem; text-transform: uppercase; padding: 6px 6px; border-bottom: 2px solid var(--border); }
td { padding: 7px 6px; border-bottom: 1px solid #f1ecdf; vertical-align: middle; }
th.num, td.num { text-align: right; }
td input {
  width: 62px;
  text-align: right;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 6px;
  font-size: .85rem;
}
.btn-quitar {
  background: #fee;
  color: var(--red);
  border: 1px solid #f3c1c1;
  border-radius: 6px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
}
.estado-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: .7rem;
  font-weight: 700;
}
.estado-Completada { background: #e3f2e3; color: var(--green); }
.estado-Anulada { background: #fdeaea; color: var(--red); }
.estado-Pendiente { background: #fff3d6; color: #a66d00; }

/* ---------- Totales ---------- */
.totales { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.total-line { display: flex; justify-content: space-between; padding: 3px 0; font-size: .9rem; }
.total-line.total { font-size: 1.35rem; font-weight: 800; color: var(--primary-dark); border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }

/* ---------- Pago ---------- */
.pago-tipo { display: flex; gap: 10px; margin-bottom: 12px; }
.radio-card {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  font-weight: 600;
}
.radio-card:has(input:checked) { border-color: var(--primary); background: #fbf6e8; }
.radio-card input { display: none; }

/* ---------- Botones ---------- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: #eef0e6; color: #4a4a4a; border: 1px solid var(--border); white-space: nowrap; }
.btn-big { padding: 16px; font-size: 1.1rem; }
.btn-small { padding: 6px 10px; font-size: .78rem; border-radius: 7px; }
.btn-danger { background: var(--red); color: #fff; }

/* ---------- Form grid ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .field { margin: 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: #fff;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 18px;
  animation: slideUp .18s ease;
}
@media (min-width: 500px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 16px; }
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { color: var(--primary-dark); }
.btn-close { border: none; background: #f1ecdf; border-radius: 50%; width: 30px; height: 30px; cursor: pointer; font-size: .9rem; }
.det-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .85rem; margin-bottom: 12px; }
.det-grid .label { color: var(--muted); }

/* ---------- QR conexion celular ---------- */
.qr-body { text-align: center; }
.qr-img {
  width: 240px;
  height: 240px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
}
.qr-url {
  margin-top: 10px;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary-dark);
  word-break: break-all;
}
.qr-nota { margin-top: 8px; font-size: .82rem; color: var(--muted); text-align: center; }
.qr-seccion { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.qr-seccion:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.qr-sub { font-size: .9rem; color: var(--primary-dark); margin-bottom: 8px; text-align: center; }
.qr-inactivo {
  text-align: center;
  color: var(--muted);
  font-size: .85rem;
  background: #fbf6e8;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 14px 10px;
}
.qr-body .btn { margin-top: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 12px 22px;
  border-radius: 30px;
  font-size: .9rem;
  z-index: 200;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
  max-width: 92%;
  text-align: center;
}
.toast.ok { background: var(--green); }
.toast.error { background: var(--red); }
.toast.hidden { display: none; }

/* ---------- Util ---------- */
.hidden { display: none !important; }
@media (max-width: 400px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
}
