/* ═══════════════════════════════════════════════════════════
   CREZUS CAPITAL — Mobile App CSS
   Transforms the site into an app-like experience on mobile
   Bottom tab nav + full-width charts + collapsible sections
═══════════════════════════════════════════════════════════ */

/* ── BOTTOM TAB BAR ──────────────────────────────────────── */
#crezus-tab-bar {
  display: none; /* shown via JS when on mobile */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 62px;
  background: #0a0d14;
  border-top: 1px solid #1c2535;
  z-index: 999;
  align-items: stretch;
  box-shadow: 0 -4px 24px rgba(0,0,0,.5);
  /* Safe area for iPhone notch */
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: #3e5068;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  border: none;
  background: none;
  padding: 6px 0;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.tab-bar-item:active {
  background: rgba(0,200,240,.05);
}

.tab-bar-item.active {
  color: #00c8f0;
}

.tab-bar-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 2px;
  background: #00c8f0;
  border-radius: 0 0 2px 2px;
}

.tab-bar-icon {
  font-size: 18px;
  line-height: 1;
}

/* ── MOBILE BODY PADDING (make room for tab bar) ─────────── */
@media (max-width: 768px) {
  body.has-tab-bar {
    padding-bottom: calc(62px + env(safe-area-inset-bottom, 0));
  }

  /* Hide desktop hamburger menu when tab bar is shown */
  body.has-tab-bar .nav-mobile-toggle {
    display: none !important;
  }

  /* Hide footer on mobile app — tab bar replaces nav */
  body.has-tab-bar #site-footer .footer-col,
  body.has-tab-bar #site-footer .footer-inner {
    display: none;
  }
  body.has-tab-bar #site-footer .footer-bottom,
  body.has-tab-bar #site-footer .footer-disclaimer {
    padding-bottom: 80px;
  }
}

/* ── PULL TO REFRESH INDICATOR ───────────────────────────── */
#ptr-indicator {
  display: none;
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  background: #00c8f0;
  color: #000;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 6px 16px;
  border-radius: 0 0 20px 20px;
  z-index: 9999;
  white-space: nowrap;
}

/* ── FULL-WIDTH CHARTS ON MOBILE ─────────────────────────── */
@media (max-width: 768px) {

  /* Analysis page — full width chart */
  .chart-container,
  #chartContainer,
  #priceChart,
  canvas[id*="chart"],
  canvas[id*="Chart"] {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: -24px !important;
    margin-right: -24px !important;
    width: calc(100% + 48px) !important;
    border-radius: 0 !important;
  }

  /* Chart range buttons — bigger tap targets */
  .range-btn,
  [data-range] {
    min-height: 36px !important;
    min-width: 44px !important;
    padding: 8px 12px !important;
    font-size: 11px !important;
  }

  /* Markets charts */
  #marketChart,
  .market-chart {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ── COLLAPSIBLE SECTIONS — ANALYSIS PAGE ────────────────── */
@media (max-width: 768px) {

  /* Section headers become tappable toggles */
  .mobile-collapsible-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 14px 16px;
    background: var(--bg-surface, #0d1117);
    border: 1px solid var(--border, #1c2535);
    border-radius: 4px;
    margin-bottom: 4px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .mobile-collapsible-header::after {
    content: '›';
    font-size: 18px;
    color: var(--text-3, #3e4f63);
    transition: transform .2s;
    transform: rotate(90deg);
    flex-shrink: 0;
  }

  .mobile-collapsible-header.collapsed::after {
    transform: rotate(0deg);
  }

  .mobile-collapsible-body {
    overflow: hidden;
    transition: max-height .3s ease, opacity .2s;
    max-height: 2000px;
    opacity: 1;
  }

  .mobile-collapsible-body.collapsed {
    max-height: 0;
    opacity: 0;
  }
}

/* ── LARGER TAP TARGETS GLOBALLY ─────────────────────────── */
@media (max-width: 768px) {

  /* All buttons minimum 44px */
  button, .btn-primary, .btn-secondary,
  [role="button"], input[type="submit"],
  a.btn, .auth-submit, .ticker-search-btn {
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Nav links */
  .main-nav a, .footer-col a {
    padding: 8px 0 !important;
    display: block !important;
  }

  /* Quick tickers */
  .quick-tick {
    min-height: 40px !important;
    min-width: 52px !important;
    font-size: 11px !important;
    padding: 8px 12px !important;
  }

  /* Analysis tabs */
  .analysis-tab {
    min-height: 44px !important;
    padding: 12px 16px !important;
  }

  /* Input fields */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  .ticker-search,
  .auth-input {
    min-height: 48px !important;
    font-size: 16px !important; /* prevents iOS auto-zoom */
    padding: 12px 16px !important;
  }
}

/* ── TYPOGRAPHY — BETTER MOBILE READABILITY ──────────────── */
@media (max-width: 768px) {

  /* Larger base font */
  body {
    font-size: 15px !important;
  }

  /* Article body */
  .article-body {
    font-size: 16px !important;
    line-height: 1.85 !important;
  }

  .article-body p {
    margin-bottom: 24px !important;
  }

  /* More padding on content sections */
  .analysis-wrap,
  div[style*="max-width:820px"],
  div[style*="max-width:900px"],
  div[style*="max-width:1200px"] {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
}

/* ── ANALYSIS PAGE — MOBILE LAYOUT ──────────────────────── */
@media (max-width: 768px) {

  /* Hide desktop sidebar */
  .analysis-wrap > aside,
  div[style*="grid-template-columns:1fr 220px"] > aside {
    display: none !important;
  }

  /* Full-width main content */
  div[style*="grid-template-columns:1fr 220px"] {
    display: block !important;
  }

  /* Stock header — stack vertically */
  .stock-header {
    padding: 16px !important;
  }

  /* Snowflake score — compact on mobile */
  #snowflakeWrap canvas {
    width: 120px !important;
    height: 120px !important;
  }

  /* Score metrics — 2 columns instead of row */
  .score-metrics {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  /* Tab bar — scrollable, full width */
  .analysis-tabs {
    overflow-x: auto !important;
    scrollbar-width: none !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .analysis-tabs::-webkit-scrollbar { display: none; }

  .analysis-tab {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }
}

/* ── MARKETS PAGE — MOBILE LAYOUT ───────────────────────── */
@media (max-width: 768px) {

  /* Index cards — 2 per row */
  .markets-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  /* Watchlist table — hide less important columns */
  .watchlist-table th:nth-child(4),
  .watchlist-table td:nth-child(4),
  .watchlist-table th:nth-child(5),
  .watchlist-table td:nth-child(5) {
    display: none !important;
  }
}

/* ── NEWS PAGE — MOBILE LAYOUT ───────────────────────────── */
@media (max-width: 768px) {

  /* News cards — single column, larger images */
  .news-grid {
    grid-template-columns: 1fr !important;
  }

  .news-card {
    display: flex !important;
    flex-direction: row !important;
    gap: 12px !important;
    align-items: flex-start !important;
  }
}

/* ── HERO SECTIONS — MOBILE ──────────────────────────────── */
@media (max-width: 768px) {

  /* Reduce hero padding */
  div[style*="padding:60px"] {
    padding-top: 32px !important;
    padding-bottom: 32px !important;
  }

  /* Hide decorative elements */
  .hero-decoration,
  .ticker-bar-wrap + div > div:last-child {
    display: none !important;
  }
}

/* ── STARTUP CARDS — MOBILE ──────────────────────────────── */
@media (max-width: 640px) {
  #startupGrid {
    grid-template-columns: 1fr !important;
  }
  .startup-cover {
    height: 90px !important;
  }
}

/* ── BROKER CARDS — MOBILE ───────────────────────────────── */
@media (max-width: 640px) {
  #brokersGrid {
    grid-template-columns: 1fr !important;
  }
}

/* ── SMOOTH TRANSITIONS ──────────────────────────────────── */
@media (max-width: 768px) {

  /* Page-like slide transitions */
  .page-transition-enter {
    animation: slideInRight .25s ease forwards;
  }

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

/* ── TABLET — 769px to 1024px ────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {

  /* 2-column grids instead of 3 */
  #startupGrid {
    grid-template-columns: 1fr 1fr !important;
  }

  #brokersGrid {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Slightly larger tap targets */
  button, .btn-primary {
    min-height: 40px !important;
  }
}

/* ── SAFE AREA PADDING (iPhone notch / Dynamic Island) ────── */
@supports (padding-top: env(safe-area-inset-top)) {
  #site-header {
    padding-top: env(safe-area-inset-top);
  }
  #crezus-tab-bar {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(62px + env(safe-area-inset-bottom));
  }
}
