/* ToolsOS — responsive behaviour (mobile-first hardening) */

/* min-width:0 lets grid/flex children shrink instead of blowing the row.
   Do NOT put overflow-x:hidden on html/body here — that creates a scroll
   container and kills desktop sticky / a fixed app-shell. */
.app, .main, .content, .studio, .studio__controls, .card { min-width: 0; }
/* Long payloads / URLs wrap instead of pushing layout. */
.mono, .scan-result, .pdf-prop dd, .toast__msg { overflow-wrap: anywhere; word-break: break-word; }

/* ===== Tablet / small desktop: single-column studios ===== */
@media (max-width: 1080px) {
  .studio { grid-template-columns: 1fr; gap: var(--sp-4); }
  .studio__preview { position: static; order: -1; }
  /* Scanner: keep the camera/controls first, result below. */
  body[data-page="qr-scan"] .studio__preview { order: 0; }
}

/* ===== Sidebar becomes an off-canvas drawer ===== */
@media (max-width: 920px) {
  :root { --sidebar-w: 0px; }
  html, body { overflow-x: hidden; }

  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: min(85vw, 300px);
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease);
    box-shadow: var(--shadow-lg);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
  }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .sidebar-backdrop { display: block; }
  .sidebar .btn.sidebar__close { display: inline-flex; }

  .main {
    grid-column: 1;
    height: auto;
    overflow: visible;
  }
  .topbar .btn.topbar__menu-btn { display: inline-flex; }
  /* Drawer is already open — hamburger would sit on top of the same menu. */
  .app.nav-open .topbar .btn.topbar__menu-btn { display: none; }
  .content { padding: var(--sp-5) var(--sp-4); }

  /* Search collapses to an icon so the label never wraps next to the hamburger. */
  .topbar { gap: var(--sp-2); padding: 0 var(--sp-4); }
  .topbar__search { flex: 0 0 auto; max-width: none; }
  .search-trigger {
    width: 40px;
    height: 40px;
    padding: 0;
    gap: 0;
    justify-content: center;
    border-radius: var(--r-sm);
  }
  .search-trigger__label,
  .search-trigger__hint { display: none; }
}

/* ===== Phone ===== */
@media (max-width: 680px) {
  /* --- Topbar: compact, tidy --- */
  .topbar {
    height: 56px;
    gap: var(--sp-2);
    padding-left: max(var(--sp-3), env(safe-area-inset-left));
    padding-right: max(var(--sp-3), env(safe-area-inset-right));
  }
  .topbar__hide-sm { display: none; } /* history + settings live in the menu */
  .topbar__search { margin-right: auto; } /* icon sits next to hamburger, actions stay right */

  /* --- Content density --- */
  .content { padding: var(--sp-4); gap: var(--sp-5); }
  .page-head__row { gap: var(--sp-2); }
  .page-title { font-size: var(--fs-xl); }
  .page-subtitle { font-size: var(--fs-sm); }

  .controls-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .preview-meta { grid-template-columns: 1fr 1fr; }

  .card { padding: var(--sp-4); border-radius: var(--r-md); }
  .card--pad-lg { padding: var(--sp-4); }
  .hero { padding: var(--sp-5); border-radius: var(--r-lg); }
  .hero h1 { font-size: var(--fs-2xl); }

  /* Keep the live preview visible but not overwhelming. */
  .preview-surface { min-height: 220px; padding: var(--sp-4); }

  /* Comfortable touch targets. */
  .btn { padding: 11px 15px; }
  .btn--sm { padding: 8px 12px; }
  .btn--icon { padding: 11px; }
  .btn--icon.btn--sm { padding: 8px; }

  /* Footer + toasts */
  .site-footer__inner { flex-direction: column; align-items: flex-start; gap: var(--sp-2); padding: var(--sp-4); }
  .toast-stack { left: var(--sp-3); right: var(--sp-3); bottom: calc(var(--sp-3) + env(safe-area-inset-bottom)); max-width: none; }

  /* Command palette closer to the top on small screens */
  .modal__dialog { margin-top: 6vh; }
}

/* iOS: inputs must be >= 16px or Safari zooms on focus. */
@media (max-width: 768px) {
  .input, .select, .textarea, .palette__input, .pdf-pagejump { font-size: 16px; }
}

/* ===== Small phone ===== */
@media (max-width: 480px) {
  .type-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
  .type-opt { padding: 10px 6px; font-size: var(--fs-xs); }
  .type-opt .icon { width: 18px; height: 18px; }

  /* Full-width segmented controls read better on phones. */
  .segment { display: flex; width: 100%; }
  .segment button { flex: 1 1 0; text-align: center; }

  .breadcrumbs ol { font-size: var(--fs-xs); }
  .hero h1 { font-size: var(--fs-xl); }
  .btn-row { gap: var(--sp-2); }
}

/* ===== PDF Studio: stack panels, horizontal thumbnails ===== */
@media (max-width: 1200px) {
  .pdf-layout,
  .pdf-layout.no-thumbs,
  .pdf-layout.no-panel,
  .pdf-layout.no-thumbs.no-panel { grid-template-columns: 1fr; }
  .pdf-thumbs {
    flex-direction: row;
    max-height: none;
    position: static;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0 6px;
  }
  .pdf-thumb { min-width: 108px; flex: 0 0 auto; }
  .pdf-panel { position: static; }
  .pdf-viewer { max-height: 68vh; }
}
@media (max-width: 680px) {
  .pdf-toolbar {
    position: static;
    gap: 6px;
    padding: var(--sp-2);
    overflow-x: auto;
    flex-wrap: nowrap;        /* single scrollable row keeps it tidy */
    -webkit-overflow-scrolling: touch;
  }
  .pdf-toolbar__group { flex: 0 0 auto; }
  .pdf-filename { display: none; }
  .pdf-viewer { max-height: 58vh; padding: var(--sp-2); }
  .pdf-tool-op .input-group { flex-wrap: wrap; }
  .pdf-tool-op .input-group .input { border-radius: var(--r-sm); }
  .pdf-tool-op .input-group .btn { border-radius: var(--r-sm); border-left: 1px solid var(--border-strong); margin-top: 6px; }
}

/* Print: show only the printable target */
@media print {
  .sidebar, .topbar, .site-footer, .toast-stack, .modal, .no-print { display: none !important; }
  body::before { display: none; }
  .app, .main, .content { display: block; margin: 0; padding: 0; max-width: none; }
  .print-area { padding: 0; }
}
