/**
 * DCA HUB — Mobile Design System
 * ==================================
 * 基于 mails.dev Macintosh 复古风格
 * 适配: 手机优先 (320px - 768px)
 * 
 * 设计原则:
 * - 底部 Tab 导航 (5+3 tabs)
 * - 卡片式布局 (full-width / swipeable)
 * - 大触摸区域 (min 44x44px)
 * - 保留复古美学，轻量适配
 */

/* ─── CSS Variables ──────────────────────────────────────────────────────────── */
:root {
  /* 沿用主站色彩系统 */
  --bg-page:   #F6F5F0;
  --bg-card:  #FDFCF9;
  --ink:      #1A1A1A;
  --ink-dim:  #666;
  --border:   #D8D4C8;
  --shadow:   rgba(0,0,0,0.08);
  
  /* 资产主题色 */
  --btc-color:   #F7931A;
  --gold-color:  #C4A035;
  --ndx-color:   #00B4AB;
  --spx-color:   #1A1A1A;
  --hsi-color:   #DC2626;
  
  /* 评分色 */
  --score-low:   #DC2626;   /* 高估-红 */
  --score-mid:   #F59E0B;   /* 合理-黄 */
  --score-high:  #16A34A;   /* 低估-绿 */
  
  /* 字体 */
  --font-serif:  'EB Garamond', Georgia, serif;
  --font-mono:   'Space Mono', 'Courier New', monospace;
  --font-sans:   'Inter', -apple-system, sans-serif;
  
  /* 间距 */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  
  /* Bottom nav height */
  --bottom-nav-h: 64px;
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

/* ─── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  /* overscroll-behavior-y: contain; disabled - blocked desktop scroll */
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px);
}

/* ─── Bottom Tab Navigation ──────────────────────────────────────────────────── */
/* Hidden on desktop by default — mobile CSS will override */
.mobile-nav,
.bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .mobile-nav,
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--bg-card);
    border-top: 1.5px solid var(--border);
    align-items: stretch;
    padding-bottom: var(--safe-bottom);
    box-shadow: 0 -4px 20px var(--shadow);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }

  .bottom-nav__tabs {
    display: flex;
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .bottom-nav__tabs::-webkit-scrollbar { display: none; }

  .bottom-nav__tab {
    flex: 1;
    min-width: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    text-decoration: none;
    color: var(--ink-dim);
    font-family: var(--font-sans);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.02em;
    border: none;
    background: none;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    scroll-snap-align: start;
    -webkit-tap-highlight-color: transparent;
    position: relative;
  }

  .bottom-nav__tab .tab-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    transition: transform 0.15s, background 0.15s;
    background: transparent;
  }

  .bottom-nav__tab .tab-label {
    font-size: 9px;
    line-height: 1;
    white-space: nowrap;
  }

  /* Active tab */
  .bottom-nav__tab.active {
    color: var(--ink);
  }
  .bottom-nav__tab.active .tab-icon {
    transform: scale(1.1);
  }

  /* Tab accent colors */
  .bottom-nav__tab.tab-btc  .tab-icon { color: var(--btc-color); }
  .bottom-nav__tab.tab-gold .tab-icon { color: var(--gold-color); }
  .bottom-nav__tab.tab-ndx  .tab-icon { color: var(--ndx-color); }
  .bottom-nav__tab.tab-spx  .tab-icon { color: var(--spx-color); }

  /* More tab (overflow) */
  .bottom-nav__tab.tab-more {
    min-width: 48px;
  }
  .bottom-nav__tab.tab-more .tab-icon {
    font-size: 18px;
  }

  /* Tab indicator dot */
  .bottom-nav__tab.active::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--ink);
  }
}


/* ─── Site Nav (top) — Mobile: hide links, keep brand ────────────────────────── */
@media (max-width: 768px) {
  .site-nav {
    padding: 10px var(--space-md);
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-card);
    border-bottom: 1.5px solid var(--border);
  }
  
  .site-nav-links,
  .site-nav-desktop {
    display: none !important;  /* Hidden on mobile — bottom nav handles navigation */
  }
  
  .site-nav-brand {
    margin: 0 auto;
  }
}

/* ─── Carousel (Main Page Computers) ────────────────────────────────────────── */
.mobile-carousel {
  display: none;
}

@media (max-width: 768px) {
  .computers-grid,
  .computer-lab,
  .workflow-container,
  .gauge-container {
    display: none !important;
  }
  
  .mobile-carousel {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    gap: var(--space-md);
    padding: var(--space-md);
    scrollbar-width: none;
    margin: 0 calc(-1 * var(--space-md));
  }
  .mobile-carousel::-webkit-scrollbar { display: none; }
  
  .mobile-carousel__item {
    flex: 0 0 85vw;
    scroll-snap-align: center;
    max-width: 340px;
  }
  
  .carousel-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: var(--space-sm);
    padding-bottom: var(--space-sm);
  }
  .carousel-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.2s, transform 0.2s;
  }
  .carousel-dot.active {
    background: var(--ink);
    transform: scale(1.3);
  }
  
  /* Carousel card (simplified Mac) */
  .mobi-card {
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 12px var(--shadow);
  }
  
  .mobi-card__header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f4f3ef;
  }
  
  .mobi-card__title {
    font-family: var(--font-serif);
    font-size: 15px;
    font-weight: 500;
  }
  
  .mobi-card__score {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 700;
  }
  
  .mobi-card__body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  
  .mobi-metric {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 6px 0;
    border-bottom: 1px dashed #eee;
  }
  
  .mobi-metric__label {
    font-family: var(--font-sans);
    font-size: 12px;
    color: var(--ink-dim);
  }
  
  .mobi-metric__value {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 700;
  }
  
  .mobi-metric__value.positive { color: var(--score-high); }
  .mobi-metric__value.negative { color: var(--score-low); }
  .mobi-metric__value.neutral  { color: var(--ink); }
  
  .mobi-mult-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 700;
    border: 1.5px solid currentColor;
    margin-top: 4px;
  }
  
  .mobi-status {
    font-family: var(--font-sans);
    font-size: 11px;
    color: var(--ink-dim);
    text-align: center;
    padding: 6px 0;
  }
  
  /* Mac screen effect on card */
  .mobi-card__screen {
    background: #1A1A1A;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
  }
  .mobi-screen-line {
    font-family: var(--font-mono);
    font-size: 11px;
    color: #33FF33;
    line-height: 1.7;
  }
  .mobi-screen-line.dim { color: #666; }
  .mobi-screen-line.bold { font-weight: 700; }
}

/* ─── Hero Section — Mobile ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hero-section {
    padding: var(--space-md);
  }
  
  .hero-card {
    border-radius: 12px;
    border: 1.5px solid var(--border);
    box-shadow: 0 2px 12px var(--shadow);
  }
  
  .hero-header {
    padding: 14px var(--space-md);
    border-bottom: 1px solid var(--border);
  }
  
  .hero-title {
    font-size: 20px;
    font-family: var(--font-serif);
  }
  
  .hero-subtitle {
    font-size: 11px;
    color: var(--ink-dim);
    font-family: var(--font-mono);
  }
  
  .hero-grid {
    padding: var(--space-md);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
  }
  
  .hero-cell {
    padding: var(--space-sm);
    border: 1px solid #eee;
    border-radius: 8px;
  }
  
  .hero-cell-label {
    font-size: 10px;
    color: var(--ink-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-family: var(--font-sans);
  }
  
  .hero-cell-value {
    font-family: var(--font-serif);
    font-size: 22px;
    font-weight: 500;
    line-height: 1.2;
    margin-top: 2px;
  }
  
  .hero-cell-value.small {
    font-size: 16px;
  }
  
  /* Stacked layout on very small screens */
  @media (max-width: 380px) {
    .hero-grid {
      grid-template-columns: 1fr;
    }
  }
}

/* ─── Dimension Cards (BTC/Gold/NASDAQ) — Mobile ─────────────────────────────── */
@media (max-width: 768px) {
  .dimensions-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: var(--space-sm) !important;
  }
  
  .dim-card {
    border-radius: 10px;
    padding: 12px 10px;
  }
  
  .dim-label {
    font-size: 11px;
  }
  
  .dim-score {
    font-size: 22px;
  }
  
  .dim-status {
    font-size: 10px;
  }
}

/* ─── History Table — Mobile Horizontal Scroll ────────────────────────────────── */
@media (max-width: 768px) {
  .table-container,
  .history-table-wrap,
  .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin: var(--space-md);
  }
  
  .data-table,
  .history-table {
    min-width: 600px;
    font-size: 12px;
  }
  
  .data-table th,
  .history-table th {
    font-size: 10px;
    white-space: nowrap;
  }
  
  .data-table td,
  .history-table td {
    padding: 8px 10px;
    white-space: nowrap;
    font-family: var(--font-mono);
    font-size: 11px;
  }
}

/* ─── Container — Mobile full-width ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .container {
    padding: var(--space-md);
  }
  
  .page-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border);
  }
  
  .page-title {
    font-size: 26px;
    font-family: var(--font-serif);
    font-weight: 500;
  }
  
  .page-tag {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--ink-dim);
  }
  
  .description {
    font-size: 13px;
    line-height: 1.6;
  }
}

/* ─── Charts — Mobile ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .chart-section {
    padding: var(--space-md);
  }
  
  .chart-canvas-wrap {
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
  }
}

/* ─── Section Title — Mobile ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--ink-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: var(--space-md) var(--space-md) var(--space-sm);
    border-bottom: 1px solid var(--border);
  }
  
  .section-title:first-of-type {
    padding-top: var(--space-sm);
  }
}

/* ─── Loading Screen — Mobile (hide, let main content load) ─────────────────── */
@media (max-width: 768px) {
  /* 加载屏幕影响底部导航交互，直接隐藏 */
  .loading-screen {
    display: none !important;
  }
  
  .main-container {
    display: block !important;  /* 强制显示主内容 */
    padding: var(--space-md) !important;
  }
}

/* ─── Radar Chart — Mobile ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .radar-container {
    max-width: 100%;
    margin: 0 var(--space-md);
  }
}

/* ─── DCA-Specific Mobile ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hero-row {
    flex-direction: column;
  }
  
  .metrics-main {
    grid-template-columns: 1fr 1fr !important;
    gap: var(--space-sm) !important;
  }
  
  .metric-big {
    font-size: 24px;
  }
  
  .metrics-sub {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: var(--space-xs) !important;
  }
  
  .metric-sub {
    padding: var(--space-sm) !important;
  }
  
  .asset-cards-grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-sm) !important;
  }
  
  .asset-card {
    padding: var(--space-md) !important;
  }
  
  .header-clock {
    position: static !important;
    width: 100%;
    margin-top: var(--space-sm);
  }
  
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  /* DCA records table */
  .records-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .records-table {
    min-width: 700px;
    font-size: 11px;
  }
}

/* ─── Lazy Portfolio — Mobile ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .lazy-grid,
  .portfolio-grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-md) !important;
  }
  
  .combo-card {
    padding: var(--space-md) !important;
  }
}

/* ─── Scroll Behavior ────────────────────────────────────────────────────────── */
/* html { scroll-behavior: smooth; } removed - caused scroll feel sluggish on desktop */

/* ─── Hide elements on mobile (not needed) ──────────────────────────────────── */
@media (max-width: 768px) {
  .header-right,
  .page-header-right,
  .footer-links,
  .desktop-only {
    display: none !important;
  }
  
  /* Remove top computer nav links (now in bottom nav) */
  .top-computer-nav {
    display: none;
  }
}

/* ─── Touch-friendly Interactions ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  button, .btn, a {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Active state for touch */
  .btn:active {
    opacity: 0.7;
    transform: scale(0.97);
  }
  
  /* Smooth scrolling */
  * {
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Tab active feedback */
  .bottom-nav__tab:active {
    background: rgba(0,0,0,0.04);
  }
}

/* ─── Safe area padding for notched phones ───────────────────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: calc(var(--safe-bottom) + 4px);
  }
}

/* ─── Accessibility ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .bottom-nav__tab:focus-visible {
    outline: 2px solid var(--ndx-color);
    outline-offset: -2px;
    border-radius: 4px;
  }
}

/* ─── Very small phones (iPhone SE) ─────────────────────────────────────────── */
@media (max-width: 374px) {
  body {
    font-size: 14px;
  }
  
  .hero-cell-value {
    font-size: 18px;
  }
  
  .bottom-nav__tab .tab-label {
    font-size: 8px;
  }
  
  .bottom-nav__tab .tab-icon {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }
}

/* ─── Landscape phone ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) and (orientation: landscape) {
  .mobile-carousel__item {
    flex: 0 0 60vw;
  }
  
  body {
    padding-bottom: calc(48px + var(--safe-bottom));
  }
}
