*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #f5f6fb;
  color: #333;
}

.page {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 16px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 20px;
}

/* Auth pages: single card, slightly left of center */
.auth-page {
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
}

.auth-page .form-card {
  width: 100%;
}

.form-card,
.preview-card {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.09);
  padding: 20px 24px 24px;
}

.form-card h1 {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  color: #f97316;
}

.preview-card h2 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 600;
}

.field {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-inline {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-hint {
  display: block;
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
}

label,
.label {
  font-size: 13px;
  font-weight: 500;
  color: #4b5563;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  border-radius: 8px;
  border: 1px solid #d1d5db;
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus {
  border-color: #fb923c;
  box-shadow: 0 0 0 1px rgba(249, 115, 22, 0.3);
}

fieldset {
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  padding: 10px 12px 12px;
}

legend {
  padding: 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: #4b5563;
}

.discount-type {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.discount-type label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.discount-type input[type="number"] {
  width: 90px;
}

.suffix {
  font-size: 13px;
  color: #6b7280;
}

.festival-list {
  max-height: 150px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  padding: 8px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.festival-list label {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.primary-btn,
.secondary-btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.12s ease,
    background 0.12s ease;
}

.primary-btn {
  width: 100%;
  background: linear-gradient(90deg, #f97316, #fb923c);
  color: #ffffff;
  box-shadow: 0 10px 18px rgba(249, 115, 22, 0.35);
}

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(249, 115, 22, 0.5);
}

.primary-btn:active {
  transform: translateY(0);
  box-shadow: 0 6px 12px rgba(249, 115, 22, 0.35);
}

.secondary-btn {
  width: 100%;
  margin-top: 10px;
  background: #111827;
  color: #f9fafb;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.5);
}

.secondary-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

.secondary-btn:not(:disabled):hover {
  transform: translateY(-1px);
}

.coupon-output {
  background: #e5e7eb;
  padding: 10px;
  border-radius: 10px;
}

/* Preview display size (canvas is 1024×731; shown smaller here) */
.coupon-canvas-wrap {
  width: 431px;
  max-width: 100%;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  background: #ffffff;
  aspect-ratio: 1024 / 731;
}

#coupon-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

@media (max-width: 880px) {
  .page {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 580px) {
  .coupon-canvas-wrap {
    border-radius: 12px;
  }
}

/* Top nav */
.top-nav {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  margin-bottom: 16px;
}
.top-nav a {
  color: #f97316;
  font-weight: 600;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 8px;
  transition: background 0.15s;
}
.top-nav a:hover {
  background: rgba(249, 115, 22, 0.1);
}
.top-nav a:first-child {
  color: #111827;
}
.top-nav .nav-active {
  background: rgba(249, 115, 22, 0.12);
  color: #ea580c;
}

.top-nav .nav-logo {
  font-weight: 800;
  font-size: 18px;
  color: #111827;
}

.nav-links {
  display: flex;
  gap: 12px;
  align-items: center;
}

.nav-logout-form {
  margin-left: auto;
}

.nav-logout-btn {
  padding-inline: 16px;
  font-size: 13px;
}

/* Home / Landing page */
.home-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.home-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(15, 23, 42, 0.12);
  padding: 48px 40px;
  max-width: 520px;
  width: 100%;
  text-align: center;
}
.home-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 800;
  color: #111827;
}
.home-subtitle {
  margin: 0 0 32px;
  font-size: 16px;
  color: #6b7280;
}
.home-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.home-option {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 24px 28px;
  background: #f9fafb;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  text-decoration: none;
  color: #111827;
  transition: all 0.15s ease;
}
.home-option:hover {
  background: #fff;
  border-color: #f97316;
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.15);
}
.home-option-icon {
  font-size: 32px;
  flex-shrink: 0;
}
.home-option-text {
  flex: 1;
  text-align: left;
}
.home-option-title {
  display: block;
  font-size: 18px;
  font-weight: 700;
}
.home-option-desc {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #6b7280;
  margin-top: 4px;
}

/* Template editor page */
.template-editor-page {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px 24px;
}
.template-editor-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.09);
  padding: 24px;
}
.template-editor-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  color: #111827;
}
.template-editor-subtitle {
  margin: 0 0 18px;
  font-size: 14px;
  color: #6b7280;
}
.template-editor-subtitle code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
}
.template-editor-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}
.template-editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 20px;
  align-items: flex-start;
}
/* Scrollable area when preview doesn't fit */
.template-editor-preview-scroll {
  overflow: auto;
  max-width: 100%;
  min-width: 0;
}
/* Preview display size (same as generator); coordinates & JSON are 1024×731 */
.template-editor-canvas-wrap {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  background: #020617;
  width: 431px;
  height: 307px;
  flex-shrink: 0;
}
.template-editor-canvas {
  position: relative;
  width: 100%;
  height: 100%;
}
.template-editor-canvas img {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
}
/* Match generator: Montserrat, shadows, weights (app.js renderCoupon) */
.field-box {
  position: absolute;
  padding: 0;
  cursor: grab;
  user-select: none;
  box-shadow: none;
  color: inherit;
  font-family: Montserrat, system-ui, sans-serif;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.field-box:active {
  cursor: grabbing;
}
.field-topbar {
  top: 6%;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffffff;
  text-align: center;
}
.field-title {
  top: 18%;
  font-size: 55px;
  font-weight: 700;
  text-transform: uppercase;
  color: #ef4444;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
.field-offer {
  top: 34%;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}
.field-offer .offer-get {
  font-size: 40px;
  font-weight: 800;
  color: #ffffff;
}
.field-offer .offer-number {
  font-size: 138px;
  font-weight: 900;
  color: #facc15;
  line-height: 1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
}
.field-offer .offer-percent {
  font-size: 80px;
  font-weight: 900;
  color: #facc15;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
}
.field-offer .offer-off {
  font-size: 48px;
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.field-min {
  top: 50%;
  font-size: 30px;
  font-weight: 900;
  color: #f59e0b;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.field-festival {
  top: 64%;
  font-size: 24px;
  font-weight: 900;
  color: #ffffff;
  text-align: right;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.field-valid {
  top: 72%;
  font-size: 18px;
  font-weight: 900;
  color: #f3e8ff;
  text-align: right;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.field-code {
  top: 82%;
  font-size: 60px;
  font-weight: 900;
  color: #ffffff;
  text-align: right;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}
.field-qr {
  top: 40%;
  right: 8%;
  width: 230px;
  height: 230px;
  border-radius: 12px;
  background: #ffffff;
  overflow: hidden;
}
.field-qr-inner {
  width: 100%;
  height: 100%;
}
.template-editor-sidebar h2 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 600;
  color: #111827;
}
.editor-values {
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  padding: 10px 12px;
  margin-bottom: 14px;
}
.value-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: #4b5563;
  padding: 4px 0;
}
.value-row.disabled {
  opacity: 0.5;
}
.value-row code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
}
.value-row-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.value-row-controls input {
  width: 64px;
}
.size-toggle {
  border: none;
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 999px;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}
.value-row.disabled .size-toggle {
  background: #e5e7eb;
  color: #9ca3af;
}
.editor-colors .color-row input[type="color"] {
  width: 36px;
  height: 28px;
  padding: 2px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
}
.layout-json {
  width: 100%;
  min-height: 170px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  resize: vertical;
}
.template-editor-sidebar .field-hint {
  margin-top: 6px;
}

@media (max-width: 900px) {
  .template-editor-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Preview buttons */
.preview-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.preview-buttons .secondary-btn {
  margin-top: 0;
  flex: 1;
  min-width: 120px;
}
.preview-index {
  font-size: 14px;
  font-weight: 500;
  color: #6b7280;
}
#prev-btn,
#next-btn {
  margin-top: 8px;
  max-width: 200px;
}

/* Scanner page */
.scanner-page {
  max-width: 480px;
  margin: 24px auto;
  padding: 0 16px;
}
.scanner-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.09);
  padding: 24px;
}
.scanner-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  color: #111827;
  text-align: center;
}
.scanner-desc {
  margin: 0 0 16px;
  color: #6b7280;
  font-size: 14px;
  text-align: center;
}
.qr-shell {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
  min-height: 280px;
  background: #020617;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-reader {
  position: relative;
  z-index: 1;
  border-radius: 12px;
  overflow: hidden;
  width: 100%;
}
.qr-reader video {
  border-radius: 12px;
}
.qr-status-visual {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: #020617;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.22s ease-out, transform 0.22s ease-out;
  pointer-events: none;
}
.qr-status-visual.visible {
  opacity: 1;
  transform: scale(1);
}
.qr-status-icon {
  width: 128px;
  height: 128px;
  border-radius: 999px;
  border: 6px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 72px;
  font-weight: 800;
  box-shadow: 0 22px 50px rgba(15, 23, 42, 0.6);
  background: radial-gradient(circle at 30% 30%, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.75));
}
.qr-status-visual.success {
  color: #bbf7d0;
  background: linear-gradient(135deg, #16a34a 0%, #22c55e 40%, #052e16 100%);
}
.qr-status-visual.error {
  color: #fee2e2;
  background: linear-gradient(135deg, #dc2626 0%, #f97373 40%, #450a0a 100%);
}
.camera-toggle-row {
  margin-bottom: 12px;
}
.camera-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.camera-toggle-btn .camera-icon {
  font-size: 1.1em;
}
.scan-result {
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  text-align: center;
  min-height: 24px;
}
.scan-result.success {
  background: #d1fae5;
  color: #065f46;
}
.scan-result.error {
  background: #fee2e2;
  color: #991b1b;
}
.manual-redeem {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
}
.manual-redeem-label {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 500;
  color: #6b7280;
}
.manual-redeem-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.manual-redeem-row input {
  width: 100%;
  box-sizing: border-box;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  padding: 12px 14px;
  font-size: 17px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.manual-redeem-row input::placeholder {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.manual-redeem-row .primary-btn {
  width: 100%;
  margin: 0;
  padding: 12px 20px;
}
.scanner-actions {
  margin-top: 16px;
}
.scanner-actions .secondary-btn {
  display: inline-block;
  text-decoration: none;
  text-align: center;
}

/* Redeem page */
.redeem-page {
  max-width: 420px;
  margin: 24px auto;
  padding: 0 16px;
}
.redeem-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.09);
  padding: 24px;
}
.redeem-card h1 {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 700;
  color: #111827;
}
.redeem-details {
  font-size: 15px;
  line-height: 1.7;
  color: #374151;
}
.redeem-details p {
  margin: 0 0 8px;
}
.redeem-hint {
  margin-top: 16px;
  font-size: 13px;
  color: #6b7280;
}
.redeem-error {
  color: #991b1b;
  font-weight: 600;
}
.hidden {
  display: none !important;
}

/* Records page */
.records-page {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px 24px;
}
.records-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.09);
  padding: 24px;
}
.records-card h1 {
  margin: 0 0 20px;
  font-size: 22px;
  font-weight: 700;
  color: #111827;
  text-align: center;
}
.records-filters {
  margin-bottom: 20px;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.filter-row label {
  font-size: 13px;
  font-weight: 500;
  color: #4b5563;
}
.filter-row input,
.filter-row select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  font-size: 14px;
}
.filter-row .primary-btn {
  width: auto;
  padding: 8px 16px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  padding: 16px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.stat-value {
  display: block;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.2;
  color: #111827;
}
.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat-generated { background: #fef3c7; }
.stat-active { background: #d1fae5; }
.stat-redeemed { background: #dbeafe; }
.stat-expired { background: #fee2e2; }
.records-table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
}
.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.records-table th {
  background: #f9fafb;
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: #374151;
  border-bottom: 2px solid #e5e7eb;
}
.records-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #e5e7eb;
  color: #4b5563;
}
.records-table tbody tr:hover {
  background: #f9fafb;
}
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.status-active { background: #d1fae5; color: #065f46; }
.status-used { background: #dbeafe; color: #1e40af; }
.status-expired { background: #fee2e2; color: #991b1b; }
.records-empty {
  text-align: center;
  color: #6b7280;
  padding: 24px;
  margin: 0;
}

.records-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.delete-btn {
  padding: 8px 16px;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
.delete-btn:hover:not(:disabled) {
  background: #b91c1c;
}
.delete-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.selected-count {
  font-size: 13px;
  color: #6b7280;
}
.col-check {
  width: 44px;
  min-width: 44px;
  text-align: center;
}
.col-serial {
  width: 60px;
  min-width: 60px;
  text-align: center;
}
.col-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}
.col-action {
  width: 60px;
  text-align: center;
}
.delete-one-btn {
  padding: 4px 10px;
  background: #fee2e2;
  color: #991b1b;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.delete-one-btn:hover {
  background: #fecaca;
}
.records-table code {
  font-family: monospace;
  font-size: 13px;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
}

.records-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  font-size: 13px;
  color: #6b7280;
}
.records-page-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}
.records-pagination .secondary-btn {
  width: auto;
  margin-top: 0;
  padding: 6px 12px;
  font-size: 12px;
}
.records-page-number {
  min-width: 90px;
  text-align: center;
  font-weight: 500;
}

