/* Mobil zuerst: Grundlayout fuer Handy, ab 700px breiter. */
:root {
  --bg: #f4f5f7; --surface: #fff; --text: #1d2330; --muted: #5e6675; --line: #d9dde3;
  --accent: #0b5cad; --accent-text: #fff; --danger: #b42318; --ok: #1f7a3d; --warn: #a15c00;
  --radius: 8px;
  /* Schreiben an Firmen (PDF/Mail) optisch getrennt von den Statusaktionen */
  --letter: #5b3cc4; --letter-bg: #f4f1fd; --letter-line: #d9d0f5;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
main { padding: 12px 16px 32px; max-width: 1100px; margin: 0 auto; }

.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 16px; background: var(--accent); color: var(--accent-text); }
.topbar a { color: var(--accent-text); text-decoration: none; }
.brand { font-weight: 700; }
.crumb { opacity: .9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.logout { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.who { font-size: .9rem; opacity: .9; }
button.link { background: none; border: 0; color: inherit; text-decoration: underline; font: inherit; cursor: pointer; padding: 0; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.narrow { max-width: 420px; margin: 24px auto; }
.muted { color: var(--muted); }
.error, .errorlist { color: var(--danger); }
.errorlist { margin: 4px 0; padding-left: 18px; }
.messages { list-style: none; padding: 0; margin: 0 0 12px; }
.messages li { padding: 10px 12px; border-radius: var(--radius); background: #e7f1fb; margin-bottom: 6px; }
.messages .msg-error { background: #fdecea; color: var(--danger); }
.messages .msg-success { background: #e8f5ec; color: var(--ok); }

/* Formulare: grosse Touch-Ziele */
label { display: block; margin-bottom: 10px; font-weight: 600; font-size: .95rem; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 10px; font: inherit; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
textarea { min-height: 90px; }
.btn { display: inline-block; min-height: 44px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }

.headrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: space-between; margin-bottom: 8px; }
.headrow h1 { margin: 0; }

/* Filter */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters label { margin: 0; font-size: .85rem; }
.filters .wide { grid-column: 1 / -1; }

/* Status */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e9ecf1; white-space: nowrap; }
.st-recorded { background: #e9ecf1; }
.st-notified { background: #fff1d6; color: var(--warn); }
.st-fix_reported { background: #e2edfb; color: var(--accent); }
.st-verified { background: #e3f4e8; color: var(--ok); }
.st-closed { background: #d7eedd; color: var(--ok); }
.st-cancelled { background: #f1f1f1; color: var(--muted); text-decoration: line-through; }
.overdue { color: var(--danger); font-weight: 700; }

/* Liste: Karten auf dem Handy */
.defects { list-style: none; padding: 0; margin: 0; }
.defects li a { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; color: inherit; text-decoration: none; }
.defects .no { font-weight: 700; grid-row: span 3; min-width: 2.5em; }
.defects .desc { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.defects .meta { font-size: .85rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 12px; }

.projects { list-style: none; padding: 0; margin: 0; }
.projects li a { display: block; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; color: inherit; text-decoration: none; }
.projects .counts { font-size: .9rem; color: var(--muted); }

/* Detail */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photos figure { margin: 0; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.photos figcaption { font-size: .75rem; color: var(--muted); }
.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.history .when { font-size: .8rem; color: var(--muted); }
.panel { border-left: 4px solid var(--accent); }
.htmx-request { opacity: .6; }

@media (min-width: 700px) {
  .filters { grid-template-columns: repeat(4, 1fr); }
  .filters .wide { grid-column: auto; }
  .detail-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; align-items: start; }
}

/* Projekt-Navigation */
.tabs { display: flex; gap: 4px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs a { padding: 10px 14px; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; font-weight: 600; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
main.wide { max-width: none; }
.small { font-size: .85rem; }
.notice { display: block; padding: 10px 12px; border-radius: var(--radius); background: #fff1d6; }

/* Planansicht */
.plan-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.plan-toolbar .btn { min-width: 44px; padding: 8px 12px; }
.plan-toolbar select { width: auto; margin: 0; }
.plan-toolbar form.inline { margin: 0; }
.pager-ctl, .zoom-ctl { display: inline-flex; gap: 4px; align-items: center; }
label.check { display: inline-flex; gap: 6px; align-items: center; margin: 0; font-weight: 400; }
label.check input { width: auto; margin: 0; }
.hint { margin: 0 0 6px; }
.plan-scroll { overflow: auto; max-height: calc(100vh - 230px); min-height: 300px; background: #e6e8ec; border: 1px solid var(--line); border-radius: var(--radius); position: relative; -webkit-overflow-scrolling: touch; }
.plan-stage { position: relative; margin: 0 auto; background: #fff; }
.plan-stage canvas { display: block; width: 100%; height: 100%; }
.pins { position: absolute; inset: 0; pointer-events: none; }
.pin { position: absolute; transform: translate(-50%, -50%); min-width: 28px; height: 28px; padding: 0 6px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; text-decoration: none; color: #fff; background: var(--warn); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); pointer-events: auto; }
.pin.st-recorded { background: #5e6675; }
.pin.st-notified { background: #c26b00; }
.pin.st-fix_reported { background: var(--accent); }
.pin.st-verified, .pin.st-closed { background: var(--ok); }
.pin.st-cancelled { background: #9aa0aa; }
.pin.hl { outline: 3px solid #e11d48; outline-offset: 2px; z-index: 2; }
.pin-new { background: #e11d48; pointer-events: none; z-index: 3; }
.plan-status { position: absolute; top: 12px; left: 12px; margin: 0; }
.pin-bar { position: sticky; bottom: 0; display: flex; gap: 8px; padding: 10px 0; background: var(--bg); }
.pin-bar .btn.primary { flex: 1; text-align: center; }
.pin-preview { display: block; padding: 10px 12px; margin-bottom: 10px; border-radius: var(--radius); background: #e7f1fb; }
.help { display: block; font-weight: 400; margin-top: 2px; }
.version-select { margin-bottom: 8px; } .version-select select { width: auto; }

/* Position im Plan (Erfassungsformular) */
fieldset.pin-picker { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; margin: 0 0 14px; }
fieldset.pin-picker legend { font-weight: 600; padding: 0 4px; }
.viewer.picker .plan-scroll { max-height: 60vh; min-height: 80px; }
.viewer.picker .pin { opacity: .75; }
.viewer.picker .pin-new { opacity: 1; }
.pin-info { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-top: 8px; }

/* Verwaltung: Zeilen mit Aktion rechts, kompakte Formulare */
.rows { list-style: none; padding: 0; margin: 0 0 12px; }
.rows li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rows form { margin: 0; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.inline-form { display: grid; gap: 4px 8px; align-items: center; }
.inline-form label { margin: 0; font-size: .85rem; }
.inline-form select, .inline-form input { margin: 0 0 6px; }
.topbar .nav { color: var(--accent-text); opacity: .9; }
fieldset.checks, fieldset.contact { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0 0 12px; }
fieldset.checks legend { font-weight: 600; padding: 0 4px; }
fieldset.checks label.check { margin: 4px 16px 4px 0; }
.grid2 { display: grid; gap: 0 12px; }
.subtabs { margin: -12px -16px 12px; }

/* Übersicht: Kennzahlen, Statusverteilung, Firmen */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.kpi { display: flex; flex-direction: column; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none; }
.kpi .num { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.kpi .lbl { font-size: .85rem; color: var(--muted); }
.kpi.alert { border-left-color: var(--danger); } .kpi.alert .num { color: var(--danger); }
.kpi.warn { border-left-color: var(--warn); } .kpi.warn .num { color: var(--warn); }
.kpi.todo { border-left-color: var(--accent); } .kpi.todo .num { color: var(--accent); }
.statusbar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: #e9ecf1; gap: 2px; }
.statusbar .seg { flex-basis: 0; min-width: 4px; }
.legend { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .9rem; }
.legend a { color: inherit; text-decoration: none; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: baseline; }
.seg.st-recorded, .dot.st-recorded { background: #5e6675; }
.seg.st-notified, .dot.st-notified { background: #c26b00; }
.seg.st-fix_reported, .dot.st-fix_reported { background: var(--accent); }
.seg.st-verified, .dot.st-verified { background: #57a773; }
.seg.st-closed, .dot.st-closed { background: var(--ok); }
.dot.st-cancelled { background: #9aa0aa; }
.by-company summary { font-weight: 600; cursor: pointer; }
.letters { list-style: none; padding: 0; margin: 0; }
.letters .actions { margin-bottom: 0; }
.notice-defects label.check { display: flex; align-items: flex-start; margin: 6px 0; }
.notice-defects label.check input { margin-top: 3px; }
.table-scroll { overflow-x: auto; margin-top: 8px; }
.by-company table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.by-company th, .by-company td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.by-company th:first-child, .by-company td:first-child { text-align: left; white-space: normal; }
.by-company th { color: var(--muted); font-weight: 600; }
@media (min-width: 700px) {
  .kpis { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
}
@media (min-width: 700px) {
  .inline-form { grid-template-columns: auto 1fr auto 1fr auto; }
  .inline-form.trade-add { grid-template-columns: auto 1fr auto; }
  .inline-form select, .inline-form input { margin: 0; }
  .grid2 { grid-template-columns: 1fr 1fr; }
}

/* Detailseite: Mangeltext als eigene Box, Aktionen in Gruppen */
.box-label, .group-label { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.defect-text { border-left: 4px solid var(--accent); }
.defect-text p { margin: 0; font-size: 1.1rem; line-height: 1.5; white-space: normal; overflow-wrap: anywhere; }
.action-group { margin: 12px 0; }
.action-group .actions { margin: 0; }
.letter-group { background: var(--letter-bg); border: 1px solid var(--letter-line); border-radius: var(--radius); padding: 10px 12px; }
.letter-group .group-label { color: var(--letter); }
.letter-group p { margin: 0 0 8px; }
.letter-group form { margin: 0; }
.btn.letter { background: var(--surface); border-color: var(--letter); color: var(--letter); }
.btn.letter:hover, .btn.letter:focus-visible { background: var(--letter); color: #fff; }

/* Fotofreigabe: Ampel (Farbe + Text, nie nur Farbe) */
.approval { display: inline-flex; align-items: flex-start; gap: 6px; font-size: .75rem; line-height: 1.3; margin-top: 2px; }
.approval .light { flex: none; width: 10px; height: 10px; margin-top: 2px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); }
.approval.green .light { background: #1f9d4c; }
.approval.yellow .light { background: #f2b705; }
.approval.red .light { background: #d92d20; }
.approval.red { color: var(--danger); }
.approval-summary { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 8px; }
.approval-summary .approval { font-size: .85rem; }
.topbar .count { display: inline-block; min-width: 1.4em; padding: 0 6px; border-radius: 999px; background: #fff; color: var(--accent); font-size: .8rem; font-weight: 700; text-align: center; }
.units li { align-items: flex-start; }
.unit-edit[open] { flex-basis: 100%; }
.unit-edit summary { list-style: none; }
.unit-add h3 { font-size: 1rem; margin: 0 0 8px; }
.inbox { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.inbox li { display: grid; gap: 12px; }
.inbox img { width: 100%; max-height: 60vh; object-fit: contain; background: #e6e8ec; border-radius: 6px; border: 1px solid var(--line); }
.inbox .decide { display: grid; gap: 8px; }
.inbox .decide form { margin: 0; }
@media (min-width: 700px) { .inbox li { grid-template-columns: 3fr 2fr; } }
