/* Setup Beautiful Design System & CSS Variables */
:root {
  --bg-color: #f8fafc;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.5);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --accent-color: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.4);
  --accent-gradient: linear-gradient(135deg, #6366f1, #3b82f6, #ec4899);
  --success-color: #10b981;
  
  --font-primary: 'Outfit', sans-serif;
  --font-secondary: 'Inter', sans-serif;
}

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

body {
  font-family: var(--font-secondary);
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  position: relative;
}

/* Background Animated Gradient Blobs */
body::before, body::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  z-index: -1;
  animation: float 20s infinite ease-in-out alternate;
}

body::before {
  width: 400px;
  height: 400px;
  background: rgba(99, 102, 241, 0.3);
  top: -10%;
  left: -10%;
}

body::after {
  width: 500px;
  height: 500px;
  background: rgba(236, 72, 153, 0.2);
  bottom: -10%;
  right: -10%;
  animation-delay: -5s;
}

@keyframes float {
  0% { transform: translate(0, 0); }
  50% { transform: translate(50px, 30px); }
  100% { transform: translate(-30px, 50px); }
}

#app {
  width: 100%;
  max-width: 500px;
  padding: 2rem;
}

body.admin-mode {
  align-items: stretch;
  padding: 20px;
}

body.admin-mode #app {
  max-width: 100% !important;
  width: 100% !important;
  display: flex;
  flex-direction: column;
}

@media (min-width: 769px) {
  /* 只有儀表板（.dash-panel）撐滿視窗；登入卡維持精簡置中 */
  body.admin-mode .dash-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 40px);
  }

  body.admin-mode .admin-layout {
    flex: 1;
    min-height: unset;
  }
}

.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 2.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.1);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s ease;
}

.view {
  display: none;
  animation: fadeIn 0.5s ease forwards;
}

.view.active {
  display: block;
}

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

h1 {
  font-family: var(--font-primary);
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

.subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

/* Form Styles */
.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input, .form-group select {
  width: 100%;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  padding: 1rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(255, 255, 255, 0.9);
}

.btn-primary {
  width: 100%;
  padding: 1rem;
  background: var(--accent-gradient);
  border: none;
  border-radius: 12px;
  color: white;
  font-family: var(--font-primary);
  font-weight: 600;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
  position: relative;
  overflow: hidden;
}

.btn-primary::after {
  content: "";
  position: absolute;
  top: 0; left: -100%;
  width: 50%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: 0.5s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(59, 130, 246, 0.5);
}

.btn-primary:hover::after {
  left: 100%;
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  width: 100%;
  padding: 0.8rem;
  background: transparent;
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  color: var(--text-secondary);
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 1rem;
}

.btn-secondary:hover {
  background: rgba(0,0,0,0.05);
  color: var(--text-primary);
}

/* Result View Styles */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 0;
}

.qr-box {
  background: white;
  padding: 1.5rem;
  border-radius: 20px;
  box-shadow: 0 0 30px rgba(0,0,0,0.1);
  margin-bottom: 1.5rem;
  position: relative;
}

.qr-box::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 24px;
  background: var(--accent-gradient);
  z-index: -1;
  animation: spin 4s linear infinite;
}

@keyframes spin {
  100% { filter: hue-rotate(360deg); }
}

.qr-success-icon {
  width: 60px;
  height: 60px;
  background: var(--success-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: white;
  margin: 0 auto 1.5rem;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
}

/* Scanner Mock View */
.scanner-frame {
  width: 100%;
  height: 250px;
  border: 2px dashed rgba(0, 0, 0, 0.2);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.scanner-line {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 2px;
  background: var(--success-color);
  box-shadow: 0 0 10px var(--success-color);
  animation: scan 2s linear infinite;
}

@keyframes scan {
  0% { top: 0; opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

.status-badge {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.85rem;
  margin-top: 1rem;
}

.status-badge.success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success-color);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Navigation tabs */
.nav-tabs {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  justify-content: center;
}

.tab {
  padding: 0.5rem 1.5rem;
  background: rgba(0,0,0,0.05);
  border-radius: 20px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.3s;
}

/* Admin styles */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}
.admin-table th, .admin-table td {
  padding: 0.8rem;
  text-align: left;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  font-size: 0.9rem;
}
.admin-table th {
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.8rem;
}
.btn-small {
  padding: 0.4rem 0.8rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-approve {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success-color);
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.btn-approve:hover { background: rgba(16, 185, 129, 0.4); }
.btn-reject {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
  margin-left: 0.5rem;
}
.btn-reject:hover { background: rgba(239, 68, 68, 0.4); }
.badge {
  display: inline-block;
  padding: 0.3rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge.pending { background: rgba(245, 158, 11, 0.2); color: #f59e0b; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge.approved { background: rgba(16, 185, 129, 0.2); color: var(--success-color); border: 1px solid rgba(16, 185, 129, 0.3); }

/* Toggle Switch Styles */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
  min-height: unset !important;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.2);
  transition: .4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
  background: var(--success-color);
}

input:focus + .slider {
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* ============================================================
   RWD — Mobile First Responsive Design
   ============================================================ */

/* Viewport meta safety (applied via CSS body fix) */
body {
  overflow-x: hidden;
}

/* Admin panel container — fluid on mobile */
body.admin-mode #app {
  padding: 0.5rem;
}

/* ── Tablet (≤ 768px) ── */
@media (max-width: 768px) {

  /* App container */
  #app {
    padding: 0.75rem;
    width: 100%;
  }

  /* Glass panel: full-width, no overflow */
  .glass-panel {
    padding: 1.2rem !important;
    border-radius: 16px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  /* ── Admin Header ── */

  /* Outer header row: logo left, actions right, allow wrap */
  .glass-panel > div[style*="display:flex; justify-content:space-between"] {
    flex-wrap: wrap !important;
    gap: 0.6rem !important;
    margin-bottom: 1rem !important;
  }

  /* Hide the email display chip on mobile to save space */
  #admin-email-display {
    display: none !important;
  }

  /* Action buttons group: smaller, tighter */
  .glass-panel > div[style*="display:flex; justify-content:space-between"] > div[style*="display:flex; align-items:center; gap:12px"] {
    gap: 6px !important;
    flex-wrap: wrap;
  }

  /* All header buttons: compact size */
  .header-btn {
    padding: 0.35rem 0.6rem !important;
    font-size: 0.8rem !important;
    gap: 4px !important;
  }

  /* Hide text labels on header buttons, show only icon on very small screens */
  @media (max-width: 420px) {
    .header-btn span,
    .header-btn:not(#btn-logout):not(#btn-tour) > *:last-child {
      display: none;
    }
  }

  /* ── Navigation Tabs ── */
  .tabs {
    gap: 0.4rem !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.4rem !important;
  }
  .tabs::-webkit-scrollbar { display: none; }

  .tabs button {
    font-size: 0.85rem !important;
    white-space: nowrap;
    padding: 0.3rem 0.7rem !important;
    flex-shrink: 0;
  }

  /* ── Section headings ── */
  h2[style*="font-size: 1.4rem"] {
    font-size: 1.1rem !important;
  }

  /* ── Dashboard / Requests Table → Card Layout ── */
  .admin-table,
  .admin-table tbody,
  .admin-table tr,
  .admin-table td {
    display: block;
    width: 100%;
  }
  .admin-table thead {
    display: none;
  }
  .admin-table tr {
    margin-bottom: 0.8rem;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 14px;
    padding: 0.9rem;
    border: 1px solid var(--glass-border);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  }
  .admin-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.5rem 0;
    border-bottom: 1px dashed rgba(0,0,0,0.08);
    font-size: 0.85rem;
    text-align: right;
  }
  .admin-table td:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }
  .admin-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-right: 0.8rem;
    text-align: left;
    flex-shrink: 0;
    padding-top: 0.2rem;
  }
  .admin-table td > div {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }
  .admin-table td[data-label="Action"] {
    justify-content: flex-end;
    gap: 0.4rem;
  }
  /* Action 開關：固定方向與尺寸，避免卡片版被拉伸成不同高度 */
  .admin-table td[data-label="Action"] > div {
    flex-direction: row !important;
    align-items: center !important;
  }
  .admin-table td[data-label="Action"] .switch {
    margin-right: 0;
    width: 50px !important;
    height: 28px !important;
    flex: 0 0 auto !important;
  }

  /* ── 2-column grid → single column ── */
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Flex rows with gap → column ── */
  div[style*="display: flex; gap: 1rem; align-items: center;"] {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.5rem !important;
  }
  div[style*="display: flex; gap: 1rem; align-items: center;"] .form-group {
    width: 100%;
  }

  /* ── Database search / export row ── */
  div[style*="flex-wrap: wrap; gap: 1rem;"] {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  div[style*="flex-wrap: wrap; gap: 1rem;"] > button {
    width: 100% !important;
  }

  /* ── Wallet Setting: preview + form side-by-side → stacked ── */
  div[style*="display: grid; grid-template-columns: 1fr 2fr"],
  div[style*="grid-template-columns: 1fr 2fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Wallet live preview: full width on mobile */
  div[style*="background: linear-gradient"][style*="border-radius: 16px"] {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ── Setting page: config inputs full width ── */
  div[style*="display:flex; gap:0.5rem"] {
    flex-direction: column !important;
    gap: 0.4rem !important;
  }
  div[style*="display:flex; gap:0.5rem"] input,
  div[style*="display:flex; gap:0.5rem"] button {
    width: 100% !important;
    border-radius: 8px !important;
  }

  /* ── Modal / access dialog ── */
  .glass-panel[style*="position: fixed"],
  div[style*="position: fixed"][style*="background: rgba(0,0,0"] > div {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    padding: 1.2rem !important;
    border-radius: 16px !important;
  }

  /* ── Visitor page QR ── */
  .qr-container {
    padding: 1rem 0;
  }
  .qr-box {
    width: 200px !important;
    height: 200px !important;
  }

  /* ── Wallet buttons (Apple / Google) ── */
  #wallet-buttons-container {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.6rem !important;
    padding: 0 0.5rem;
  }
  #btn-apple-wallet,
  #btn-google-wallet {
    justify-content: center !important;
    width: 100% !important;
    padding: 0.8rem 1rem !important;
  }

  /* ── General touch target minimum ── */
  button, a, input[type="checkbox"], label {
    min-height: 38px;
  }

  /* ── Sync status badge: smaller ── */
  #sync-status {
    font-size: 0.65rem !important;
  }

  /* ── Nav tabs (class-based) ── */
  .nav-tabs {
    flex-wrap: wrap !important;
    gap: 0.4rem !important;
    justify-content: center !important;
  }
  .tab {
    padding: 0.35rem 0.75rem !important;
    font-size: 0.82rem !important;
  }
}

/* ── Small Phone (≤ 420px) ── */
@media (max-width: 420px) {
  h1 { font-size: 1.6rem !important; }
  .subtitle { font-size: 0.8rem !important; }
  .btn-primary { padding: 0.85rem !important; font-size: 1rem !important; }
  .glass-panel { padding: 1rem !important; border-radius: 14px !important; }

  /* Logo: scale down slightly */
  .glass-panel > div > div[style*="font-family: 'Inter'"] span {
    font-size: 1rem !important;
  }

  /* Tab text even smaller */
  .tabs button { font-size: 0.78rem !important; padding: 0.25rem 0.55rem !important; }

  /* Table cards: tighter */
  .admin-table tr { padding: 0.7rem; }
  .admin-table td { font-size: 0.8rem; }
}
