:root {
  --bg: #0e0f13;
  --card: #1a1c23;
  --card-2: #22252e;
  --line: #2c2f3a;
  --text: #f4f5f7;
  --muted: #9aa0ad;
  --accent: #34c759;
  --accent-dim: #1f7a3a;
  --danger: #ff453a;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#root {
  max-width: 460px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.app-header {
  padding: 22px 4px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-header h1 { font-size: 20px; margin: 0; letter-spacing: -0.3px; }
.app-header .mesa-pill {
  font-size: 13px;
  color: var(--muted);
  background: var(--card-2);
  border: 1px solid var(--line);
  padding: 5px 11px;
  border-radius: 999px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}

.card h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin: 0 0 14px;
  font-weight: 600;
}

.item-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.item-row:last-child { border-bottom: none; }
.item-name { font-size: 15px; }
.item-qty { color: var(--muted); font-size: 13px; margin-left: 6px; }
.item-price { font-variant-numeric: tabular-nums; color: var(--text); }

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.total-row .label { font-size: 15px; color: var(--muted); }
.total-row .amount { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

.split-control {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.split-btn {
  flex: 1;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 12px 0;
  border-radius: 12px;
  cursor: pointer;
  transition: all .12s ease;
}
.split-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #fff;
}

.diner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.diner.you { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.diner .who { font-size: 15px; }
.diner .who small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.diner .part { font-variant-numeric: tabular-nums; font-weight: 600; margin-right: 12px; }

.pay-others {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.badge-paid {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Botón con el logo oficial de Apple Pay */
.apple-pay-button-custom {
  width: 100%;
  height: 52px;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .12s ease;
}
.apple-pay-button-custom:active { opacity: .8; }
.apple-pay-button-custom:disabled { opacity: .5; cursor: default; }

.ap-mark {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.ap-logo {
  width: 26px;
  height: 26px;
  display: block;
}
.ap-pay {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.5px;
  line-height: 1;
}
.ap-busy { font-size: 16px; font-weight: 600; }

.your-part {
  text-align: center;
  margin: 6px 0 16px;
}
.your-part .label { color: var(--muted); font-size: 14px; }
.your-part .amount { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -1px; }

.note {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 14px;
  line-height: 1.5;
}

.success {
  text-align: center;
  padding: 60px 16px;
}
.success .check {
  width: 96px; height: 96px;
  margin: 0 auto 24px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 52px;
  animation: pop .35s ease;
}
@keyframes pop { 0% { transform: scale(0); } 80% { transform: scale(1.1); } 100% { transform: scale(1); } }
.success h2 { font-size: 26px; margin: 0 0 8px; }
.success p { color: var(--muted); margin: 4px 0; }
.success .paid-amount { font-size: 34px; font-weight: 800; color: var(--text); margin: 14px 0; font-variant-numeric: tabular-nums; }

.summary-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.summary-line:last-child { border-bottom: none; }
.summary-line span:last-child { color: var(--accent); font-weight: 600; }

.loading { text-align: center; color: var(--muted); padding: 80px 0; }

.demo-banner {
  background: rgba(255, 159, 10, 0.12);
  border: 1px solid rgba(255, 159, 10, 0.4);
  color: #ffb340;
  font-size: 12px;
  text-align: center;
  padding: 8px;
  border-radius: 10px;
  margin-bottom: 14px;
}

/* --- Botón para abrir el modal de invitación --- */
.invite-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 14px 0;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 14px;
  transition: all .12s ease;
}
.invite-btn:active { opacity: .8; }
.invite-btn-ic { font-size: 18px; line-height: 1; color: var(--accent); }
.invite-btn-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: #fff;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* --- Modal de invitación (QR + liga) --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 20px 22px;
  text-align: center;
  animation: pop .2s ease;
}
.modal h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin: 0 0 12px;
  font-weight: 600;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Nombre editable --- */
.name-edit {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.name-edit .edit-ic { color: var(--muted); font-size: 13px; }
.name-input {
  background: var(--bg);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  width: 160px;
  max-width: 100%;
  outline: none;
}

/* --- QR + liga (usados dentro del modal) --- */
.invite-help {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 16px;
}
.qr-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.qr-img {
  width: 220px;
  height: 220px;
  border-radius: 14px;
  background: #fff;
  padding: 10px;
  display: block;
  /* El data-URL es un bitmap de módulos; escalar "pixelado" mantiene los
     cuadros nítidos (escaneable), en vez de difuminar los bordes. */
  image-rendering: pixelated;
}
.qr-fallback {
  width: 220px;
  min-height: 220px;
  border-radius: 14px;
  border: 1px dashed var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  padding: 14px;
  text-align: center;
}
.qr-link a { color: var(--accent); word-break: break-all; }
.copy-link {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 0;
  border-radius: 12px;
  cursor: pointer;
  transition: all .12s ease;
}
.copy-link:active { opacity: .8; }
.invite-count {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.of-total { color: var(--muted); font-size: 14px; font-weight: 500; }

.summary-line span.pending { color: var(--muted); font-weight: 500; }
.settled-msg {
  margin-top: 18px;
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
}

/* --- División por productos / monto manual --- */
.claim-tag {
  display: inline-block;
  margin-left: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(52, 199, 89, 0.14);
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
}
.item-row.item-claimed .item-name { color: var(--muted); }
.item-row.item-claimed .item-price { color: var(--muted); }

.your-hint { font-size: 13px; color: var(--muted); font-weight: 500; }
.your-part .amount.amount-bad { color: var(--danger); }

.split-edit {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 11px;
  border-radius: 12px;
  cursor: pointer;
  margin: 4px 0 14px;
}
.split-edit:active { opacity: .7; }

.recon-bad {
  background: rgba(255, 69, 58, 0.12);
  border: 1px solid rgba(255, 69, 58, 0.4);
  color: #ff6b61;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 12px;
}

/* Modal de split */
.split-modal { text-align: left; }
.split-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}
.split-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 0;
  border-radius: 9px;
  cursor: pointer;
}
.split-tab.active { background: var(--card-2); color: var(--text); }

.split-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 46vh;
  overflow-y: auto;
  margin-bottom: 14px;
}
.split-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 15px;
}
.split-item.checked { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.split-item.taken { opacity: .55; cursor: not-allowed; }
.si-check {
  width: 22px; height: 22px;
  flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.split-item.checked .si-check { background: var(--accent); border-color: var(--accent); color: #062; }
.si-name { flex: 1; }
.si-price { font-variant-numeric: tabular-nums; color: var(--muted); }

.split-sum {
  text-align: right;
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 12px;
}
.split-sum b { color: var(--text); font-size: 18px; }

.split-manual-label { display: block; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.split-manual-input {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 24px;
  font-weight: 700;
}
.split-manual-input span { color: var(--muted); }
.split-manual-input input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
  outline: none;
  width: 100%;
  font-variant-numeric: tabular-nums;
}

.split-save {
  width: 100%;
  background: #fff;
  color: #000;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  padding: 13px;
  cursor: pointer;
}
.split-save:disabled { opacity: .5; cursor: default; }

.split-reset {
  width: 100%;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  padding: 11px;
  cursor: pointer;
  margin-top: 10px;
}
.split-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin: 14px 0 0;
  text-align: center;
}

/* --- Separador "o" entre métodos de pago --- */
.pay-or {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 14px 0;
}
.pay-or::before, .pay-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.pay-or span { padding: 0 12px; }

/* --- Botón "Pagar con tarjeta" --- */
.card-pay-btn {
  width: 100%;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  transition: all .12s ease;
}
.card-pay-btn:active { opacity: .85; }
.card-pay-btn:disabled { opacity: .4; cursor: default; }
.cpb-ic { font-size: 20px; }

/* --- Modal de tarjeta --- */
.card-modal { max-width: 380px; }

/* Tarjeta 3D vistosa que se va llenando */
.pay-card {
  perspective: 1000px;
  width: 100%;
  aspect-ratio: 1.586;      /* proporción de tarjeta real */
  margin: 6px 0 22px;
}
.pay-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform .55s cubic-bezier(.2,.7,.2,1);
  transform-style: preserve-3d;
}
.pay-card.flipped .pay-card-inner { transform: rotateY(180deg); }
.pay-card.shake { animation: cardShake .45s ease; }
@keyframes cardShake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}

.pay-card-face {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
  color: #fff;
}
.pay-card-front {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    radial-gradient(120% 140% at 0% 0%, #3a8dff 0%, transparent 45%),
    radial-gradient(120% 140% at 100% 100%, #7b41ff 0%, transparent 50%),
    linear-gradient(135deg, #1f2740 0%, #121523 100%);
}
.pay-card-shine {
  position: absolute;
  top: -60%;
  left: -20%;
  width: 60%;
  height: 220%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.18), transparent);
  transform: rotate(20deg);
  pointer-events: none;
}
.pay-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pay-chip {
  width: 42px;
  height: 32px;
  border-radius: 6px;
  background: linear-gradient(135deg, #f6d365, #d4a12a);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
  position: relative;
}
.pay-chip::after {
  content: "";
  position: absolute;
  inset: 6px 8px;
  border: 1px solid rgba(0,0,0,.3);
  border-radius: 3px;
}
.pay-brand {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .5px;
  font-style: italic;
  opacity: .95;
}
.pay-number {
  font-size: 20px;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  transition: color .2s ease;
  word-spacing: 4px;
}
.pay-number.ok { color: #8affc0; }
.pay-card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}
.pay-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.pcf-label {
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: .6;
}
.pcf-value {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.pay-card-back {
  transform: rotateY(180deg);
  background: linear-gradient(135deg, #232a3d 0%, #12141f 100%);
  padding-top: 20px;
}
.pay-stripe {
  position: absolute;
  top: 22px;
  left: 0;
  right: 0;
  height: 42px;
  background: #000;
}
.pay-cvv-row {
  position: absolute;
  top: 82px;
  right: 20px;
  left: 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}
.pay-cvv-box {
  background: #fff;
  color: #111;
  font-family: ui-monospace, Menlo, monospace;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 6px 12px;
  border-radius: 5px;
  min-width: 64px;
  text-align: right;
}
.pay-brand-back {
  position: absolute;
  bottom: 16px;
  right: 20px;
  font-size: 14px;
  opacity: .8;
}

/* Formulario */
.card-form { text-align: left; }
.cf-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin: 12px 0 6px;
  font-weight: 600;
}
.cf-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
  font-variant-numeric: tabular-nums;
}
.cf-input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.cf-input.bad { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.cf-input::placeholder { color: #565b68; }
.cf-row { display: flex; gap: 12px; }
.cf-col { flex: 1; }

.card-error {
  margin-top: 14px;
  background: rgba(255, 69, 58, .12);
  border: 1px solid rgba(255, 69, 58, .4);
  color: #ff6b61;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
  text-align: center;
}

.card-submit {
  width: 100%;
  margin-top: 18px;
  height: 52px;
  background: var(--accent);
  color: #06210f;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  transition: opacity .12s ease;
}
.card-submit:active { opacity: .85; }
.card-submit:disabled { opacity: .55; cursor: default; }

.card-demo-hint {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
  margin: 14px 0 0;
  text-align: center;
}
.card-demo-hint b { color: var(--text); }
