/* @import "tailwindcss"; */

/* ============================================
   好食惠 HSHAPP — Design System
   ============================================ */

@layer base {
  :root {
    /* Brand Colors */
    --primary: #0040a0;
    --primary-dark: #003080;
    --primary-light: #1a5ab5;
    --primary-50: #f0f5ff;
    --primary-100: #deebff;

    --gold: #f5a623;
    --gold-dark: #d4891a;
    --gold-light: #fbbf24;

    --red: #e01010;
    --red-light: #ffe3e3;

    /* Neutrals */
    --bg: #f8f6f3;
    --surface: #ffffff;
    --surface-2: #fafaf9;
    --border: #e8e4df;
    --border-dark: #d4cfc9;

    /* Text */
    --text: #1c1917;
    --text-2: #44403c;
    --text-3: #78716c;
    --text-muted: #a8a29e;

    /* Status */
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --info: #2563eb;
    --info-bg: #eff6ff;

    /* Layout */
    --app-width: 430px;
    --header-h: 56px;
    --bottom-nav-h: 64px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.06);
    --shadow-lg: 0 16px 40px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.08);
    --shadow-primary: 0 4px 16px rgba(0,64,160,0.25);
    --shadow-gold: 0 4px 16px rgba(245,166,35,0.30);
  }

  * {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
  }

  html {
    height: 100%;
    overflow-x: hidden;
  }

  body {
    font-family: 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', 
                 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
  }

  /* Mobile-first app container */
  #root {
    width: 100%;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    background: var(--bg);
  }

  /* Input / textarea base */
  input, textarea, select, [contenteditable="true"] {
    font-family: inherit;
    font-size: 16px; /* prevent iOS auto-zoom */
    user-select: text !important;
    -webkit-user-select: text !important;
  }

  a {
    text-decoration: none;
    color: inherit;
  }

  button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
  }

  img {
    display: block;
    max-width: 100%;
  }
}

/* ============================================
   App Shell
   ============================================ */

.app-shell {
  width: 100%;
  max-width: var(--app-width);
  min-height: 100vh;
  background: var(--surface);
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

/* Page with bottom nav */

.page {
  flex: 1;
  padding-top: var(--header-h);
  padding-bottom: var(--bottom-nav-h);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Page without header/nav (auth pages) */

.page-auth {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Page with header, no bottom nav (detail pages) */

.page-detail {
  flex: 1;
  padding-top: var(--header-h);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   TopBar / Header
   ============================================ */

.topbar {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-width);
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
}

.topbar-title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  text-align: center;
}

.topbar-action {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-2);
  transition: background 0.15s;
  flex-shrink: 0;
}

.topbar-action:hover { background: var(--bg); }

.topbar-action:active { background: var(--border); }

/* ============================================
   Bottom Navigation
   ============================================ */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-width);
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 100%;
  color: var(--text-muted);
  transition: color 0.15s;
  position: relative;
}

.bottom-nav-item.active {
  color: var(--primary);
}

.bottom-nav-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bottom-nav-label {
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1;
}

.bottom-nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 20px);
  background: var(--danger);
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--surface);
}

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 0 20px;
  height: 48px;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
  cursor: pointer;
  border: none;
}

.btn:active { transform: scale(0.97); }

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

.btn:disabled:active { transform: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-primary);
}

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

.btn-gold {
  background: var(--gold);
  color: #fff;
  box-shadow: var(--shadow-gold);
}

.btn-gold:hover { background: var(--gold-dark); }

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

.btn-outline:hover { background: var(--primary-50); }

.btn-ghost {
  background: var(--bg);
  color: var(--text-2);
}

.btn-ghost:hover { background: var(--border); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  height: 36px;
  font-size: 0.8125rem;
  padding: 0 14px;
  border-radius: 8px;
}

.btn-lg {
  height: 56px;
  font-size: 1rem;
  border-radius: var(--radius-lg);
}

.btn-full { width: 100%; }

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius);
}

/* ============================================
   Cards
   ============================================ */

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.2s;
}

.card:active { transform: scale(0.99); }

.card-hoverable:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* ============================================
   Merchant Card
   ============================================ */

.merchant-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  gap: 0;
  transition: box-shadow 0.2s, transform 0.15s;
}

.merchant-card:active { transform: scale(0.99); }

/* ============================================
   Coupon Card
   ============================================ */

.coupon-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.coupon-card-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--red) 100%);
  padding: 20px 20px 32px;
  position: relative;
}

.coupon-card-body {
  padding: 16px 20px 20px;
  position: relative;
}

/* Coupon tear effect */

.coupon-tear {
  position: absolute;
  left: 0;
  right: 0;
  top: -1px;
  height: 20px;
  background: var(--bg);
  border-radius: 0 0 50% 50% / 0 0 20px 20px;
}

.coupon-notch-left {
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--bg);
}

.coupon-notch-right {
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--bg);
}

/* ============================================
   Form Elements
   ============================================ */

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

.form-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-2);
}

.form-input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9375rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(232,93,38,0.12);
}

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

.form-input.error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220,38,38,0.10);
}

.form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9375rem;
  outline: none;
  resize: vertical;
  min-height: 100px;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(232,93,38,0.12);
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.form-error {
  font-size: 0.8125rem;
  color: var(--danger);
}

/* ============================================
   Badges / Tags
   ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.badge-primary  { background: var(--primary-100); color: var(--primary-dark); }

.badge-success  { background: var(--success-bg); color: var(--success); }

.badge-warning  { background: var(--warning-bg); color: var(--warning); }

.badge-danger   { background: var(--danger-bg); color: var(--danger); }

.badge-info     { background: var(--info-bg); color: var(--info); }

.badge-muted    { background: var(--border); color: var(--text-3); }

.badge-gold     { background: #fff8e6; color: var(--gold-dark); }

/* ============================================
   Status Pills (coupon status)
   ============================================ */

.status-active   { color: var(--success); background: var(--success-bg); }

.status-used     { color: var(--text-muted); background: var(--border); }

.status-expired  { color: var(--danger); background: var(--danger-bg); }

.status-refunded { color: var(--info); background: var(--info-bg); }

.status-pending  { color: var(--warning); background: var(--warning-bg); }

.status-approved { color: var(--success); background: var(--success-bg); }

.status-rejected { color: var(--danger); background: var(--danger-bg); }

/* ============================================
   Divider
   ============================================ */

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.divider-dashed {
  border: none;
  border-top: 1.5px dashed var(--border);
  margin: 16px 0;
}

/* ============================================
   Section Headers
   ============================================ */

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

.section-title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
}

.section-more {
  font-size: 0.875rem;
  color: var(--primary);
  font-weight: 500;
}

/* ============================================
   Category Chips (horizontal scroll)
   ============================================ */

.category-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 4px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.category-scroll::-webkit-scrollbar { display: none; }

.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.category-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-primary);
}

/* ============================================
   Banner Carousel
   ============================================ */

.banner-container {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-xl);
  margin: 0 16px;
}

.banner-slide {
  width: 100%;
  aspect-ratio: 16/7;
  object-fit: cover;
  border-radius: var(--radius-xl);
}

.banner-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 0;
}

.banner-dot {
  width: 6px;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  transition: all 0.3s;
}

.banner-dot.active {
  width: 20px;
  background: var(--primary);
}

/* ============================================
   Price Display
   ============================================ */

.price-display {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.price-currency {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
}

.price-amount {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.price-original {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: line-through;
}

/* ============================================
   Empty State
   ============================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  gap: 12px;
}

.empty-icon {
  font-size: 3rem;
  line-height: 1;
  opacity: 0.6;
}

.empty-title {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-2);
}

.empty-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ============================================
   Loading / Skeleton
   ============================================ */

@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, #f5f5f5 50%, var(--border) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.5s infinite linear;
  border-radius: 8px;
}

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

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

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 3.5px;
}

/* ============================================
   Toast / Alert
   ============================================ */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  line-height: 1.5;
}

.alert-error  { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }

.alert-success{ background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }

.alert-warning{ background: var(--warning-bg); color: var(--warning); border: 1px solid #fde68a; }

.alert-info   { background: var(--info-bg); color: var(--info); border: 1px solid #bfdbfe; }

/* ============================================
   Modal / Overlay
   ============================================ */

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-sheet {
  width: 100%;
  max-width: var(--app-width);
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  animation: slideUp 0.3s ease;
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}

/* ============================================
   QR Code container
   ============================================ */

.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.qr-code-used {
  filter: grayscale(100%);
  opacity: 0.4;
}

/* ============================================
   Avatar
   ============================================ */

.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--primary-100);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-weight: 700;
  flex-shrink: 0;
}

.avatar-sm  { width: 36px; height: 36px; font-size: 0.875rem; }

.avatar-md  { width: 48px; height: 48px; font-size: 1rem; }

.avatar-lg  { width: 64px; height: 64px; font-size: 1.25rem; }

.avatar-xl  { width: 80px; height: 80px; font-size: 1.5rem; }

/* ============================================
   List Row (settings, profile menu)
   ============================================ */

.list-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  transition: background 0.1s;
  cursor: pointer;
}

.list-row:active { background: var(--bg); }

.list-row-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.25rem;
}

.list-row-content {
  flex: 1;
  min-width: 0;
}

.list-row-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
}

.list-row-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.list-row-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ============================================
   Page transitions
   ============================================ */

@keyframes pageEnter {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.page-enter {
  animation: pageEnter 0.25s ease;
}

/* ============================================
   Utilities
   ============================================ */

.truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sticky-bottom {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.px-page { padding-left: 16px; padding-right: 16px; }

.py-page { padding-top: 16px; padding-bottom: 16px; }

/* Text helpers */

.text-primary { color: var(--primary); }

.text-gold { color: var(--gold); }

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

.text-success { color: var(--success); }

.text-danger { color: var(--danger); }

/* Navigation highlight outline outline safety override */

.bottom-nav-item.active svg,
.bottom-nav-item.active svg * {
  fill: none !important;
}

@keyframes slideUpFullscreen {
  from { transform: translate(-50%, 100%); }
  to { transform: translate(-50%, 0); }
}

/* Fullscreen modal overlay to persist scroll state of underlying lists */

.fullscreen-modal {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translate(-50%, 100%);
  width: 100%;
  max-width: var(--app-width);
  height: 100%;
  background: var(--bg);
  z-index: 999;
  overflow: hidden;
  animation: slideUpFullscreen 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Scroll Lock for Modals */

body[data-modal-count] .fullscreen-modal:not(:last-of-type) {
  overflow-y: hidden !important;
}

body[data-modal-count] .fullscreen-modal:not(:last-of-type) .page-detail {
  overflow-y: hidden !important;
}

/* Modal App Shell alignment */

.fullscreen-modal .app-shell {
  height: 100%;
  min-height: 100% !important;
  display: flex;
  flex-direction: column;
}

/* ============================================
   Merchant Onboarding Responsive Layout
   ============================================ */

.onboarding-container {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.onboarding-header {
  background: linear-gradient(160deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  padding: 24px 32px 32px;
  position: relative;
  border-radius: 0 0 16px 16px;
  box-shadow: var(--shadow-sm);
}

.onboarding-body {
  padding: 24px 32px 40px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.onboarding-card {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding: 32px 40px;
  margin-top: -24px;
  position: relative;
  z-index: 10;
  flex: 1;
}

/* Responsive styles for mobile screens */

@media (max-width: 640px) {
  .onboarding-header {
    padding: 16px 16px 28px;
    border-radius: 0;
  }
  .onboarding-body {
    padding: 16px 12px 32px;
  }
  .onboarding-card {
    padding: 16px 8px;
    margin-top: -16px;
    border-radius: 12px;
    border: none;
    box-shadow: none;
    background: transparent;
  }
}
