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

:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --success: #22c55e;
  --danger: #ef4444;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #475569;
  --radius: 12px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.hidden {
  display: none !important;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ========== LOGIN VIEW ========== */
.login-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}

.login-logo {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  object-fit: contain;
  margin-bottom: 16px;
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.4);
  background: var(--primary);
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--primary);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.error-msg {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 8px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  background: var(--bg-input);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
  width: auto;
}

/* ========== HOME VIEW ========== */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px;
}

.home-header-left h1 {
  font-size: 20px;
  font-weight: 700;
}

.home-header-left span {
  font-size: 13px;
  color: var(--text-muted);
}

.ios-install-btn {
  width: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.home-logo {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: contain;
  margin-bottom: 4px;
}

.search-box {
  position: relative;
  margin-bottom: 12px;
}

.search-box .form-input {
  padding-left: 40px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 16px;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.event-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid var(--border);
}

.event-card:active {
  transform: scale(0.98);
}

.event-img {
  width: 100%;
  height: 160px;
  background-size: cover;
  background-position: center;
  background-color: var(--bg-input);
}

.event-info {
  padding: 14px 16px;
}

.event-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.3;
}

.event-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ========== HOME TABS ========== */
.home-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn--active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ========== HISTORY LIST ========== */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border);
}

.history-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.history-qr {
  font-size: 13px;
  font-weight: 600;
  word-break: break-all;
  color: var(--text);
  line-height: 1.4;
}

.history-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  text-align: right;
  line-height: 1.5;
}

.history-card-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.history-meta-item {
  font-size: 12px;
  color: var(--text-muted);
}

.history-meta-item strong {
  color: var(--text);
}

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 0;
  color: var(--text-muted);
  gap: 12px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px 0;
}

.page-info {
  font-size: 13px;
  color: var(--text-muted);
}

.empty-state,
.error-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
  font-size: 15px;
}

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

/* ========== SCANNER VIEW ========== */
.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px;
}

.scanner-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.scanner-container {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  min-height: 300px;
}

.scanner-container video {
  width: 100%;
  border-radius: var(--radius);
}

.camera-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  min-height: 300px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.camera-placeholder-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.camera-placeholder-text {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

.scanner-footer {
  text-align: center;
  padding: 16px 0;
}

.scanner-hint {
  color: var(--text-muted);
  font-size: 14px;
}

.scanner-error {
  text-align: center;
  padding: 48px 24px;
  color: var(--danger);
  background: var(--bg-card);
  border-radius: var(--radius);
}

.scanner-error-detail {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ========== MANUAL INPUT ========== */
.manual-input {
  padding: 0;
}

.manual-input-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  text-align: center;
}

.manual-input-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}

.manual-input-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.manual-input .form-input {
  text-align: center;
  font-size: 18px;
  letter-spacing: 2px;
  margin-bottom: 16px;
}

.manual-input-actions {
  display: flex;
  gap: 10px;
}

.manual-input-actions .btn {
  flex: 1;
}

/* ========== RESULT VIEW ========== */
.result-wrapper {
  padding-top: 16px;
}

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

.result-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.result-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
}

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 20px;
}

.result-badge.success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.result-badge.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.result-item {
  margin-bottom: 16px;
}

.result-item:last-child {
  margin-bottom: 0;
}

.result-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.result-value {
  font-size: 15px;
  word-break: break-all;
}

.result-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.result-actions .btn {
  flex: 1;
}

/* ========== TOAST ========== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 14px;
  color: var(--text);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  animation: toastIn 0.3s ease;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ========== HTML5 QR OVERRIDES ========== */
#qr-reader {
  border: none !important;
}

#qr-reader__scan_region {
  min-height: 300px;
}

#qr-reader__scan_region img {
  display: none;
}

#qr-reader__dashboard {
  padding: 12px !important;
  background: var(--bg-card) !important;
  border: none !important;
}

#qr-reader__dashboard button {
  background: var(--primary) !important;
  color: white !important;
  border: none !important;
  border-radius: 8px !important;
  padding: 10px 20px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
}

/* ========== PWA INSTALL BANNER ========== */
.pwa-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
  transition: transform 0.4s ease, opacity 0.4s ease;
}

.pwa-banner--hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

.pwa-banner--visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.pwa-banner-content {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
  margin: 0 12px 12px;
  border-radius: var(--radius);
}

.pwa-banner-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: contain;
  flex-shrink: 0;
}

.pwa-banner-body {
  flex: 1;
  min-width: 0;
}

.pwa-banner-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.pwa-banner-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.pwa-banner-action {
  flex-shrink: 0;
}

.pwa-banner-action .btn-sm {
  width: auto;
}

.pwa-banner-action svg {
  display: none;
}

.pwa-banner.is-ios .btn-sm {
  display: none;
}

.pwa-banner.is-ios .pwa-banner-action svg {
  display: block;
}

.pwa-banner .btn-sm {
  flex-shrink: 0;
  width: auto;
}

.btn-dismiss {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.btn-dismiss:hover {
  background: var(--bg-input);
  color: var(--text);
}
