/**
 * mobile.css — Web Demo Only
 * Comprehensive mobile responsive overrides for the Otalytix web app.
 * Loaded AFTER app.css to override desktop layout for mobile viewports.
 * This file lives at web-demo/ root and is copied to web-demo/src/ by build.sh.
 * It is NOT used in the Electron desktop app.
 *
 * Works in conjunction with mobile-helper.js which handles:
 * - Creating .mobile-hamburger button in .app-header-banner
 * - Creating .sidebar-overlay on document.body
 * - Toggling .mobile-open on .sidebar
 * - Toggling .visible on .sidebar-overlay
 */


/* ═══════════════════════════════════════════════════════════════════════
   A. HAMBURGER BUTTON — always-available styles, hidden on desktop
   ═══════════════════════════════════════════════════════════════════════ */

.mobile-hamburger {
  display: none; /* Hidden on desktop */
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease;
  z-index: 10;
}
.mobile-hamburger:active {
  background: rgba(255, 255, 255, 0.2);
}
.mobile-hamburger svg {
  display: block;
}


/* ═══════════════════════════════════════════════════════════════════════
   B. SIDEBAR OVERLAY — always-available styles
   ═══════════════════════════════════════════════════════════════════════ */

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}


/* ═══════════════════════════════════════════════════════════════════════
   C. CORE LAYOUT — Mobile Portrait (≤768px)
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* Show hamburger */
  .mobile-hamburger {
    display: flex;
  }

  /* App container */
  .app {
    height: 100dvh;
    overflow: hidden;
  }

  /* ── Sidebar: off-screen left, slides in ── */
  .sidebar {
    position: fixed;
    top: 0;
    left: -290px;
    width: 280px;
    height: 100dvh;
    z-index: 999;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.mobile-open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  /* Sidebar internals — tighter spacing */
  .sidebar-header {
    padding: 16px 14px;
  }
  .sidebar-header h1 {
    font-size: 18px;
  }
  .nav {
    padding: 10px 10px;
  }
  .nav-item {
    padding: 11px 14px;
    margin-bottom: 3px;
    font-size: 14px;
  }
  .nav-label {
    font-size: 14px;
  }
  .nav-badge {
    font-size: 10px;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
  }
  .nav-section-header {
    padding: 8px 14px;
    font-size: 11px;
  }
  .model-selector-container {
    padding: 10px 12px;
  }

  /* ── Main content: full width ── */
  .main {
    width: 100%;
    flex: 1;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Purple header banner: tighter padding ── */
  .app-header-banner {
    padding: 10px 12px;
    gap: 8px;
  }
  .banner-content h1 {
    font-size: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .banner-content p {
    display: none; /* Hide subtitle on mobile to save space */
  }
  .banner-actions {
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .banner-actions button,
  .banner-actions .btn {
    font-size: 11px;
    padding: 5px 10px;
  }

  /* ── Section headers inside views ── */
  .header {
    padding: 12px 14px;
  }

  /* ── Universal overflow prevention ── */
  * {
    max-width: 100vw;
  }
  body {
    overflow-x: hidden;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   D. VIEW-SPECIFIC SIDEBARS — collapse to full-width stacked layout
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* ── Documents — list panel becomes top section ── */
  .list-panel {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 35vh;
    border-right: none;
    border-bottom: 1px solid #E2E8F0;
    flex-shrink: 0;
    padding: 12px;
  }

  /* ── Synthesis sidebar ── */
  .synthesis-sidebar {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 35vh;
    border-right: none;
    border-bottom: 1px solid #E2E8F0;
    padding: 12px;
  }

  /* ── Lit Search — analysis config sidebar ── */
  .analysis-config {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 35vh;
    border-right: none;
    border-bottom: 1px solid #E2E8F0;
    padding: 12px;
  }

  /* ── RCT Explorer sidebar ── */
  .rct-sidebar {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid #E2E8F0;
    padding: 12px;
  }

  /* ── Meta-Analysis sidebar ── */
  .ma-sidebar {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid #E2E8F0;
  }

  /* ── Drug Labels (views14.jsx) — 3-column → stacked ── */
  .dl-columns {
    flex-direction: column !important;
  }
  .dl-specialty-sidebar {
    width: 100% !important;
    min-width: 0 !important;
    max-height: 20vh !important;
    flex-shrink: 0 !important;
    border-right: none !important;
    border-bottom: 1px solid #E2E8F0 !important;
    overflow-y: auto !important;
  }
  .dl-drug-list {
    width: 100% !important;
    max-height: 30vh !important;
    flex-shrink: 0 !important;
    border-right: none !important;
    border-bottom: 1px solid #E2E8F0 !important;
    overflow-y: auto !important;
  }
  .dl-detail-panel {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 14px !important;
  }
  .dl-intl-summary {
    grid-template-columns: 1fr 1fr !important;
  }

  /* ── Natural History (views15.jsx) — 2-column → stacked ── */
  .nh-columns {
    flex-direction: column !important;
  }
  .nh-disease-sidebar {
    width: 100% !important;
    min-width: 0 !important;
    max-height: 35vh !important;
    flex-shrink: 0 !important;
    border-right: none !important;
    border-bottom: 1px solid #E2E8F0 !important;
    overflow-y: auto !important;
  }
  .nh-detail-panel {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 14px !important;
  }

  /* ── Retinal Science (views18.jsx) — encyclopedia 2-column → stacked ── */
  .sci-encyclopedia {
    flex-direction: column !important;
    gap: 10px !important;
    min-height: auto !important;
  }
  .sci-enc-sidebar {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 35vh;
    flex-shrink: 0;
    overflow-y: auto;
  }
  .sci-enc-content {
    min-width: 0 !important;
  }
  .sci-top-bar {
    flex-direction: column;
    gap: 8px;
    padding: 8px 12px;
  }
  .sci-tab-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
  }
  .sci-search-input {
    width: 100% !important;
  }
  .sci-content {
    padding: 12px !important;
  }

  /* ── Force flex-direction: column for class-based view layouts ── */
  .doc-container,
  .synthesis-layout,
  .ma-layout,
  .compare-layout {
    flex-direction: column !important;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   E. COPILOT PANEL — full-screen on mobile
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .copilot-panel {
    width: 100vw;
    right: -100vw;
  }
  .copilot-panel.open {
    right: 0;
  }
  .copilot-panel-header {
    padding: 12px 14px;
  }
  .copilot-panel-body {
    padding: 12px;
  }
  .copilot-panel-footer {
    padding: 10px 12px;
  }
  .copilot-panel-footer textarea {
    font-size: 14px; /* Prevent iOS zoom on focus */
  }

  /* Agent Inbox floating button */
  .agent-inbox-btn-floating {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   F. COMPARE DRAWER — full-screen on mobile
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .rct-compare-drawer {
    width: 100vw;
    max-width: 100vw;
    padding: 14px;
  }
  .rct-compare-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .rct-compare-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   G. DASHBOARD — responsive grids
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .dash-sections-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px;
    padding: 12px;
  }
  .dash-section-card {
    min-height: 90px;
    padding: 12px 8px;
  }
  .dashboard-twin-row {
    grid-template-columns: 1fr !important;
  }
  .dashboard-content {
    padding: 12px;
  }

  /* Daily brief card */
  .daily-brief-card {
    margin: 8px 12px;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   H. MODALS & POPUPS — full-width on mobile
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* Generic modals */
  .modal-content,
  .popup-content,
  .rct-save-modal,
  .save-modal-content {
    width: 95vw !important;
    max-width: 95vw !important;
    min-width: auto !important;
    margin: 10px auto;
  }

  /* Reanalyze dropdown */
  .reanalyze-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 16px 16px 0 0;
    max-height: 70vh;
    overflow-y: auto;
    min-width: auto;
    z-index: 1000;
  }

  /* Settings / preferences modal */
  .settings-modal,
  .preferences-modal {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* Label Figures modal */
  .label-figures-modal {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh;
    border-radius: 0;
  }

  /* Team update preview popup */
  .team-update-preview {
    width: 90vw !important;
    max-width: 90vw !important;
    left: 5vw !important;
    right: 5vw !important;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   I. TABLES & DATA — horizontal scroll
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .edt-header,
  .edt-row {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .pipeline-table-wrap,
  .calendar-month-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   J. FIXED / FLOATING ELEMENTS
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* Toast notifications */
  .toast,
  .toast-notification,
  .save-toast {
    left: 12px !important;
    right: 12px !important;
    bottom: 20px !important;
    top: auto !important;
    max-width: none !important;
    transform: none !important;
  }

  /* Undo button */
  .undo-button,
  .undo-toast {
    bottom: 20px !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    max-width: 90vw;
  }

  /* Tooltips */
  .tooltip,
  .tippy-content,
  [data-tooltip] {
    max-width: 85vw !important;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   K. SMALL PHONE ADJUSTMENTS (≤480px)
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  .app-header-banner {
    padding: 8px 10px;
  }
  .banner-content h1 {
    font-size: 16px;
  }
  .dash-sections-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px;
    padding: 8px;
  }
  .dash-section-card {
    min-height: 80px;
    padding: 10px 6px;
    font-size: 12px;
  }

  /* Sidebar slightly narrower on very small screens */
  .sidebar {
    width: 260px;
    left: -270px;
  }
  .sidebar.mobile-open {
    left: 0;
  }

  /* Document / analysis text */
  .doc-detail-content,
  .analysis-text,
  .doc-text {
    font-size: 13px;
    line-height: 1.6;
  }

  /* Buttons */
  .btn, button {
    font-size: 12px;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   L. LANDSCAPE MODE — phones held sideways
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 900px) and (orientation: landscape) {
  .mobile-hamburger {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -270px;
    width: 260px;
    height: 100dvh;
    z-index: 999;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .sidebar.mobile-open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  .main {
    width: 100%;
  }

  .app-header-banner {
    padding: 6px 12px;
  }
  .banner-content h1 {
    font-size: 16px;
  }
  .banner-content p {
    display: none;
  }

  /* View sidebars — shorter in landscape */
  .list-panel,
  .synthesis-sidebar,
  .analysis-config,
  .rct-sidebar,
  .dl-specialty-sidebar,
  .dl-drug-list,
  .nh-disease-sidebar,
  .sci-enc-sidebar {
    max-height: 25vh;
  }

  /* Stack view columns in landscape too */
  .dl-columns,
  .nh-columns,
  .sci-encyclopedia {
    flex-direction: column !important;
  }
  .dl-specialty-sidebar,
  .dl-drug-list,
  .nh-disease-sidebar {
    width: 100% !important;
    min-width: 0 !important;
    border-right: none !important;
    border-bottom: 1px solid #E2E8F0 !important;
  }
  .sci-enc-sidebar {
    width: 100% !important;
    max-width: 100% !important;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   M. SAFE AREA INSETS — notched phones (iPhone X+)
   ═══════════════════════════════════════════════════════════════════════ */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    .sidebar {
      padding-bottom: env(safe-area-inset-bottom);
    }
    .main {
      padding-bottom: env(safe-area-inset-bottom);
    }
    .copilot-panel-footer {
      padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
    .reanalyze-dropdown {
      padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
    .toast,
    .toast-notification,
    .save-toast {
      bottom: calc(20px + env(safe-area-inset-bottom)) !important;
    }
    .agent-inbox-btn-floating {
      bottom: calc(16px + env(safe-area-inset-bottom));
    }
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   N. TOUCH DEVICE ENHANCEMENTS
   ═══════════════════════════════════════════════════════════════════════ */

@media (hover: none) and (pointer: coarse) {
  /* Minimum touch target sizes */
  .nav-item {
    min-height: 44px;
  }
  .btn, button, [role="button"], a.btn {
    min-height: 36px;
  }

  /* Prevent sticky hover states on touch */
  .nav-item:hover {
    background: inherit;
  }
  .nav-item.active:hover {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.1) 0%, rgba(139, 92, 246, 0.06) 100%);
  }

  /* Smoother scrolling */
  .main,
  .sidebar,
  .list-panel,
  .rct-sidebar,
  .synthesis-sidebar,
  .copilot-panel-body {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  /* Prevent text selection on interactive elements */
  .nav-item,
  .dash-section-card,
  .mobile-hamburger {
    -webkit-user-select: none;
    user-select: none;
  }

  /* Disable hover zoom/elevation on cards (causes jank on touch) */
  .dash-section-card:hover {
    transform: none;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   O. DRUG LABELS — image grids & figure modal
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* Figure grid — 2 columns on mobile */
  .figure-grid,
  .label-figures-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px;
    padding: 8px;
  }

  /* Drug cards grid */
  .drug-card-grid,
  .drug-list-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 480px) {
  .figure-grid,
  .label-figures-grid {
    grid-template-columns: 1fr !important;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   P. COMPETITIVE INTEL — card layout
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .ci-live-scroll {
    flex-direction: column;
  }
  .ci-live-card {
    max-width: 100%;
    min-width: 100%;
  }
  .ci-grid,
  .ci-card-grid {
    grid-template-columns: 1fr !important;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   Q. SLIDE DECK EDITOR — collapse panels
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .deck-editor-slides {
    display: none;
  }
  .deck-editor-sidebar {
    width: 100% !important;
    min-width: auto !important;
    max-height: 35vh;
    border-left: none;
    border-top: 1px solid #E2E8F0;
  }
  .deck-editor-layout {
    flex-direction: column !important;
  }
  .deck-inspector-panel {
    display: none;
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   R. CALENDAR / PIPELINE — horizontal scroll
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .calendar-container,
  .pipeline-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .calendar-month-grid {
    min-width: 600px; /* Force scroll instead of crushing */
  }
}


/* ═══════════════════════════════════════════════════════════════════════
   S. FIGURE VAULT — responsive grid
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .vault-grid,
  .figure-vault-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px;
  }
}
@media (max-width: 480px) {
  .vault-grid,
  .figure-vault-grid {
    grid-template-columns: 1fr !important;
  }
}
