/* Form controls and protocol content */
input,
textarea,
select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: var(--inset-highlight);
  font-size: 16px;
}

textarea {
  min-height: 98px;
  resize: vertical;
}

/* Safari on iOS keeps a native intrinsic width for date and time inputs that
   width:100% cannot shrink: the field grows past its row and centres its value.
   Only visible on real Apple hardware, never in a Chromium browser. Dropping the
   native appearance makes them lay out like every other input; the date picker
   itself is unaffected, it is a platform control. */
input[type="date"],
input[type="datetime-local"],
input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
}

input[type="date"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value {
  text-align: left;
}

select {
  padding-right: 3.4rem;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--primary) 50%),
    linear-gradient(135deg, var(--primary) 50%, transparent 50%),
    linear-gradient(to right, var(--line), var(--line));
  background-position:
    calc(100% - 18px) calc(1.2rem),
    calc(100% - 12px) calc(1.2rem),
    calc(100% - 2.8rem) 50%;
  background-size:
    6px 6px,
    6px 6px,
    1px 60%;
  background-repeat: no-repeat;
}

.document-heading {
  padding: 1.5rem 1.6rem 0.6rem;
  background: linear-gradient(180deg, rgba(24, 52, 135, 0.06), transparent);
}
.document-kicker,
.document-heading p:first-child {
  margin: 0 0 0.35rem;
  color: var(--primary-deep);
  font-weight: 800;
}
.document-heading h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
}
.document-heading .document-note {
  max-width: 860px;
  margin-top: 0.8rem;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.5;
}

.protocol-page {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0.65rem 1.6rem 1.8rem;
}
.protocol-page-2 {
  border-top: 1px dashed rgba(127, 149, 171, 0.6);
  background: linear-gradient(180deg, rgba(24, 52, 135, 0.03), transparent);
}

fieldset {
  width: 100%;
  min-width: 0;
  margin: 1rem 0 2rem;
  padding: 0;
  border: 0;
}
legend {
  width: 100%;
  margin-bottom: 1rem;
  padding-bottom: 0.55rem;
  border-bottom: 2px solid var(--primary-deep);
  color: var(--primary-deep);
  font-size: 1.16rem;
  font-weight: 800;
}

.subheading {
  margin: 0.4rem 0 1rem;
  text-align: center;
  text-decoration: underline;
  font-weight: 700;
}

.form-row {
  margin: 0 0 1rem;
}
.numbered-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 2.1rem minmax(180px, 300px) 1fr;
  gap: 0.7rem;
  align-items: center;
}
.number {
  align-self: start;
  padding-top: 0.85rem;
  color: var(--primary-deep);
  font-weight: 800;
}
.label-text {
  font-weight: 700;
}
.textarea-row {
  align-items: start;
}
.textarea-row .label-text {
  padding-top: 0.85rem;
}

.split-row {
  grid-template-columns: 2.1rem 1fr 1fr;
  align-items: start;
}

.split-row label,
.stacked-fields label,
.signature-grid label,
.count-grid label,
.sample-meta label,
.map-grid label,
.compound-fields label {
  display: grid;
  gap: 0.4rem;
  color: var(--ink);
  font-weight: 700;
}

.continued-fieldset {
  margin-top: 0.5rem;
}
.count-row,
.compound-row,
.transport-row,
.map-row,
.sketch-row,
.signature-row {
  align-items: start;
}
.count-grid {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 0.8rem;
}
.count-grid .wide {
  grid-column: 1 / -1;
}
.compound-fields {
  display: grid;
  grid-template-columns: minmax(150px, 0.45fr) minmax(220px, 1fr);
  gap: 0.8rem;
}
.stacked-fields {
  grid-column: 2 / -1;
  display: grid;
  gap: 0.8rem;
}
.map-grid {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(140px, 1fr) minmax(
      140px,
      1fr
    );
  gap: 0.8rem;
  align-items: end;
}
.sketch-wrap {
  grid-column: 2 / -1;
}
.sketch-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.55rem;
  font-weight: 700;
}
#sketchCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1200 / 620;
  border: 2px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface-raised);
  box-shadow: var(--inset-ring);
  touch-action: none;
}
.hint {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}
.signature-grid {
  grid-column: 2 / -1;
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 0.8rem;
}

.samples-heading {
  display: grid;
  grid-template-columns: minmax(180px, 0.45fr) 1fr;
  gap: 1.5rem;
  align-items: start;
  padding-bottom: 1.25rem;
}
.sample-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.6rem 1rem;
}
.table-scroll {
  overflow: auto;
  padding: 0 1.1rem 1.5rem;
}
table {
  width: 100%;
  min-width: 1500px;
  border-collapse: collapse;
  table-layout: fixed;
}
th,
td {
  padding: 0.34rem;
  border: 1px solid var(--line-strong);
  vertical-align: top;
}
th {
  background: linear-gradient(180deg, var(--thead-from), var(--thead-to));
  color: var(--primary-deep);
  font-size: 0.82rem;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
  hyphens: auto;
}
td input,
td textarea,
td select {
  /* 44 px: the smallest target a wet or gloved finger hits reliably. */
  min-height: 44px;
  padding: 0.5rem;
  border: 0;
  border-radius: 8px;
  background-color: transparent;
  box-shadow: none;
}
td textarea {
  min-height: 74px;
}
.row-actions-column {
  width: 52px;
}

td input.air-computed {
  color: var(--primary-deep);
  font-weight: 700;
  background-color: var(--computed-bg);
  cursor: default;
}

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

/* KA6 horizons: one collapsible panel each instead of a 40-column table. */
.horizon-list {
  display: grid;
  gap: 0.75rem;
  padding: 0 1.6rem 1rem;
}

.horizon-panel {
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface-raised);
  overflow: hidden;
}

.horizon-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.8rem 0.9rem;
  background: linear-gradient(180deg, var(--thead-from), var(--thead-to));
  color: var(--primary-deep);
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.horizon-summary::-webkit-details-marker {
  display: none;
}

.horizon-summary::before {
  content: "▸";
  margin-right: 0.15rem;
  transition: transform 0.15s ease;
}

.horizon-panel[open] > .horizon-summary::before {
  transform: rotate(90deg);
}

.horizon-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.horizon-body {
  display: grid;
  gap: 1rem;
  padding: 0.9rem;
}

.horizon-group-title {
  margin: 0 0 0.55rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--line);
  color: var(--primary-deep);
  font-size: 0.86rem;
  font-weight: 800;
}

/* Steady-state ("Beharrungszustand") indicator of the water measurement series *

/* Validation dialog */
.validation-heading {
  margin: 1rem 0 0.4rem;
  font-size: 0.95rem;
}

.validation-heading.is-warning {
  color: var(--warn-ink);
}

.validation-list {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.35rem;
  font-size: 0.88rem;
  line-height: 1.4;
}

.validation-jump {
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary-deep);
  font: inherit;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
}

.validation-note {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.validation-note.is-ok {
  color: var(--ok-ink);
  font-weight: 700;
}

/* Field highlighted from the validation dialog */
.is-flagged {
  outline: 3px solid var(--danger);
  outline-offset: 2px;
}

.air-check-cell input[type="checkbox"] {
  /* Deliberately large: this is a yes/no tapped in the field, often with wet
     gloves, and it decides whether a sample counts as taken. */
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  accent-color: var(--primary-deep);
}

/* Mode-specific protocol controls */
.mode-control,
.gps-panel {
  grid-column: 3;
}

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

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

.gps-panel {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, var(--surface), var(--panel-alt));
}

.gps-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.gps-actions .button {
  flex: 0 0 auto;
}

.gps-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.gps-grid label {
  display: grid;
  gap: 0.4rem;
  color: var(--ink);
  font-weight: 700;
}

.privacy-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

/* Water sampling protocol */
.water-page {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: grid;
  gap: 0.25rem;
}

.water-form-grid,
.measurement-grid {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.water-field,
.measurement-grid label,
.water-signature-grid label {
  min-width: 0;
  display: grid;
  gap: 0.4rem;
  color: var(--ink);
  font-weight: 700;
}

.water-field-wide {
  grid-column: 1 / -1;
}

.measurement-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.sensory-grid {
  margin-top: 0.5rem;
}

.water-detail-panel {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, var(--surface), var(--panel-alt));
}

.water-detail-panel h3 {
  margin: 0 0 0.9rem;
  color: var(--primary-deep);
  font-size: 1rem;
}

.water-detail-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.water-signature-grid {
  grid-column: auto;
  margin-top: 1rem;
}

#appShell[data-active-pnp-type="water"] .tabbar {
  grid-template-columns: 1fr;
}

/* Water measurement time series */
.water-table-hint {
  margin-bottom: 0.75rem;
}

.water-table-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  padding: 0 0 0.35rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-raised);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
  contain: inline-size;
}

.water-data-table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  table-layout: fixed;
}

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

.water-data-table th {
  padding: 0.58rem 0.42rem;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, var(--thead-from), var(--thead-to));
  color: var(--primary-deep);
  font-size: 0.76rem;
  line-height: 1.2;
  text-align: center;
  vertical-align: middle;
}

.water-data-table td {
  padding: 0.25rem;
  border: 1px solid var(--line-strong);
  background: var(--surface-raised);
  vertical-align: middle;
}

.water-data-table td input,
.water-data-table td select {
  min-height: 44px;
  padding: 0.48rem 0.5rem;
  border: 0;
  border-radius: 7px;
  background-color: transparent;
  box-shadow: none;
}

.water-data-table td input:focus,
.water-data-table td select:focus {
  background-color: var(--surface-raised);
}

.water-time-cell {
  min-width: 108px;
  color: var(--primary-deep);
  font-weight: 800;
  text-align: center;
}

/* The measurement table is about 1160 px wide and has to scroll sideways on a
   phone. Without a pinned first column the pump time - the only thing that says
   WHICH reading a cell belongs to - scrolls out of sight, and the sampler ends
   up typing into an unlabelled cell. Both the header cell and the body cell of
   the first column stay put; they need an opaque background so the columns
   passing underneath do not show through. */
.water-measurement-table th:first-child,
.water-measurement-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
}

.water-measurement-table td:first-child {
  background: var(--surface-raised);
  box-shadow: 1px 0 0 var(--line-strong);
}

.water-measurement-table th:first-child {
  z-index: 4;
}

.water-time-cell select {
  min-width: 100px;
  font-weight: 750;
}

.water-sensory-section {
  margin-top: 1.15rem;
}

/* Read-only computed cell (corrected redox potential) */
.water-data-table td input.water-computed {
  color: var(--primary-deep);
  font-weight: 750;
  background-color: var(--computed-bg);
  cursor: default;
}

/* Pump start / stop capture controls */
.water-pump-times {
  margin-bottom: 1rem;
}

.water-pump-label {
  color: var(--ink);
  font-weight: 700;
}

.pump-time-control {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.pump-time-control input {
  flex: 1 1 auto;
  min-width: 0;
}

.pump-time-control .button {
  flex: 0 0 auto;
  padding-inline: 1rem;
}

/* CSV export of the last measurement row */
.water-csv-export {
  margin-top: 0.9rem;
  display: grid;
  gap: 0.4rem;
}

.water-csv-export .hint {
  margin: 0;
}

legend,
label,
.label-text,
.document-heading,
.document-note,
.water-field,
.water-detail-panel,
.gps-panel {
  min-width: 0;
  overflow-wrap: anywhere;
}

.gps-actions .button.is-capturing {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

/* Running pump time. Reads as a stopwatch, not as a form field. */
.pump-runtime {
  margin: 0.15rem 0 0.9rem;
  color: var(--primary-deep);
  font-size: 1.28rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.pump-runtime.is-running::after {
  content: "";
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-left: 0.5rem;
  border-radius: 50%;
  background: var(--danger);
  vertical-align: middle;
}

.water-row-add {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
  padding: 0.9rem 1.6rem 0;
}

.water-row-add .hint {
  margin: 0;
}

/* Row editor: the eleven values of one reading, underneath each other instead
   of across a table 3.7 screen widths wide. */
.measurement-editor-card {
  display: flex;
  flex-direction: column;
  max-height: 92vh;
}

.measurement-editor-body {
  overflow-y: auto;
  display: grid;
  gap: 0.7rem;
  padding: 0.2rem 0 0.9rem;
}

.measurement-editor-field {
  display: grid;
  gap: 0.3rem;
  font-weight: 700;
}

.measurement-editor-field span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

/* The three buttons stay reachable with the thumb while the list scrolls. */
.measurement-editor-actions {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.6rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}

.measurement-dialog .pump-runtime {
  margin: 0 0 0.5rem;
}

/* Opens the row editor. Fills the whole cell, so the whole row is the target. */
.row-edit-button {
  width: 100%;
  min-height: 44px;
  margin-top: 0.3rem;
  padding: 0.3rem;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface-sunken, var(--surface-raised));
  color: var(--primary-deep);
  font-size: 0.8rem;
  font-weight: 800;
}
