/* ============================================================
   MOBILE PACK  (v3.0.0)
   Phone-first layout fixes. Loaded after responsive.css.
   Only layout / touch-comfort rules: no feature or colour changes.
   ============================================================ */

:root { --bn-h: 62px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px); }

html, body { max-width: 100%; }
img, svg, video, canvas, iframe, embed, object { max-width: 100%; }
input, select, textarea, button { max-width: 100%; }
select, input, textarea { min-width: 0; }
textarea { resize: vertical; }

/* grid / flex children are allowed to shrink instead of pushing the page wider */
[style*="grid-template-columns"] > *, [style*="display:grid"] > *, [style*="display: grid"] > *,
.notes-grid > *, .features-grid > *, .stats-row > *, .form-row > * { min-width: 0; }

@media (max-width: 768px) {
  /* ── Touch comfort ───────────────────────────────────── */
  a, button, summary, label, select, [role="button"] { touch-action: manipulation; }
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; line-height: 1.2; }
  .btn.btn-sm, .btn-sm { min-height: 38px; }
  button, .btn, .sidebar-link, .nav-mobile-panel a { -webkit-tap-highlight-color: rgba(79,70,229,.12); }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]),
  select { min-height: 44px; }
  input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; }

  /* ── Page rhythm ─────────────────────────────────────── */
  .dashboard-container, .profile-container, .browse-container, .browse-page, .viewer-page { padding-left: 14px; padding-right: 14px; }
  .section, .section-card, .profile-card { border-radius: 14px; }
  h1 { line-height: 1.25; }
  p, li { overflow-wrap: anywhere; }
  .stats-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { padding: 14px 12px; }
  .stats-row > .stat-card:last-child:nth-child(odd) { grid-column: 1 / -1; }

  /* ── Buttons that sit in a row should wrap, not overflow ─ */
  .hero-buttons, .action-btns, .dashboard-header > div:last-child { flex-wrap: wrap; }
  .action-btns .btn, .action-btns a, .action-btns button { flex: 1 1 auto; }

  /* ── Alerts ──────────────────────────────────────────── */
  .alert { font-size: 13px; }

  /* ── Modals fit the screen and scroll inside ─────────── */
  .modal-box, .pin-modal, [id$="-modal"] > div { max-height: 88vh; overflow-y: auto; max-width: calc(100vw - 24px); }

  /* ── Filter / search bars stack ──────────────────────── */
  .filter-form { flex-direction: column; align-items: stretch; gap: 10px; }
  .filter-form > * { width: 100%; }

  /* ── Forms ───────────────────────────────────────────── */
  .form-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .vis-option, .vis-card { min-width: 0; }
  .visibility-toggle { flex-wrap: wrap; }

  /* ── Wide non-card tables scroll inside their own box ── */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; border-radius: 12px; }
  .table-scroll > table { min-width: 560px; }
}

/* Touch screens have no hover: the badge tooltip only widens the page */
@media (hover: none), (max-width: 768px) {
  .vbadge::after, .vbadge::before { display: none !important; }
}

/* ── Management tables turn into cards on phones ───────────── */
@media (max-width: 720px) {
  table.mgmt-table, table.mgmt-table tbody, table.mgmt-table tr, table.mgmt-table td { display: block; width: 100%; }
  table.mgmt-table { background: transparent; box-shadow: none; border-radius: 0; overflow: visible; margin-top: 8px; }
  table.mgmt-table thead { display: none; }
  table.mgmt-table tbody tr {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 14px;
    margin-bottom: 12px; padding: 6px 14px; box-shadow: 0 1px 4px rgba(0,0,0,.04);
  }
  table.mgmt-table tbody tr:hover { background: #fff; }
  table.mgmt-table tbody tr.row-banned { background: #fef2f2 !important; border-color: #fecaca; }
  table.mgmt-table td {
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    padding: 9px 0; border-bottom: 1px solid #f1f5f9; text-align: right;
    overflow-wrap: anywhere; font-size: 13.5px;
  }
  table.mgmt-table td:last-child { border-bottom: none; }
  table.mgmt-table td::before {
    content: attr(data-label); flex: 0 0 auto; max-width: 42%;
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    color: #94a3b8; text-align: left; margin-right: auto;
  }
  table.mgmt-table td[data-label=""]::before { display: none; }
  table.mgmt-table td.action-btns, table.mgmt-table td[data-label="Actions"], table.mgmt-table td[data-label="Action"] {
    flex-wrap: wrap; justify-content: flex-start; padding-top: 12px;
  }
  table.mgmt-table td.action-btns::before, table.mgmt-table td[data-label="Actions"]::before, table.mgmt-table td[data-label="Action"]::before { flex-basis: 100%; max-width: 100%; }
  table.mgmt-table td.action-btns form, table.mgmt-table td[data-label="Actions"] form { display: inline-block; }
  table.mgmt-table td > form, table.mgmt-table td > a { text-align: left; }
  table.mgmt-table td[style*="display:flex"] { flex-wrap: wrap; }
}

/* ── Bottom tab bar (logged-in users on phones) ────────────── */
.bottom-nav { display: none; }
@media (max-width: 768px) {
  body.has-bn { padding-bottom: calc(var(--bn-h) + var(--safe-b) + 8px); }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
    height: calc(var(--bn-h) + var(--safe-b)); padding: 0 6px var(--safe-b);
    background: rgba(255,255,255,.96); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-top: 1.5px solid #e2e8f0; box-shadow: 0 -4px 18px rgba(15,23,42,.06);
    align-items: stretch; justify-content: space-around;
  }
  .bn-item {
    flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: none; border: none; cursor: pointer; text-decoration: none; color: #64748b;
    font-family: inherit; font-size: 10.5px; font-weight: 600; padding: 6px 2px; position: relative;
  }
  .bn-item svg, .bn-item i { width: 22px; height: 22px; stroke-width: 2; }
  .bn-item span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bn-item.active { color: #4f46e5; }
  .bn-item.active::before {
    content: ''; position: absolute; top: 0; left: 28%; right: 28%; height: 3px;
    background: #4f46e5; border-radius: 0 0 4px 4px;
  }
  .bn-item:active { background: #f1f5f9; }
  .bn-fab { flex: 0 0 64px; position: relative; justify-content: flex-end; padding-bottom: 12px; }
  .bn-fab .bn-fab-btn {
    position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
    width: 52px; height: 52px; border-radius: 50%; background: #4f46e5; color: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 18px rgba(79,70,229,.45); border: 4px solid #fff;
  }
  .bn-fab .bn-fab-btn svg, .bn-fab .bn-fab-btn i { width: 24px; height: 24px; }
  body.kb-open .bottom-nav { display: none; }
  body.no-bn .bottom-nav { display: none; }
  body.no-bn.has-bn { padding-bottom: 0; }

  /* floating buttons clear the tab bar */

  /* top bar: safe-area and tidy title */
  .mobile-topbar { padding-top: var(--safe-t); height: calc(56px + var(--safe-t)) !important; }
  body { padding-top: calc(60px + var(--safe-t)); }
  .sidebar-hamburger { top: calc(7px + var(--safe-t)) !important; }
  .sidebar { padding-bottom: calc(var(--safe-b) + 12px); }
}
@media (max-width: 360px) {
  .bn-item { font-size: 10px; }
  .dashboard-container, .profile-container { padding-left: 10px; padding-right: 10px; }
  .stats-row { gap: 8px; }
}

/* ── Radio / option cards that sit side by side wrap on narrow screens ── */
@media (max-width: 480px) {
  div:has(> label[style*="flex:1"][style*="display:flex"]) { flex-wrap: wrap; }
  label[style*="flex:1"][style*="display:flex"] { flex: 1 1 140px !important; min-width: 0; }
}

/* Page headers with action buttons: title on its own line, buttons wrap in rows beneath */
@media (max-width: 768px) {
  .dashboard-header { flex-direction: row !important; flex-wrap: wrap; align-items: center !important; gap: 8px !important; }
  .dashboard-header > div:first-child { flex: 1 1 100%; min-width: 0; }
  .dashboard-header > .btn, .dashboard-header > a.btn, .dashboard-header > form { margin-right: 0 !important; }
  .dashboard-header > .btn { flex: 0 1 auto; }
}
