:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1e293b;
  --accent: #2563eb;
  --ok: #16a34a;
  --ok-dark: #15803d;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(15 23 42 / 8%), 0 1px 3px rgb(15 23 42 / 6%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; opacity: .55; }
.boot { padding: 2rem; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #0f172a; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover:not(:disabled) { background: var(--ok-dark); }
.btn-danger { background: var(--surface); border-color: #fca5a5; color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-sm { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.btn-lg { min-height: 60px; font-size: 1.2rem; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field label { font-size: .9rem; font-weight: 600; }
.field .hint { font-size: .8rem; color: var(--muted); }
.input, select.input, textarea.input {
  min-height: 44px; padding: .5rem .7rem; border-radius: 8px;
  border: 1px solid #cbd5e1; background: #fff; width: 100%;
}
.input:focus, .btn:focus-visible { outline: 3px solid #93c5fd; outline-offset: 1px; }
.check { display: flex; align-items: center; gap: .6rem; min-height: 44px; font-weight: 600; }
.check input { width: 22px; height: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }
.form-error { background: var(--danger-bg); color: #991b1b; padding: .6rem .8rem; border-radius: 8px; margin-bottom: .8rem; }

/* ---------- Estructura ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  background: var(--primary); color: #fff; padding: .4rem .8rem; min-height: 56px;
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar nav { display: flex; gap: .3rem; flex-wrap: wrap; }
.topbar a, .topbar button {
  color: #e2e8f0; text-decoration: none; padding: .5rem .75rem; border-radius: 8px;
  min-height: 42px; display: inline-flex; align-items: center; background: none; border: 0; font-weight: 600;
}
.topbar a[aria-current="page"] { background: rgb(255 255 255 / 14%); color: #fff; }
.topbar a:hover, .topbar button:hover { background: rgb(255 255 255 / 10%); }
.topbar .user { font-size: .85rem; color: #cbd5e1; padding: 0 .4rem; }
.page { padding: 1rem; max-width: 1200px; width: 100%; margin: 0 auto; }
.page h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.toolbar .field { margin: 0; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.data th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: #f8fafc; }
table.data tr.inactive td { color: var(--muted); }
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: #e2e8f0; color: #334155; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.off { background: #f1f5f9; color: #64748b; }
.badge.danger { background: var(--danger-bg); color: #991b1b; }
.badge.admin { background: #e0e7ff; color: #3730a3; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: .4rem; border: 1px solid rgb(0 0 0 / 10%); }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.summary .card .label { font-size: .8rem; color: var(--muted); }
.summary .card .value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: .8rem; }

/* ---------- Pantalla de venta ---------- */
.pos { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 380px; min-height: 0; }
.pos-main { display: flex; flex-direction: column; min-height: 0; padding: .8rem; gap: .7rem; }
.families { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .2rem; }
.family-btn {
  flex: 0 0 auto; min-height: 52px; padding: .5rem 1.1rem; border-radius: 10px; font-weight: 700;
  border: 2px solid var(--fam, #94a3b8); background: #fff; color: var(--text);
}
.family-btn[aria-pressed="true"] { background: var(--fam, #475569); color: #fff; }
.search { position: relative; }
.search .input { padding-left: 2.4rem; min-height: 50px; font-size: 1.05rem; }
.search::before { content: "⌕"; position: absolute; left: .85rem; top: 50%; transform: translateY(-52%); font-size: 1.4rem; color: var(--muted); }
.articles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; overflow-y: auto; align-content: start; padding-bottom: 1rem; }
.article-btn {
  min-height: 96px; border-radius: 12px; border: 0; background: #fff; box-shadow: var(--shadow);
  border-top: 6px solid var(--fam, #94a3b8); padding: .6rem; text-align: left;
  display: flex; flex-direction: column; justify-content: space-between; gap: .4rem;
}
.article-btn:active:not(:disabled) { transform: scale(.97); background: #f1f5f9; }
.article-btn .name { font-weight: 700; font-size: 1.05rem; line-height: 1.2; word-break: break-word; }
.article-btn .price { font-weight: 700; color: var(--accent); font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 2rem 1rem; text-align: center; }

.ticket { display: flex; flex-direction: column; background: #fff; border-left: 1px solid var(--border); min-height: 0; }
.ticket-head { display: flex; justify-content: space-between; align-items: center; padding: .7rem .9rem; border-bottom: 1px solid var(--border); }
.ticket-head h2 { margin: 0; font-size: 1.1rem; }
.ticket-lines { flex: 1; overflow-y: auto; }
.tline { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .2rem .6rem; padding: .6rem .9rem; border-bottom: 1px solid var(--border); }
.tline .tname { font-weight: 700; overflow-wrap: anywhere; }
.tline .tunit { font-size: .85rem; color: var(--muted); }
.tline .ttotal { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.tline .qty { grid-column: 1 / -1; display: flex; align-items: center; gap: .4rem; }
.qty button { width: 44px; height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); font-size: 1.3rem; font-weight: 700; line-height: 1; }
.qty .q { min-width: 2.2rem; text-align: center; font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.qty .remove { margin-left: auto; width: auto; padding: 0 .7rem; font-size: .9rem; color: var(--danger); background: #fff; border-color: #fecaca; }
.ticket-foot { border-top: 2px solid var(--border); padding: .8rem .9rem; display: flex; flex-direction: column; gap: .6rem; background: var(--surface-2); }
.total-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.15rem; font-weight: 700; }
.total-row .amount { font-size: 2rem; font-variant-numeric: tabular-nums; }
.charge-btn { min-height: 68px; font-size: 1.4rem; }
.pending-banner { background: var(--warn-bg); color: #78350f; padding: .7rem .9rem; font-weight: 600; display: flex; flex-direction: column; gap: .5rem; }

@media (max-width: 860px) {
  .pos { grid-template-columns: 1fr; }
  .ticket { border-left: 0; border-top: 1px solid var(--border); }
  .ticket-lines { max-height: 40vh; }
  .ticket-foot { position: sticky; bottom: 0; }
  .articles { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

/* ---------- Modales y avisos ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgb(15 23 42 / 55%); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: calc(100vh - 2rem); overflow-y: auto; box-shadow: 0 20px 50px rgb(0 0 0 / 30%); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; }
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-body { padding: 1.1rem; }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; padding: .9rem 1.1rem; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: #fff; }
.close-x { border: 0; background: none; font-size: 1.6rem; width: 44px; height: 44px; border-radius: 8px; }
.close-x:hover { background: var(--surface-2); }

.charge-total { text-align: center; margin-bottom: 1rem; }
.charge-total .label { color: var(--muted); font-weight: 600; }
.charge-total .amount { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1rem; }
.methods button { min-height: 64px; border-radius: 10px; border: 2px solid var(--border); background: #fff; font-weight: 700; font-size: 1.05rem; }
.methods button[aria-pressed="true"] { border-color: var(--accent); background: #eff6ff; color: #1d4ed8; }
.quick { display: flex; flex-wrap: wrap; gap: .4rem; margin: -.3rem 0 .9rem; }
.quick button { min-height: 44px; min-width: 64px; }
.change { display: flex; justify-content: space-between; font-size: 1.3rem; font-weight: 700; padding: .7rem .9rem; border-radius: 10px; background: #f0fdf4; color: #166534; font-variant-numeric: tabular-nums; }
.change.bad { background: var(--danger-bg); color: #991b1b; }
.notice { font-size: .85rem; color: var(--muted); margin-top: .6rem; }

#toast-root { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: .5rem; width: min(92vw, 460px); }
.toast { background: var(--primary); color: #fff; padding: .8rem 1rem; border-radius: 10px; box-shadow: 0 8px 20px rgb(0 0 0 / 25%); font-weight: 600; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- Login ---------- */
.login-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login { width: 100%; max-width: 380px; }
.login h1 { margin: 0 0 .2rem; font-size: 1.5rem; }
.login p { margin: 0 0 1.2rem; color: var(--muted); }

/* ---------- Ticket ---------- */
.receipt { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; color: #000; max-width: 340px; margin: 0 auto; line-height: 1.35; }
.receipt .center { text-align: center; }
.receipt .biz { font-size: 16px; font-weight: 700; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt td { padding: 1px 0; vertical-align: top; }
.receipt .r { text-align: right; white-space: nowrap; }
.receipt .total td { font-size: 16px; font-weight: 700; padding-top: 4px; }
.receipt .small { font-size: 11px; }
.receipt .voided { border: 2px solid #000; text-align: center; font-weight: 700; padding: 4px; margin: 6px 0; }

#print-area { display: none; }
@media print {
  @page { margin: 6mm; }
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  .receipt { max-width: 80mm; }
}
