/* ==========================================================================
   RISKOS UNIVERSAL MOBILE RESPONSIVENESS SUITE (mobileResponsive.css)
   Institutional dark aesthetic, pixel-precise responsive layouts,
   safe-area insets, touch optimizations, and unified drawer handling.
   ========================================================================== */

html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden !important;
  box-sizing: border-box;
}

*, *::before, *::after {
  box-sizing: inherit;
}

/* ── Universal Logo Hardening & Defensive Containment ────────────────────── */
.logo-img,
.logo-btn img,
.logo-container img,
.signup-logo-img,
.login-logo-link img,
.mobile-logo-img,
.obs-logo,
img[src*="logo"] {
  max-width: 38px !important;
  max-height: 38px !important;
  object-fit: contain !important;
  border-radius: 8px !important;
  flex-shrink: 0 !important;
  display: inline-block !important;
}

/* ── Universal Dark High-Performance Scrollbar ───────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: #090a0f;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* ── Accessibility: High-Visibility Focus Outline ────────────────────────── */
:focus-visible {
  outline: 2px solid #22d3ee !important;
  outline-offset: 2px !important;
}

/* ── Responsive Tables & Sticky Primary Columns ──────────────────────────── */
.table-responsive-wrapper,
.ticker-table-wrapper,
.table-container {
  width: 100%;
  max-width: 100vw;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  margin-bottom: 1rem;
  scrollbar-width: thin;
}

.table-responsive-wrapper table th:first-child,
.table-responsive-wrapper table td:first-child,
.ticker-table th:first-child,
.ticker-table td:first-child {
  position: sticky;
  left: 0;
  background: #090a0f;
  z-index: 2;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.5);
}

/* ── Mobile Frosted Bottom Navigation Bar ────────────────────────────────── */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(62px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(10, 11, 16, 0.94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 9005;
  align-items: center;
  justify-content: space-around;
  padding-inline: 4px;
  box-shadow: 0 -4px 25px rgba(0, 0, 0, 0.6);
}

.mob-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #a1a1aa;
  text-decoration: none;
  font-size: 0.65rem;
  font-weight: 600;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  transition: all 0.2s ease;
  min-width: 50px;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.mob-nav-item i {
  font-size: 1.05rem;
}

.mob-nav-item:hover,
.mob-nav-item.active {
  color: #22d3ee;
}

/* ── Mobile Slide-Up More Sheet ──────────────────────────────────────────── */
.mobile-more-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 30000;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.mobile-more-sheet-overlay.active {
  display: flex;
}

.mobile-more-sheet {
  background: #0d0e15;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom, 0px)) 20px;
  box-shadow: 0 -15px 50px rgba(0, 0, 0, 0.9);
  animation: slideUpSheet 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUpSheet {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.more-sheet-handle {
  width: 44px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.3);
  margin: 0 auto 16px auto;
}

.more-sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.more-sheet-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  text-decoration: none;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  min-height: 52px;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.more-sheet-card:hover,
.more-sheet-card.active {
  background: rgba(34, 211, 238, 0.12);
  border-color: rgba(34, 211, 238, 0.3);
}

.more-sheet-card i {
  font-size: 1.1rem;
  width: 24px;
  text-align: center;
}

/* ── Media Query: 900px and Below (Tablet Navigation Handoff) ─────────────── */
@media (max-width: 900px) {
  body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .mobile-bottom-nav {
    display: flex !important;
  }

  .topbar .controls, .header-inner .nav-pill {
    display: none !important;
  }

  .topbar, .header {
    padding: 8px 14px !important;
  }
}

/* ── Media Query: 768px and Below (Tablet & Mobile Layouts) ──────────────── */
@media (max-width: 768px) {
  body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .mobile-bottom-nav {
    display: flex !important;
  }

  .bloomberg-function-strip {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  .bbg-fn-track {
    display: inline-flex !important;
    padding: 4px 10px;
  }

  /* Universal Grids Stacking */
  .grid-2-col, .grid-3-col, .grid-4-col,
  .obs-macro-grid, .sector-columns-grid,
  .beast-kpi-grid, .factor-radar-grid,
  .metrics-grid, .understandable-insights-grid,
  .sim-workspace-grid, .math-proof-grid, .limitations-grid,
  .intuition-grid, .card-grid-2, .card-grid-3, .po-grid {
    grid-template-columns: 1fr !important;
  }

  canvas {
    max-width: 100% !important;
  }

  /* Touch Target Sizing */
  button, .btn, .nav-link, select, input[type="text"], input[type="number"], .seg-btn, .c-time-btn {
    min-height: 42px;
    touch-action: manipulation;
  }

  .topbar .controls, .header-inner .nav-pill {
    display: none !important;
  }

  .topbar, .header {
    padding: 8px 14px !important;
  }

  h1, .hero-title, .page-title {
    font-size: clamp(1.5rem, 5vw, 2.2rem) !important;
    line-height: 1.2 !important;
  }

  /* Full Screen Mobile Drawers */
  .ticker-drawer-panel,
  .universal-drawer-panel,
  .comp-detail-drawer,
  .drawer-panel,
  .sec-picker-panel {
    width: 100vw !important;
    max-width: 100vw !important;
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
  }

  /* Labs Layout Mobile Adjustments */
  .lab-module-header {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 16px !important;
  }

  .sim-chart-canvas-box {
    height: 290px !important;
  }

  .sim-result-box {
    flex-direction: column !important;
    gap: 8px !important;
  }

  /* Screener Layout Mobile Adjustments */
  .filter-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .pill-segmented-control {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    flex-wrap: nowrap !important;
    max-width: 100% !important;
    padding-bottom: 4px !important;
  }

  .drawer-metrics-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .drawer-canvas-container {
    height: 280px !important;
  }
}

/* ── Media Query: 480px and Below (Compact Mobile) ────────────────────────── */
@media (max-width: 480px) {
  .more-sheet-grid {
    grid-template-columns: 1fr;
  }

  .drawer-metrics-grid {
    grid-template-columns: 1fr !important;
  }

  .sim-chart-canvas-box {
    height: 260px !important;
  }

  .mob-nav-item span {
    font-size: 0.6rem;
  }

  .mob-nav-item i {
    font-size: 0.95rem;
  }

  /* "Why This Number?" & Universal Explainer Mobile Optimization */
  .why-modal-card,
  .ue-modal {
    width: 95vw !important;
    max-width: 95vw !important;
    padding: 12px 14px !important;
    border-radius: 12px !important;
    margin: 8px auto !important;
  }

  .why-formula-card,
  .ue-formula-card,
  .why-math-expanded,
  .why-formula-card mjx-container,
  .why-formula-card .katex-display,
  .ue-formula-card mjx-container,
  .ue-formula-card .katex-display,
  mjx-container,
  .katex-display {
    overflow-x: auto !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch !important;
    font-size: 0.95rem !important;
    padding: 8px 4px !important;
  }

  .why-title {
    font-size: 0.95rem !important;
  }

  .ws-text {
    font-size: 0.76rem !important;
  }
}

