/* A narrow split view on a touch tablet still has room for a scannable QR. */
@media (min-width: 700px) and (min-height: 550px),
       (any-pointer: coarse) and (min-device-width: 600px) and (min-device-height: 600px) {
  a.coffee-link { display: none; }
  .coffee-qr-trigger { display: inline-flex; }
}

@media (min-width: 700px) and (min-height: 550px) {
  .welcome-view, .library-view, .results-view.has-results, .draft-form.has-selection {
    display: grid;
    column-gap: clamp(24px, 4vw, 56px);
  }

  .welcome-view {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    grid-template-rows: 1fr auto auto auto 1fr;
  }
  .welcome-view .hero {
    grid-column: 1;
    grid-row: 1 / -1;
    height: 100%;
    min-height: clamp(310px, 42vw, 550px);
  }
  .welcome-view .lead {
    grid-column: 2;
    grid-row: 2;
    margin: 0 0 24px;
    max-width: 23em;
    color: var(--ink);
    font-size: clamp(19px, 2.2vw, 28px);
    line-height: 1.55;
    letter-spacing: -.045em;
  }
  .welcome-view .button { grid-column: 2; grid-row: 3; max-width: 23rem; }
  .welcome-view .previous-library { grid-column: 2; grid-row: 4; justify-self: start; }

  .library-view {
    grid-template-columns: minmax(0, 1.7fr) minmax(215px, .8fr);
    align-items: start;
  }
  .library-view .section-head { grid-column: 1; }
  .library-view .group-list { grid-column: 1; grid-row: 2; }
  .library-view .actions { grid-column: 2; grid-row: 2; margin-top: 0; }

  .draft-form { margin-top: 24px; }
  .draft-form:not(.has-selection) { max-width: 30rem; }
  .draft-form.has-selection {
    grid-template-columns: minmax(0, 1.6fr) minmax(215px, .84fr);
    align-items: start;
  }
  .draft-form .pick-row { margin-top: 0; }
  .draft-form .draft-photos { gap: 16px 12px; }
  .draft-form .draft-photos li { min-width: 0; }
  .draft-form .draft-filename {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .draft-form .draft-nav { margin-top: 8px; }
  .draft-form.has-selection .draft-details {
    padding: clamp(16px, 2vw, 28px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
  }
  .draft-details .field { margin-top: 0; }
  .import-status:empty { display: none; }

  .results-view.has-results {
    grid-template-columns: minmax(235px, .8fr) minmax(0, 1.3fr);
    grid-template-rows: auto 1fr;
    align-items: start;
    row-gap: 24px;
  }
  .result-summary { min-width: 0; }
  .result-summary > .meta { margin-bottom: 6px; overflow-wrap: anywhere; }
  .result-summary .actions { margin-bottom: 8px; }
  .result-files { grid-column: 2; grid-row: 1 / 3; min-width: 0; }
  .result-followup { grid-column: 1; }
  .results-view:not(.has-results) .result-followup { max-width: 26rem; margin-top: 24px; }

  #sheet-dialog, .file-dialog {
    width: min(35rem, calc(100% - 64px));
    max-height: calc(100dvh - 48px);
    padding: 16px 24px 22px;
  }
  #sheet-dialog, #photo-dialog {
    width: min(56rem, calc(100% - 64px));
  }
  .photo-viewer { --photo-height: min(68dvh, calc(100dvh - 16rem)); }
  #sheet-dialog .sheet-preview { max-height: min(62dvh, calc(100dvh - 17rem)); }
  .sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
  .sheet-actions .button { width: auto; min-width: 9rem; }
}

@media (min-width: 700px) and (min-height: 550px) and (orientation: portrait) {
  .welcome-view {
    grid-template-columns: minmax(0, 1.5fr) minmax(210px, 1fr);
    grid-template-rows: auto auto auto;
    align-items: start;
  }
  .welcome-view .hero {
    grid-column: 1 / -1;
    grid-row: 1;
    height: clamp(360px, 58svh, 760px);
    min-height: 0;
    margin-bottom: 26px;
  }
  .welcome-view .hero h1 { font-size: clamp(38px, 5.5vw, 58px); }
  .welcome-view .lead { grid-column: 1; grid-row: 2 / 4; margin: 0; }
  .welcome-view .button { grid-row: 2; max-width: none; }
  .welcome-view .previous-library { grid-row: 3; }
}

#photo-dialog.pick-gallery[open] {
  display: flex;
  flex-direction: column;
  width: min(100%, 90rem);
  max-width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  padding: max(4px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
           max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  border: 0;
  border-radius: 0;
  background: var(--well);
}
.pick-gallery .sheet-head { flex: none; min-width: 0; padding-bottom: 4px; }
.pick-gallery .sheet-head h2 {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
}
.pick-gallery .pick-zoom {
  flex: none;
  min-height: 44px;
  padding-inline: 8px;
  color: var(--muted);
  font-size: 14px;
}
.pick-gallery .photo-viewer { flex: 1; display: flex; flex-direction: column; min-height: 7rem; }
.pick-gallery .viewer-stage {
  flex: 1;
  position: relative;
  height: auto;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pick-gallery .viewer-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  -webkit-user-drag: none;
}
.pick-gallery .photo-navigation { flex: none; }
.pick-gallery .sheet-actions:not(:has(button:not([hidden]))) { display: none; }
