*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --black: #000;
  --white: #fff;
  --accent: #E8E052;
  --accent-glow: rgba(232,224,82,0.3);
  --text-dark: #fff;
  --text-dark-muted: rgba(255,255,255,0.5);
  --text-light: #1a1a1a;
  --text-light-muted: #8e8e93;
  --icon-bg: #f2f2f7;
  --card-border: #f0f0f0;
  --danger: #f87171;
  --success: #34d399;
  --radius: 20px;
  --radius-sm: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-height: 64px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--black);
  color: var(--text-dark);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideSheet {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@keyframes scanLine {
  0% { top: 0; }
  50% { top: calc(100% - 2px); }
  100% { top: 0; }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* ===== SPLASH SCREEN ===== */
.splash {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease-out;
}
.splash.hidden { display: none !important; }
.splash-content { text-align: center; padding: 2rem; }
.splash-logo { margin-bottom: 1.5rem; animation: float 3s ease-in-out infinite; }
.splash-title {
  font-size: 2rem; font-weight: 800; letter-spacing: -0.03em;
  color: #fff; margin-bottom: 0.3rem;
}
.splash-sub { font-size: 0.9rem; color: rgba(255,255,255,0.4); margin-bottom: 2rem; }
.splash-btn {
  display: inline-block; padding: 0.85rem 2.5rem;
  background: var(--accent); color: #000;
  font-size: 1rem; font-weight: 700; font-family: inherit;
  border-radius: 50px; text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 24px var(--accent-glow);
}
.splash-btn:active { transform: scale(0.95); }

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== APP HEADER ===== */
.app-header {
  background: var(--black);
  padding: 1rem 1.25rem 1.5rem;
  padding-top: calc(env(safe-area-inset-top, 0px) + 1rem);
}
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.header-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dark-muted);
}
.header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  overflow: hidden;
  cursor: pointer;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-initials {
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}
.header-hero { text-align: left; }
.hero-total {
  display: block;
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-dark);
  line-height: 1.1;
}
.hero-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dark-muted);
  margin-top: 0.25rem;
}

/* ===== TABS ===== */
.tab { display: none; }
.tab.active { display: block; }

/* ===== PULL-UP CARD ===== */
.pull-card {
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  min-height: calc(100vh - 180px);
  padding: 0.75rem 1.25rem;
  padding-bottom: calc(var(--nav-height) + var(--safe-b) + 1.5rem);
}
.card-handle {
  width: 36px;
  height: 4px;
  background: #ddd;
  border-radius: 2px;
  margin: 0 auto 0.75rem;
}
.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-light);
  text-align: center;
  margin-bottom: 1rem;
}

/* ===== ACTIVITY LIST ===== */
.activity-date {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-light-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.75rem 0 0.4rem;
}
.activity-date:first-child { padding-top: 0; }

.activity-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
  border-bottom: 1px solid #f5f5f5;
}
.activity-row:active { opacity: 0.6; }
.activity-row:last-child { border-bottom: none; }

.activity-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--icon-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.activity-info {
  flex: 1;
  min-width: 0;
}
.activity-store {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.activity-category {
  font-size: 0.75rem;
  color: var(--text-light-muted);
  margin-top: 0.1rem;
}
.activity-amount {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-light);
  white-space: nowrap;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-light-muted);
}
.empty-icon {
  font-size: 3rem;
  margin-bottom: 0.6rem;
  animation: float 3s ease-in-out infinite;
}
.empty-state p { font-size: 0.9rem; color: var(--text-light-muted); }
.empty-sub { font-size: 0.78rem; opacity: 0.7; margin-top: 0.3rem; }

/* ===== WALLET ===== */
.wallet-hero {
  padding: 0.5rem 1.25rem 0;
}
.loyalty-card {
  width: 100%;
  border-radius: 16px;
  padding: 1.2rem;
  color: #fff;
  margin-bottom: -36px;
  position: relative;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  transition: transform 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.loyalty-card:active { transform: scale(0.98); }
.loyalty-card:last-child { margin-bottom: 0; }

.lc-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.lc-name { font-size: 0.95rem; font-weight: 700; }
.lc-emoji { font-size: 1.2rem; }
.lc-barcode {
  font-family: 'Courier New', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  opacity: 0.7;
  margin-bottom: 0.5rem;
}
.lc-status { margin-top: 0.25rem; }
.lc-points { font-size: 1.8rem; font-weight: 800; line-height: 1.1; }
.lc-points-label { font-size: 0.75rem; font-weight: 500; opacity: 0.8; }
.lc-synced { font-size: 0.65rem; opacity: 0.6; margin-top: 0.15rem; }
.lc-unconnected { font-size: 0.8rem; opacity: 0.7; }
.lc-setup {
  font-size: 0.75rem; font-weight: 600;
  background: rgba(255,255,255,0.2);
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  margin-top: 0.3rem;
}
.lc-stamps { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-bottom: 0.25rem; }
.stamp-dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.5);
}
.stamp-dot.filled { background: #fff; border-color: #fff; }
.lc-stamps-count { font-size: 0.7rem; opacity: 0.7; }

.add-card {
  background: rgba(255,255,255,0.08) !important;
  border: 2px dashed rgba(255,255,255,0.25);
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 80px;
  margin-bottom: 0 !important;
}
.add-card-icon { font-size: 1.5rem; font-weight: 300; opacity: 0.6; }
.add-card-text { font-size: 0.9rem; font-weight: 600; opacity: 0.6; }

.wallet-receipts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.wallet-receipts-header .card-title { text-align: left; margin-bottom: 0; }
.see-all-btn {
  background: none; border: none;
  color: var(--accent); font-size: 0.8rem;
  font-weight: 600; font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Card detail */
.cd-preview {
  border-radius: 16px;
  padding: 1.2rem;
  color: #fff;
  margin-bottom: 1rem;
}
.cd-barcode-display { text-align: center; margin-top: 0.5rem; }
.cd-barcode-display canvas {
  width: 100%; max-width: 200px;
  height: 50px; border-radius: 4px;
}
.cd-barcode-text {
  font-family: 'Courier New', monospace;
  font-size: 0.75rem; letter-spacing: 0.15em;
  opacity: 0.8; margin-top: 0.25rem;
}
.cd-points-display {
  font-size: 2.5rem; font-weight: 800;
  color: var(--text-light); text-align: center;
}
.cd-points-label-display {
  font-size: 0.85rem; color: var(--text-light-muted);
  text-align: center; margin-bottom: 1rem;
}
.cd-stamps-row { margin-bottom: 1rem; }
.cd-stamps-row .lc-stamps { justify-content: center; }
.cd-stamps-row .stamp-dot { border-color: var(--text-light-muted); }
.cd-stamps-row .stamp-dot.filled { background: var(--text-light); border-color: var(--text-light); }
.cd-stamps-row .lc-stamps-count { text-align: center; color: var(--text-light-muted); margin-top: 0.25rem; }

/* Forms */
.form-group { margin-bottom: 0.75rem; }
.form-group label {
  display: block; font-size: 0.75rem; font-weight: 600;
  color: var(--text-light-muted); margin-bottom: 0.25rem;
}
.form-input {
  width: 100%; padding: 0.6rem 0.75rem;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem; font-family: inherit;
  background: var(--white); color: var(--text-light);
  transition: border-color 0.2s;
}
.form-input:focus { outline: none; border-color: var(--text-light); }
.cd-field { margin-bottom: 0.75rem; }
.cd-field label {
  display: block; font-size: 0.75rem; font-weight: 600;
  color: var(--text-light-muted); margin-bottom: 0.25rem;
}
.cd-field input {
  width: 100%; padding: 0.6rem 0.75rem;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem; font-family: inherit;
  background: var(--white); color: var(--text-light);
}
.cd-field input:focus { outline: none; border-color: var(--text-light); }
.btn-primary { background: var(--accent); color: #000; font-weight: 700; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-b));
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding-bottom: var(--safe-b);
  background: var(--white);
  border-top: 1px solid var(--card-border);
  z-index: 50;
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  background: none;
  border: none;
  padding: 0.4rem 1.5rem;
  color: var(--text-light-muted);
  font-size: 0.65rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s;
}
.nav-item.active { color: var(--text-light); }
.nav-item svg { width: 24px; height: 24px; }

.nav-scan {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -24px;
  box-shadow: 0 4px 16px var(--accent-glow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s, box-shadow 0.15s;
}
.nav-scan:active { transform: scale(0.92); }
.nav-scan svg { width: 24px; height: 24px; }

/* ===== OVERLAY / SHEET ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease-out;
}

.sheet {
  background: var(--white);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  padding: 1rem 1.5rem calc(1.5rem + var(--safe-b));
  animation: slideSheet 0.25s ease-out;
}
.sheet-handle {
  width: 36px;
  height: 4px;
  background: #ddd;
  border-radius: 2px;
  margin: 0 auto 1rem;
}
.sheet h3 { font-size: 1.05rem; font-weight: 700; color: var(--text-light); margin-bottom: 0.4rem; }
.sheet p { font-size: 0.85rem; color: var(--text-light-muted); margin-bottom: 1rem; }
.sheet-actions { display: flex; gap: 0.5rem; }
.sheet-actions .btn { flex: 1; }

.btn {
  padding: 0.7rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-ghost { background: var(--icon-bg); color: var(--text-light); }
.btn-danger { background: var(--danger); color: #fff; }

/* ===== RECEIPT DETAIL SHEET ===== */
.detail-sheet {
  position: relative;
  max-height: 85vh;
  overflow-y: auto;
}
.detail-close-btn {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: var(--icon-bg);
  border: none;
  color: var(--text-light-muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.detail-close-btn:active { background: #e5e5ea; color: var(--text-light); }
.detail-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.3rem;
}
.detail-store { font-size: 1.15rem; font-weight: 700; color: var(--text-light); }
.detail-date { font-size: 0.8rem; color: var(--text-light-muted); margin-bottom: 0.75rem; }
.detail-notes {
  font-size: 0.82rem;
  color: var(--text-light-muted);
  background: var(--icon-bg);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}
.detail-items {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}
.detail-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: #f9f9f9;
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--text-light);
}
.detail-item-name {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.detail-item-qty { color: var(--text-light-muted); font-size: 0.75rem; flex-shrink: 0; }
.detail-item-price { font-weight: 600; flex-shrink: 0; }
.detail-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 1px solid var(--card-border);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-light);
}

.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-size: 0.65rem;
  font-weight: 600;
  background: var(--icon-bg);
  color: var(--text-light-muted);
}

/* ===== SCANNER (FULLSCREEN) ===== */
.scanner-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
  animation: fadeIn 0.2s ease-out;
}
#scanner-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#scanner-canvas {
  position: absolute;
  top: 0; left: 0;
  visibility: hidden;
}
.scanner-chrome {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}
.scanner-topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  padding-top: calc(env(safe-area-inset-top, 0px) + 0.75rem);
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
  pointer-events: auto;
}
.scanner-back {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.scanner-back:active { background: rgba(255,255,255,0.25); }
.scanner-title { color: #fff; font-weight: 700; font-size: 1rem; }

.scanner-frame {
  position: relative;
  width: 260px;
  height: 260px;
  margin: auto;
}
.scanner-corner {
  position: absolute;
  width: 32px;
  height: 32px;
  border-color: var(--accent);
  border-style: solid;
  border-width: 0;
}
.tl { top: 0; left: 0; border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 12px; }
.tr { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 12px; }
.bl { bottom: 0; left: 0; border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 12px; }
.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 12px; }

.scanner-line {
  position: absolute;
  left: 4px; right: 4px;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 30%, var(--accent) 70%, transparent 100%);
  box-shadow: 0 0 16px var(--accent-glow), 0 0 4px var(--accent);
  animation: scanLine 2.2s ease-in-out infinite;
  border-radius: 1px;
}

.scanner-bottom {
  padding: 2rem 1rem;
  padding-bottom: calc(var(--safe-b) + 2rem);
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
  text-align: center;
  pointer-events: auto;
}
#scanner-status {
  color: rgba(255,255,255,0.8);
  font-size: 0.88rem;
  font-weight: 500;
}

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 0.75rem);
  left: 1rem; right: 1rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  pointer-events: none;
}
.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  animation: fadeUp 0.25s ease-out;
  pointer-events: auto;
  cursor: pointer;
}
.toast-success { background: rgba(52,211,153,0.2); border: 1px solid rgba(52,211,153,0.3); color: #6ee7b7; }
.toast-error { background: rgba(248,113,113,0.2); border: 1px solid rgba(248,113,113,0.3); color: #fca5a5; }
.toast-info { background: rgba(232,224,82,0.2); border: 1px solid rgba(232,224,82,0.3); color: #E8E052; }
.toast-exit { animation: fadeIn 0.2s ease-out reverse forwards; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

/* ===== PROFILE ===== */
.profile-header {
  text-align: center;
  margin-bottom: 1.5rem;
}
.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  margin: 0 auto 0.75rem;
  overflow: hidden;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.profile-avatar .avatar-initials {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
}
.profile-name {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-light);
}
.profile-email {
  font-size: 0.85rem;
  color: var(--text-light-muted);
  margin-top: 0.15rem;
}
.profile-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.profile-stat {
  text-align: center;
  padding: 0.75rem 0.5rem;
  background: var(--surface-light);
  border-radius: var(--radius-sm);
}
.profile-stat-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-light);
}
.profile-stat-label {
  font-size: 0.7rem;
  color: var(--text-light-muted);
  margin-top: 0.15rem;
}
.profile-signout {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--danger);
  background: none;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s;
}
.profile-signout:active {
  background: rgba(239, 68, 68, 0.08);
}

/* ===== DESKTOP ===== */
@media (min-width: 640px) {
  .app-header { padding: 1.5rem 2rem 2rem; }
  .hero-total { font-size: 3rem; }
  .pull-card { padding: 1rem 2rem; padding-bottom: calc(var(--nav-height) + var(--safe-b) + 1.5rem); }
  .bottom-nav {
    max-width: 500px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 20px 20px 0 0;
  }
  .activity-row:hover { background: #fafafa; border-radius: 8px; margin: 0 -0.5rem; padding-left: 0.5rem; padding-right: 0.5rem; }
}

@media (min-width: 960px) {
  .app-header { max-width: 600px; margin: 0 auto; }
  .tab { max-width: 600px; margin: 0 auto; }
}
