/* ==========================================================================
   StockSmartPro — phone ergonomics layer
   Loaded after app.css. Every layout rule here is scoped to narrow viewports,
   so tablet/desktop rendering is unchanged. Brand tokens come from app.css.

   Rules of this layer:
   - interactive controls are at least 44x44 CSS px (glove/hurry use in a kitchen)
   - form controls are 16px so iOS Safari does not zoom on focus
   - nothing may widen the viewport: no horizontal page scroll at 320px
   - fixed bottom tabs respect env(safe-area-inset-*) on notched phones
   ========================================================================== */

/* ---------------------------------------------- collapsible form sections */
/* Markup: <details class="disclose" data-fold open><summary>…</summary><div>…</div></details>
   Desktop hides the summary chrome so the page looks exactly as before; the
   phone layer closes data-fold sections on load (see templates) and shows the
   summary as a 48px tap row. */
.disclose > summary { cursor: pointer; font-weight: 600; color: var(--forest-700); }
.disclose > summary::-webkit-details-marker { display: none; }
.disclose > summary:focus-visible { outline: 2px solid var(--forest-500); outline-offset: 2px; }
.disclose > .disclose-body { min-width: 0; }
@media (min-width: 901px) {
  .disclose > summary { display: none; }
  .disclose > .disclose-body { padding: 0; }
}

/* Grouping inside a long form: plain on desktop, separated blocks on phones. */
fieldset.form-group { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.form-group > legend { padding: 0; }

/* --------------------------------------------------------------- baseline */
img, svg, video, canvas { max-width: 100%; }
pre, code, samp { max-width: 100%; }

@media (max-width: 900px) {
  /* 16px prevents iOS focus zoom; 44px is the Apple/WCAG target minimum. */
  input[type="text"], input[type="email"], input[type="password"], input[type="number"],
  input[type="date"], input[type="datetime-local"], input[type="search"], input[type="time"],
  input[type="tel"], input[type="url"], input:not([type]), select, textarea {
    font-size: 16px;
    min-height: 44px;
    padding: .62rem .7rem;
    line-height: 1.35;
  }
  input[type="file"] { font-size: 16px; max-width: 100%; }
  textarea { min-height: 110px; }

  .btn { min-height: 44px; padding: .68rem 1.05rem; font-size: .95rem; }
  .btn-sm { min-height: 44px; font-size: .84rem; padding: .45rem .8rem; }
  .icon-button { min-width: 44px; min-height: 44px; }
  .check { min-height: 44px; align-items: center; gap: .65rem; font-size: .92rem; }
  .check input { width: 22px; height: 22px; margin-top: 0; flex: none; }

  .field { gap: .35rem; }
  .field-label { font-size: .75rem; letter-spacing: .06em; }
  .field-hint { font-size: .8rem; line-height: 1.45; }
  .inline-actions { gap: .5rem; }
  .inline-actions .btn { flex: 1 1 auto; }

  .page-head h1 { font-size: clamp(1.35rem, 5.6vw, 1.75rem); }
  .lede { font-size: .93rem; }
  h2 { font-size: 1.12rem; }
  h3 { font-size: .98rem; }

  .table-wrap { -webkit-overflow-scrolling: touch; max-width: 100%; }
  .table th, .table td { padding: .55rem .5rem; }
  .queue li { flex-wrap: wrap; gap: .4rem; }
  .queue li .link { min-height: 44px; display: inline-flex; align-items: center; }
  .filters { gap: .6rem; }

  /* The phone accordion: a full-width 48px tap row, warm paper, forest ink. */
  .disclose {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper-3);
    margin: .75rem 0 0;
    overflow: hidden;
  }
  .disclose > summary {
    display: flex;
    align-items: center;
    gap: .55rem;
    min-height: 48px;
    padding: .8rem .9rem;
    font-size: .95rem;
    list-style: none;
  }
  .disclose > summary::after {
    content: "+";
    margin-left: auto;
    font-size: 1.15rem;
    line-height: 1;
    color: var(--muted);
    transition: transform .15s ease;
  }
  .disclose[open] > summary::after { content: "\2013"; }
  .disclose[open] > summary { border-bottom: 1px solid var(--line); background: rgba(20, 48, 36, .035); }
  .disclose > .disclose-body { padding: .85rem .9rem 1rem; }
  .disclose > summary .sum-note {
    margin-left: auto;
    max-width: 52%;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.3;
    color: var(--muted);
    font-weight: 500;
    font-size: .8rem;
  }
  .disclose > summary::after { margin-left: .35rem; }

  /* Guided jobs: one-thumb actions, never two squeezed buttons. */
  .wf-actions { gap: .5rem; }
  .wf-actions .btn { flex: 1 1 100%; }
  .wf-card .wf-cta { flex-direction: column; align-items: stretch; }
  .wf-card .wf-cta .btn { width: 100%; min-height: 48px; }
  .wf-card .wf-cta .link { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .wf-step { min-height: 36px; }
  .wf-meta { gap: .4rem 1rem; }
  .wf-qty { max-width: none; width: 100%; text-align: right; }

  fieldset.form-group { margin-top: 1rem; padding-top: .85rem; border-top: 1px dashed var(--line-strong); }
  fieldset.form-group:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }
  fieldset.form-group > legend {
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--amber-ink);
    margin-bottom: .55rem;
  }
}

/* ------------------------------------------------------------- phone only */
@media (max-width: 640px) {
  body { font-size: 14.5px; }

  /* Notch / home-indicator safe areas, plus room for the fixed tab bar. */
  .topbar {
    padding-top: max(.55rem, env(safe-area-inset-top));
    padding-left: max(.9rem, env(safe-area-inset-left));
    padding-right: max(.9rem, env(safe-area-inset-right));
  }
  .content {
    padding-left: max(.85rem, env(safe-area-inset-left));
    padding-right: max(.85rem, env(safe-area-inset-right));
    padding-bottom: calc(5.6rem + env(safe-area-inset-bottom));
  }
  .app-foot { padding-bottom: calc(5.6rem + env(safe-area-inset-bottom)); }

  .card { padding: .95rem .85rem 1rem; border-radius: 12px; }
  .panel { padding: .95rem .85rem 1rem; }

  /* Stacked primary actions read better than two squeezed buttons. */
  .page-actions { flex-direction: column; align-items: stretch; }
  .page-actions .btn { width: 100%; }

  .flash { font-size: .92rem; }

  /* Small chrome still needs a thumb-sized row (branch picker, evidence fold). */
  summary { min-height: 44px; }
  .branch-menu summary { display: flex; align-items: center; gap: .3rem; }

  /* The branch popover becomes a bottom sheet: it can never run off a 320px screen. */
  .branch-menu .menu {
    position: fixed;
    left: .5rem;
    right: .5rem;
    top: auto;
    bottom: calc(4.7rem + env(safe-area-inset-bottom));
    width: auto;
    min-width: 0;
    max-height: 60vh;
    overflow-y: auto;
    border-radius: 14px;
  }
  .menu-item { min-height: 48px; }

  /* Small screens: 2-up numeric fields, description on its own row. */
  .invoice-fields { grid-template-columns: minmax(0, 1fr); }
  .invoice-line.invoice-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem .65rem; }
  .invoice-line.invoice-fields > .field:first-child { grid-column: 1 / -1; }

  /* Keep the primary submit reachable in a long invoice form. */
  .save-bar { margin-top: 1rem; }
  .save-bar .btn { width: 100%; min-height: 52px; }


}

/* --------------------------------------------------- fixed bottom tab bar */
.mobile-tabs { display: none; }
@media (max-width: 640px) {
  .mobile-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 34;
    display: flex;
    align-items: stretch;
    gap: .15rem;
    padding: .3rem .35rem calc(.3rem + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, var(--forest-900), var(--forest-950));
    border-top: 1px solid rgba(0, 0, 0, .4);
    box-shadow: 0 -12px 28px -22px rgba(0, 0, 0, .8);
  }
  .mobile-tabs .mtab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .18rem;
    flex: 1 1 0;
    min-width: 0;
    min-height: 52px;
    padding: .35rem .2rem;
    border-radius: 10px;
    color: rgba(232, 228, 215, .72);
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .02em;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-tabs .mtab .ico { width: 21px; height: 21px; }
  .mobile-tabs .mtab:active { background: rgba(255, 255, 255, .07); }
  .mobile-tabs .mtab.active { color: #f7f2e6; background: rgba(193, 134, 58, .18); }
  .mobile-tabs .mtab.active .ico { color: var(--amber); }
  body.auth-body .mobile-tabs { display: none; }
  body.nav-open .mobile-tabs { display: none; }
}

/* A phone-only header shortcut so the long review form can be saved from the top. */
@media (min-width: 641px) { .actions-mobile { display: none; } }

/* ------------------------------------------- wide tables become line cards */
@media (max-width: 640px) {
  .table.stack { border-collapse: separate; }
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
  .table.stack tr {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper-3);
    padding: .55rem .7rem;
    margin-bottom: .6rem;
    box-shadow: var(--shadow);
  }
  .table.stack tbody tr:hover { background: var(--paper-3); }
  .table.stack td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .8rem;
    border: 0;
    padding: .3rem 0;
    text-align: left;
    min-height: 40px;
  }
  .table.stack td::before {
    content: attr(data-label);
    flex: none;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .table.stack td[data-label=""]::before, .table.stack td[data-label="Item"]::before { content: none; }
  .table.stack td[data-label="Item"] { display: block; padding-bottom: .35rem; }
  .table.stack td[data-label="Item"] strong { font-size: 1rem; }
  .table.stack td .wf-qty, .table.stack td input { max-width: 9rem; text-align: right; }
  .table.stack td.right { text-align: right; }
}

/* Print: never show phone chrome. */
@media print {
  .mobile-tabs, .line-jump { display: none !important; }
  .content, .app-foot { padding-bottom: 0 !important; }
}
