/* ================================================================
   Phone + iPad layer (loaded last, every site).
   Phone   = up to 640px wide
   Tablet  = 641px to 1180px (iPad portrait and landscape)
   Touch   = any screen with a finger instead of a mouse
   ================================================================ */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: hidden; }
img, video, canvas, svg { max-width: 100%; }
.content > *, .content > .page-root > * { max-width: 100%; }
pre, code { white-space: pre-wrap; word-break: break-word; }

/* ---------- touch screens (phones + iPads) and any phone-width screen ---------- */
@media (pointer: coarse), (max-width: 640px) {
  /* iOS zooms the page when a field under 16px gets focus: keep fields at 16px */
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]), select, textarea { font-size: 16px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  /* 40 px or more to tap (QA report 2026-12-02: header icons 36 px, Export / Share 27-32 px) */
  button, .btn { min-height: 40px; }
  button.small, .btn.small { min-height: 40px; }
  .gear-btn { width: 40px; height: 40px; }
  .tn-me { min-height: 40px; }
  .ch-plus { min-width: 40px; }
  select { min-height: 40px; }
  .eb-side a { min-height: 40px; box-sizing: border-box; }
  .cab-crumbs a { min-height: 40px; display: inline-flex; align-items: center; box-sizing: border-box; }
  .va-btn, .brand-sw { min-height: 40px; }
  button.spm-tick { width: 40px; height: 40px; }
  .pl-edit { min-width: 36px; justify-content: center; }
  .tab { padding-top: 11px; padding-bottom: 11px; }
  .tn-pop .tn-link { padding-top: 11px; padding-bottom: 11px; }
  .legend label, .weekdays label { padding: 7px 12px; }
  table.data tr.click td { padding-top: 11px; padding-bottom: 11px; }
  /* things that only showed on mouse hover are always shown */
  .sw-more, .fm-tile-who { opacity: 1 !important; }
  .fc .fc-button { padding: 8px 12px; }
}

/* ---------- phone-width screens: same 40 px tap size even when the browser reports a mouse
   (QA report 2026-12-02: header icons 36 px, site switcher 34 px, Share 27-38 px, drop-downs 33-38 px) ---------- */
@media (max-width: 640px) {
  button, .btn, button.small, .btn.small, select { min-height: 40px; }
  .gear-btn { width: 40px; height: 40px; }
  .tn-me, .va-btn, .brand-sw { min-height: 40px; }
  .ch-plus { min-width: 40px; }
  button.spm-tick { width: 40px; height: 40px; }
  .cab-crumbs a { display: inline-flex; align-items: center; min-height: 40px; }
}

/* ---------- more phone-width tap sizes (QA report 2026-12-02, Chiquita: chat section headers 20 px, calendar arrows 33 px,
   fields in table rows) ---------- */
@media (pointer: coarse), (max-width: 640px) {
  [role=button], .mn-share.small { min-height: 40px; }
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]) { min-height: 40px; }
  .gear-btn, .va-btn { min-width: 40px; }
  .pl-edit { min-width: 40px; }
  .ch-sec-h { min-height: 40px; }
  .fc .fc-button { min-height: 40px; min-width: 40px; }
  table.data td select, table.data td input:not([type=checkbox]):not([type=radio]) { min-height: 40px; }
}
.bk-sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }

/* ---------- tablets and phones ---------- */
@media (max-width: 1180px) {
  .shell.tn .content { padding: 16px; }
  .drawer.wide { width: 100%; }
  .modal.wide { max-width: min(860px, 100%); }
  /* wide tables scroll sideways inside their box instead of pushing the page */
  .panel, .stat, .widget { min-width: 0; }
  .table-wrap { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  /* dropdowns and boxes inside table rows keep a usable width (the table scrolls instead) */
  table.data td select, table.data td input:not([type=checkbox]):not([type=radio]) { min-width: 124px; }
}

/* ---------- iPad portrait and smaller ---------- */
@media (max-width: 900px) {
  .kv { grid-template-columns: 110px minmax(0, 1fr); }
  .kv > * { min-width: 0; overflow-wrap: anywhere; }
  .page-head h1 { font-size: 20px; }
  .fin-cols { columns: 1; }
}

/* ---------- phones ---------- */
@media (max-width: 640px) {
  body { font-size: 15px; }
  h1 { font-size: 20px; }
  .shell.tn .content { padding: 12px 10px 24px; }
  .panel { padding: 12px; }
  .panel.flush { padding: 0; }
  .page-head { gap: 8px; margin-bottom: 12px; align-items: flex-start; }
  .page-head > div:first-child { min-width: 0; }
  .page-head .row { flex-wrap: wrap; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 9px 11px; }
  .stat .v { font-size: 17px; overflow-wrap: anywhere; }
  .row > input, .row > select { flex: 1 1 150px; min-width: 0; width: auto; }
  .row > input[type=checkbox], .row > input[type=radio] { flex: none; }
  .tabs { scrollbar-width: none; }
  .tab { padding-left: 11px; padding-right: 11px; white-space: nowrap; flex: none; }
  .seg { max-width: 100%; overflow-x: auto; }
  .seg button { flex: none; }

  /* tables: keep columns readable and let the box scroll sideways */
  table.data th, table.data td { padding: 8px 8px; }

  /* popups become full-screen sheets */
  /* align-items stays flex-start so a long form makes the sheet taller (stretch pinned it to the
     screen height and the bottom fields floated over the page); min-width 0 stops wide content
     from making the sheet wider than the phone. 100vw is the phone's own width even when Android
     widens the page behind for wide content, so the sheet never runs off the right edge */
  .overlay { padding: 0; align-items: flex-start; right: auto; width: 100%; max-width: 100vw; overflow-x: hidden; }
  .modal, .modal.wide { width: 100%; min-width: 0; max-width: 100%; min-height: 100%; border-radius: 0; display: flex; flex-direction: column; box-shadow: none; }
  .modal-body { min-width: 0; overflow-wrap: anywhere; }
  .modal-body input:not([type=checkbox]):not([type=radio]):not([type=range]), .modal-body select, .modal-body textarea { max-width: 100%; }
  .modal-body .seg { flex-wrap: wrap; }
  .modal-head { position: sticky; top: 0; background: var(--panel); z-index: 2; padding: 12px 14px; }
  .modal-head h2 { font-size: 17px; min-width: 0; overflow-wrap: anywhere; }
  .modal-body { padding: 14px; flex: 1; }
  .modal-foot { position: sticky; bottom: 0; background: var(--panel); z-index: 2; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .drawer, .drawer.wide { width: 100%; }
  .drawer .modal-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }

  /* header: smaller logos, and it slides away while you scroll down */
  .tn-logo { height: 30px; }
  .tn-head { transition: transform .22s ease; }
  .tn-head.tn-away { transform: translateY(-100%); }
  .toast-box { bottom: calc(16px + env(safe-area-inset-bottom)); width: calc(100% - 24px); }
  .toast { max-width: 100%; text-align: center; }

  /* calendar */
  .fc .fc-toolbar-title { font-size: 16px; }
  .fc .fc-toolbar.fc-header-toolbar { margin-bottom: 10px; }
  .fc .fc-toolbar-chunk { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
  .fc .fc-daygrid-day-number { font-size: 12px; padding: 2px 4px; }
  .fc .fc-daygrid-event { font-size: 11px; }
  .fc .fc-col-header-cell-cushion { font-size: 11px; padding: 4px 1px; }
}

@media print {
  .tn-head.tn-away { transform: none; }
}

/* video calls on phones */
@media (max-width: 640px) {
  .vc-bar .vc-title { max-width: 32vw; }
  .vc-bar [data-min] { display: none; }
  .vc-dock { left: 8px; right: 8px; bottom: auto; top: 8px; border-radius: 16px; flex-wrap: wrap; }
  .vc-dock-t { flex: 1 1 100%; }
  .vc-banner { padding: 8px 10px; }
  .vc-card { max-width: 100%; }
}
