/* ══════════════════════════════════════════════════════════════════════════
   Responsive foundation (mobile support)

   BREAKPOINTS — the only two values allowed anywhere in src/css/ (the
   survey player's play.css is the one exception):
     @media (max-width: 999px)  "mobile"      — same cutoff as the nav rule in main.css
     @media (max-width: 599px)  "small phone" — extra step for cramped layouts
   Desktop (≥1000px) must render exactly as it did before this file existed.

   RESPONSIVE TABLE PATTERN (opt-in)
   On mobile, a table becomes a list of cards: one card per row, with each
   cell shown as a "label: value" line. To use it:
     1. Add the `responsive-table` class to the <table>. Tables without it are
        never affected (e.g. the desktop-only admin tables that also use
        .dash-table or .users-table).
     2. On each ordinary <td>, add data-label="…" using the same translated
        text as the matching <th> (e.g. data-label="{{t.dashboard.colOwner}}").
     3. Give the row's name/title cell the `rt-primary` class (no data-label):
        it becomes the card heading.
     4. Give the row's actions cell the `rt-actions` class (no data-label): its
        buttons/links become full-width and stacked. (It may itself be the flex
        container, e.g. <td class="dash-actions rt-actions">, or wrap one.)
     Compact variant: also add `responsive-table--compact` for denser cards —
     fields in two columns (label above value), actions in a single row.
     5. Optional: a full-width grouping row (e.g. <td colspan="8"> owner
        headers) gets the `rt-group` class on its <tr>; it renders as a plain
        section heading rather than a card.
   The primary cell is always shown first in the card, even when it isn't the
   first column (e.g. tables that start with an ID column).
   ══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 999px) {

  /* ── Responsive table → cards ─────────────────────────────────────────── */

  table.responsive-table,
  table.responsive-table tbody,
  table.responsive-table td {
    display: block;
    width: 100%;
  }

  /* Rows hidden with an inline display:none (e.g. collapsed groups) stay hidden */
  table.responsive-table tr {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  table.responsive-table {
    background: transparent;
    border: none;
  }

  table.responsive-table thead {
    display: none;
  }

  table.responsive-table tr {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
  }

  table.responsive-table td {
    border: none;
    padding: 0.3rem 0;
    text-align: left;
  }

  table.responsive-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    margin-bottom: 0.1rem;
  }

  table.responsive-table td.rt-primary {
    order: -1;
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--color-text);
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid var(--color-border);
  }

  table.responsive-table td.rt-actions,
  table.responsive-table td.rt-actions .dash-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    width: 100%;
  }

  table.responsive-table td.rt-actions {
    padding-top: 0.6rem;
  }

  table.responsive-table td.rt-actions :is(a, button) {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 44px;
  }

  /* Play / Close / Reopen have no styles of their own (native buttons on
     desktop); inside mobile cards, match the neighbouring link actions. */
  table.responsive-table td.rt-actions :is(.dash-play, .dash-close, .dash-reopen) {
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-accent);
    font-size: 0.85rem;
    font-weight: 600;
  }

  table.responsive-table tr.rt-group {
    background: transparent;
    border: none;
    padding: 0;
    margin: 0.5rem 0;
  }

  table.responsive-table tr.rt-group td {
    min-height: 44px;
    text-align: left;
  }

  /* Links inside cards: tappable icons, wrapping long URLs */
  .dash-ext-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
  }

  .survey-copy-btn {
    min-height: 44px;
    padding: 0 0.85rem;
  }

  /* ── Compact card variant (responsive-table--compact) ──────────────────── */

  /* Two columns of fields: name across the top, then label-above-value
     pairs side by side, then the action row across the bottom */
  table.responsive-table--compact tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    -moz-column-gap: 1rem;
         column-gap: 1rem;
    row-gap: 0.45rem;
    padding: 0.6rem 0.85rem;
    margin-bottom: 0.5rem;
  }

  table.responsive-table--compact td.rt-primary,
  table.responsive-table--compact td.rt-actions {
    grid-column: 1 / -1; /* full width: name and actions */
  }

  /* Grouping rows (e.g. owner headings) stay a single full-width line */
  table.responsive-table--compact tr.rt-group {
    display: block;
    padding: 0;
  }

  table.responsive-table--compact td.rt-primary {
    font-size: 0.98rem;
    padding-bottom: 0.4rem;
    margin-bottom: 0;
  }

  table.responsive-table--compact td[data-label] {
    padding: 0;
    overflow-wrap: anywhere;
  }

  table.responsive-table--compact td[data-label]::before {
    font-size: 0.68rem;
    margin-bottom: 0;
  }

  table.responsive-table--compact .dash-ext-link {
    min-height: 1.5rem;
    min-width: 0;
    justify-content: flex-start;
  }

  table.responsive-table--compact td.rt-actions,
  table.responsive-table--compact td.rt-actions .dash-actions {
    flex-direction: row;
  }

  table.responsive-table--compact td.rt-actions {
    padding-top: 0.5rem;
  }

  table.responsive-table--compact td.rt-actions :is(a, button) {
    flex: 1;
  }

  /* Primary button made unavailable on mobile (e.g. Dashboard "+ New survey") */
  .lp-btn-primary.is-disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
  }

  /* ── Stat tiles: two-column grid ──────────────────────────────────────── */

  .dash-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row dense; /* let half-width tiles fill gaps left by wide ones */
    gap: 0.75rem;
  }

  .dash-stat {
    min-width: 0;
    padding: 1rem 1.1rem;
    align-items: center;
    text-align: center;
  }

  .dash-stat-sub {
    max-width: 100%;
  }

  .dash-stat--wide {
    grid-column: 1 / -1;
  }

  /* ── Form fields: ≥16px so iOS Safari doesn't zoom the page on focus ───── */

  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea {
    font-size: max(16px, 1em);
  }

  /* ── Page header: title above, actions full-width below ───────────────── */

  .dash-header {
    flex-direction: column;
    align-items: stretch;
  }

  .dash-header > :not(:first-child) {
    width: 100%;
  }

  .dash-header > :not(:first-child):is(a, button),
  .dash-header > :not(:first-child) > :is(a, button) {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 44px;
  }
}
