:root {
  --green: #14532d;
  --green-2: #166534;
  --green-soft: #ecfdf5;
  --red: #9f1239;
  --red-2: #be123c;
  --red-soft: #fff1f2;
  --gold: #b45309;
  --gold-soft: #fef3c7;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f4ef;
  --card: #ffffff;
  --blue: #1d4ed8;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}
h1, h2, h3 { margin: 0 0 0.6rem; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: var(--green-2); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden, [hidden] { display: none !important; }

/* Barra superior */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.7rem 1.2rem;
  background: linear-gradient(90deg, var(--green), var(--red));
  color: #fff;
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand { font-weight: 700; font-size: 1.05rem; }
.topbar nav { display: flex; gap: 0.3rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: #fff; text-decoration: none; padding: 0.35rem 0.8rem; border-radius: 999px; opacity: 0.85; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,0.18); opacity: 1; }
.topbar .user { display: flex; align-items: center; gap: 0.6rem; }
.topbar .user small { opacity: 0.8; display: block; font-size: 0.72rem; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,0.5); }

main { max-width: 1200px; margin: 0 auto; padding: 1.2rem 16px 3rem; }

/* Tarjetas */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.2rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.layout-sell { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .layout-sell { grid-template-columns: 1fr; } }
.sticky { position: sticky; top: 70px; }

/* Formularios */
label { display: block; font-size: 0.85rem; font-weight: 600; margin: 0.6rem 0 0.25rem; color: #374151; }
input, select, textarea {
  width: 100%; padding: 0.6rem 0.75rem; font: inherit;
  border: 1px solid #d1d5db; border-radius: 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #86efac; border-color: var(--green-2); }
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1; min-width: 140px; }
.row > .btn { flex: 0 0 auto; min-width: 0; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.6rem 1.1rem; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--green-2); color: #fff;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-red { background: var(--red-2); }
.btn-blue { background: var(--blue); }
.btn-gold { background: var(--gold); }
.btn-wa { background: #16a34a; }
.btn-light { background: #fff; color: var(--ink); border-color: #d1d5db; }
.btn-ghost { background: transparent; border-color: #d1d5db; color: var(--ink); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.btn-lg { padding: 0.9rem 1.4rem; font-size: 1.05rem; }
.btn-block { width: 100%; }

/* Pestañas */
.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tab { padding: 0.55rem 1rem; border-radius: 999px; border: 1px solid #d1d5db; background: #fff; cursor: pointer; font: inherit; font-weight: 600; }
.tab.active { background: var(--green); color: #fff; border-color: var(--green); }
.tab .count { display: inline-block; min-width: 1.4em; padding: 0 0.35em; margin-left: 0.3rem; border-radius: 999px; background: var(--red-2); color: #fff; font-size: 0.75rem; }

/* Estadísticas */
.stat { padding: 1rem; border-radius: 12px; background: var(--green-soft); }
.stat .num { font-size: 1.8rem; font-weight: 800; color: var(--green); }
.stat .lbl { font-size: 0.85rem; color: var(--muted); }
.bar { height: 10px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-top: 0.4rem; }
.bar > span { display: block; height: 100%; background: var(--green-2); }
.bar > span.red { background: var(--red-2); }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f9fafb; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; background: #e5e7eb; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-err { background: #fee2e2; color: #991b1b; }
.badge-warn { background: var(--gold-soft); color: #92400e; }
.badge-blue { background: #dbeafe; color: #1e40af; }

/* Mapa de sillas */
.seatmap { overflow-x: auto; padding: 0.5rem 0 1rem; }
.seat-grid { display: flex; flex-direction: column; gap: 4px; min-width: max-content; margin: 0 auto; width: max-content; }
.stage {
  margin: 0 auto 0.4rem; width: 60%; text-align: center; padding: 0.9rem 0.5rem;
  background: #bfbfbf; border: 2px solid #374151; color: #111827;
  font-weight: 800; letter-spacing: 0.15em; font-size: 1rem;
}
.zone-gap { height: 18px; }
.walkway { height: 26px; background: #8eaadb; margin: 6px 0; border-radius: 2px; }
.seat-row { display: grid; grid-template-columns: 1fr 26px 1fr; align-items: center; }
.seat-row.single { display: flex; justify-content: center; }
.seat-row .block { display: flex; gap: 3px; }
.seat-row .block.left { justify-content: flex-end; }
.seat-row .block.right { justify-content: flex-start; }
.row-label {
  width: 32px; height: 30px; border: 1px solid #d1d5db; background: #fff; border-radius: 6px;
  font-weight: 800; font-size: 0.78rem; color: #111827; padding: 0; font-family: inherit; cursor: default;
}
.row-label[tabindex] { cursor: default; }
.clickable-rows .row-label { cursor: pointer; }
.clickable-rows .row-label:hover { background: #fef3c7; }
.seat {
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid rgba(0,0,0,0.25);
  background: var(--zone, #d1fae5); color: #111827; font-size: 0.72rem; font-weight: 700;
  cursor: pointer; padding: 0; font-family: inherit; position: relative;
}
.seat:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,0.25); }
.seat-selected { background: #111827; color: #fff; border-color: #111827; box-shadow: 0 0 0 2px #fbbf24; }
.seat-sold { background: var(--sold, #dc2626); color: #fff; border-color: rgba(0,0,0,0.35); }
.seat-blocked { background: #6b7280; color: #e5e7eb; border-color: #4b5563;
  background-image: repeating-linear-gradient(45deg, transparent 0 4px, rgba(0,0,0,0.25) 4px 6px); }
.seat-reserved, .seat.is-reserved.seat-selected { outline: 2px dashed #7c3aed; outline-offset: -3px; }
.seat-reserved { background: #ede9fe; color: #5b21b6; }
.seat:disabled { cursor: not-allowed; }
.seat.checked::after { content: "✓"; position: absolute; top: -6px; right: -5px; width: 15px; height: 15px; border-radius: 50%;
  background: #111827; color: #fff; font-size: 0.6rem; line-height: 15px; }
.legend { display: flex; gap: 0.4rem 1rem; flex-wrap: wrap; font-size: 0.8rem; color: #374151; margin-bottom: 0.4rem; }
.legend i { display: inline-block; width: 15px; height: 15px; border-radius: 4px; margin-right: 5px; vertical-align: -3px; border: 1px solid rgba(0,0,0,0.2); }
.lg-selected { background: #111827; }
.lg-reserved { background: #ede9fe; outline: 2px dashed #7c3aed; outline-offset: -3px; }
.lg-blocked { background: #6b7280; }
.lg-checked { background: #111827; border-radius: 50% !important; }

/* Tipo de compra */
.type-pills { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.type-pill { flex: 1 1 45%; padding: 0.55rem; border-radius: 10px; border: 2px solid var(--c); background: #fff; color: var(--c);
  font: inherit; font-weight: 700; cursor: pointer; font-size: 0.88rem; }
.type-pill.active { background: var(--c); color: #fff; }
.type-badge { display: inline-block; padding: 0.12rem 0.55rem; border-radius: 999px; color: #fff; font-size: 0.75rem; font-weight: 700; }

/* Estudiantes */
.student-row { display: grid; grid-template-columns: 1fr 120px 34px; gap: 0.4rem; margin-bottom: 0.4rem; }
.student-row button { padding: 0; }
.edit-banner { background: var(--gold-soft); border: 2px solid #f59e0b; border-radius: 12px; padding: 0.7rem 1rem; margin-bottom: 1rem;
  display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; font-weight: 600; color: #92400e; }

/* Resumen de compra */
.summary-event { padding: 0.6rem 0.8rem; border-left: 4px solid var(--red-2); background: var(--red-soft); border-radius: 8px; margin: 0.5rem 0; font-size: 0.9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; background: #fff; border: 1px solid #fda4af; font-size: 0.78rem; font-weight: 700; }
.total { display: flex; justify-content: space-between; font-size: 1.1rem; font-weight: 800; padding-top: 0.6rem; border-top: 1px dashed #d1d5db; margin-top: 0.6rem; }

/* Pasos de entrega */
.steps { list-style: none; padding: 0; margin: 0.6rem 0; }
.steps li { padding: 0.35rem 0; font-size: 0.92rem; }
.steps li[data-state="run"]::before { content: "⏳ "; }
.steps li[data-state="ok"]::before { content: "✅ "; }
.steps li[data-state="error"]::before { content: "❌ "; }
.steps li[data-state="wait"]::before { content: "▫️ "; }
.ticket-preview { max-width: 100%; border-radius: 12px; box-shadow: var(--shadow); display: block; margin: 0.6rem auto; max-height: 520px; }

/* Escáner */
.scan-layout { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 860px) { .scan-layout { grid-template-columns: 1fr; } }
#reader { width: 100%; border-radius: 12px; overflow: hidden; background: #111; min-height: 60px; }
#reader video { border-radius: 12px; }
.result-banner { padding: 1rem 1.2rem; border-radius: 12px; font-weight: 800; font-size: 1.15rem; margin-bottom: 0.8rem; }
.result-ok { background: #dcfce7; color: #14532d; border: 2px solid #22c55e; }
.result-warn { background: var(--gold-soft); color: #92400e; border: 2px solid #f59e0b; }
.result-err { background: #fee2e2; color: #991b1b; border: 2px solid #ef4444; }
.event-card { border: 2px solid var(--line); border-radius: 12px; padding: 0.9rem; margin: 0.7rem 0; }
.event-card.current { border-color: var(--green-2); background: var(--green-soft); }
.event-card.other { opacity: 0.92; }
.seat-pick { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.4rem 0.7rem; margin: 3px; border-radius: 10px; border: 2px solid #d1d5db; background: #fff; font-weight: 700; cursor: pointer; font: inherit; }
.seat-pick.on { border-color: var(--blue); background: #dbeafe; color: #1e3a8a; }
.seat-pick.done { border-color: #22c55e; background: #dcfce7; color: #166534; cursor: default; }
.seat-pick small { font-weight: 400; font-size: 0.72rem; }

/* Login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--green), var(--red)); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; padding: 2rem 1.6rem; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.auth-card img { display: block; max-width: 180px; margin: 0 auto 1rem; }
.auth-card h1 { text-align: center; font-size: 1.35rem; }
.auth-card p.sub { text-align: center; color: var(--muted); margin-top: -0.3rem; }
.error-msg { color: #b91c1c; font-size: 0.9rem; min-height: 1.2em; margin-top: 0.5rem; }

/* Modal, toasts, loader */
.modal-overlay { position: fixed; inset: 0; background: rgba(17,24,39,0.55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; position: relative; padding: 1.4rem; }
.modal-wide { max-width: 860px; }
.modal-close { position: absolute; top: 0.5rem; right: 0.7rem; background: none; border: 0; font-size: 1.8rem; cursor: pointer; color: var(--muted); }
.toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 0.5rem; z-index: 60; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 0.7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); max-width: 420px; pointer-events: auto; }
.toast-ok { background: var(--green-2); }
.toast-error { background: #b91c1c; }
.toast-warn { background: var(--gold); }
.loader-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.75); display: grid; place-items: center; z-index: 70; }
.loader-box { text-align: center; font-weight: 600; }
.spinner { width: 44px; height: 44px; border: 4px solid #d1d5db; border-top-color: var(--red-2); border-radius: 50%; margin: 0 auto 0.6rem; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Validación y colores por ciclo */
input.invalid, select.invalid { border-color: #dc2626; background: #fef2f2; outline: 2px solid #fecaca; }
.ticket-band { padding: 0.55rem 0.9rem; border-radius: 10px; font-weight: 800; margin: 0.4rem 0; text-shadow: 0 1px 2px rgba(0,0,0,0.25); }
.student-row { grid-template-columns: 1fr 110px 34px; }
