:root {
  --bg: #f4f6f8; --surface: #fff; --text: #0b1c2b; --muted: #5a6a78; --line: #dce4ea; --line-strong: #b9c6d0;
  --brand: #0e7aab; --brand-dark: #0a5f86; --brand-soft: #e8f3f8;
  --warn: #b3261e; --warn-soft: #fdecea; --ok: #1b6e3c; --ok-soft: #e6f4ea;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 1rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--brand-dark); }
h1 { font-size: 1.5rem; margin: 0; font-weight: 650; }
h2 { font-size: 1rem; margin: 0 0 .7rem; font-weight: 650; }
.muted { color: var(--muted); }
.warntext { color: var(--warn); font-weight: 600; }
code { font: .87rem ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); padding: .1rem .3rem; border-radius: 4px; word-break: break-all; }

.top { display: flex; align-items: center; gap: 1.5rem; padding: .7rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.top nav { display: flex; gap: .25rem; flex: 1; }
.top nav a { padding: .35rem .7rem; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 550; }
.top nav a[aria-current] { background: var(--brand-soft); color: var(--brand-dark); }
.who { display: flex; align-items: center; gap: .9rem; color: var(--muted); font-size: .9rem; }

main { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }
main.medium { max-width: 860px; }
main.narrow { max-width: 400px; padding-top: 12vh; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; flex-wrap: wrap; }
.crumb { margin: 0 0 .5rem; font-size: .9rem; }
.meta { margin: -.5rem 0 1rem; font-size: .9rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.stack > * + * { margin-top: 1rem; }

button, .button { font: inherit; font-weight: 550; padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.4; }
button:hover, .button:hover { border-color: var(--brand); }
button.primary, .button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--brand-dark); }
button.link { border: 0; background: none; padding: 0; color: var(--brand-dark); text-decoration: underline; font-weight: 400; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

label { display: block; font-size: .87rem; font-weight: 600; color: var(--muted); }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; font: inherit; color: var(--text); padding: .45rem .6rem; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 650; padding: 0; margin-bottom: .6rem; }
fieldset > * + * { margin-top: .8rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.actions { display: flex; gap: .6rem; }
.login label + label, .login button { margin-top: .9rem; }
.login h1 { margin-bottom: .2rem; }

.flash { padding: .6rem .9rem; border-radius: 6px; margin: 0 0 1rem; background: var(--ok-soft); color: var(--ok); font-weight: 550; }
.flash.err { background: var(--warn-soft); color: var(--warn); }

.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .9rem; }
.tabs a { padding: .35rem .7rem; border-radius: 999px; text-decoration: none; color: var(--muted); background: var(--surface); border: 1px solid var(--line); font-weight: 550; font-size: .92rem; }
.tabs a[aria-current] { background: var(--brand); border-color: var(--brand); color: #fff; }
.count { font-variant-numeric: tabular-nums; opacity: .8; margin-left: .15rem; }
.count.warn { color: var(--warn); opacity: 1; font-weight: 700; }
.tabs a[aria-current] .count.warn { color: #fff; }
.filter { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter input, .filter select { margin: 0; width: auto; }
.filter input[type=search] { flex: 1; min-width: 200px; }

.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.list th { text-align: left; font-size: .8rem; font-weight: 650; color: var(--muted); padding: .6rem .8rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: .65rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list tr.due td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.list .num { color: var(--muted); font-variant-numeric: tabular-nums; }
table.list.plain { margin-bottom: 1rem; }
table.list.plain td, table.list.plain th { padding-left: 0; }
.rowlink { font-weight: 650; text-decoration: none; }
.rowlink:hover { text-decoration: underline; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 650; white-space: nowrap; background: var(--bg); color: var(--muted); }
.badge.big { font-size: .9rem; padding: .25rem .8rem; }
.s-neu { background: #e6f1fb; color: #0c447c; }
.s-in_klaerung { background: #faeeda; color: #633806; }
.s-angebot_gesendet { background: #eeedfe; color: #3c3489; }
.s-gewonnen { background: var(--ok-soft); color: var(--ok); }
.s-verloren { background: #eceff1; color: #4a5a68; }

.cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; align-items: start; }
.statusbuttons { display: flex; flex-wrap: wrap; gap: .5rem; }
.lost { display: flex; gap: .5rem; margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--line); }
.lost input { margin: 0; }
.inline { display: flex; gap: .6rem; flex-wrap: wrap; }
.inline input, .inline select { margin: 0; width: auto; }
.inline input[type=text] { flex: 1; min-width: 200px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .5rem 0 .5rem .9rem; border-left: 2px solid var(--line); }
.timeline li.k-notiz { border-left-color: var(--brand); }
.timeline li.k-status { border-left-color: #7f77dd; }
.timeline p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline span { font-size: .82rem; }
.raw { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: .9rem; margin: 0; background: var(--bg); padding: .7rem; border-radius: 6px; max-height: 320px; overflow-y: auto; }
.extra { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .3rem .9rem; font-size: .9rem; }
.extra dt { color: var(--muted); }
.extra dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.quick { display: flex; gap: .6rem; margin: 0 0 1rem; flex-wrap: wrap; }
.lbl { display: none; }
main { padding-left: max(1.25rem, env(safe-area-inset-left)); padding-right: max(1.25rem, env(safe-area-inset-right)); padding-bottom: max(1.25rem, env(safe-area-inset-bottom)); }
.top { padding-left: max(1.25rem, env(safe-area-inset-left)); padding-right: max(1.25rem, env(safe-area-inset-right)); padding-top: max(.7rem, env(safe-area-inset-top)); }

/* Handy und schmale Fenster */
@media (max-width: 820px) {
  html { font-size: 16px; -webkit-text-size-adjust: 100%; }
  /* Unter 16 px vergrößert iOS die Seite beim Antippen eines Feldes. */
  input, select, textarea { font-size: 16px; min-height: 44px; }
  button, .button { min-height: 44px; padding: .6rem 1rem; display: inline-flex; align-items: center; justify-content: center; }
  button.link { min-height: 44px; padding: 0 .2rem; }
  main, .top { padding-left: max(.9rem, env(safe-area-inset-left)); padding-right: max(.9rem, env(safe-area-inset-right)); }
  main.narrow { padding-top: 6vh; }
  .top { gap: .5rem; position: sticky; top: 0; z-index: 5; }
  .top nav a { padding: .6rem .7rem; }
  .who span { display: none; }
  h1 { font-size: 1.3rem; }
  .cols, .grid2 { grid-template-columns: 1fr; }
  .card { padding: 1rem; }
  .head .button { flex: none; }

  .tabs { flex-wrap: nowrap; overflow-x: auto; margin: 0 -.9rem .9rem; padding: 0 .9rem .2rem; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: none; padding: .55rem .9rem; }
  .filter input[type=search] { flex: 1 1 100%; }
  .filter select { flex: 1; min-width: 0; }

  /* Die Tabelle wird zu einer Liste antippbarer Karten. */
  .tablewrap { background: none; border: 0; overflow: visible; }
  table.cards, table.cards tbody { display: block; }
  table.cards thead { display: none; }
  table.cards tr { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .25rem .75rem; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: .6rem; }
  table.cards tr.due { border-left: 4px solid var(--warn); }
  table.cards td { display: block; padding: 0; border: 0; box-shadow: none !important; min-width: 0; overflow-wrap: anywhere; }
  table.cards .c-num { display: none; }
  table.cards .c-who { grid-column: 1; grid-row: 1; }
  table.cards .c-status { grid-column: 2; grid-row: 1; text-align: right; }
  table.cards .c-what, table.cards .c-next, table.cards .c-in, table.cards .c-src { grid-column: 1 / -1; }
  table.cards .c-next:not(:has(.lbl)) { display: none; }
  table.cards .lbl { display: inline; color: var(--muted); }
  table.cards .c-in, table.cards .c-src { font-size: .85rem; color: var(--muted); }
  table.cards .c-in br, table.cards .c-src br { display: none; }
  table.cards .c-in span::before, table.cards .c-src span::before { content: " · "; }
  table.cards .rowlink { font-size: 1.05rem; }
  table.cards .rowlink::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }

  /* Detailseite: zuerst Status und Notiz, dann die Felder, zuletzt Verlauf und Rohfassung. */
  .cols { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
  .side { display: contents; }
  .o-status { order: 1; } .o-note { order: 2; } .o-form { order: 3; } .o-log { order: 4; } .o-raw { order: 5; }
  .statusbuttons form, .statusbuttons button { flex: 1 1 auto; width: 100%; }
  .statusbuttons form { width: auto; }
  .quick .button { flex: 1; }
  .actions button, .actions .button { flex: 1; }
  .lost { flex-wrap: wrap; }
  .lost input { flex: 1 1 60%; }
  .inline input[type=text] { flex: 1 1 100%; }
  table.list.plain { display: block; overflow-x: auto; }
}
