/*
 * Touch layouts. Two breakpoints, two jobs:
 *
 *   ≤ 1024px  (phones, tablets in portrait)  — every table is replaced by its
 *              server-rendered card twin (<ul data-cards>), two cards across on
 *              a tablet and one on a phone; column funnels become a
 *              Filter · Sort sheet; controls grow to 44px for fingers.
 *   ≤ 700px   (phones)                        — bottom tab bar, an Add button that
 *              opens the page's form in a bottom sheet, report filters collapse
 *              to a summary line, dialogs go full-screen.
 *
 * Landscape tablets and laptops keep the tables. Everything here is additive
 * to app.css; the desktop markup is untouched.
 */

/* Each side hides the other's elements without forcing a display value, so a
   mobile element keeps whatever display its own rule gives it (flex, grid…). */
@media (min-width: 1025px) { .only-mobile { display: none !important; } }
@media (min-width: 701px) { .tabbar, .fab, .filters-summary { display: none !important; } }

/* ============ ≤ 1024: cards instead of tables, touch-sized controls ============ */
@media (max-width: 1024px) {
  .only-desktop { display: none !important; }

  .btn { min-height: 44px; }
  .btn--small { min-height: 44px; font-size: 13px; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
  input[type=checkbox] { min-height: 0; width: 22px; height: 22px; }
  .pill--toggle { min-height: 44px; padding: 8px 14px; font-size: 12px; }
  .th-filter { display: none; }
  .table-reset, .mfilter { min-height: 44px; }
  .card h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }

  /* ---- bottom sheets ---- */
  .sheet--bottom { position: fixed; inset: auto 0 0 0; margin: 0; width: 100vw; max-width: 100vw; height: auto; max-height: 88dvh; border-radius: 16px 16px 0 0; }
  .sheet--bottom .sheet__body { max-height: 88dvh; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); }
  .sheet__grip { width: 40px; height: 4px; border-radius: 2px; background: #d5d9e0; margin: 6px auto 12px; }
  .sheet__bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
  .sheet__bar h3 { margin: 0; font-size: 15px; }

  /* Filter · Sort sheet */
  .msheet__cols { display: flex; flex-direction: column; gap: 6px; }
  .msheet__col { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font: inherit; text-align: left; color: var(--ink); }
  .msheet__col.filtered { border-color: var(--teal); background: #eef4f6; }
  .msheet__col .muted { font-size: 12px; }
  .msheet__sort { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
  .msheet__sort select { flex: 1; }
  .msheet__slot .picker { position: static; width: 100%; box-shadow: none; border: 0; padding: 0; margin-top: 8px; }
  .msheet__slot .picker__list { max-height: 40dvh; }
  .msheet__slot .picker__item { min-height: 44px; }
  .msheet__back { margin-bottom: 8px; }

  /* Detail cards: inline forms wrap one field per line instead of running off the sheet. */
  .sheet .inline, .sheet form.inline, .sheet .sheet__inline { flex-wrap: wrap; }
  .sheet .inline label, .sheet .sheet__inline label { flex: 1 1 100%; }
  .sheet .sheet__inline input, .sheet .sheet__inline select { width: 100%; }
  .sheet .sheet__inline .btn { flex: 1 1 100%; }
  .sheet .inline input, .sheet .inline select { width: 100% !important; min-width: 0 !important; flex: 1 1 100%; }
  .sheet .inline .btn { flex: 1 1 auto; }
  .sheet .sheet__row label { flex: 1 1 100%; }
  .sheet .select--inline { width: 100%; }
  .brand-box .inline .btn { flex: 1 1 30%; }

  /* ---- row cards: the mobile twin of a table ---- */
  .cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .rowcard { border: 1px solid var(--line); border-radius: 12px; padding: 12px 12px 10px; background: #fff; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
  .rowcard--over { border-color: #f5c6c2; background: #fff8f7; }
  .rowcard--hot { border-color: #f4dfa1; }
  .rowcard--draft { border-style: dashed; }
  .rowcard--nonbill { opacity: 0.75; }
  .rowcard--inactive { opacity: 0.6; }
  .rowcard__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
  .rowcard__top > div:first-child { min-width: 0; }
  .rowcard__title { font-weight: 650; font-size: 15px; line-height: 1.25; min-width: 0; overflow-wrap: anywhere; }
  .rowcard__title a, .rowcard__title .linkish--name { color: var(--navy-deep); font-size: 15px; }
  .rowcard__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 12.5px; color: var(--muted); }
  .rowcard__desc { font-size: 14px; line-height: 1.4; color: var(--ink); overflow-wrap: anywhere; }
  .rowcard__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .rowcard__stats > div { background: var(--bg); border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
  .rowcard__stats .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
  .rowcard__stats .v { font: 600 14px var(--mono); color: var(--navy-deep); }
  .rowcard__stats .v.bad { color: var(--bad); }
  .rowcard__bar { display: flex; align-items: center; gap: 8px; }
  .rowcard__bar .bar { flex: 1; }
  .rowcard__actions { display: flex; gap: 8px; margin-top: 2px; }
  .rowcard__actions .btn { flex: 1; justify-content: center; display: inline-flex; align-items: center; }
  .rowcard__right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
  .rowcard__amount { font: 600 15px var(--mono); color: var(--navy-deep); }
  .rowcard__hours { font: 500 12.5px var(--mono); color: var(--muted); white-space: nowrap; }
  .rowcard .chip__logo { width: 16px; height: 16px; }
  .rowcard .pick { width: 22px; height: 22px; margin: 2px 4px 0 0; }
  .cards .rowcard[hidden] { display: none; }
}

/* ============ ≤ 700: the phone shell ============ */
@media (max-width: 700px) {
  .main { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); }
  .page-head { margin-bottom: 12px; }
  .card { margin-bottom: 12px; }
  .card h2 { font-size: 13px; }
  .stats { gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat__value { font-size: 20px; }
  .toast { left: 12px; right: 12px; bottom: calc(72px + env(safe-area-inset-bottom)); max-width: none; text-align: center; }
  .cards { grid-template-columns: 1fr; gap: 8px; }

  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; background: #fff; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -6px 20px rgba(20,29,51,0.06); }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 56px;
    font: 600 10.5px/1 var(--sans, inherit); letter-spacing: 0.02em; color: var(--muted); background: none; border: 0; text-decoration: none; }
  .tabbar svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar a.active { color: var(--navy); }
  .tabbar a.active svg { stroke-width: 2.2; }
  .tabbar a:hover, .tabbar button:hover { text-decoration: none; }

  .fab { position: fixed; right: 14px; bottom: calc(68px + env(safe-area-inset-bottom)); z-index: 39; display: inline-flex; align-items: center; gap: 6px;
    min-height: 48px; padding: 0 18px 0 14px; border-radius: 999px; background: var(--coral); color: #fff; font-weight: 650; border: 0; box-shadow: 0 8px 24px rgba(232,104,52,0.4); }
  .fab:hover { background: var(--coral-deep); }
  .fab__plus { font-size: 22px; line-height: 1; font-weight: 400; }

  .topbar__toggle { width: 44px; height: 44px; }
  .period { width: 100%; justify-content: space-between; }
  .period__label strong { font-size: 13px; }
  .period .btn { min-width: 44px; padding: 8px 10px; }
  .tabs { width: 100%; }
  .tabs a { flex: 1; text-align: center; padding: 10px 8px; }
  .exports { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
  .exports .btn { padding: 8px 10px; font-size: 13px; }

  /* Forms are hidden on the page; the Add button opens them in a sheet. */
  .card--form { display: none; }
  .sheet--form .entry-form label, .sheet--form .sheet__form label { flex: 1 1 100%; }
  .sheet--form .entry-form .btn--primary { width: 100%; margin-top: 6px; }

  /* Report filters collapse to a summary line; the sheet holds the form. */
  #main #report-filters.filters { display: none; }
  .filters-summary { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font: inherit; color: var(--ink); }
  .filters-summary__text { flex: 1; min-width: 0; font-size: 13px; line-height: 1.35; }
  .filters-summary__text strong { display: block; }
  .filters-summary__cta { color: var(--teal); font-weight: 600; font-size: 13px; }
  .sheet--form #report-filters.filters { display: flex; }
  .sheet--form .filters label { flex: 1 1 100%; }
  .sheet--form .filters .spacer { display: none; }
  .sheet--form .filters .btn--primary { width: 100%; }
}
