/* ── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red:      #CC0000;
  --red-dark: #990000;
  --red-lite: #ffeeee;
  --bg:       #f4f4f7;
  --card:     #ffffff;
  --text:     #1a1a2e;
  --muted:    #6b7280;
  --border:   #e5e7eb;
  --radius:   12px;
  --shadow:   0 4px 24px rgba(0,0,0,.08);
  --font:     'Inter', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Nav ──────────────────────────────────────────────────────────────── */
.nav {
  background: var(--red);
  box-shadow: 0 2px 12px rgba(204,0,0,.3);
  position: sticky; top: 0; z-index: 100;
}
.nav-inner {
  max-width: 1100px; margin: auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1.5rem;
}
.nav-brand {
  display: flex; align-items: center; gap: .6rem;
  color: #fff; text-decoration: none;
  font-size: 1.25rem; font-weight: 800; letter-spacing: -.3px;
}
.nav-logo { font-size: 1.5rem; }
.nav-links { list-style: none; display: flex; gap: .4rem; }
.nav-links a {
  color: rgba(255,255,255,.8);
  text-decoration: none; font-weight: 500;
  padding: .45rem 1rem; border-radius: 8px;
  transition: background .2s, color .2s;
}
.nav-links a:hover, .nav-links a.active {
  background: rgba(255,255,255,.2);
  color: #fff;
}

/* ── Main ─────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  max-width: 1100px; margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
}

/* ── Alerts ───────────────────────────────────────────────────────────── */
.alert {
  padding: .9rem 1.2rem; border-radius: 10px;
  margin-bottom: 1.5rem; font-weight: 500;
}
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}
.card-title {
  font-size: 1.4rem; font-weight: 700;
  margin-bottom: 1.5rem; color: var(--text);
  display: flex; align-items: center; gap: .5rem;
}

/* ── Form ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block; font-weight: 600;
  font-size: .85rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .6px;
  margin-bottom: .45rem;
}
.form-control {
  width: 100%; padding: .85rem 1rem;
  border: 2px solid var(--border); border-radius: 10px;
  font-family: var(--font); font-size: .95rem; color: var(--text);
  background: #fafafa;
  transition: border .2s, box-shadow .2s;
  appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(204,0,0,.12);
  background: #fff;
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .85rem 1.6rem; border-radius: 10px;
  font-family: var(--font); font-weight: 700; font-size: .95rem;
  cursor: pointer; border: none; text-decoration: none;
  transition: transform .15s, box-shadow .15s, background .2s;
}
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--red); color: #fff;
  box-shadow: 0 4px 14px rgba(204,0,0,.35);
}
.btn-primary:hover { background: var(--red-dark); box-shadow: 0 6px 18px rgba(204,0,0,.4); }

.btn-secondary {
  background: #f3f4f6; color: var(--text);
  border: 2px solid var(--border);
}
.btn-secondary:hover { background: #e9eaf0; }

.btn-sm { padding: .5rem 1rem; font-size: .83rem; border-radius: 8px; }
.btn-outline {
  background: transparent; color: var(--red);
  border: 2px solid var(--red);
}
.btn-outline:hover { background: var(--red-lite); }

.btn-block { width: 100%; }
.btn-green  { background: #059669; color:#fff; box-shadow: 0 4px 14px rgba(5,150,105,.3); }
.btn-green:hover { background: #047857; }

/* ── Ticket Type Rows ─────────────────────────────────────────────────── */
.ticket-types-wrapper { display: flex; flex-direction: column; gap: .7rem; }
.ticket-type-row {
  display: flex; gap: .7rem; align-items: center;
}
.ticket-type-row .form-control { flex: 1; }
.ticket-type-row .qty-input    { width: 90px; flex: none; text-align: center; }
.btn-remove {
  background: #fee2e2; color: #dc2626;
  border: none; border-radius: 8px;
  width: 38px; height: 38px;
  font-size: 1.2rem; cursor: pointer; flex: none;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.btn-remove:hover { background: #fecaca; }

.btn-add-type {
  background: var(--red-lite); color: var(--red);
  border: 2px dashed var(--red);
  border-radius: 10px; padding: .7rem;
  width: 100%; font-weight: 700; font-size: 1.5rem;
  cursor: pointer; transition: background .2s;
  margin-top: .3rem;
}
.btn-add-type:hover { background: #ffe0e0; }

/* ── Page Layouts ─────────────────────────────────────────────────────── */
.page-generate {
  max-width: 480px; margin: 0 auto;
}

/* ── Dashboard ────────────────────────────────────────────────────────── */
.dash-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem;
}
.dash-title { font-size: 1.6rem; font-weight: 800; }
.stats-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--card); border-radius: var(--radius);
  padding: 1.2rem 1.5rem; box-shadow: var(--shadow);
}
.stat-card .stat-num {
  font-size: 2rem; font-weight: 800; color: var(--red);
}
.stat-card .stat-lbl {
  font-size: .82rem; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px;
}

/* ── Filters ──────────────────────────────────────────────────────────── */
.filters {
  display: flex; flex-wrap: wrap; gap: .7rem;
  margin-bottom: 1.2rem; align-items: center;
}
.filters .form-control { flex: 1; min-width: 180px; margin: 0; }
.filters .form-group { margin: 0; flex: 1; min-width: 140px; }

/* ── Table ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.tbl {
  width: 100%; border-collapse: collapse;
  background: var(--card); font-size: .9rem;
}
.tbl th {
  background: #f9fafb; padding: .9rem 1rem;
  text-align: left; font-weight: 700;
  font-size: .8rem; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.tbl td {
  padding: .85rem 1rem; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl tbody tr:hover { background: #fafafa; }
.tbl tbody tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
  display: inline-block; padding: .25rem .7rem;
  border-radius: 999px; font-size: .75rem; font-weight: 700;
}
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-gray   { background: #f3f4f6; color: #6b7280; }
.badge-red    { background: #fee2e2; color: #991b1b; }

/* ── QR modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-box {
  background: #fff; border-radius: 16px;
  padding: 2rem; max-width: 380px; width: 90%;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.25);
  transform: scale(.92); transition: transform .25s;
}
.modal-overlay.open .modal-box { transform: scale(1); }
.modal-box h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; }
.modal-qr-img {
  width: 200px; height: 200px; border: 3px solid var(--border);
  border-radius: 10px; margin: .5rem auto 1.2rem;
  display: block;
}
.modal-code {
  font-family: monospace; font-size: 1.2rem; font-weight: 700;
  background: #f3f4f6; padding: .4rem .8rem; border-radius: 6px;
  letter-spacing: 2px; margin-bottom: 1rem; display: inline-block;
}
.modal-actions { display: flex; gap: .7rem; justify-content: center; flex-wrap: wrap; }
.modal-close-btn {
  position: absolute; top: .7rem; right: .9rem;
  background: none; border: none; font-size: 1.5rem;
  cursor: pointer; color: var(--muted);
}

/* ── Scanner ──────────────────────────────────────────────────────────── */
.scanner-wrap { max-width: 560px; margin: 0 auto; }
.scanner-header { text-align: center; margin-bottom: 1.5rem; }
.scanner-header h1 { font-size: 1.8rem; font-weight: 800; }
.scanner-header p  { color: var(--muted); margin-top: .4rem; }

.cam-container {
  position: relative; width: 100%; aspect-ratio: 1;
  border-radius: 14px; overflow: hidden;
  background: #111; box-shadow: var(--shadow);
}
#cam-video { width: 100%; height: 100%; object-fit: cover; }
.scan-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.scan-frame {
  width: 65%; aspect-ratio: 1;
  border: 3px solid var(--red);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.35);
  position: relative;
}
.scan-frame::before {
  content: ''; position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: var(--red);
  animation: scan-line 2s linear infinite;
}
@keyframes scan-line {
  0%   { top: 0; }
  100% { top: 100%; }
}
.scan-result {
  margin-top: 1.5rem; padding: 1.2rem;
  border-radius: var(--radius); text-align: center;
  font-weight: 700; font-size: 1rem;
  display: none;
}
.scan-result.show { display: block; }
.scan-result.success { background: #ecfdf5; color: #065f46; border: 2px solid #6ee7b7; }
.scan-result.error   { background: #fef2f2; color: #991b1b; border: 2px solid #fca5a5; }
.scan-result.already { background: #fffbeb; color: #92400e; border: 2px solid #fcd34d; }

.scan-info-box {
  background: var(--card); border-radius: var(--radius);
  padding: 1.2rem 1.5rem; margin-top: 1rem;
  box-shadow: var(--shadow); display: none;
}
.scan-info-box.show { display: block; }
.scan-info-row { display: flex; justify-content: space-between;
  padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.scan-info-row:last-child { border-bottom: none; }
.scan-info-row .lbl { color: var(--muted); font-weight: 600; }

.cam-controls { display: flex; gap: .7rem; margin-top: 1rem; justify-content: center; }

/* ── Manual check ─────────────────────────────────────────────────────── */
.manual-check { margin-top: 2rem; }
.manual-check-row { display: flex; gap: .7rem; }
.manual-check-row .form-control { flex: 1; }

/* ── Ticket Preview Card ──────────────────────────────────────────────── */
.ticket-preview {
  background: linear-gradient(135deg, var(--red) 0%, var(--red-dark) 100%);
  color: #fff; border-radius: 14px;
  padding: 1.5rem; position: relative; overflow: hidden;
  box-shadow: 0 8px 30px rgba(204,0,0,.4);
  margin-top: 2rem;
}
.ticket-preview::after {
  content: ''; position: absolute;
  top: -40px; right: -40px;
  width: 180px; height: 180px;
  background: rgba(255,255,255,.07);
  border-radius: 50%;
}
.ticket-preview .tp-event { font-size: 1.25rem; font-weight: 800; }
.ticket-preview .tp-meta  { font-size: .85rem; opacity: .8; margin-top: .4rem; }
.ticket-preview .tp-type  { margin-top: 1rem; background: rgba(255,255,255,.15);
  display: inline-block; padding: .3rem .8rem; border-radius: 99px; font-size: .82rem; font-weight: 700; }
.ticket-preview .tp-code  { font-family: monospace; font-size: 1.5rem; font-weight: 800;
  letter-spacing: 3px; margin-top: .8rem; }

/* ── Footer ───────────────────────────────────────────────────────────── */
.footer {
  text-align: center; padding: 1.5rem;
  color: var(--muted); font-size: .82rem;
  border-top: 1px solid var(--border);
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .nav-links a { padding: .4rem .7rem; font-size: .88rem; }
  .dash-header  { flex-direction: column; align-items: flex-start; }
  .main { padding: 1.2rem 1rem; }
}
