:root {
  --brand: #003649;
  --brand-deep: #001E29;
  --brand-soft: #0B4D66;
  --gold: #C9A227;
  --gold-soft: #E3C766;
  --cream: #F2E6D2;
  --ink: #1F1A17;
  --muted: #8A7F76;
  --bg: #FAF7F2;
  --line: #E6DED3;
  --ok: #2F7D4F;
  --err: #B3261E;
  --warn: #9A6B00;
  --radius: 14px;
  font-family: "Work Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.45; -webkit-text-size-adjust: 100%; }
body.dark { background: radial-gradient(circle at 50% 0%, var(--brand-soft), var(--brand-deep) 70%) fixed; color: var(--cream); min-height: 100vh; }
a { color: var(--brand); }
.dark a { color: var(--gold-soft); }
h1 { font-family: "Fraunces", Georgia, "Times New Roman", serif; font-weight: 700; margin: 0 0 .5rem; font-size: 1.6rem; }
h2 { font-size: 1.05rem; margin: 1.2rem 0 .6rem; }
code { font-size: .85em; }
.muted { color: var(--muted); }
.dark .muted { color: #CBB9A6; }
.small { font-size: .85rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.neg { color: var(--err); }

.narrow { max-width: 460px; margin: 0 auto; padding: 16px 16px 40px; }
.wide { max-width: 1200px; margin: 0 auto; padding: 16px 16px 60px; }

.brand { text-align: center; padding: 24px 0 8px; }
.logo { width: min(320px, 80%); height: auto; }
.logo-sm { height: 26px; width: auto; display: block; }
.kicker { letter-spacing: .25em; text-transform: uppercase; color: var(--gold); font-size: .8rem; margin: .6rem 0 0; }
.foot { text-align: center; font-size: .8rem; margin-top: 24px; }

.card-panel { background: rgba(255,255,255,.06); border: 1px solid rgba(242,230,210,.15); border-radius: var(--radius); padding: 20px; margin-top: 16px; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }

/* Formularios */
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: .9rem; font-weight: 600; }
.form label.check { grid-template-columns: 22px 1fr; align-items: start; font-weight: 400; }
input, select { font: inherit; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); width: 100%; min-width: 0; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; margin: 0; accent-color: var(--brand); }
.dark input, .dark select { background: rgba(255,255,255,.92); border-color: transparent; }
.dark input[type=checkbox], .dark input[type=radio] { accent-color: var(--gold); }
input.pin { font-size: 1.6rem; letter-spacing: .5em; text-align: center; }
input.short { width: 80px; }
.grid-form { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.form.inline, .inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input { width: auto; flex: 1 1 140px; padding: 8px 10px; }
.inline-form label { display: flex; gap: 6px; align-items: center; font-size: .85rem; }
.row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }

.btn { display: inline-flex; justify-content: center; align-items: center; gap: 6px; font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--brand); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--brand-deep); }
.btn-gold:hover { background: var(--gold-soft); border-color: var(--gold-soft); }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn-ghost { background: transparent; color: inherit; border-color: rgba(242,230,210,.3); width: 100%; margin-top: 10px; }
.btn-big { padding: 16px; font-size: 1.1rem; width: 100%; }
.btn-wallet { display: flex; background: #000; color: #fff !important; border-color: #000; margin-top: 16px; padding: 14px; text-decoration: none; }
.link { background: none; border: none; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; padding: 4px; }
.link.danger { color: var(--err); }
.dark .link.danger { color: #FF8A80; }

.flash { padding: 10px 14px; border-radius: 10px; margin: 0 0 14px; font-weight: 500; }
.flash-ok { background: #E3F2E8; color: var(--ok); }
.flash-error { background: #FBE4E2; color: var(--err); }
.flash-warn { background: #FFF4D6; color: var(--warn); }

/* Botellas (contador) */
.bottles { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.bottle { height: 46px; width: auto; flex: none; }
.bottle path { fill: rgba(255,255,255,.05); stroke: rgba(242,230,210,.55); stroke-width: 2.5px; vector-effect: non-scaling-stroke; }
.bottle.on path { fill: #8E1F3E; stroke: #D4637F; }
.bottle .cap { fill: var(--gold); }
.bottle .lbl { fill: var(--cream); }
.admin .bottle path { stroke: #BFB3A6; fill: transparent; }
.admin .bottle.on path { fill: #8E1F3E; stroke: #6E1428; }
#view-result .bottles { justify-content: center; }
#view-result .bottle { height: 64px; }
/* Estrellas (antiguo) */
.stars { display: flex; gap: 6px; font-size: 2rem; line-height: 1; margin: 6px 0; }
.star { color: rgba(201,162,39,.35); }
.star.on { color: var(--gold); text-shadow: 0 0 12px rgba(201,162,39,.45); }
.admin .star { color: #D9CFC3; }
.admin .star.on { color: var(--gold); text-shadow: none; }

/* Tarjeta del cliente (mismo diseño que en Wallet) */
.loyalty-card { margin-top: 16px; background: var(--brand); border-radius: 18px; overflow: hidden; color: #fff;
  box-shadow: 0 24px 60px rgba(0,0,0,.5), 0 0 0 1px rgba(212,175,55,.35); }
.lc-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px 14px; }
.lc-logo { width: 58%; max-width: 230px; height: auto; display: block; }
.lc-count { text-align: right; line-height: 1.1; }
.lc-count small { display: block; color: #C8D6DC; letter-spacing: .12em; font-size: .68rem; font-weight: 600; }
.lc-count strong { font-size: 1.35rem; font-weight: 600; }
.lc-strip { display: block; width: 100%; height: auto; }
.lc-stars { padding: 18px; background: linear-gradient(135deg, #0A4A62, var(--brand-deep)); }
.loyalty-card .stars { font-size: 2.4rem; gap: 10px; }
.lc-fields { display: grid; grid-template-columns: 1fr 1.3fr; gap: 14px; padding: 16px 18px 6px; }
.lc-fields small { display: block; color: #C8D6DC; letter-spacing: .12em; font-size: .68rem; font-weight: 600; margin-bottom: 2px; }
.lc-fields span { font-size: 1.02rem; font-weight: 500; line-height: 1.3; }
.lc-fields .has-reward { color: var(--gold-soft); font-weight: 700; }
.lc-qr { background: #fff; border-radius: 14px; padding: 12px; margin: 14px 18px 18px; display: grid; justify-items: center; gap: 4px; color: var(--ink); }
.lc-qr svg { width: 180px; height: 180px; }
.lc-qr span { font-family: ui-monospace, Menlo, monospace; letter-spacing: .12em; font-weight: 600; font-size: .9rem; }
.help { margin-top: 16px; background: rgba(255,255,255,.06); border-radius: 12px; padding: 12px 14px; }
.help summary { cursor: pointer; font-weight: 600; }

/* Capitán */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: rgba(0,0,0,.25); }
.topbar .who { margin-left: auto; font-weight: 600; }
.camera { position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 60vh; border-radius: 14px; overflow: hidden; background: #000; margin-bottom: 12px; }
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 20% 12%; border: 3px solid var(--gold); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); pointer-events: none; }
.scan-hint { position: absolute; left: 12px; right: 12px; bottom: 14px; margin: 0; padding: 10px 12px; border-radius: 10px; text-align: center;
  background: rgba(0,0,0,.6); color: #fff; font-weight: 600; font-size: .95rem; }
.scan-hint.error { background: rgba(179,38,30,.9); }
.cam-close { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.6); color: #fff; font-size: 1.3rem; cursor: pointer; }
.btn-scan { width: 100%; padding: 22px; font-size: 1.25rem; }
.manual { margin-top: 14px; }
.manual summary { cursor: pointer; color: #CBB9A6; font-size: .9rem; text-decoration: underline; list-style: none; text-align: center; }
.manual summary::-webkit-details-marker { display: none; }
.manual form { margin-top: 10px; }
.products { border: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.products legend { font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.product { display: flex !important; grid-template-columns: none !important; align-items: center; gap: 12px; padding: 14px; border-radius: 12px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(242,230,210,.2); font-weight: 600; cursor: pointer; }
.product:has(input:checked) { border-color: var(--gold); background: rgba(201,162,39,.18); }
.reward { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px; margin: 10px 0; border-radius: 12px;
  background: rgba(201,162,39,.2); border: 1px solid var(--gold); font-weight: 600; }
.big-check { font-size: 3.4rem; color: var(--gold); line-height: 1; margin-bottom: 8px; }
#view-result .stars { justify-content: center; font-size: 2.6rem; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(128,128,128,.2); font-size: .9rem; flex-wrap: wrap; }
.list li.voided span { text-decoration: line-through; opacity: .6; }

/* Admin */
.admin-top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--brand); color: var(--cream); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.admin-top .nav-desktop { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.admin-top .nav-desktop a { color: var(--cream); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .9rem; }
.admin-top .nav-desktop a.active, .admin-top .nav-desktop a:hover { background: rgba(255,255,255,.14); }
.admin-top .who { font-size: .85rem; opacity: .85; }
.admin-top .link { color: var(--gold-soft); }
.admin main h1 { margin-top: 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 44%), 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat small { color: var(--muted); display: block; }
.stat strong { font-size: 1.8rem; font-family: Georgia, serif; color: var(--brand); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 16px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar > form { flex: 1; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.panel .table-wrap { border: none; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #F5EFE7; font-weight: 600; white-space: nowrap; }
tr.voided td { opacity: .5; }
tr.alert td { background: #FFF1F0; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; }
.badge.gold { background: #FBF0CC; color: #7A5C00; }
.badge.red { background: #FBE4E2; color: var(--err); }
details.panel summary { cursor: pointer; font-weight: 600; }
details.panel[open] summary { margin-bottom: 12px; }

@media (max-width: 520px) {
  .row { grid-template-columns: 1fr; }
}

/* ---------- Menú del panel ---------- */
.nav-mobile { display: none; }
.admin-top .brand-link { display: block; }

/* ---------- Celular ---------- */
@media (max-width: 760px) {
  /* márgenes seguros en iPhone con notch */
  .narrow, .wide { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right));
    padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  .topbar { padding-top: max(12px, env(safe-area-inset-top)); }
  .topbar .link { min-height: 44px; padding: 8px 4px; }
  .card-panel { padding: 16px; }
  h1 { font-size: 1.45rem; }

  /* áreas táctiles de al menos 44 px */
  .btn, input, select { min-height: 46px; }
  .help summary, .manual summary { padding: 10px 0; }
  .form label.check { font-size: .95rem; }

  /* Panel de administración */
  .admin-top { flex-wrap: nowrap; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 14px 10px; }
  .admin-top .nav-desktop, .admin-top .who { display: none; }
  .admin-top .logout { margin-left: auto; }
  .admin-top .logout .link { min-height: 44px; }
  .nav-mobile { display: block; }
  .nav-mobile summary { list-style: none; cursor: pointer; padding: 10px 14px; border-radius: 10px; background: rgba(255,255,255,.14);
    font-weight: 600; white-space: nowrap; min-height: 44px; display: flex; align-items: center; }
  .nav-mobile summary::-webkit-details-marker { display: none; }
  .nav-mobile[open] summary { background: rgba(255,255,255,.24); }
  .nav-mobile nav { position: absolute; left: 0; right: 0; top: 100%; background: var(--brand); padding: 12px 14px 16px;
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px; box-shadow: 0 12px 24px rgba(0,0,0,.25); }
  .nav-mobile nav a { color: var(--cream); text-decoration: none; padding: 13px 12px; border-radius: 10px; background: rgba(255,255,255,.08); font-weight: 500; }
  .nav-mobile nav a.active { background: var(--gold); color: var(--brand-deep); font-weight: 700; }
  .wide { padding-top: 12px; }
  .admin main h1 { font-size: 1.35rem; }
  .stat { padding: 12px; }
  .stat strong { font-size: 1.5rem; }
  .panel { padding: 14px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar > form, .toolbar > .btn { width: 100%; }
  .inline-form { width: 100%; }
  .inline-form input, .inline-form select { flex: 1 1 100%; width: 100%; padding: 10px 12px; }
  .inline-form label { flex: 1 1 100%; justify-content: space-between; }
  .inline-form label input, .inline-form label select { flex: 1 1 60%; width: auto; }
  .inline-form .btn { flex: 1 1 auto; }
  .inline-form .link { min-height: 44px; }
  .grid-form { grid-template-columns: 1fr; }
  .list li { padding: 10px 0; }

  /* Tablas → tarjetas */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr { display: block; width: 100%; }
  table.responsive tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  table.responsive tr:last-child { border-bottom: none; }
  table.responsive td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 5px 0; border: none;
    text-align: right; font-size: .95rem; }
  table.responsive td::before { content: attr(data-label); flex: none; max-width: 45%; text-align: left; font-weight: 600; color: var(--muted); font-size: .85rem; }
  table.responsive td[data-label=""]::before { display: none; }
  table.responsive td[colspan] { display: block; text-align: left; }
  table.responsive td:has(form) { display: block; text-align: left; }
  table.responsive td:has(form)::before { display: block; max-width: none; margin-bottom: 6px; }
  table.responsive td.nowrap { white-space: normal; }
  table.responsive td code { word-break: break-word; }
  .table-wrap { overflow-x: visible; }
}


/* Pasar la tarjeta al teléfono del cliente */
.handover-link { display: block; margin: 4px 0 8px; color: var(--gold-soft); font-weight: 600; }
.handover { text-align: center; margin: 8px 0 14px; }
.qr-box { background: #fff; border-radius: 14px; padding: 10px; display: inline-block; line-height: 0; }
.qr-box svg, .qr-box img { width: 220px; height: 220px; }
.handover-admin { margin: 10px 0; }
.handover-admin summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.handover-admin .qr-box { border: 1px solid var(--line); margin-top: 10px; }
