:root {
  --brand: #007bff;
  --brand-dark: #0056b3;
  --muted: #6c757d;
  --danger: #dc3545;
  --success: #27ae60;
  --warning: #f39c12;
  --card-bg: #ffffff;
  --page-bg: #f4f7fb;
  --border: #e9ecef;
  --shadow: rgba(0, 0, 0, 0.08);
  --shadow-hover: rgba(0, 0, 0, 0.12);
  --surface-overlay: rgba(15, 23, 42, 0.55);
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --radius-lg: 24px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--page-bg);
  color: #222;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
  min-height: 100vh;
}

header {
  padding: 20px 16px 18px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: white;
  box-shadow: 0 2px 8px var(--shadow);
}

.header-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.brand {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

h1 {
  font-size: 1.45rem;
  font-weight: 600;
}

.subtitle {
  font-size: 0.9rem;
  opacity: 0.9;
}

.header-install-btn {
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid white;
  border-radius: 999px;
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  backdrop-filter: blur(12px);
}

.header-install-btn:hover {
  background: rgba(255, 255, 255, 0.26);
  transform: translateY(-1px);
}

.header-install-btn:active {
  transform: translateY(0);
}

.tabs {
  display: flex;
  background: white;
  border-bottom: 2px solid var(--border);
  margin: 0 auto;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.tab-btn {
  flex: 1;
  padding: 14px 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  background: #f8f9fa;
  color: var(--brand);
}

.tab-btn.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  background: #f8f9fa;
  font-weight: 600;
}

main {
  padding: 0;
}

.tab-content {
  display: none;
  padding: 24px 16px 32px;
  max-width: 960px;
  margin: 0 auto;
  animation: fadeIn 0.3s ease-in;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px var(--shadow);
  border: 1px solid var(--border);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: 0 4px 12px var(--shadow-hover);
}

.card-subtitle {
  margin-bottom: 16px;
  font-size: 0.95rem;
  color: var(--muted);
}

.row {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  align-items: center;
}

input[type="number"],
input[type="text"] {
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid var(--border);
  min-width: 120px;
  font-size: 1rem;
  transition: border-color 0.2s ease;
  background: white;
}

input[type="number"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

button {
  padding: 11px 18px;
  border-radius: 12px;
  border: none;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

button:hover:not(:disabled) {
  background: var(--brand-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 123, 255, 0.28);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.generate-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.generate-controls {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 210px;
}

.action-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.action-btn {
  padding: 10px 16px;
  background: white;
  border: 1px solid #dadde1;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
  color: #2d3748;
}

.action-btn:hover {
  background: #f8f9fa;
  border-color: var(--brand);
  color: var(--brand);
}

.tickets-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.ticket-count-badge {
  background: var(--brand);
  color: white;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

.qrcode-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  min-height: 120px;
}

.qr-status-banner {
  width: 100%;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: #fffaf2;
  border: 1px solid rgba(243, 156, 18, 0.35);
  border-radius: 14px;
  color: #8c5b00;
  font-size: 0.88rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.qr-box {
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qrcode-grid .item {
  width: 150px;
  text-align: center;
  font-size: 0.85rem;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s, box-shadow 0.2s;
}

.qrcode-grid .item.qr-error-state {
  border-color: rgba(220, 53, 69, 0.6);
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.18);
}

.qrcode-grid .item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.08);
}

.qr-error {
  display: block;
  font-size: 0.75rem;
  color: var(--danger);
  margin-top: 6px;
}

.reader {
  width: 100%;
  max-width: 420px;
  margin: 16px auto;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 2px 8px var(--shadow);
}

.scanner-guidance {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin: 12px auto;
  max-width: 420px;
  background: rgba(0, 123, 255, 0.08);
  color: var(--brand-dark);
  padding: 12px 16px;
  border-radius: 16px;
}

.scanner-icon {
  font-size: 1.4rem;
}

.scan-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

.scan-result {
  text-align: center;
  margin-top: 14px;
  font-size: 1rem;
  min-height: 38px;
  padding: 10px;
  border-radius: 12px;
  background: #f8f9fa;
}

.scan-feedback {
  position: fixed;
  inset: 0;
  background: var(--surface-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1050;
  padding: 24px;
}

.scan-feedback.hidden {
  display: none;
}

.feedback-content {
  background: white;
  border-radius: 24px;
  padding: 32px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.28);
}

.feedback-icon {
  font-size: 64px;
  margin-bottom: 18px;
}

.feedback-icon.success {
  color: var(--success);
}

.feedback-icon.warning {
  color: var(--warning);
}

.feedback-icon.error {
  color: var(--danger);
}

.feedback-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: #222;
}

.feedback-code {
  font-family: "Courier New", monospace;
  font-size: 1.05rem;
  color: #444;
  margin-bottom: 10px;
  word-break: break-all;
  padding: 10px;
  background: #f5f7fb;
  border-radius: 12px;
}

.feedback-message {
  font-size: 0.95rem;
  color: #555;
}

.feedback-hint {
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--muted);
}

.stats {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.stat {
  flex: 1;
  text-align: center;
  padding: 18px 12px;
  background: linear-gradient(135deg, #f8fbff 0%, #ffffff 100%);
  border-radius: 16px;
  border: 1px solid var(--border);
  transition: transform 0.2s ease;
}

.stat:hover {
  transform: translateY(-2px);
}

.stat-value {
  font-weight: 700;
  font-size: 1.8rem;
  color: var(--brand);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 6px;
}

.setting-item {
  padding: 18px;
  background: #f8f9fa;
  border-radius: 12px;
  border: 1px solid #e9ecef;
}

.setting-desc {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 4px 0 12px;
}

.install-instructions {
  margin-top: 16px;
  padding: 14px;
  background: #f8f9fa;
  border-radius: 12px;
  border-left: 4px solid var(--brand);
}

.install-heading {
  margin: 0 0 10px;
  font-weight: 600;
  font-size: 0.92rem;
}

.install-step {
  margin: 4px 0 10px 16px;
  color: var(--muted);
  font-size: 0.86rem;
}

.install-note {
  margin-top: 12px;
  border-top: 1px solid #e2e8f0;
  padding-top: 8px;
  color: var(--warning);
  font-size: 0.85rem;
}

footer {
  text-align: center;
  padding: 22px 16px;
  color: var(--muted);
  font-size: 0.86rem;
  border-top: 1px solid var(--border);
  background: white;
}

button.danger {
  background: var(--danger);
}

.hidden {
  display: none;
}

@media (max-width: 860px) {
  .card {
    padding: 20px;
    border-radius: 18px;
  }

  .action-buttons {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  .stats {
    flex-direction: column;
  }
}

@media (max-width: 680px) {
  header {
    padding: 16px 14px;
  }

  .header-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-install-btn {
    width: 100%;
    justify-content: center;
  }

  h1 {
    font-size: 1.2rem;
  }

  .tabs {
    position: sticky;
    top: 0;
  }

  .tab-btn {
    padding: 12px 8px;
    font-size: 0.88rem;
  }

  .tab-content {
    padding: 18px 12px 28px;
  }

  .generate-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .input-group {
    min-width: 100%;
  }

  .action-buttons {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }

  .scanner-guidance {
    margin: 12px 0;
  }

  .scan-feedback {
    align-items: flex-end;
  }

  .feedback-content {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding: 26px 22px;
  }
}

@media (max-width: 480px) {
  .logo {
    width: 44px;
    height: 44px;
  }

  h1 {
    font-size: 1.05rem;
  }

  .subtitle {
    font-size: 0.82rem;
  }

  .qrcode-grid .item {
    width: 100%;
  }

  .scanner-guidance {
    flex-direction: column;
    text-align: center;
  }

  .scanner-icon {
    font-size: 1.2rem;
  }

  .card {
    padding: 18px 16px;
  }

  footer {
    font-size: 0.8rem;
  }
}

/* Cloud sync, loader, and empty-state UI */

.global-loader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--surface-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.global-loader.hidden {
  display: none;
}

.global-loader.show {
  opacity: 1;
}

.global-loader-box {
  background: white;
  border-radius: 16px;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  color: #222;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.28);
}

.inline-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid rgba(0, 123, 255, 0.25);
  border-top-color: var(--brand);
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.sync-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
}

.sync-status-badge.hidden {
  display: none;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.sync-status-badge.online .sync-dot {
  background: var(--success);
}

.sync-status-badge.syncing .sync-dot {
  background: var(--warning);
}

.sync-status-badge.manual-mode .sync-dot {
  background: var(--brand);
}

.sync-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  margin: 12px 16px 0;
  background: #fdecea;
  color: var(--danger);
  border: 1px solid rgba(220, 53, 69, 0.25);
  border-radius: 12px;
  font-size: 0.9rem;
}

.sync-alert.hidden {
  display: none;
}

.sync-alert #syncAlertDismiss {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

button.is-loading {
  opacity: 0.75;
  cursor: progress;
}

button.locked {
  opacity: 0.6;
  cursor: not-allowed;
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}

.empty-state-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.qr-status-banner {
  grid-column: 1 / -1;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: #fff8e6;
  color: #8a6300;
  border: 1px solid rgba(243, 156, 18, 0.35);
  border-radius: 10px;
  font-size: 0.85rem;
}

.qr-error-state {
  border-color: var(--danger) !important;
}
