/**
 * DCA HUB — Mobile UX Enhancements
 * ================================
 * "Best-in-class mobile experience" — not just "it works on mobile"
 * 
 * Principles:
 * 1. Mobile-first: design for thumb, not shrunk desktop
 * 2. Progressive disclosure: show most important first
 * 3. Gesture-native: swipe, pull, long-press
 * 4. Perceived performance: skeletons > spinners > blank
 * 5. Tactile feedback: confirm every interaction
 */

/* ─── Pull-to-Refresh ──────────────────────────────────────────────────────────── */
.pull-to-refresh {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 8px;
  pointer-events: none;
  transform: translateY(-70px);
  transition: transform 0.3s ease;
  background: linear-gradient(to bottom, rgba(246,245,240,0.95) 0%, transparent 100%);
}
.pull-to-refresh.pulling {
  transform: translateY(0px);
}
.pull-to-refresh.refreshing {
  transform: translateY(0px);
}
.pull-to-refresh .ptr-arrow {
  width: 20px;
  height: 20px;
  border: 2px solid #888;
  border-top: none;
  border-right: none;
  transform: rotate(-135deg);
  transition: transform 0.2s;
  margin-bottom: 4px;
}
.pull-to-refresh.pulling .ptr-arrow {
  transform: rotate(-315deg);
}
.pull-to-refresh.refreshing .ptr-arrow {
  animation: ptr-spin 0.8s linear infinite;
  border-color: #2563EB;
  border-top-color: transparent;
}
@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}
.pull-to-refresh-label {
  font-size: 10px;
  color: #888;
  font-family: var(--font-sans);
  letter-spacing: 0.05em;
}

/* ─── Skeleton Loading ──────────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #f0efe9 25%, #e8e6e1 50%, #f0efe9 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: 6px;
  display: block;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.skeleton-line {
  height: 12px;
  border-radius: 4px;
}
.skeleton-line.short { width: 40%; }
.skeleton-line.medium { width: 65%; }
.skeleton-line.full { width: 100%; }
.skeleton-line.large { height: 24px; }
.skeleton-line.xlarge { height: 36px; width: 50%; }
.skeleton-badge {
  display: inline-block;
  width: 60px;
  height: 20px;
  border-radius: 4px;
}

/* Mobile hero skeleton */
.mobile-hero-skeleton {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mobile-hero-skeleton .skeleton-badge { width: 80px; height: 24px; }
.mobile-hero-skeleton .sk-price { height: 44px; width: 55%; }
.mobile-hero-skeleton .sk-mult { height: 36px; width: 35%; border-radius: 20px; }

/* ─── Mobile Hero — Full Redesign ─────────────────────────────────────────────── */
/* 
 * Mobile hero is the FIRST thing users see.
 * Desktop hero: tiny numbers in a grid, forces eye scanning
 * Mobile hero: ONE clear number, ONE action, full-screen impact
 */
@media (max-width: 768px) {
  /* Main asset display — big hero */
  .hero-section {
    padding: 0 !important;
  }
  
  .hero-card {
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
  }
  
  .hero-header {
    padding: var(--space-md) !important;
    background: var(--bg-card);
    border-bottom: 1.5px solid var(--border);
    border-radius: 0 !important;
  }
  
  .hero-title {
    font-family: var(--font-serif) !important;
    font-size: 24px !important;
    font-weight: 500 !important;
  }
  
  .hero-subtitle {
    font-size: 11px !important;
    font-family: var(--font-mono) !important;
  }
  
  /* Big numbers — the mobile hero uses a full-width stacked layout */
  .hero-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
    padding: 0 !important;
  }
  
  .hero-cell {
    border: none !important;
    border-bottom: 1px solid #f0eee9 !important;
    border-radius: 0 !important;
    padding: var(--space-md) var(--space-md) !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    background: var(--bg-card) !important;
    transition: background 0.15s;
  }
  .hero-cell:active { background: #f5f4ef !important; }
  
  .hero-cell-label {
    font-size: 12px !important;
    font-family: var(--font-sans) !important;
    color: var(--ink-dim) !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  
  /* Super-size the key numbers */
  .hero-cell-value {
    font-family: var(--font-serif) !important;
    font-size: 32px !important;
    font-weight: 500 !important;
    line-height: 1 !important;
  }

  .hero-cell-value.price {
    font-size: 36px !important;
  }

  /* Multiplier badge — large and tappable (BTC/Gold use hero-mult-badge) */
  .hero-mult-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    border-radius: 24px;
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 700;
    border: 2px solid currentColor;
    min-width: 90px;
    text-align: center;
  }

  /* SP500 / general multiplier — ensure big font on mobile */
  .multiplier-display {
    font-family: var(--font-mono) !important;
    font-size: 24px !important;
    font-weight: 700 !important;
    padding: 8px 16px !important;
    border-radius: 24px !important;
    border: 2px solid currentColor !important;
    display: inline-block !important;
    text-align: center !important;
    min-width: 80px !important;
  }
  
  /* CTA Button — full width, big touch target */
  .hero-cta {
    display: block;
    margin: var(--space-md);
    padding: 14px var(--space-md);
    background: var(--ink);
    color: white;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font-sans);
    text-align: center;
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: transform 0.1s, opacity 0.1s;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  }
  .hero-cta:active {
    transform: scale(0.97);
    opacity: 0.85;
  }
  
  /* Last update time — subtle */
  .hero-update {
    text-align: center;
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--ink-dim);
    padding: var(--space-xs) 0 var(--space-md);
  }
}

/* ─── Horizontal Scroll Cards (Dimensions) ──────────────────────────────────── */
/*
 * Desktop: 2x3 or 3x2 grid of dimension cards
 * Mobile: horizontal scroll row — fast, thumb-friendly
 */
@media (max-width: 768px) {
  /* Reset dim-section completely to block flow */
  .dim-section {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    /* Unset any grid layout from desktop */
    grid-template-columns: unset !important;
    grid-template-rows: unset !important;
  }
  
  .section-title {
    padding: var(--space-md) var(--space-md) var(--space-sm) !important;
    font-size: 12px !important;
  }
  
  /* The cards grid → horizontal scroll */
  .dim-cards-grid {
    display: flex !important;
    overflow-x: auto !important;
    scroll-snap-type: x mandatory !important;
    -webkit-overflow-scrolling: touch !important;
    gap: var(--space-sm) !important;
    padding: var(--space-xs) var(--space-md) var(--space-md) !important;
    scrollbar-width: none !important;
    margin: 0 !important;
    /* Override desktop's grid-template-columns */
    grid-template-columns: unset !important;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)) !important;
    /* Fallback to flex */
    flex-flow: row nowrap !important;
    /* Ensure each card keeps its width */
    -webkit-box-lines: none !important;
  }
  .dim-cards-grid::-webkit-scrollbar { display: none !important; }
  
  .dim-card {
    flex: 0 0 110px !important;
    scroll-snap-align: start !important;
    border-radius: 12px !important;
    padding: 12px 8px !important;
    border: 1.5px solid var(--border) !important;
    background: var(--bg-card) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 5px !important;
    min-height: 90px !important;
    max-height: 120px !important;
    transition: transform 0.15s, box-shadow 0.15s !important;
    box-sizing: border-box !important;
    /* Override desktop grid's equal columns */
    width: 110px !important;
    min-width: 110px !important;
    max-width: 110px !important;
    /* Prevent flex shrinking below 110px */
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
  }
  .dim-card:active {
    transform: scale(0.96);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }
  
  .dim-label {
    font-size: 10px !important;
    font-family: var(--font-sans) !important;
    font-weight: 600 !important;
    color: var(--ink-dim) !important;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap !important;
  }
  
  .dim-score {
    font-family: var(--font-serif) !important;
    font-size: 24px !important;
    font-weight: 500 !important;
    line-height: 1 !important;
  }
  
  .dim-value {
    font-size: 10px !important;
    font-family: var(--font-mono) !important;
    color: var(--ink-dim) !important;
  }
  
  .dim-bar {
    width: 100% !important;
    height: 3px !important;
    border-radius: 2px !important;
    background: #e8e6e1 !important;
    overflow: hidden !important;
  }
  
  .dim-status {
    font-size: 9px !important;
    font-family: var(--font-sans) !important;
    color: var(--ink-dim) !important;
    text-align: center !important;
    white-space: nowrap !important;
  }
}

/* ─── Scroll Hint (indicates horizontal scroll exists) ─────────────────────── */
@media (max-width: 768px) {
  .scroll-hint {
    display: flex !important;
    align-items: center;
    gap: 4px;
    padding: 0 var(--space-md) var(--space-xs);
    font-size: 10px;
    font-family: var(--font-sans);
    color: #aaa;
  }
  .scroll-hint-icon {
    font-size: 12px;
  }
}

/* ─── DCA Records — Mobile Optimized ────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Hero section for DCA — stacked metrics, large numbers */
  .metrics-main {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: var(--space-sm) !important;
    padding: var(--space-sm) !important;
  }
  
  .metric-big {
    font-size: 28px !important;
    padding: var(--space-sm) !important;
    border-right: none !important;
    border-bottom: 1px dashed #e8e6e1 !important;
    border-radius: 0 !important;
  }
  
  .metric-big .metric-big-lbl {
    font-size: 10px !important;
    color: var(--ink-dim) !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px !important;
  }
  
  .metric-big .metric-big-val {
    font-size: 36px !important;
    font-family: var(--font-serif) !important;
    font-weight: 500 !important;
  }
  
  .metrics-sub {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-xs) !important;
    padding: var(--space-sm) !important;
  }
  
  .metric-sub {
    padding: var(--space-sm) !important;
    border-radius: 8px !important;
    background: var(--bg-card) !important;
    border: 1px solid var(--border) !important;
  }
  
  .metric-sub .metric-sub-lbl {
    font-size: 10px !important;
    color: var(--ink-dim) !important;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px !important;
  }
  
  .metric-sub .metric-sub-val {
    font-family: var(--font-serif) !important;
    font-size: 20px !important;
    font-weight: 500 !important;
  }
  
  /* DCA Records table — card style on mobile */
  .records-section-title {
    padding: var(--space-md) var(--space-md) var(--space-sm) !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    color: var(--ink-dim) !important;
    text-transform: uppercase !important;
    letter-spacing: 0.08em !important;
    border-bottom: 1px solid var(--border) !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
  }
  
  .records-table-wrap {
    overflow-x: hidden !important;
    border: none !important;
  }
  
  .records-table {
    min-width: unset !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 1px !important;
    padding: 0 !important;
  }
  
  /* Mobile: show records as a vertical list of cards */
  .records-table thead {
    display: none !important;  /* hide desktop header */
  }
  
  .records-table tbody {
    display: flex !important;
    flex-direction: column !important;
    gap: var(--space-xs) !important;
  }
  
  .records-table tr {
    display: flex !important;
    flex-direction: column !important;
    background: var(--bg-card) !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px !important;
    padding: var(--space-sm) var(--space-md) !important;
    margin: 0 var(--space-md) !important;
    gap: 4px !important;
    break-inside: avoid !important;
  }
  
  .records-table td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 2px 0 !important;
    border: none !important;
    font-size: 12px !important;
    font-family: var(--font-sans) !important;
    white-space: normal !important;
  }
  
  .records-table td::before {
    content: attr(data-label) !important;
    font-size: 10px !important;
    color: var(--ink-dim) !important;
    font-family: var(--font-sans) !important;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    min-width: 60px;
  }
  
  .records-table td:last-child {
    border-top: 1px dashed #eee !important;
    margin-top: 4px !important;
    padding-top: 6px !important;
    justify-content: flex-end !important;
  }
  
  /* Asset name as card header */
  .records-table tbody tr td:first-child {
    font-size: 14px !important;
    font-weight: 600 !important;
    font-family: var(--font-serif) !important;
    padding-bottom: 4px !important;
    border-bottom: 1px solid #f0eee9 !important;
    margin-bottom: 2px !important;
  }
}

/* ─── Lazy Portfolio — Card Grid Mobile ─────────────────────────────────── */
@media (max-width: 768px) {
  .lazy-grid,
  .portfolio-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: var(--space-sm) !important;
    padding: 0 !important;
  }
  
  /* Show cards as full-width stacked — pf-card is used by lazy page */
  .combo-card,
  .pf-card,
  .portfolio-card {
    padding: var(--space-md) !important;
    border-radius: 12px !important;
    border: 1.5px solid var(--border) !important;
    background: var(--bg-card) !important;
    margin: 0 var(--space-md) var(--space-sm) !important;
    transition: transform 0.15s !important;
    display: flex !important;
    flex-direction: column !important;
    gap: var(--space-sm) !important;
  }
  .combo-card:active,
  .pf-card:active {
    transform: scale(0.98);
  }
}

/* ─── Page Transitions ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Slide-in animation for tab navigation */
  .bottom-nav__tab {
    transition: background 0.15s;
  }
  
  /* Smooth scroll between sections */
  section, .section {
    scroll-behavior: smooth;
  }
  
  /* Active section highlight on scroll */
  section:target {
    animation: section-highlight 1s ease;
  }
  @keyframes section-highlight {
    0%   { background: rgba(37, 99, 235, 0.05); }
    100% { background: transparent; }
  }
}

/* ─── Sticky Section Headers ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  .section-title {
    position: sticky;
    top: 50px;  /* below top nav */
    background: var(--bg-page);
    z-index: 50;
  }
}

/* ─── Quick-Action Floating Button ─────────────────────────────────────────── */
.mobile-fab {
  display: none;
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px);
  right: 16px;
  z-index: 900;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #2563EB;
  color: white;
  border: none;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
  font-size: 22px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.mobile-fab:active {
  transform: scale(0.9);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

@media (max-width: 768px) {
  .mobile-fab {
    display: flex;
  }
}

/* ─── Toast Notifications ─────────────────────────────────────────────────── */
.mobile-toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  z-index: 9000;
  background: rgba(26, 26, 26, 0.92);
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  font-family: var(--font-sans);
  pointer-events: none;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.mobile-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.mobile-toast.success { background: rgba(22, 163, 74, 0.92); }
.mobile-toast.error   { background: rgba(220, 38, 38, 0.92); }
.mobile-toast.info    { background: rgba(37, 99, 235, 0.92); }

/* ─── Haptic Feedback (CSS-only simulation via visual cues) ────────────────── */
/* On mobile, every tap needs instant visual confirmation */
@media (max-width: 768px) {
  .hero-cell:active,
  .dim-card:active,
  .mobi-card:active,
  .btn:active,
  .asset-card:active {
    transform: scale(0.95) !important;
    opacity: 0.8 !important;
    transition: transform 0.08s, opacity 0.08s !important;
  }
  
  /* Ripple effect on buttons */
  .btn {
    position: relative;
    overflow: hidden;
  }
  .btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at var(--x, 50%) var(--y, 50%), rgba(255,255,255,0.3) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.3s;
  }
  .btn:active::after {
    opacity: 1;
  }
}

/* ─── Data Refresh Animation ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .data-refreshing .hero-cell-value,
  .data-refreshing .mobi-card__score,
  .data-refreshing .mobi-metric__value {
    animation: data-flash 0.4s ease;
  }
  @keyframes data-flash {
    0%   { opacity: 1; }
    50%  { opacity: 0.3; }
    100% { opacity: 1; }
  }
}

/* ─── Mobile Market Status Badge ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .market-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-family: var(--font-mono);
    font-weight: 600;
    margin-left: var(--space-sm);
  }
  .market-status-badge.open {
    background: #dcfce7;
    color: #16A34A;
  }
  .market-status-badge.closed {
    background: #fee2e2;
    color: #DC2626;
  }
  .market-status-badge .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse-dot 2s ease infinite;
  }
  @keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
  }
}

/* ─── Network Status Banner ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .network-banner {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    padding: 6px;
    text-align: center;
    font-size: 12px;
    font-family: var(--font-sans);
    background: #FEF08A;
    color: #713F12;
    border-bottom: 1px solid #FDE047;
  }
  .network-banner.offline {
    display: block;
  }
}
