/* Phones and small tablets. The desktop layout is untouched above 900px.
   Below it: the sidebar becomes a slide-out menu opened from a top bar, content stacks to one
   column, tables scroll inside their card, and the clients list turns into cards. */

.mobile-bar, .nav-backdrop { display: none; }

@media (max-width: 900px) {
  /* ---- shell */
  .app { display: block; }
  .mobile-bar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 40; height: 56px; padding: 0 14px;
    background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border-subtle); }
  .mb-menu { width: 42px; height: 42px; min-height: 0; border-radius: 12px; background: var(--bg-surface-elevated); color: var(--text-primary); }
  .mobile-bar img { width: 30px; height: 30px; border-radius: 9px; object-fit: cover; }
  .mb-title { font-weight: 800; letter-spacing: -0.02em; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; height: 100dvh; width: min(292px, 86vw); z-index: 60;
    transform: translateX(-104%); transition: transform .22s ease; box-shadow: none; }
  body.nav-open .sidebar { transform: none; box-shadow: 8px 0 40px rgba(15, 23, 42, 0.25); }
  .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(15, 23, 42, 0.45); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .nav-item { padding: 12px 12px; }

  .main-content { padding: 0 16px 40px; max-width: 100%; }

  /* ---- page header: title, then search and the main button on one row */
  .topbar-header { position: static; margin: 0 -16px 16px; padding: 16px 16px 12px; gap: 12px; backdrop-filter: none; background: transparent; border-bottom: 0; }
  .topbar-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title cta" "search search"; align-items: start; }
  .topbar-actions { display: contents; }
  .topbar-title-wrap { grid-area: title; min-width: 0; }
  .page-title { font-size: 1.45rem; overflow-wrap: anywhere; }
  .btn-topbar-cta { grid-area: cta; align-self: start; }
  .gsearch { grid-area: search; width: auto; min-width: 0; }
  .gsearch .kbd-badge { display: none; }
  .gsearch input { padding-right: 14px; }
  .gs-results { min-width: 0; right: 0; left: 0; }
  .btn-topbar-cta { flex: none; padding: 10px 14px; white-space: nowrap; }

  /* ---- content */
  .cx-stats, .cx-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .cx-fact { padding: 12px 14px; }
  .cx-fact-label { font-size: 0.68rem; }
  .cx-fact-value { font-size: 1.15rem; }
  .cx-card { padding: 16px; }
  .cx-card.cx-table-card, .cx-card.rq-detail { padding: 0; }
  .cx-grid, .issue-license-grid { grid-template-columns: 1fr; }
  .cx-item { flex-wrap: wrap; gap: 8px 12px; }
  .cx-item .cx-actions, .cx-item > .cx-item-btn { margin-left: auto; }
  .rq-split { grid-template-columns: 1fr; }
  .rq-detail .rq-head, .rq-detail .rq-body, .rq-decide { padding-left: 16px; padding-right: 16px; }
  .rq-outcome { margin-left: 16px; margin-right: 16px; }
  .cx-dl { grid-template-columns: 110px 1fr; }
  .cx-row > .field { min-width: 120px; }
  .cx-tabs { margin-left: -16px; margin-right: -16px; padding: 0 12px; }
  .cx-todo { grid-template-columns: 1fr; gap: 10px; }
  .cx-todo-card { flex-direction: row; align-items: baseline; justify-content: flex-start; flex-wrap: wrap; gap: 4px 12px; text-align: left; }
  .cx-todo-d { flex-basis: 100%; }
  .cx-todo-n { font-size: 1.5rem; }

  /* ---- forms: 16px stops iOS zooming in on focus, and fingers need room */
  input, select, textarea { font-size: 16px; }
  .btn-primary, .btn-secondary, .btn-danger, .cx-item-btn { min-height: 44px; }
  .row { flex-wrap: wrap; }
  .row .field { flex: 1 1 140px; }

  /* ---- dialogs */
  .cx-dialog { width: calc(100vw - 24px); padding: 18px; border-radius: 16px; }
  .cx-dialog-actions { flex-direction: column-reverse; }
  .cx-dialog-actions button { width: 100%; }

  /* ---- My clients: a card per client instead of a wide table */
  .cx-static { min-width: 0; }
  .cx-static thead { display: none; }
  .cx-static, .cx-static tbody, .cx-static tr, .cx-static td { display: block; width: 100%; }
  .cx-static tr { padding: 14px 16px; border-bottom: 1px solid var(--border-subtle); }
  .cx-static tr:last-child { border-bottom: 0; }
  .cx-static td { padding: 4px 0; border: 0; white-space: normal; text-align: left; }
  .cx-static td.num { text-align: left; }
  .cx-static td[data-label]::before { content: attr(data-label); display: inline-block; min-width: 118px; font-size: 0.74rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
  .cx-static td:first-child { padding-bottom: 8px; }
  .cx-static td:first-child::before { display: none; }
  .cx-static .cx-actions { justify-content: flex-start; flex-wrap: wrap; margin-top: 8px; }
  .cx-static .cx-actions .cx-item-btn { flex: 1 1 auto; }

  .cx-toast { width: calc(100vw - 32px); text-align: center; bottom: 16px; }
}

@media (max-width: 420px) {
  .cx-stats, .cx-facts { grid-template-columns: 1fr 1fr; }
  .cx-dl { grid-template-columns: 1fr; gap: 2px 0; }
  .cx-dl dd { margin-bottom: 8px; }
  .page-title { font-size: 1.3rem; }
  .btn-topbar-cta { padding: 10px 12px; font-size: 0.82rem; }
}

@media (prefers-reduced-motion: reduce) { .sidebar, .nav-backdrop { transition: none; } }

/* "Your requests" on a phone: the name gets the full row, the status and Withdraw sit under it */
@media (max-width: 600px) {
  #pcPending .cx-item { flex-wrap: wrap; row-gap: 6px; }
  #pcPending .cx-item-main { flex: 1 1 calc(100% - 20px); }
  #pcPending .cx-chip, #pcPending .cx-link { margin-left: 14px; }
}
