/* EpiParam on phones (< 768 px). Loaded after epiparam-theme.css.
 *
 * epiparam-ux.js keeps flexdashboard on its desktop layout (its own phone
 * layout breaks this app); this file reshapes that layout for small screens:
 * one scrolling column of cards, the sidebar as a slide-in panel opened by a
 * floating button, finger-sized controls. Nothing here applies to wider screens.
 */
@media (max-width: 767.98px) {

  /* ---- one scrolling column instead of a fixed, filled screen ------------- */
  html, body { height: auto !important; overflow-x: hidden !important; overflow-y: auto !important; }
  #dashboard-container, .dashboard-page-wrapper, .section.level1,
  .section.level2, .dashboard-row, .dashboard-column, .dashboard-row-flex {
    height: auto !important; min-height: 0 !important; width: auto !important;
    max-width: 100vw; overflow: visible !important;
  }
  .dashboard-page-wrapper, .section.level1 { padding-left: 0 !important; padding-right: 0 !important; }
  .section.level1.dashboard-row-orientation, .section.level1.dashboard-column-orientation,
  .dashboard-row, .dashboard-column, .dashboard-row-flex {
    display: block !important; flex: none !important;
  }
  #dashboard-container { padding: 10px 10px 96px !important; box-sizing: border-box; }

  /* ---- cards ------------------------------------------------------------------ */
  .chart-wrapper, .nav-tabs-custom {
    display: block !important; flex: none !important; width: 100% !important; height: auto !important;
    margin: 0 0 12px !important; transform: none !important; box-sizing: border-box;
  }
  /* inactive tabs stay hidden (the rule above would show them) */
  .nav-tabs-custom .tab-pane:not(.active) { display: none !important; }
  .chart-wrapper .chart-stage { position: relative !important; height: auto !important; }
  /* the outputs inside fill their stage, so the stage gets a height per kind */
  .chart-wrapper[data-epx-card="value"]  .chart-stage { height: 128px !important; }
  .chart-wrapper[data-epx-card="table"]  .chart-stage { height: 280px !important; }
  .chart-wrapper[data-epx-card="chart"]  .chart-stage,
  .chart-wrapper[data-epx-card="network"] .chart-stage { height: 340px !important; }
  .chart-wrapper[data-epx-card="tabbed"] .chart-stage { height: 420px !important; }
  .nav-tabs-custom .tab-content, .nav-tabs-custom .tab-pane { height: auto !important; }
  .nav-tabs-custom .chart-wrapper { margin: 0 !important; }

  /* headline numbers stay readable without dominating */
  .chart-wrapper[data-epx-card="value"] .chart-stage h1,
  .chart-wrapper[data-epx-card="value"] .chart-stage h2 { font-size: 2rem !important; margin: 0; }

  /* wide tables scroll inside their own card, never the page */
  .dataTables_wrapper, .chart-stage .datatables, .chart-stage .html-widget { max-width: 100%; }
  .dataTables_wrapper { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  .dataTables_wrapper .dataTables_filter input { width: 9em !important; }

  /* tabs: one swipeable row */
  .nav-tabs-custom > .nav-tabs {
    display: flex !important; flex-wrap: nowrap !important; overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .nav-tabs-custom > .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tabs-custom > .nav-tabs > li { flex: 0 0 auto; }
  .nav-tabs .nav-link, .nav-tabs > li > a { min-height: 44px; display: flex !important; align-items: center; white-space: nowrap; }

  /* ---- top bar and page menu ---------------------------------------------------- */
  .navbar .navbar-brand { font-size: 1.5rem !important; }
  .navbar .navbar-collapse { max-height: 75vh; overflow-y: auto; }
  .navbar .navbar-collapse .nav-link, .navbar .navbar-collapse .navbar-nav > li > a {
    display: block; min-height: 44px; padding: 11px 16px !important; margin: 2px 0; border-radius: 10px;
  }
  .navbar-toggler, .navbar-toggle { min-width: 48px; min-height: 44px; border-color: rgba(255, 255, 255, .35) !important; }

  /* ---- the sidebar as a slide-in panel -------------------------------------- */
  .section.sidebar {
    position: fixed !important; top: 0 !important; bottom: 0 !important; left: 0 !important;
    width: min(86vw, 340px) !important; height: 100% !important; z-index: 2100 !important;
    padding: 18px 14px 24px !important; overflow-y: auto !important;
    transform: translateX(-105%); transition: transform .28s cubic-bezier(.2, .7, .2, 1);
    box-shadow: none !important;
  }
  body.epx-drawer-open .section.sidebar { transform: none; box-shadow: 8px 0 30px rgba(10, 26, 63, .35) !important; }
  body.epx-drawer-open { overflow: hidden !important; }
  .section.sidebar > form { padding-bottom: 96px !important; }
  .section.sidebar .btn, .section.sidebar .form-control, .section.sidebar .selectize-input,
  .section.sidebar .shiny-download-link { min-height: 44px; }
  .section.sidebar .form-control, .section.sidebar input, .section.sidebar select { font-size: 16px !important; } /* no zoom on focus (iOS) */

  .epx-backdrop {
    position: fixed; inset: 0; z-index: 2050; background: rgba(10, 26, 63, .45);
    opacity: 0; pointer-events: none; transition: opacity .25s;
  }
  body.epx-drawer-open .epx-backdrop { opacity: 1; pointer-events: auto; }

  .epx-fab {
    position: fixed; right: 14px; bottom: 16px; z-index: 2200;
    display: inline-flex; align-items: center; gap: 8px;
    min-height: 48px; padding: 0 18px 0 14px; border: 0; border-radius: 999px;
    background: linear-gradient(135deg, var(--ep-blue-600, #2563EB), var(--ep-cyan, #06B6D4));
    color: #fff; font: 600 15px/1 Jost, "Segoe UI", Roboto, Arial, sans-serif;
    box-shadow: 0 8px 24px rgba(37, 99, 235, .45);
  }
  .epx-fab:active { transform: scale(.97); }
  .epx-fab-icon {
    width: 18px; height: 18px; flex: 0 0 auto; background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4 6h10M18 6h2M4 12h4M12 12h8M4 18h12M20 18h0'/%3E%3Ccircle cx='16' cy='6' r='2'/%3E%3Ccircle cx='10' cy='12' r='2'/%3E%3Ccircle cx='18' cy='18' r='2'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4 6h10M18 6h2M4 12h4M12 12h8M4 18h12M20 18h0'/%3E%3Ccircle cx='16' cy='6' r='2'/%3E%3Ccircle cx='10' cy='12' r='2'/%3E%3Ccircle cx='18' cy='18' r='2'/%3E%3C/svg%3E") center / contain no-repeat;
  }

  /* status messages sit above the floating button */
  .epx-pill { bottom: 78px; max-width: calc(100vw - 28px); font-size: 13px; }
  .epx-toast { bottom: 128px; }
  .shiny-notification-panel { bottom: 76px !important; right: 0 !important; width: 100% !important; max-width: 100vw; padding: 0 10px; }

  /* placeholders and hints fit the narrow cards */
  .chart-stage[data-epx-hint]::before { width: 88% !important; padding: 14px 14px 14px 46px !important; font-size: 13px !important; background-position: 12px 50% !important; }
  .chart-stage[data-epx-ph]:not([data-epx-hint])::after { font-size: 12px; }

  /* no hover lift on touch screens */
  .chart-wrapper:hover { transform: none !important; }
}

/* the floating button and backdrop exist only on phones */
@media (min-width: 768px) {
  .epx-fab, .epx-backdrop { display: none !important; }
}
