/* La app es de tema claro: se evita que el navegador (o una extensión) la oscurezca a la fuerza y cambie los colores de marca. */
:root { color-scheme: only light; }
:root {
  --bg: #FAF6F0;
  --surface: #FFFFFF;
  --text: #1F2A2E;
  --text-2: #5B6B6E;
  --primary: #0F8B8D;
  --primary-dark: #0B6B6D;
  --accent: #E8734A;
  --border: #E7E0D4;
  --green: #2E7D4F;
  --red: #C0392B;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Work Sans', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3 {
  font-family: 'Fraunces', Georgia, serif;
  margin: 0;
}

a { text-decoration: none; color: inherit; }

.app-shell {
  max-width: 420px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: 32px 24px 40px;
}

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--primary-dark);
  margin-bottom: 24px;
}

.view { display: none; flex-direction: column; gap: 18px; flex-grow: 1; }
.view.active { display: flex; }

.icon-badge {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
}

p.lead { font-size: 15px; line-height: 1.5; color: var(--text-2); margin: 0; max-width: 320px; }

label.field-label {
  font-size: 13px; font-weight: 600; color: var(--text); display: block; margin-bottom: 6px;
}

input[type=text], input[type=password], select {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}

input[type=text]:focus, input[type=password]:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.codigo-input {
  letter-spacing: 4px;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
}

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 26px;
  height: 52px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:disabled { background: #a9c9c9; cursor: not-allowed; }
.btn-secondary { background: transparent; color: var(--primary-dark); border: 1.5px solid var(--primary); }
.btn-link { background: none; color: var(--text-2); font-weight: 500; height: auto; padding: 8px; }

.hint-row { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 12.5px; margin-top: -8px; }

.error-box {
  background: #FBE9E7; border: 1px solid #E8734A; color: #8a3419;
  padding: 12px 14px; border-radius: 10px; font-size: 14px; display: none;
}
.error-box.show { display: block; }

.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chip {
  flex: none; padding: 8px 14px; border-radius: 20px; border: 1.5px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--text-2); background: var(--surface); cursor: pointer;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px; display: flex; flex-direction: column; gap: 6px; cursor: pointer;
}
.card .top-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card .name { font-weight: 700; font-size: 16px; }
.card .categoria { font-size: 12px; color: var(--text-2); }
.card .descuento { color: var(--primary-dark); font-weight: 700; font-size: 14px; }
.badge {
  font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 12px; white-space: nowrap;
}
.badge.disponible { background: #E3F2EE; color: var(--green); }
.badge.canjeado { background: #EEE; color: var(--text-2); }
.badge.vencido { background: #FDECEA; color: var(--red); }

.list { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }

.top-bar { display: flex; align-items: center; gap: 12px; }
.back-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); height: auto; }

.detail-row { display: flex; justify-content: space-between; font-size: 13px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-row .k { color: var(--text-2); }
.detail-row .v { font-weight: 600; text-align: right; }

.qr-wrap {
  background: var(--surface); border-radius: 20px; padding: 24px; display: flex;
  flex-direction: column; align-items: center; gap: 12px; border: 1px solid var(--border);
}
.qr-wrap img { width: 220px; height: 220px; }
.token-text { font-family: monospace; font-size: 18px; letter-spacing: 2px; font-weight: 700; }

.result-card {
  border-radius: 20px; padding: 28px 20px; text-align: center; display: flex; flex-direction: column; gap: 10px;
}
.result-card.ok { background: #E3F2EE; border: 1.5px solid var(--green); }
.result-card.error { background: #FDECEA; border: 1.5px solid var(--red); }
.result-card .titulo { font-size: 20px; font-weight: 700; }
.result-card.ok .titulo { color: var(--green); }
.result-card.error .titulo { color: var(--red); }

.footer-note { font-size: 12px; color: var(--text-2); text-align: center; margin-top: auto; }

.spacer { flex-grow: 1; }

.stat-box { display: flex; justify-content: space-between; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 18px; }
.stat-box .num { font-size: 28px; font-weight: 700; color: var(--primary-dark); font-family: 'Fraunces', serif; }
.stat-box .label { font-size: 12px; color: var(--text-2); }

.logo-thumb {
  width: 32px; height: 32px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); flex: none;
  background: var(--surface);
}
.card .top-row .name-row { display: flex; align-items: center; gap: 10px; }

/* ------------------------------------------------------------------ */
/* Consola de administración                                           */
/* ------------------------------------------------------------------ */

.admin-shell {
  max-width: 1180px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 28px 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-login {
  max-width: 360px;
  margin: 80px auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.admin-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.admin-header h1 { font-size: 24px; }

.tabs { display: flex; gap: 4px; border-bottom: 1.5px solid var(--border); overflow-x: auto; }
.tab-btn {
  background: none; border: none; padding: 10px 16px; font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--text-2); cursor: pointer; border-bottom: 3px solid transparent; height: auto; white-space: nowrap;
}
.tab-btn.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

.tab-panel { display: none; flex-direction: column; gap: 16px; }
.tab-panel.active { display: flex; }

.panel-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.panel-card h3 { font-size: 16px; font-family: 'Work Sans', sans-serif; font-weight: 700; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-grid.single { grid-template-columns: 1fr; }
textarea {
  width: 100%; border: 1.5px solid var(--border); border-radius: 12px; padding: 12px 14px;
  font-size: 14px; font-family: inherit; color: var(--text); background: var(--surface); resize: vertical; min-height: 60px;
}

.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-2); padding: 8px 10px; border-bottom: 1.5px solid var(--border); }
.admin-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }

.mini-btn {
  height: 30px; padding: 0 12px; border-radius: 16px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.mini-btn.primary { background: var(--primary); color: #fff; }
.mini-btn.ghost { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.mini-btn.danger { background: transparent; border: 1.5px solid var(--red); color: var(--red); }

.acciones-fila { display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 90px; }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0; background: #ccc; border-radius: 22px; transition: 0.15s;
}
.switch-slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.15s;
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }

.file-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.file-row input[type=file] { font-size: 13px; }

.preview-fondo, .preview-logo {
  border-radius: 12px; border: 1px solid var(--border); object-fit: cover; background: var(--bg);
}
.preview-fondo { width: 100%; max-width: 320px; height: 120px; }
.preview-logo { width: 56px; height: 56px; }

.bar-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .bar-nombre { width: 160px; flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex-grow: 1; height: 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); }
.bar-row .bar-num { width: 28px; text-align: right; font-weight: 700; flex: none; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 50;
}
.toast.show { opacity: 1; }

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

/* ---------------------------------------------------------------------------
   Contraste de los textos sobre el fondo con foto.
   Los textos que quedan directamente sobre la imagen (no dentro de tarjetas)
   se oscurecen y llevan un halo claro muy suave para leerse bien sobre
   cualquier parte de la foto. Solo aplica a las apps del cliente y del comercio.
   --------------------------------------------------------------------------- */
:root { --text-2: #26353A; }

.app-shell p.lead,
.app-shell .hint-row,
.app-shell .footer-note,
.app-shell .btn-link { color: var(--text); font-weight: 500; }
.app-shell .footer-note { font-weight: 600; font-size: 12.5px; }
.app-shell .btn-link { font-weight: 600; }
.app-shell .eyebrow { color: #053F41; font-weight: 700; }
.app-shell #cupon-descuento,
.app-shell #ficha-descuento { color: #07494B !important; font-weight: 700; }
.app-shell .back-btn { font-weight: 700; }
.app-shell .btn-secondary { background: rgba(255, 255, 255, 0.88); }

.app-shell .eyebrow,
.app-shell .view > h1, .app-shell .view > h2, .app-shell .top-bar h2,
.app-shell p.lead, .app-shell .hint-row, .app-shell .footer-note,
.app-shell .btn-link, .app-shell .back-btn, .app-shell .field-label {
  text-shadow: 0 0 7px rgba(250, 246, 240, 1), 0 0 4px rgba(250, 246, 240, 0.95), 0 0 2px rgba(250, 246, 240, 1);
}
.app-shell .card, .app-shell .card *, .app-shell .chip, .app-shell .badge,
.app-shell .btn-primary, .app-shell .btn-secondary, .app-shell input, .app-shell select,
.app-shell .qr-wrap, .app-shell .qr-wrap *, .app-shell .result-card, .app-shell .result-card *,
.app-shell .stat-box, .app-shell .stat-box * { text-shadow: none; }

/* Comercio: últimos cupones validados */
.ultimos-lista { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ultimos-lista li { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.ultimos-lista .tk { font-family: Consolas, "Courier New", monospace; font-weight: 600; letter-spacing: 1px; color: var(--primary-dark); }
.ultimos-lista .hr { color: var(--text-2); font-size: 12px; }
.ultimos-lista .vacio { justify-content: center; color: var(--text-2); }
#view-validar { padding-bottom: 56px; }

/* Admin: orden de los comercios */
.orden-btns { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.orden-btns .mini-btn { padding: 3px 9px; line-height: 1; }
.orden-btns .mini-btn:disabled { opacity: 0.3; cursor: default; }
.orden-num { font-weight: 700; font-size: 13px; color: var(--primary-dark); }

/* Ficha del comercio: logo o foto cargado desde el administrador */
.ficha-imagen { display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.94); border: 1px solid var(--border); border-radius: 18px; padding: 10px; }
.ficha-imagen img { display: block; max-width: 100%; max-height: 190px; object-fit: contain; border-radius: 10px; }
.ficha-imagen[hidden] { display: none; }
