/* ============================================================
   Wohnungsübergabeprotokoll – screen + print styles
   ============================================================ */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1c1f26;
  --ink-soft: #5a6272;
  --line: #dfe3ea;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --danger: #c8392b;
  --ok: #1f8a5b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 900px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
}
.brand { font-weight: 650; margin-right: auto; white-space: nowrap; }
.brand span { display: none; }
@media (min-width: 560px) { .brand span { display: inline; } }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.save-state { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 8px; padding: 8px 13px; font: inherit; font-size: 14px; font-weight: 550;
  cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: #f7f8fa; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #2560d8; }

.lang-select {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  border-radius: 8px; padding: 8px 9px; font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; text-align: center;
}
.lang-select:hover { background: #f7f8fa; color: var(--ink); }

.icon-btn {
  appearance: none; border: 1px solid transparent; background: transparent; color: var(--ink-soft);
  border-radius: 7px; width: 30px; height: 30px; font-size: 15px; line-height: 1;
  cursor: pointer; flex: none;
}
.icon-btn:hover { background: #eef0f4; color: var(--ink); }
.icon-btn.danger:hover { background: #fdecea; color: var(--danger); }

/* ---------- Overflow menu ---------- */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 24, 40, .12); padding: 6px; min-width: 240px;
}
.menu-item {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 9px 10px; border-radius: 7px; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink);
}
.menu-item:hover { background: #f2f4f8; }
.menu-item.danger { color: var(--danger); }

/* ---------- Layout ---------- */
.wrap { max-width: 900px; margin: 0 auto; padding: 20px 16px 96px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px;
}
.card > h2, .card-head h2 { font-size: 16px; }
.card-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card > h2 { margin-bottom: 12px; }
.hint { font-size: 12.5px; color: var(--ink-soft); }
.footnote { font-size: 12.5px; color: var(--ink-soft); text-align: center; margin: 24px 8px 0; }

/* ---------- Fields ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span2 { grid-column: 1 / -1; }
@media (max-width: 560px) { .grid { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 550; color: var(--ink-soft); }

input[type="text"], input:not([type]), input[type="date"], input[type="time"],
input[type="number"], textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
}
textarea { resize: vertical; min-height: 44px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
::placeholder { color: #a3aab8; }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block; padding: 8px 14px; font-size: 13.5px; font-weight: 550; cursor: pointer;
  border-right: 1px solid var(--line); color: var(--ink-soft); user-select: none;
}
.segmented label:last-child span { border-right: 0; }
.segmented input:checked + span { background: var(--accent); color: #fff; }
.segmented.status input[value="ok"]:checked + span { background: var(--ok); color: #fff; }
.segmented.status input[value="defects"]:checked + span { background: #b8791b; color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (max-width: 480px) {
  .segmented span { padding: 8px 9px; font-size: 12.5px; }
}

/* ---------- Rooms ---------- */
.rooms { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }

.room { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow: hidden; }
.room-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 4px; background: #fafbfc; }
.room-head-actions { display: flex; align-items: center; gap: 2px; }
.room-name { border: 1px solid transparent !important; background: transparent; font-weight: 600; flex: 1; min-width: 0; }
.room-name:hover { background: #fff; border-color: var(--line) !important; }
.badge {
  font-size: 11.5px; color: var(--ink-soft); background: #eef0f4;
  border-radius: 20px; padding: 3px 9px; white-space: nowrap;
}
.badge:empty { display: none; }
.room-body { padding: 14px; display: flex; flex-direction: column; gap: 14px; border-top: 1px solid var(--line); }
.room.collapsed .room-body { display: none; }
.room.collapsed [data-act="toggle"] { transform: rotate(-90deg); }

/* ---------- Photos ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.photos:empty { display: none; }

.photo { margin: 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: #fff; }
.photo-img { aspect-ratio: 4 / 3; background: #eceff3; }
.photo-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Text kommt aus der Übersetzung, damit er der UI-Sprache folgt. */
.photo.missing .photo-img::after {
  content: attr(data-missing); display: flex; height: 100%;
  align-items: center; justify-content: center; text-align: center;
  font-size: 12px; color: var(--danger); padding: 8px;
}
.photo-caption { border: 0 !important; border-top: 1px solid var(--line) !important; border-radius: 0; font-size: 13px; padding: 8px 10px; }
.photo-actions { display: flex; gap: 2px; padding: 4px 6px; border-top: 1px solid var(--line); background: #fafbfc; }
.photo-actions .icon-btn:last-child { margin-left: auto; }

.photo-add {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px dashed #c2c9d6; border-radius: 9px; padding: 14px; cursor: pointer;
  font-size: 14px; font-weight: 550; color: var(--ink-soft); background: #fbfcfd;
}
.photo-add:hover { border-color: var(--accent); color: var(--accent); background: #f4f8ff; }

/* ---------- Add row / presets ---------- */
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; min-width: 0; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.preset {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  border-radius: 20px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.preset:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Repeating rows (meters, keys) ---------- */
.rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; min-width: 0; }
.row input.narrow { flex: 0 0 100px; }
@media (max-width: 560px) {
  .row { flex-wrap: wrap; }
  .row input { flex: 1 1 100%; }
  .row input.narrow { flex: 1 1 100%; }
}

/* ---------- Preview mode ---------- */
body.preview .no-print { display: none; }
body.preview #previewBar { display: flex; }
.preview-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  display: none; gap: 10px; justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .94); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
}
body.preview .doc {
  display: block; margin: 24px auto 100px; background: #fff; max-width: 800px;
  padding: 28px; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ============================================================
   DOCUMENT
   ============================================================ */
.doc { display: none; color: #000; font-size: 11pt; line-height: 1.45; }
.doc h1 { font-size: 17pt; margin-bottom: 1mm; }
.doc h1.alt-title { font-size: 12.5pt; font-weight: 500; color: #444; margin-bottom: 2mm; }
.doc h2 {
  font-size: 12pt; margin: 7mm 0 2.5mm;
  border-bottom: 1.2pt solid #000; padding-bottom: 1.2mm;
  display: flex; align-items: baseline; justify-content: space-between; gap: 4mm;
}
.doc .subtitle { font-size: 10.5pt; color: #333; margin-bottom: 5mm; }

/* Zweite Sprache: kleiner, grau, immer der ersten untergeordnet. */
.doc .alt { font-weight: 400; font-size: .82em; color: #666; }
.doc h2 .alt { text-align: right; }
.doc dt .alt, .doc th .alt { display: block; line-height: 1.25; }
.doc .alt-block { color: #555; font-size: .9em; margin-top: 1mm; }

.doc dl.kv { display: grid; grid-template-columns: 52mm 1fr; gap: 2.2mm 4mm; margin: 0; }
.doc dl.kv dt { color: #333; }
.doc dl.kv dd { margin: 0; font-weight: 600; white-space: pre-line; }

.doc table { width: 100%; border-collapse: collapse; font-size: 10pt; }
.doc th, .doc td { border: .6pt solid #999; padding: 1.8mm 2.2mm; text-align: left; vertical-align: top; }
.doc th { background: #eee; font-weight: 600; }
.doc tr { break-inside: avoid; page-break-inside: avoid; }
.doc thead { display: table-header-group; }  /* Kopfzeile auf Folgeseiten wiederholen */

/* Räume dürfen über Seiten laufen (kompakteres Protokoll); Überschrift und
   Notizen bleiben aber zusammen, und einzelne Fotos werden nie zerschnitten. */
.doc .room-doc { margin-top: 5mm; }
.doc .room-doc > h3 + .notes { break-before: avoid; page-break-before: avoid; }
.doc .room-doc h3 {
  font-size: 11.5pt; margin-bottom: 1.5mm;
  display: flex; align-items: baseline; gap: 3mm; justify-content: space-between;
  border-bottom: .6pt solid #bbb; padding-bottom: 1.2mm;
}
.doc .status-tag { font-size: 9pt; font-weight: 600; padding: .6mm 2mm; border: .8pt solid #000; border-radius: 2mm; white-space: nowrap; }
.doc .status-tag.ok { border-color: #1f8a5b; color: #1f8a5b; }
.doc .status-tag.defects { border-color: #a8660f; color: #a8660f; }
.doc .notes { white-space: pre-line; margin: 1.5mm 0 0; }
.doc .notes.empty { color: #777; font-style: italic; }

.doc .photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3mm; margin-top: 3mm; }
.doc .photo-grid figure { margin: 0; break-inside: avoid; page-break-inside: avoid; }
/* Feste Bildhöhe: Querformat füllt die Zelle, Hochformat wird zentriert
   eingepasst – so bleiben die Zeilen im Raster gleich hoch. */
.doc .photo-grid img {
  width: 100%; height: 66mm; object-fit: contain; object-position: center;
  display: block; border: .6pt solid #bbb; background: #f6f6f6;
}
.doc .photo-grid figcaption { font-size: 8.5pt; color: #333; margin-top: .8mm; line-height: 1.3; }

/* Überschrift, Unterschriftslinien und Hinweis wandern gemeinsam auf eine Seite. */
.doc .sign-block { break-inside: avoid; page-break-inside: avoid; }
.doc .signatures {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10mm 12mm; margin-top: 10mm;
}
.doc .sig { border-top: .8pt solid #000; padding-top: 1.5mm; line-height: 1.35; }
.doc .sig b { display: block; font-size: 10.5pt; }
.doc .sig .role { display: block; font-size: 9pt; }
.doc .sig .hint { display: block; font-size: 8pt; color: #666; margin-top: .4mm; }
.doc .sig-space { height: 16mm; }
/* Der Hinweis gehört zum Unterschriftenblock und darf nicht allein auf eine neue Seite rutschen. */
.doc .disclaimer {
  margin-top: 6mm; font-size: 8pt; color: #555; line-height: 1.35;
  break-before: avoid; page-break-before: avoid;
}
.doc .page-break { break-before: page; page-break-before: always; }

/* ---------- Print ---------- */
@page { size: A4; margin: 14mm 13mm; }

@media print {
  html, body { background: #fff; }
  .no-print, .topbar, #editor, #previewBar { display: none !important; }
  .doc {
    display: block !important; max-width: none; margin: 0; padding: 0;
    border: 0; border-radius: 0; box-shadow: none;
  }
  .doc h2 { break-after: avoid; page-break-after: avoid; }
  .doc .room-doc h3 { break-after: avoid; page-break-after: avoid; }
  a { text-decoration: none; color: inherit; }
}
