/* mobile-setup.css — setup page on phones and tablets.
   Phone layout = (max-width: 640px), (pointer: coarse) and (orientation:
   portrait) and (max-width: 1100px), as in mobile-map/sheet/touch.css.
   Touch sizes also apply to landscape touch tablets ((pointer: coarse)),
   which otherwise keep the desktop layout. A desktop with a mouse (> 640 px,
   fine pointer) is not touched by anything in this file. */

/* ── Touch sizes: phones and every coarse-pointer screen ─────────── */
@media (max-width: 640px), (pointer: coarse) {
  /* tabs */
  .setup-tab { min-height: 44px; padding-left: 16px; padding-right: 16px; }

  /* footer options and buttons */
  .region-field { height: 44px; }
  .setup-card .region-field input { font-size: 16px; }            /* 16 px: no iOS zoom on focus */
  .opt-chip { height: 44px; padding: 0 16px; font-size: 13.5px; }
  .opt-chip input[type=checkbox] { width: 18px; height: 18px; }
  .setup-foot .setup-actions .btn { min-height: 44px; font-size: 14px; }

  /* small round buttons on tiles and in the editor: same look, 44 px hit area */
  .sonar-edit::after, .tile-clear::after, .setup-alert-x::after {
    content: ""; position: absolute; left: 50%; top: 50%; width: 44px; height: 44px;
    transform: translate(-50%, -50%); border-radius: 50%;
  }
  .setup-alert-x { position: relative; }
  .sonar-edit { width: 34px; height: 34px; }
  .tile-clear { width: 30px; height: 30px; }
  .se-close { width: 44px; height: 44px; font-size: 20px; }

  /* echosounder editor fields */
  .setup-card .se-params input[type=number] { height: 44px; font-size: 16px; }
  .se-params .ctrl { justify-content: space-between; }      /* inputs line up when a label has an ⓘ or wraps */
  .setup-card .se-name { font-size: 19px; min-height: 36px; }
  .se-foot { flex-wrap: wrap; }
  .se-foot .btn.sm { min-height: 44px; padding: 0 16px; font-size: 13.5px; }
  .se-foot #se-done { padding: 0 22px; }
}

/* ── Phone layout: phones and portrait touch tablets ─────────────── */
@media (max-width: 640px), (pointer: coarse) and (orientation: portrait) and (max-width: 1100px), (pointer: coarse) and (orientation: landscape) and (max-height: 500px), (max-width: 950px) and (orientation: landscape) and (max-height: 500px) {
  /* the card fills the screen, so the option bar can sit at its bottom
     even when the tiles are short; no bottom padding under the bar */
  #setup { padding-bottom: 0; overflow-x: hidden; }
  .setup-card { min-height: 100%; }

  /* Option bar pinned to the bottom of the scrolling #setup. Sticky, not
     fixed: it keeps its place in the flow, so the last tiles scroll up
     above it and never hide behind it.  */
  .setup-card > .setup-foot {
    position: sticky; bottom: 0; z-index: 5;
    /* edge to edge of the screen whatever the card width (the card is
       centred, so half the difference goes on each side); the content
       stays lined up with the card */
    --sf-bleed: calc(50vw - 50%);
    margin: auto calc(-1 * var(--sf-bleed)) 0;
    padding: 10px max(var(--sf-bleed), env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(var(--sf-bleed), env(safe-area-inset-left, 0px));
    gap: 6px;
    background: color-mix(in srgb, var(--surface2) 84%, transparent);
    -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(0, 12, 34, .08);
  }
  .setup-foot > .err:empty { display: none; }
  .setup-foot .setup-actions { gap: 8px; }
  .opt-bar { gap: 8px; flex: 1 1 0; }
  .region-field { flex: 1 1 180px; }

  .tile-grid, .sonar-grid { gap: 12px; }

  /* recent sets: the file names (long mono text, and the tile name already
     says which set it is) crowded the ↓ and the badge; keep the settings */
  .tile-recent .tile-info .recent-file, .tile-recent .tile-info .tile-bounds { display: none; }
}
/* 3 tiles per row on portrait tablets (2 stays for phones) */
@media (pointer: coarse) and (orientation: portrait) and (min-width: 641px) and (max-width: 880px) {
  .tile-grid, .sonar-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ── Echosounder editor stacked under its card (phones, touch screens ≤ 900 px) ── */
@media (max-width: 640px), (pointer: coarse) and (max-width: 900px) {
  .sonar-grid.editing { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  /* the active card becomes a compact row: picture left, name right */
  .sonar-grid.editing > .sonar-card.active {
    max-width: none; flex-direction: row; align-items: center; gap: 4px;
  }
  .sonar-grid.editing > .sonar-card.active .tile-thumb { flex: none; width: 88px; }
  .sonar-grid.editing > .sonar-card.active .tile-info { display: none; }
  .sonar-grid.editing > .sonar-card.active .tile-body { flex: 1; min-width: 0; padding: 6px 10px; }
  .sonar-editor { padding: 14px 14px 12px; }
}

/* ── Phones only ─────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #setup { padding-top: 14px; padding-left: 16px; padding-right: 16px; }
  .setup-card { gap: 12px; }

  /* compact brand header */
  .setup-card .brand { gap: 8px; margin-bottom: 4px; }
  .setup-logo { height: 16px; }
  .setup-card .brand-rule { width: 14px; }
  .setup-card .brand-sub { font-size: 9px; }
  .setup-card h1 { font-size: 18px; }

  /* tabs share the width */
  .setup-tab { flex: 1 1 0; padding-left: 8px; padding-right: 8px; font-size: 14px; }

  /* tiles: two per row, smaller type so a title fits two lines */
  .tile-grid, .sonar-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { --tile-r: 16px; --tile-gap: 5px; }
  .tile-body { gap: 5px; padding: 8px 6px 6px; }
  .tile-meta { font-size: 10.5px; }
  .tile-name { font-size: 14.5px; }
  .tile-tag { right: 10px; bottom: 10px; }
  .tile-sample .tile-name { padding-right: 50px; }
  .tile-recent .tile-name { padding-right: 36px; }
  .tile-plus { width: 48px; height: 48px; font-size: 27px; }
  .tile-upload .tile-info-sub { display: none; }
  /* recent sets: one line per setting on the small picture */
  .tile-info { padding: 9px; font-size: 10.5px; }
  .tile-recent .tile-info { gap: 1px; }
  .tile-recent .tile-info > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .recent-badge { top: 7px; left: 7px; }

  /* option bar: Region with the ⓘ beside it, the two chips below, then Open */
  .opt-bar { flex: 1 1 100%; }
  .region-field { order: 0; flex: 1 1 calc(100% - 52px); }
  .opt-bar > .info { order: 1; margin: 0 12px 0 4px; }
  .opt-chip { order: 2; flex: 1 1 auto; justify-content: center; padding: 0 12px; }
  .setup-foot .setup-actions .btn { padding: 0 16px; }
  .setup-foot #btn-open { order: 2; flex: 1 1 0; min-width: 0; margin-left: 0; min-height: 48px; font-size: 15px; font-weight: 600; }
  .setup-foot #btn-setup-cancel { order: 1; flex: 0 0 auto; min-height: 48px; }
  .setup-foot .err { font-size: 13px; }

  /* editor: two columns of parameters, inputs lined up even when a label wraps */
  .se-params { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
  .se-params .ctrl { gap: 4px; }
  .se-params .ctrl label { font-size: 10px; line-height: 1.25; }
  .se-foot .btn.sm { flex: 1 1 auto; }
  .se-foot #se-done { flex: 1 1 100%; margin-left: 0; order: 3; }
}
