/* Touch layouts: every interactive element has at least a 44x44 CSS px hit area (WCAG 2.5.5 / 2.5.8) and nothing overflows sideways.
   Loaded LAST on every page (and last in scripts/build-assets.mjs's per-page lists, which are read from the HTML), so it wins by order.
   Audited by scripts/mobile-check.mjs (7 languages x 320/360/390/414 x every page). Where a control is short by design (chips, table
   tags) the hit area grows with a ::after layer instead of padding, so the visual design stays as it is. Two controls that sit next to
   each other keep >= 8px between their boxes or share one 44px box.
   Condition: a touch device, or any narrow window (a desktop browser narrowed to phone width gets the same layout). */

@media (pointer: coarse), (max-width: 860px) {
  /* ---- form fields: 44px tall ---- */
  input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=range]), select, textarea { min-height: 44px; }
  select { padding-block: 8px; }
  .fld input, .fld select, .fld textarea { min-height: 44px; }
  .search { padding-block: 3px; min-width: 0; }
  .search input { width: 0; } /* an input's intrinsic width (~180px) otherwise stops the form shrinking: 'Анализировать' pushed it 45px past a 320px screen */
  .search input { min-height: 44px; padding-block: 8px; }
  .search kbd { display: none; }
  .search .btn { min-height: 44px; flex: none; }
  .search svg { flex: none; }

  /* ---- buttons, icon buttons, toggles ---- */
  .btn, button.btn, a.btn, .icon-btn, .cns-btn, .sw, [role="tab"], summary { min-height: 44px; }
  .icon-btn { min-width: 44px; }
  .sw { min-width: 52px; }
  .btn { align-items: center; justify-content: center; }
  [role="tab"], .seg button, .tabs button, #cycle button, .pill-tabs button { min-height: 44px; }
  .seg, #cycle { gap: 4px; }

  /* ---- every other button: 44px each way (the panel's small ghost / text / chip / dialog / close buttons) ---- */
  button:not(.sw) { min-height: 44px; min-width: 44px; }
  .nav a, .nav-group-b a, .nav-group-h, .side a { min-height: 44px; display: flex; align-items: center; }
  a.hm-lchip, a.sm-link, .up-btn, a.up-btn, .mg-btn { min-height: 44px; display: inline-flex; align-items: center; }
  a.sm-link { padding-inline: 10px; min-width: 44px; justify-content: center; }
  .ghost-btn, .text-btn, .ct-btn, .up-x { min-width: 44px; min-height: 44px; }
  .mg-btn, .ct-btn, .ct.compact .ct-btn { min-height: 44px !important; min-width: 44px !important; } /* injected / more specific sheets set their own heights */
  .th-switch { gap: 8px; }
  .th-switch a { min-height: 44px; display: inline-flex; align-items: center; padding-inline: 12px; }
  .pf-row { flex-wrap: wrap; }
  .pf-row > *, .pf-f { min-width: 0; max-width: 100%; }
  .pf-f { flex-wrap: wrap; }
  .pf-f > div, .pf-f .seg { display: flex; flex-wrap: wrap; gap: 4px; max-width: 100%; }
  a.dx-credits { min-height: 44px; display: inline-flex; align-items: center; }
  input[type=range] { min-height: 44px; }

  /* ---- short controls that keep their look: the hit area grows with an invisible layer ---- */
  .hit, .hit-lg, a.dx-status, .dx-key-list a, .legal-nav a, .sf li a, .sf-legal a, .tbl button, .tbl .tag-btn, .tbl a.tag,
  table button:not(.btn):not(.icon-btn), table a.tag, th button { position: relative; }
  .hit::after, .sf li a::after, .sf-legal a::after, .tbl button::after, table button:not(.btn):not(.icon-btn)::after, table a.tag::after, th button::after { content: ""; position: absolute; inset: -12px -6px; }
  .hit-lg::after { content: ""; position: absolute; inset: -6px -4px; }
  a.dx-status, .dx-key-list a { min-height: 44px; padding-inline: 12px; }
  .acc-jump a, .dx-foot-links a { min-width: 44px; justify-content: center; min-height: 44px; display: inline-flex; align-items: center; }
  .acc-jump { gap: 4px 8px; }
  .dx-foot-links { gap: 8px 18px; flex-wrap: wrap; }
  a.brand, .dx-top .brand { min-width: 44px; }
  #cx button, #cx [data-p] { min-height: 44px; }
  a.link, #helpLine a, .refund a, #trust a { position: relative; }
  a.link::after, #helpLine a::after, .refund a::after, #trust a::after { content: ""; position: absolute; inset: -12px -4px; }
  .legal-nav a { min-height: 44px; display: inline-flex; align-items: center; }
  .sf li a, .sf-legal a { display: inline-block; }
  .sf ul { gap: 14px; }
  th button { min-height: 44px; display: inline-flex; align-items: center; }

  /* ---- sign-in / sign-up cards: the "forgot password" link beside a label, the alternate-action line, the footer links, the logo ---- */
  .au-lbl a, .au-alt a, .au-foot a, .dx-hint a { position: relative; }
  /* R5-3: the "forgot password" link beside the password label has its own 44px box (the label row keeps its height through the negative margin) */
  .au-lbl a { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; margin-block: -14px; padding-inline: 4px; box-sizing: border-box; }
  .au-lbl a::after, .au-alt a::after, .au-foot a::after, .dx-hint a::after { content: ""; position: absolute; inset: -14px -10px; }
  a.au-logo { min-height: 44px; display: inline-flex; align-items: center; }

  /* ---- back-office (admin page) ---- */
  .card-head a.hint, a.hint { display: inline-flex; align-items: center; min-height: 44px; }
  label:has(> input[type=checkbox]), label:has(> input[type=radio]), label.chk { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
  tr.click > td, tr.click > th { height: 44px; }

  /* ---- links inside running text (paragraphs, list items, table cells, notes): a 20px line is a mis-tap risk on a phone, so the
     hit area grows with an invisible layer (the look and the line spacing stay). scripts/mobile-check.mjs measures them (no inline exemption). ---- */
  /* vertical padding on an inline box does not move the lines but IS part of its hit area, on every line fragment of a link that wraps
     (a pseudo-element would sit on the first fragment only). The negative inline margin keeps the text where it was. */
  :is(p, li, dd, dt, td, small, figcaption, blockquote, .hint, .lead, .note) a:not([class]) { padding: 14px 8px; margin-inline: -8px; }
}

/* ---- the public header: brand + theme + menu always fit (320 wide, any language). The call-to-action moves into the menu. ---- */
@media (max-width: 860px) {
  .sh .wrap { min-width: 0; }
  .sh-brand { min-width: 0; }
  .sh-brand span { overflow: hidden; text-overflow: ellipsis; }
  .sh-right { min-width: 0; flex: none; }
  .sh-right .icon-btn { width: 44px; height: 44px; }
  .sh-nav a, .sh-nav .sh-out { min-height: 44px; display: flex; align-items: center; }
  .sh-nav .sh-cta { background: var(--primary); color: var(--primary-fg, #fff); border-radius: 8px; justify-content: center; margin-top: 10px; border-bottom: 0; font-weight: 700; }
}
@media (max-width: 560px) {
  .sh-right .hide-xs { display: none; }
  .sh .wrap { padding-left: 16px; padding-right: 16px; }
}
@media (min-width: 561px) { .sh-nav .only-xs { display: none; } }

/* the idle sample strip of the report box: three cells that fit a 320px screen with a long word (ru 'Приблизительная метка') */
@media (max-width: 420px) { .mr-box .mr-idle { grid-template-columns: minmax(0, 1fr); } }

/* API docs header: the code-language tabs (44px each) and the theme button move to their own row on a phone */
@media (max-width: 560px) {
  .dx-top { flex-wrap: wrap; height: auto; padding-bottom: 6px; row-gap: 4px; }
  .dx-top .top-right { flex: 1 1 100%; order: 3; margin-left: 0; justify-content: space-between; min-width: 0; }
  .dx-top .dx-lang { min-width: 0; flex: 1 1 auto; overflow-x: auto; }
}

/* a card head with a long translated badge ("Näherungswert") wraps instead of pushing past a 320px screen */
@media (max-width: 480px) { .card-head { flex-wrap: wrap; } .card-head > * { min-width: 0; max-width: 100%; } #scoreSource { max-width: 100%; } }
