/* ============================================================
   responsive.css - phone and tablet guards that apply to every page.
   Loaded last (see _HeadAssets.cshtml), so these win over the component CSS.

   What goes here: rules that fix a whole CLASS of mobile problem (a grid column that stretches the page, a
   tap target that is too small, an input that makes iOS zoom). A fix for one screen belongs in that screen's CSS.
   Breakpoints follow Tailwind: sm 640, md 768, lg 1024. "Phone" = under 640, "tablet" = 640-1023.
   ============================================================ */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-wrap: break-word; }
img, video, canvas { max-width: 100%; }
img[width][height] { height: auto; }

/* A bare `grid` has ONE auto-sized column, which grows to the widest unbreakable child (a long word, a row of
   buttons) and drags the whole page wider than the screen. Let those children shrink (and truncate / wrap)
   instead. Grids that declare their columns (grid-cols-*, or their own grid-template) already use minmax(0, 1fr). */
.grid > *,
.hm-show > *,
.flex > .min-w-0 { min-width: 0; }

/* Long headwords, e-mail addresses and URLs wrap rather than push a card past the screen edge. break-word (not
   anywhere) on purpose: "anywhere" also shrinks the min-content width, which squeezes table columns to one letter. */
.card, .hm-feature, .hm-shot-body { overflow-wrap: break-word; }

/* Anything that scrolls sideways on purpose (tables) must not make the PAGE scroll sideways. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- touch targets: 40px is comfortable, 32px the least we accept ---------- */
.tap { display: inline-flex; align-items: center; min-height: 2.5rem; }

@media (max-width: 1023px) {
  /* breadcrumbs are text links on one line - give them height without changing how they look */
  nav[aria-label="مسیر صفحه"] a { display: inline-flex; align-items: center; min-height: 2.5rem; }
  nav[aria-label="مسیر صفحه"] { margin-bottom: 1rem; }
  a.lvl-pill, .chip { min-height: 2.25rem; }
  a.lvl-pill { padding-inline: .8rem; }
  a.ms-auto.text-sm { min-height: 2.5rem; display: inline-flex; align-items: center; }
}

/* iOS Safari zooms the whole page when a field under 16px gets focus - and never zooms back. */
@media (max-width: 767px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
  select, textarea { font-size: 16px; }
}

/* ---------- small phones (320-360px) ---------- */
@media (max-width: 359px) {
  .site-header .h-16 { gap: .5rem; }
  .btn { padding-inline: 1rem; }
  h1 { overflow-wrap: anywhere; }
}

/* ---------- the bottom tab bar and the iPhone home indicator ---------- */
@supports (padding: max(0px)) {
  body.has-bottom-nav { padding-bottom: max(4rem, calc(4rem + env(safe-area-inset-bottom))); }
}

/* ---------- tall phones with the address bar showing: use the real viewport height ---------- */
.min-h-screen { min-height: 100vh; }
@supports (min-height: 100dvh) { .min-h-screen { min-height: 100dvh; } }

/* ---------- landscape phones: do not let sticky/fixed bars eat half the screen ---------- */
@media (max-height: 480px) and (orientation: landscape) {
  .site-header { position: static; }
  [data-bottom-nav] { position: static !important; }
}

/* ---------- admin: the sidebar is a drawer below 1024px ---------- */
.admin-backdrop { display: none; }
.admin-close { display: none; }
@media (max-width: 1023px) {
  [data-admin-side] {
    display: block !important; position: fixed; z-index: 70; inset-block: 0; inset-inline-start: 0;
    width: min(18rem, 86vw); max-width: 86vw; overflow-y: auto; overscroll-behavior: contain; padding-top: 3.25rem;
    box-shadow: 0 0 44px rgba(10, 10, 30, .4); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s;
  }
  [dir="rtl"] [data-admin-side] { transform: translateX(105%); }
  [dir="ltr"] [data-admin-side] { transform: translateX(-105%); }
  [data-admin-side].is-open { transform: none !important; visibility: visible; transition: transform .22s ease; }
  .admin-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(10, 10, 30, .45); }
  .admin-close {
    display: grid; place-items: center; position: absolute; top: .6rem; inset-inline-end: .6rem; width: 2.5rem; height: 2.5rem;
    border-radius: .75rem; color: var(--text-muted); background: var(--surface-2);
  }
  html.is-drawer-open { overflow: hidden; }
  [data-admin-side] a { min-height: 2.75rem; }
}
@media (prefers-reduced-motion: reduce) { [data-admin-side] { transition: none; } }

/* ---------- tables that become a list of cards on phones: <table class="rtable">, each <td data-label="..."> ---------- */
@media (max-width: 767px) {
  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
  .rtable tr { padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
  .rtable tr:last-child { border-bottom: 0; }
  .rtable td { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .3rem 0 !important; border: 0; text-align: end; }
  .rtable td::before { content: attr(data-label); flex-shrink: 0; font-size: .75rem; font-weight: 600; color: var(--text-muted); text-align: start; }
  .rtable td[data-label=""]::before, .rtable td:not([data-label])::before { content: none; }
  .rtable td[data-primary] { justify-content: flex-start; padding-bottom: .6rem !important; }
  .rtable td[data-primary]::before { content: none; }
  .rtable td[data-actions] { justify-content: flex-end; padding-top: .6rem !important; margin-top: .3rem; border-top: 1px dashed var(--border); }
  .rtable td[data-actions]::before { content: none; }
  /* a cell whose text is left-to-right (e-mail, an English example) keeps its own direction; flip the row so the label still sits at the start side */
  .rtable td[dir="ltr"], .rtable td[dir="auto"] { flex-direction: row-reverse; text-align: start; }
  .rtable td { white-space: normal !important; max-width: none !important; overflow-wrap: anywhere; }
  .rtable td > * { min-width: 0; }
  .rtable td .truncate { max-width: 62vw; }
}

/* The hidden attribute must always win over component display rules (.btn, .card ...). */
[hidden] { display: none !important; }
