/* Tablet and phone layouts */
@media (max-width: 980px) {
  .count-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .toolbar {
    /* Not sticky on phones, but still positioned: the action menu panel is
       absolutely positioned against the toolbar. */
    position: relative;
  }

  .numbered-row,
  .split-row {
    grid-template-columns: 2rem minmax(0, 1fr);
  }

  .numbered-row > .label-text,
  .numbered-row > input,
  .numbered-row > textarea,
  .numbered-row > select,
  .numbered-row > .compound-fields,
  .split-row label,
  .count-grid,
  .stacked-fields,
  .map-grid,
  .sketch-wrap,
  .signature-grid,
  .compound-fields,
  .mode-control,
  .gps-panel {
    grid-column: 2;
  }

  .map-grid,
  .compound-fields,
  .gps-grid,
  .measurement-grid,
  .water-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .signature-grid,
  .samples-heading {
    grid-template-columns: 1fr;
  }

  #appShell[data-active-mode="standard"] .standard-single-row {
    grid-template-columns: 2rem minmax(0, 1fr);
  }
}

@media (max-width: 700px) {
  .mode-selector {
    place-items: start center;
    padding: 0;
    background: linear-gradient(180deg, var(--surface) 0%, var(--bg-accent) 100%);
  }

  .mode-panel {
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(0.7rem, env(safe-area-inset-top)) 1rem
      max(0.9rem, env(safe-area-inset-bottom));
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .mode-panel-header,
  .app-header {
    gap: 0.6rem;
  }

  .brand-logo-large,
  .header-logo {
    width: 112px;
    max-width: 100%;
    margin-left: auto;
  }

  .mode-panel-header h1,
  .app-header h1 {
    max-width: none;
    margin: 0.15rem 0 0;
    line-height: 1.14;
  }

  .mode-panel-header h1 {
    font-size: clamp(1.3rem, 5vw, 1.6rem);
  }

  .app-header h1 {
    font-size: clamp(1.1rem, 4.2vw, 1.35rem);
  }

  .subtitle {
    max-width: 36rem;
    margin: 0.4rem 0 0;
    font-size: 0.98rem;
    line-height: 1.42;
  }

  .status-group {
    display: grid;
    gap: 0.4rem;
    margin-top: 0.3rem;
    padding: 0.4rem 0.5rem;
  }

  /* Every line counts on a phone. The whole card is the button, so the action
     pill ("Bereich auswählen") is dropped and a chevron carries the affordance
     instead. That saves about 60 px per card, which is what makes all three
     cards fit on one screen without scrolling. */
  .mode-card {
    position: relative;
    min-height: 0;
    gap: 0.3rem;
    padding: 0.85rem 2.2rem 0.85rem 0.95rem;
    border-radius: 16px;
  }

  .mode-card-action {
    display: none;
  }

  .mode-card::after {
    content: "›";
    position: absolute;
    top: 50%;
    right: 0.85rem;
    transform: translateY(-50%);
    color: var(--primary);
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
  }

  .mode-card strong {
    font-size: 1.15rem;
  }

  .mode-card-kicker {
    font-size: 0.68rem;
  }

  .mode-card > span:not(.mode-card-kicker):not(.mode-card-action) {
    font-size: 0.88rem;
    line-height: 1.35;
  }

  .mode-privacy {
    margin-top: 0.7rem;
    font-size: 0.78rem;
  }



  .mode-grid {
    grid-template-columns: 1fr;
    gap: 0.8rem;
    margin-top: 1rem;
  }

  .mode-card {
    min-height: 0;
    gap: 0.45rem;
    padding: 1rem 1.05rem;
  }

  .mode-card strong {
    font-size: 1.45rem;
  }

  .mode-card-action {
    margin-top: 0.25rem;
  }

  .mode-privacy {
    margin-top: 0.8rem;
  }

  .app-header {
    min-height: 0;
    padding: max(0.6rem, env(safe-area-inset-top)) 1rem 0.6rem;
  }

  .tabbar {
    padding-top: 0.55rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab {
    white-space: nowrap;
  }

  /* Wide measurement tables scroll inside their own container and never
     increase the page width. */
  .water-table-scroll {
    margin-inline: 0;
    border-radius: 12px;
  }

  .water-data-table {
    display: table;
    width: 100%;
    min-width: 1120px;
  }

  .water-measurement-table {
    min-width: 1160px;
  }

  .water-summary-table {
    min-width: 1040px;
  }

  .water-data-table thead {
    display: table-header-group;
  }

  .water-data-table tbody {
    display: table-row-group;
  }

  .water-data-table tr {
    display: table-row;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .water-data-table th,
  .water-data-table td {
    display: table-cell;
    width: auto;
    border: 1px solid var(--line-strong);
  }

  .water-data-table td::before {
    content: none;
  }
}

@media (max-width: 620px) {
  main {
    padding: 0.75rem 0.75rem 1.5rem;
  }

  .view {
    width: 100%;
    max-width: 100%;
    border: 1px solid rgba(127, 149, 171, 0.32);
    border-radius: 16px;
  }

  .document-heading {
    padding: 1.1rem 1rem 0.45rem;
  }

  .document-heading h1 {
    font-size: 1.55rem;
    line-height: 1.12;
  }

  .document-heading .document-note {
    margin-top: 0.55rem;
    font-size: 0.86rem;
  }

  .protocol-page {
    padding: 0.5rem 1rem 1.25rem;
  }

  fieldset {
    margin: 0.85rem 0 1.5rem;
  }

  legend {
    margin-bottom: 0.8rem;
    font-size: 1.08rem;
    line-height: 1.25;
  }

  .water-form-grid,
  .measurement-grid,
  .water-detail-grid,
  .water-signature-grid,
  .sample-meta,
  .count-grid,
  .map-grid,
  .compound-fields,
  .gps-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .water-field-wide {
    grid-column: auto;
  }

  .water-field,
  .water-signature-grid label,
  .split-row label,
  .stacked-fields label,
  .count-grid label,
  .map-grid label,
  .compound-fields label {
    font-size: 0.95rem;
  }

  input,
  textarea,
  select {
    min-height: 46px;
    padding: 0.72rem 0.78rem;
    border-radius: 11px;
  }

  textarea {
    min-height: 88px;
  }

  .toolbar {
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
  }

  .toolbar-primary {
    flex: 1 1 auto;
    min-height: 50px;
    padding-inline: 0.8rem;
    font-size: 0.96rem;
  }

  .toolbar-menu-toggle {
    min-width: 104px;
    min-height: 50px;
    padding-inline: 0.75rem;
  }

  .toolbar-menu-panel {
    width: min(350px, calc(100vw - 1.5rem));
  }

  .sketch-label {
    align-items: flex-start;
    flex-direction: column;
  }

  .sketch-label .button {
    flex: 0 0 auto;
    width: auto;
  }

  .table-scroll {
    padding-inline: 0.7rem;
    overflow: visible;
  }

  .horizon-list {
    padding-inline: 0.7rem;
  }

  /* The solid and air tables become card lists on phones. */
  #sampleTable,
  #sampleTable tbody,
  #sampleTable tr,
  #sampleTable td,
  #airMeasurementTable,
  #airMeasurementTable tbody,
  #airMeasurementTable tr,
  #airMeasurementTable td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  #sampleTable thead,
  #airMeasurementTable thead {
    display: none;
  }

  #sampleTable tr,
  #airMeasurementTable tr {
    margin-bottom: 1rem;
    padding: 0.45rem;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    background: var(--surface-raised);
    box-shadow: 0 8px 18px rgba(35, 48, 61, 0.05);
  }

  #sampleTable td,
  #airMeasurementTable td {
    display: grid;
    grid-template-columns: minmax(112px, 0.7fr) minmax(0, 1fr);
    align-items: start;
    gap: 0.5rem;
    padding: 0.45rem;
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  #sampleTable td::before,
  #airMeasurementTable td::before {
    content: attr(data-label);
    padding-top: 0.55rem;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 800;
    overflow-wrap: anywhere;
    hyphens: auto;
  }

  #sampleTable td:last-child,
  #airMeasurementTable td:last-child {
    border-bottom: 0;
  }

  .air-check-cell {
    text-align: left;
  }

  .row-actions-column {
    width: auto;
  }

  .gps-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .gps-actions .button {
    width: 100%;
  }

  #appShell[data-active-mode="standard"] .count-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .water-detail-panel {
    padding: 0.85rem;
    border-radius: 14px;
  }

  .selector-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .pdf-dialog {
    width: calc(100vw - 1rem);
    max-height: calc(100dvh - 1rem);
  }
}

@media (max-width: 420px) {
  .brand-logo-large,
  .app-header .header-logo {
    width: 96px;
  }

  .mode-panel-header h1 {
    font-size: 1.3rem;
  }

  /* Very narrow devices: tighter cards, so that the template screen still fits
     three cards plus the back button without scrolling. */
  .mode-card {
    padding: 0.6rem 2rem 0.6rem 0.75rem;
    gap: 0.2rem;
  }

  .mode-card strong {
    font-size: 1.05rem;
  }

  .mode-card > span:not(.mode-card-kicker):not(.mode-card-action) {
    font-size: 0.82rem;
  }

  .mode-grid {
    gap: 0.5rem;
  }

  .app-header h1 {
    font-size: 1.12rem;
  }

  .subtitle {
    font-size: 0.94rem;
  }

}

@media (max-width: 700px) {





}

@media (max-width: 430px) {

}
