/* Base layout of Tectum: plain, without a build step. Colours and radii come from tokens.css. */
:root {
  font-family: var(--font-family);
  color: var(--text);
  background: var(--background);
  line-height: 1.5;
}

* { box-sizing: border-box; }
body { margin: 0; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
a { color: var(--accent); }

a.btn { text-decoration: none; }

.content { max-width: 64rem; margin: 2rem auto; padding: 0 1rem; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.5rem; margin-bottom: 1rem;
}
.card.narrow { max-width: 24rem; margin: 3rem auto; }

label { display: block; font-weight: 600; margin: .75rem 0 .25rem; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: .5rem .6rem; font: inherit;
  border: 1px solid var(--input-line); border-radius: var(--radius); background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Buttons tragen keine eigenen Abstände – für den Raum sorgen die Container (.buttons u. a.). */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; margin: 0; padding: .5rem 1rem; font: inherit; cursor: pointer;
  color: var(--on-accent); background: var(--accent); border: 1px solid var(--accent); border-radius: var(--radius);
}
.btn:hover { background: var(--accent-dark); }
.btn.secondary { color: var(--accent); background: transparent; }
.btn.secondary:hover { background: var(--background); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
/* quiet variant: reads as plain text, e.g. Abmelden in the header */
.btn.link { color: var(--muted); background: none; border: 0; padding: .25rem; }
.btn.link:hover { color: var(--accent); background: none; text-decoration: underline; text-underline-offset: .25em; }
/* destructive actions: red, set apart from the others */
.btn.danger { color: var(--bad); background: transparent; border-color: var(--bad); }
.btn.danger:hover { color: var(--on-accent); background: var(--bad); }

.error { color: var(--bad); margin: .25rem 0; }
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.message { padding: .6rem 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.message.success { border-color: var(--ok); }
.message.error { border-color: var(--bad); }

.status { font-weight: 600; }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.bad { color: var(--bad); }

/* Waiting animation while the worker is busy (preselection, release): three dots fading one after the other.
   The span is aria-hidden; the status text already announces itself through its role. */
.dots { display: inline-flex; gap: 3px; margin-left: .3rem; align-items: baseline; }
.dots i { width: .28em; height: .28em; border-radius: 50%; background: currentColor; animation: dots 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes dots { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; } }
.muted { color: var(--muted); }
code { font-size: .95em; }

/* Lists, forms, properties */
input[type=search], input[type=date], input[type=tel], input[type=number], input[type=url] {
  width: 100%; padding: .5rem .6rem; font: inherit;
  border: 1px solid var(--input-line); border-radius: var(--radius); background: var(--surface);
}
fieldset { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0 0; padding: .5rem 0 0; }
fieldset:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
legend { font-weight: 700; font-size: 1.05rem; padding: 0; }
label.choice { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.required { color: var(--bad); }
.help { color: var(--muted); font-size: .9em; margin-top: .2rem; }
.buttons { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }
/* Button direkt im Formular (ohne .buttons-Zeile): Abstand zum Inhalt oberhalb */
form > .btn { margin-top: 1rem; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.title-row h1, .title-row h2 { margin-bottom: .5rem; }
.title-row + dl.properties { margin-top: .75rem; }
/* a card that only carries the list of the page still gets a heading, but one the eye does not need */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.site-choice { margin-top: .5rem; }
.breadcrumbs { margin: 0 0 .25rem; color: var(--muted); }

table.list { width: 100%; border-collapse: collapse; margin-top: .75rem; }
table.list th, table.list td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: .9em; color: var(--muted); font-weight: 600; }
.version { margin: 2rem auto 1rem; text-align: center; color: var(--muted); font-size: .8rem; }
.picker { max-height: 20rem; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.list th.sortable { cursor: pointer; user-select: none; }
table.list th.sortable::after { content: " ↕"; color: var(--line); }
table.list th[aria-sort="ascending"]::after { content: " ↑"; color: var(--accent); }
table.list th[aria-sort="descending"]::after { content: " ↓"; color: var(--accent); }
table.list td.narrow { width: 1%; white-space: nowrap; }
/* A cell whose value is more than one element (badge + title, widget + error) wraps them in one box:
   on phones the cell is a two-column grid, and every further child would slide under the label. */
.cell { min-width: 0; overflow-wrap: anywhere; }

dl.properties { display: grid; grid-template-columns: minmax(10rem, max-content) 1fr; gap: .35rem 1.25rem; margin: 0; }
dl.properties dt { color: var(--muted); }
dl.properties dd { margin: 0; }
/* a status inside a property row is a value, not a chip in a sentence: the colour stays, the bold goes */
dl.properties .status { font-weight: inherit; }

.type-badge {
  display: inline-block; padding: 0 .4rem; border-radius: var(--radius); font-size: .85em; font-weight: 600;
  background: var(--background); border: 1px solid var(--line); white-space: nowrap;
}
.suggestion { display: flex; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.suggestion input[type=checkbox] { margin-top: .35rem; }
.suggestion .reason { color: var(--muted); margin: .1rem 0 0; }
.suggestion label { margin: 0; font-weight: 400; }
.search-bar { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.search-bar input[type=search] { flex: 1 1 18rem; width: auto; }
.search-bar select { width: auto; }
.search-bar label.choice { margin: 0; }
.preformatted { white-space: pre-line; }
ul.tasks { list-style: none; padding: 0; margin: 0; }
ul.tasks li { padding: .4rem 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: .25rem .75rem; }
ul.tasks li:last-child { border-bottom: 0; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }

/* Documents: review with a form per document */
.document h2 { margin: 0; }
.document-status { white-space: nowrap; }
.fields { display: grid; gap: .1rem; margin: .5rem 0; }
.field-row { display: grid; grid-template-columns: 1fr 11rem; gap: 0 1rem; align-items: end; padding: .15rem 0; }
.field-row label { display: grid; grid-template-columns: minmax(8rem, 14rem) 1fr; gap: 1rem; align-items: center; margin: .2rem 0; font-weight: 400; }
.field-row label > span { color: var(--muted); }
.field-row .error { grid-column: 1 / -1; }
.field-row.open input, .field-row.open select, .field-row.open textarea { border-color: var(--bad); }
.origin { font-size: .85em; color: var(--muted); padding-bottom: .55rem; }
.origin.missing { color: var(--bad); font-weight: 600; }
.origin-input { color: var(--accent); }
.fixed-value { padding: .5rem 0; }
.message.warning-box { border-color: var(--warn); }
.message form.inline { display: inline; }
.btn.small { font-size: .85em; padding: .25rem .5rem; }
form.discard { margin-top: .75rem; }
details summary { cursor: pointer; color: var(--accent); margin: .5rem 0; }
@media (max-width: 40rem) {
  .field-row, .field-row label { grid-template-columns: 1fr; gap: .25rem; }
  .origin { padding-bottom: 0; }
}
.origin-column { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; padding-bottom: .4rem; }
.origin-column .origin { padding-bottom: 0; }
.origin-cleared { color: var(--warn); }
.message.warning { border-color: var(--warn); }

.jump-list ul { list-style: none; padding: 0; margin: .5rem 0 0; columns: 2 18rem; column-gap: 1.5rem; }
.jump-list li { break-inside: avoid; padding: .15rem 0; }
.jump-list a { text-decoration: none; }
.jump-list label.choice { margin-top: 0; }
@media (max-width: 40rem) { .jump-list ul { columns: 1; } }

/* Photo inspection: progress, traffic lights, photo cards */
.progress { height: .6rem; background: var(--background); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s; }
.section-title { margin: 1.5rem 0 .75rem; }
.light { display: inline-block; width: .8em; height: .8em; border-radius: 50%; vertical-align: baseline; }
.light-red { --light: var(--light-red); --light-text: var(--on-accent); }
.light-yellow { --light: var(--light-yellow); --light-text: var(--on-light); }
.light-green { --light: var(--light-green); --light-text: var(--on-light); }
.light.light-red, .light.light-yellow, .light.light-green { background: var(--light); }
.light-label, select.light-select {
  display: inline-block; min-width: 4.2rem; padding: .1rem .4rem; border-radius: var(--radius); font-weight: 600;
  text-align: center; background: var(--light); color: var(--light-text); border: 1px solid var(--light);
}
select.light-select { width: auto; font: inherit; font-size: .9em; }
.photo-grid { display: grid; grid-template-columns: minmax(10rem, 18rem) 1fr; gap: 1.25rem; }
.photo-grid img { width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--line); }
.photo-grid h3 { margin: 0; }
.photo-texts label { font-weight: 400; color: var(--muted); margin: .4rem 0 .15rem; }
/* the observation is the main text on site: it starts at three lines and grows with its content instead of
   hiding the rest behind a scrollbar (browsers without field-sizing keep the three rows) */
.photo-texts textarea[name="observation"] { field-sizing: content; min-height: 5.5rem; }
ul.measures { list-style: none; padding: 0; margin: .75rem 0; }
li.measure { display: flex; gap: .75rem; align-items: flex-start; padding: .4rem 0; border-bottom: 1px solid var(--line); }
li.measure form { margin: 0; }
li.measure .measure-text { flex: 1; }
li.measure.removed .measure-text { text-decoration: line-through; color: var(--muted); }
li.measure.removed .measure-text .small { text-decoration: none; }
.small { font-size: .85em; }
.photo-actions { margin-top: .75rem; }
form.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; max-width: 100%; }
form.inline-form select { width: auto; max-width: 100%; min-width: 0; }
/* the shared field: search on the left, the traffic light and the own measure on the right */
.measure-add { margin: 1rem 0 .75rem; }
.measure-add input[type=search] { flex: 1 1 14rem; }
@media (max-width: 40rem) {
  .photo-grid { grid-template-columns: 1fr; }
  /* one measure per row: light and remove on top, the text below across the full width */
  li.measure { display: grid; grid-template-columns: 1fr auto; gap: .25rem .6rem; align-items: center; }
  li.measure > form:first-child, li.measure > .light-label { grid-column: 1; grid-row: 1; justify-self: start; }
  li.measure > form:last-child { grid-column: 2; grid-row: 1; justify-self: end; }
  li.measure .measure-text { grid-column: 1 / -1; grid-row: 2; }
  .photo-actions { gap: .5rem; }
}

/* Error of a background request (tectum.js); stays visible while scrolling */
.request-error { position: sticky; top: .5rem; z-index: 10; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.request-error[hidden] { display: none; }
.save-state { font-size: .85rem; }

/* Phones (on site): tables scroll on their own, larger touch targets; the header lives in header.css */
@media (max-width: 40rem) {
  .content { margin: 1rem auto; }
  .card { padding: 1rem; }
  /* data tables become cards: the label comes from data-label, so date and status stay visible */
  table.list, table.list tbody, table.list tr, table.list td { display: block; }
  table.list thead {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  table.list tr {
    padding: .4rem .75rem; margin-bottom: .75rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  }
  table.list td, table.list th { padding: .2rem 0; border: 0; }
  /* the label track is capped instead of max-content: the value column then has the same width in every
     table, and long labels wrap instead of pushing the values together */
  table.list td[data-label] { display: grid; grid-template-columns: minmax(5.5rem, 38%) minmax(0, 1fr); gap: .2rem .75rem; overflow-wrap: anywhere; hyphens: auto; }
  /* the label itself is never hyphenated or broken mid-word: only the value may wrap */
  table.list td[data-label]::before { content: attr(data-label); color: var(--muted); font-weight: 600; hyphens: none; overflow-wrap: normal; }
  table.list td.narrow { width: auto; white-space: normal; }
  table.list td[colspan] { display: block; }
  table.list td[colspan]::before { content: none; }
  dl.properties { grid-template-columns: 1fr; gap: 0; }
  dl.properties dd { margin-bottom: .4rem; }
  .btn, .btn.small, select, select.light-select { min-height: 2.75rem; }
  .btn.small { padding: .4rem .75rem; }
  /* Touch targets: every tappable line reaches 44 px, every field 16 px (below that iOS zooms into it) */
  details > summary, label.choice, input[type=search], input[type=file] { min-height: 2.75rem; }
  input[type=file]::file-selector-button { padding: .6rem .8rem; }
  input[type=checkbox], input[type=radio] { inline-size: 1.15rem; block-size: 1.15rem; }
  input, select, textarea, select.light-select { font-size: 1rem; }
  /* long values outside the tables (paths, codes, company names) must not push the card past the edge */
  dl.properties dd, .card p, .card li, code { overflow-wrap: anywhere; }
  .type-badge { white-space: normal; }
  /* a detail page puts its action on its own line, whatever the length of the title */
  .title-row { align-items: flex-start; }
  .title-row > .btn { flex: 1 1 100%; text-align: center; }
  .search-bar { display: grid; grid-template-columns: 1fr; gap: .5rem; }
  .search-bar input[type=search], .search-bar select { width: 100%; }
  .search-bar label.choice { margin: 0; }
  /* the field gets its own row; light and own measure share the next one instead of stacking three deep */
  form.measure-add { display: grid; grid-template-columns: auto 1fr; }
  form.measure-add input[type=search] { grid-column: 1 / -1; }
}

/* Photo upload: progress and failed files */
.upload-progress progress { width: 100%; margin-top: .75rem; }
.upload-failed { color: var(--bad); margin: .25rem 0; padding-left: 1.25rem; }

/* Print: protocols and lists on paper — no navigation, no controls, no clipped rows */
@media print {
  @page { margin: 1.5cm; }
  :root { color: black; background: white; }
  body { background: white; }
  a { color: black; text-decoration: none; }
  .version, .messages, .breadcrumbs, .request-error, .jump-list, .buttons,
  .photo-actions, .upload-progress, .save-state, .dots,
  .btn, button, input, select, textarea { display: none; }
  .content { max-width: none; margin: 0; padding: 0; }
  .card, .message, .picker, table.list, table.list th, table.list td { border-color: black; }
  .card, .message, .photo, .document, table.list tr { break-inside: avoid; }
  .photo-grid { grid-template-columns: minmax(5cm, 7cm) 1fr; gap: .75cm; }
  .light, .light-label, .type-badge { background: white; color: black; border: 1px solid black; }
  .muted, .help, .origin, .small { color: black; }
  h1, h2, h3 { break-after: avoid; }
}
