/* Phone layer — loaded LAST on every page, after the page's own <style> and the skin,
 * so these rules win without !important wars. Only phone widths are touched; desktop
 * is unchanged. Findings come from an automated pass over every screen at 360–412px
 * (tap targets < 30px, text < 11px, iOS focus-zoom on inputs under 16px).
 */
@media (max-width: 640px) {
    /* Off-canvas drawers and RTL tables inside sideways-scrolling wrappers nudged the
       document a few dozen px wider than the phone, so the browser zoomed the whole page
       out and it sat shifted with a blank strip (home: 409px on a 375px phone). `clip`
       stops that without making body a scroll container — `hidden` would break the
       sticky top bars. Content that truly doesn't fit is still caught by the audit. */
    html, body { overflow-x: clip; }

    /* The real culprit on the home page: each table's visually-hidden <caption> is
       position:absolute, and with no positioned ancestor it escaped the sideways-
       scrolling wrapper and widened the page by the table's overflow. */
    .table-scroll-wrap, .table-wrap, .table-section { position: relative; }

    /* iOS zooms the page into any focused field whose text is under 16px, and stays
       zoomed — the main annoyance when typing mortality into the grid. */
    input:not([type=checkbox]):not([type=radio]):not([type=range]), select, textarea {
        font-size: 16px;
    }

    /* Grid/flex form cells default to min-width:auto, so a <select> with a long option
       refused to shrink and pushed the calculators page 69px past the screen. */
    .form-grid > *, .field, .top-row > *, .bld-fields > * { min-width: 0; }
    .field input, .field select, .field textarea { max-width: 100%; min-width: 0; box-sizing: border-box; }

    /* The back arrow was an 11×13px target on every flock screen. */
    .back-btn {
        min-width: 40px; min-height: 40px;
        justify-content: center;
        font-size: 18px;
        border-radius: 10px;
    }

    /* Bottom bar: readable labels, a bigger icon, and a partly-visible last item so it
       is obvious the bar scrolls sideways. */
    .bottom-nav a { min-width: 64px; font-size: 11px; }
    .bottom-nav a i { font-size: 16px; }

    /* Small icon buttons (edit / delete / view in record tables, admin lists). */
    .icon-btn, .item-btn, .btn-ghost.icon-edit, .btn-ghost.icon-del, .flock-card-delete, .cu-view, .del-btn {
        min-width: 36px; min-height: 36px;
        display: inline-flex; align-items: center; justify-content: center;
    }

    /* Text links used as buttons ("לכל הארכיון", "חזרה") and icon-only close buttons. */
    .view-archive-link, .back-link, .farm-header-back { display: inline-flex; align-items: center; min-height: 36px; }
    button[title="סגור"] { min-width: 36px; min-height: 36px; }

    /* Wide admin tables scroll inside their card instead of spilling off the screen. */
    .fp-table { display: block; overflow-x: auto; }

    /* Mortality grid: 28px rows were hard to hit with a thumb. */
    .cell-input { min-height: 36px; }
    .notes-input { min-height: 36px; }

    /* Text under 11px: card labels on the grower home, the weather strip, chart hints. */
    .slabel, .stat-tile .slabel, .wx-lo, .wx-hi, .kpi-label, .tile-label { font-size: 11.5px; }
    small { font-size: 11px; }
    /* Home-page data tables were 10px; they already scroll sideways, so a readable size
       costs nothing but a little more scrolling. */
    .data-table th, .data-table td { font-size: 11.5px; }
    .ssub, .mwc-today-pill { font-size: 11px; }

    /* Flock home header: farm name under the title, the two actions side by side across
       the width, the display-skin preference last. */
    .flock-actions { width: 100%; }
    .flock-actions .header-btn { flex: 1 1 0; justify-content: center; min-height: 42px; white-space: nowrap; }
    .flock-actions .skin-toggle { order: 3; flex: 0 0 auto; margin-inline-start: auto; }
    .flock-actions::after { content: ""; order: 2; flex-basis: 100%; height: 0; }

    /* Form footers (שמור / ביטול): full-width, thumb-height buttons. */
    .form-actions { display: flex; gap: 8px; }
    .form-actions .btn { flex: 1 1 0; min-height: 44px; justify-content: center; }

    /* Page header: title on its own line, actions as a wrapping row under it. */
    .page-header { align-items: flex-start; }
    .page-header .page-actions { width: 100%; flex-wrap: wrap; gap: 8px; }
    .page-header .page-actions .btn { min-height: 40px; }
}

/* Side drawers (home: .db-mobile-menu, farmer-nav: .mobile-menu) are fixed and parked
   off-screen to the right while closed; in RTL that still widened the document (home
   scrolled 32px with a blank strip). Closed = not rendered; opening slides it in. */
@media (max-width: 900px) {
    .db-mobile-menu:not(.open), .mobile-menu:not(.open) { display: none; }
    .db-mobile-menu.open, .mobile-menu.open { animation: muDrawerIn .25s ease; }
    @keyframes muDrawerIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
}

@media (max-width: 380px) {
    /* Smallest phones (iPhone SE / small Android): give the content the width. */
    .main { padding-left: 10px; padding-right: 10px; }
}
