/* =====================================================================
   Phones (2.45.48): one consistent design for screens up to 640px wide.
   Bigger, calmer type; nothing wider than the screen; nothing cut off with
   "…"; rows that stack instead of squeezing; one floating button, clear of
   the content. Long explanations and long tables are trimmed by js/phone.js
   ("Show more"), so every screen starts with what matters.
   ===================================================================== */
/* Phone-only controls stay out of the way on bigger screens (e.g. a window made narrow, then wide again). */
.ph-more, .ph-showall { display: none; }

@media (max-width: 640px) {
  :root { --gutter: 16px; }
  /* Sideways overflow is clipped by app.css (overflow-x: clip). Never "hidden" on html/body: that makes the body a
     scroll container, and the Android app's pull-to-refresh then thinks the page is always at the top (no scrolling up). */
  body { font-size: 15px; line-height: 1.55; }
  main.page { padding-top: 18px; }
  main, .card, .modal { overflow-wrap: break-word; }
  main img, main video, main iframe, main svg:not(.ic) { max-width: 100%; }

  /* Type: readable sizes, nothing smaller than ~12.5px. */
  h1 { font-size: 1.6rem; line-height: 1.2; }
  h2 { font-size: 1.22rem; }
  h3 { font-size: 1.06rem; }
  .small { font-size: .9rem; }
  .tiny, small { font-size: .82rem; }
  .chip { font-size: .8rem; padding: 4px 10px; }
  .muted { line-height: 1.5; }

  /* Page heading: title, one short line, then the main button full width. */
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 18px; }
  .page-head > div { min-width: 0; }
  .page-head p { font-size: .95rem; }
  .page-head > .btn, .page-head > a.btn, .page-head .head-actions .btn { width: 100%; justify-content: center; }
  .page-head .head-actions { width: 100%; }

  /* Cards and their headers: title on one line, controls below at full width. */
  .card { padding: 16px; border-radius: 18px; }
  .card.pad-0 { padding: 0; }
  .card-head { flex-wrap: wrap; align-items: flex-start; row-gap: 10px; }
  .card-head > div:first-child { min-width: 0; flex: 1 1 auto; }
  .card-head > .row { width: 100%; flex-wrap: wrap; justify-content: stretch; margin: 0; gap: 8px; }
  .card-head > .row > * { margin: 0; }
  .card-head > .row > select, .card-head select { flex: 1 1 100%; width: 100%; }
  .card.pad-0 > .card-head { padding: 16px 16px 10px !important; }

  /* Tabs wrap onto two lines rather than scrolling sideways. */
  .tabs { display: flex; flex-wrap: wrap; overflow: visible; width: 100%; border-radius: 16px; }
  .tabs button { flex: 1 1 auto; padding: 8px 12px; font-size: .88rem; }

  /* Segmented filters (admin: Today / Yesterday / 7 days …) wrap like tabs. */
  .seg { display: flex; flex-wrap: wrap; max-width: 100%; border-radius: 16px; }
  .seg button { flex: 1 1 auto; }

  /* Rows of buttons share the width; nothing squeezes text into a narrow column. */
  .card-head > .row .btn, .row.gap > .btn, .row.gap > a.btn { flex: 1 1 auto; justify-content: center; }
  .btn { white-space: normal; text-align: center; }
  .notice { font-size: .92rem; padding: 12px 14px; }

  /* Job lists: icon on the left, the full title (two lines max), then price and status underneath. */
  .proj { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 14px 16px 14px 64px; min-height: 0; }
  .proj > .svc-ic { position: absolute; left: 16px; top: 14px; }
  .proj .t { flex: 1 1 100%; }
  .proj .t b { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .98rem; line-height: 1.35; }
  .proj .t span { display: block; font-size: .84rem; margin-top: 2px; }
  .proj .cr { font-size: .84rem; }
  .proj > .ic:last-child { display: none; }

  /* Choosing a job: a compact two-column grid (icon, name, price); the description shows on the job's own page. */
  .svc-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .svc-card { padding: 14px; gap: 8px; border-radius: 16px; }
  .svc-card p { display: none; }
  .svc-card h3 { font-size: .95rem; line-height: 1.3; flex: 1; margin: 0; }
  .svc-card .svc-ic { width: 38px; height: 38px; border-radius: 11px; }
  .svc-card .meta { font-size: .8rem; flex-wrap: wrap; }
  .svc-card .meta > .ic, .svc-card .meta .chip { display: none; }
  .svc-card .from { font-weight: 600; }

  /* A job's order form: the back link on its own line, the workspace picker full width under it. */
  .ix-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
  .ix-top > a { flex: 1 1 100%; white-space: nowrap; }
  .ix-top > label, .ix-top > .ws-pick, .ix-top > div { flex: 1 1 100%; }
  .ix-top select { width: 100%; }
  .ix-top > .ws-for { display: flex; align-items: center; gap: 10px; }
  .ix-top > .ws-for select { flex: 1 1 auto; min-width: 0; }

  /* Activity rows: the same shape. */
  .act-row { align-items: flex-start; }
  .act-t b { white-space: normal; }

  /* A job's page: heading stacks; delivery buttons get the full width. */
  .proj-head { gap: 10px; margin-bottom: 16px; }
  .proj-head h1 { font-size: 1.4rem; }
  .preview iframe { height: 420px; }

  /* Header: the essentials only (dark mode lives in the menu). */
  body.authed .topbar .theme-btn { display: none; }
  .topbar .user { gap: 6px; }

  /* One floating button: the assistant, as a round avatar above the tab bar. Feedback is in the menu. */
  .feedback-fab { display: none !important; }
  .as-launch { right: 12px; bottom: calc(80px + env(safe-area-inset-bottom)); padding: 6px; width: 52px; height: 52px; justify-content: center; }
  .as-launch > span { display: none; }
  .as-launch .as-avatar { margin: 0; width: 40px; height: 40px; }
  body.authed main.page { padding-bottom: calc(140px + env(safe-area-inset-bottom)); }

  /* Forms: full-width fields and comfortable targets. */
  .field input, .field select, .field textarea, .input, select, textarea, input[type="text"], input[type="email"], input[type="number"], input[type="password"], input[type="url"] { max-width: 100%; font-size: 16px; }
  form .row.gap > .field { flex: 1 1 100%; }
  /* Any text box that has no style of its own gets the standard one (low priority: styled boxes keep theirs). */
  main :where(input[type="text"], input[type="email"], input[type="tel"], input[type="url"], input[type="number"], input[type="password"], input[type="search"], input:not([type]), select, textarea) {
    width: 100%; border: 1px solid var(--line); background: var(--input); color: var(--ink); border-radius: var(--r-sm); padding: 11px 14px; min-height: 46px; font: inherit; font-size: 16px; }
  main :where(input, select, textarea):focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

  /* Trimmed text and lists (js/phone.js). */
  p.ph-clamp, div.ph-clamp { margin-bottom: 0 !important; }
  .ph-clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .ph-more { display: inline-flex !important; align-items: center; gap: 4px; margin: 2px 0 12px; padding: 6px 0; border: 0; background: none; color: var(--brand); font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; }
  .ph-hidden { display: none !important; }
  .notice { flex-wrap: wrap; }
  .notice > div { flex: 1 1 0; min-width: 0; }
  .notice > .ph-more { flex: 1 1 100%; margin: -4px 0 0 32px; padding: 2px 0; text-align: left; justify-content: flex-start; }
  .ph-showall { display: block !important; width: 100%; margin: 10px 0 0; }

  /* Tables are cards on phones (js/phone.js adds the labels). */
  .tbl-wrap, .table-wrap { overflow: visible !important; }
  table.tbl.cardify tr { padding: 4px 14px; margin-bottom: 8px; }
  table.tbl.cardify td { padding: 6px 0; font-size: .9rem; }
  table.tbl.cardify td > * { max-width: 62%; }
  .coupon-form input::placeholder { text-transform: none; }
  table.tbl.cardify td:not([data-label]) { justify-content: flex-start; text-align: left !important; }
  table.tbl.cardify td:not([data-label]) > * { max-width: 100%; }
}

@media (max-width: 380px) {
  h1 { font-size: 1.45rem; }
  .card { padding: 14px; }
  .proj { padding-left: 58px; }
  .proj > .svc-ic { left: 12px; }
}
