/* ============================================================================
   Janus — Responsive layer  (mobile + tablet)
   ----------------------------------------------------------------------------
   Desktop styles live in style.css and are intentionally UNTOUCHED.
   This file ONLY adds overrides, scoped inside @media breakpoints, so it is
   safe to reason about and easy to extend.

   Load AFTER style.css.

   Breakpoints
     • tablet   : max-width 1024px  — denser grids, narrower rail
     • mobile   : max-width  768px  — sidebar becomes a drawer, panes stack
     • small    : max-width  480px  — single-column everything

   How the app shell adapts on mobile
     - The fixed 220px sidebar turns into an off-canvas drawer (slides in on
       `.app.nav-open`, with a backdrop injected by responsive.js).
     - `.main` becomes the single scroll container; every multi-pane layout
       (.two-col / .three-col / Split.js panes / KG columns) collapses to a
       vertical flow so nothing overflows the viewport.
   ============================================================================ */

/* ------------------------------- Tablet ---------------------------------- */
@media (max-width: 1024px) {
  :root { --nav-w: 196px; }

  .stat-row     { grid-template-columns: repeat(3, 1fr); }
  .eval-grid    { grid-template-columns: repeat(2, 1fr); }
  #ov-grid      { grid-template-columns: 1fr !important; }
  #ov-lifecycle { grid-template-columns: repeat(4, 1fr) !important; }  /* 7 stages → 4-wide on tablet */
  .three-col    { grid-template-columns: 220px 1fr; }   /* right detail col folds away below */
}

/* ------------------------------- Mobile ---------------------------------- */
@media (max-width: 768px) {

  /* ---- Sidebar → off-canvas drawer ------------------------------------- */
  .app,
  .app.nav-collapsed { grid-template-columns: 1fr; }   /* main spans full width */

  .sidenav {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(82vw, 288px);
    z-index: 300;
    transform: translateX(-100%);
    transition: transform .24s ease;
    opacity: 1 !important;              /* cancel the desktop collapse fade */
    pointer-events: auto !important;
  }
  .app.nav-open .sidenav { transform: translateX(0); }

  /* backdrop element is injected by responsive.js */
  .nav-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 290;
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  .app.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

  /* hamburger stays pinned top-left at all times */
  .nav-toggle,
  .app:not(.nav-collapsed) .nav-toggle { left: 8px !important; }
  .nav-toggle { width: 34px; height: 34px; z-index: 310; }

  /* ---- Single scroll container: let main flow ------------------------- */
  .main   { overflow-y: auto !important; -webkit-overflow-scrolling: touch; }
  .topbar { position: sticky; top: 0; z-index: 50; padding-left: 48px; }

  .view.active {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* multi-pane layouts collapse to a vertical stack */
  .two-col, .three-col, .kg-shell,
  #eval-workspace, .eval-main, .split, .viewer-body {
    display: block !important;
    grid-template-columns: 1fr !important;
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* fixed-width children become full-width rows */
  .col, .audit-main, .pane,
  #kg-left-col, #kg-detail-col, .file-tree {
    width: 100% !important;
    height: auto !important;
    border-right: none !important;
    border-left: none !important;
  }
  .col, .pane { border-bottom: 1px solid var(--border); }

  /* graph / code surfaces keep a usable height while stacked */
  .kg-graph    { min-height: 58vh; }
  .code-viewer { max-height: 64vh; }
  .file-tree   { max-height: 168px; }

  /* the thin vertical KG toggle rails are meaningless when stacked */
  .kg-shell > button { display: none !important; }

  /* ---- Grids reflow ---------------------------------------------------- */
  .stat-row      { grid-template-columns: repeat(2, 1fr); }
  .eval-grid     { grid-template-columns: repeat(2, 1fr); }
  .provider-grid { grid-template-columns: 1fr; }
  #admin-stats   { grid-template-columns: repeat(2, 1fr) !important; }
  #ov-grid       { grid-template-columns: 1fr !important; }
  #ov-lifecycle  { grid-template-columns: repeat(2, 1fr) !important; }  /* dense stage tiles: 2-wide on phones */

  /* ---- Dense list rows: let the title breathe, wrap badges below ------ */
  .req-card-head   { flex-wrap: wrap; }
  .req-card-title  { flex: 1 1 60%; min-width: 0; }           /* title keeps the first row */
  .req-card-badges { width: 100%; padding-left: 28px; flex-wrap: wrap; }  /* badges drop under it */

  /* chip / scope rows wrap instead of clipping (findings repo scope, etc.) */
  #fnd-repos, .chip-row { flex-wrap: wrap; }

  /* ---- Tables scroll horizontally instead of overflowing -------------- */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table      { min-width: 560px; }

  /* ---- Comfortable touch targets & tighter chrome --------------------- */
  .btn      { min-height: 40px; }
  .nav-item { padding-top: 10px; padding-bottom: 10px; }
  .audit-main, .settings-main, .col-body, .annot-body { padding: var(--sp-3) !important; }

  /* modals / auth cards fit the viewport */
  .modal, .login-card, .modal-card { max-width: calc(100vw - 24px) !important; }
}

/* ---------------------------- Small phones ------------------------------- */
@media (max-width: 480px) {
  .stat-row, .eval-grid, #admin-stats, #ov-grid { grid-template-columns: 1fr !important; }
  .topbar-title { font-size: var(--fs-lg); }
  .audit-toolbar { gap: var(--sp-2); }
  .audit-toolbar .input,
  .audit-toolbar .select { max-width: 100% !important; width: 100% !important; }
}
