:root {
  --bg: #101418;
  --surface: #1a2027;
  --surface-2: #232a33;
  --text: #f0f2f4;
  --text-dim: #8a94a0;
  --accent: #f0c446;
  --danger: #e8584b;
  --border: #2a313a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ok: #6fcf97;
}
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef1;
  --text: #15191e;
  --text-dim: #5f6b78;
  --accent: #e2ac1c;
  --danger: #d23f31;
  --border: #d8dce1;
  --ok: #3fae6e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

.view {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}
.sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

.icon-btn {
  background: var(--surface-2);
  border: none;
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn-accent { background: var(--accent); color: #1a1a1a; }
.topbar-actions { display: flex; gap: 8px; }

.entry-list {
  list-style: none;
  margin: 0;
  padding: 12px 16px calc(100px + var(--safe-bottom));
  overflow-y: auto;
  flex: 1;
}

.entry-card {
  display: flex;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 10px;
}
.entry-card img, .entry-card canvas {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
}
.entry-card-noimg {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  flex-shrink: 0;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
}
.entry-card .entry-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.entry-card .entry-room {
  font-weight: 600;
  font-size: 14px;
}
.entry-card .entry-note {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.entry-card .entry-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
}
.entry-card .entry-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
}
.entry-card .entry-actions button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  padding: 4px;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  margin-top: 25%;
  padding: 0 24px;
}
.empty-state p:first-child { color: var(--text); font-size: 16px; font-weight: 600; }

.bottombar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 16px calc(14px + var(--safe-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
}
.btn-secondary { background: var(--surface-2); color: var(--text); flex: 1; }
.btn-danger { background: var(--danger); color: #fff; }

.fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  font-size: 28px;
  font-weight: 400;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
  flex-shrink: 0;
}

.entry-form {
  padding: 20px 16px;
  overflow-y: auto;
  flex: 1;
}

.photo-picker {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 20px;
}
.photo-picker img, .photo-picker canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 14px;
}
.camera-icon { font-size: 34px; }
#photo-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
}

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input, .field textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); }

.danger-zone { margin-top: 36px; }
.danger-zone button { width: 100%; }

.viewer {
  background: #000;
  justify-content: center;
  align-items: center;
}
.viewer img, .viewer canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.viewer-close {
  position: absolute;
  top: calc(16px + var(--safe-top));
  right: 16px;
  z-index: 2;
  background: rgba(255,255,255,.15);
}

.hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

.context-chip {
  margin: 12px 16px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
}
.chip-btn {
  background: var(--surface-2);
  color: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  padding: 0;
  font-size: inherit;
  text-decoration: underline;
}
.pin-field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.pin-field-header label { margin-bottom: 0; }

.floor-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 14px;
}
.floor-tab {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  white-space: nowrap;
}
.floor-tab.active {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
  font-weight: 600;
}

.floorplans-list { list-style: none; margin: 0; padding: 0; }
.floorplan-card {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 10px;
}
.floorplan-card img, .floorplan-card canvas {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
  flex-shrink: 0;
}
.floorplan-card .fp-main { flex: 1; min-width: 0; }
.floorplan-card .fp-name { font-weight: 600; font-size: 15px; }
.floorplan-card .fp-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.floorplan-card .fp-actions { display: flex; flex-direction: column; gap: 6px; }
.floorplan-card .fp-actions button {
  background: var(--surface-2);
  border: none;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
}

.zone-rect {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(240, 196, 70, 0.22);
  border-radius: 4px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}
.zone-rect .zone-label {
  background: var(--accent);
  color: #1a1a1a;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 0 0 6px 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.zone-rect.zone-active {
  border-color: #6fcf97;
  background: rgba(111, 207, 151, 0.25);
}
.zone-rect.zone-active .zone-label { background: #6fcf97; }
.zone-draft {
  border-style: dashed;
  background: rgba(240, 196, 70, 0.12);
  pointer-events: none;
}
.zone-rect.zone-selected {
  border-color: #6fcf97;
  background: rgba(111, 207, 151, 0.22);
  z-index: 2;
}
.zone-rect.zone-selected .zone-label { background: #6fcf97; }
.zone-handle {
  position: absolute;
  width: 22px;
  height: 22px;
  margin: -11px;
  border-radius: 50%;
  background: #6fcf97;
  border: 2px solid #101418;
  pointer-events: auto;
}
.zone-handle.nw { left: 0; top: 0; cursor: nwse-resize; }
.zone-handle.ne { left: 100%; top: 0; cursor: nesw-resize; }
.zone-handle.sw { left: 0; top: 100%; cursor: nesw-resize; }
.zone-handle.se { left: 100%; top: 100%; cursor: nwse-resize; }

.zone-edit-panel {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  align-items: center;
}
.zone-edit-panel input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
}
.zone-edit-delete { color: var(--danger); }

.room-picker-floor { margin-bottom: 22px; }
.room-picker-floor h3 { font-size: 14px; color: var(--text-dim); margin: 0 0 10px; }
.room-chip-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.room-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
}
.pdf-pages-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.pdf-page-card {
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: var(--surface);
}
.pdf-page-imgwrap {
  position: relative;
  aspect-ratio: 3/4;
}
.pdf-page-imgwrap img, .pdf-page-imgwrap canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  display: block;
}
.pdf-page-card.selected { border-color: var(--accent); }
.pdf-page-card.excluded .pdf-page-imgwrap img, .pdf-page-card.excluded .pdf-page-imgwrap canvas { opacity: 0.35; filter: grayscale(1); }
.pdf-page-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}
.pdf-page-card.excluded .pdf-page-check { background: var(--surface-2); color: var(--text-dim); }
.pdf-page-fields {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pdf-page-fields input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 9px;
  font-size: 13px;
  width: 100%;
}
.pdf-page-fields input::placeholder { color: var(--text-dim); }

.room-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1a1a;
  font-weight: 600;
}

.pin-map {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  touch-action: manipulation;
}
.pin-map img, .pin-map canvas { width: 100%; height: auto; display: block; }
/* Im Zimmer-Editor darf der Browser beim Ziehen nicht scrollen/zoomen, sonst bricht die Geste ab */
#zone-editor-map {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#zone-editor-map img, #zone-editor-map canvas { pointer-events: none; -webkit-user-drag: none; }
#pin-zones, #overview-zones, #zone-editor-zones {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.pin-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  color: var(--danger);
  font-size: 26px;
  text-shadow: 0 0 4px rgba(0,0,0,.6);
  pointer-events: none;
}
.map-pin {
  z-index: 2;
  position: absolute;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}

.floorplan-upload {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 10px;
}
.floorplan-upload img, .floorplan-upload canvas { width: 100%; height: 100%; object-fit: cover; }
#floorplan-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
}

.map-content {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 10;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.dialog-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  width: 100%;
  max-width: 360px;
}
.dialog-msg { margin: 0 0 14px; color: var(--text); font-size: 15px; line-height: 1.4; }
.dialog-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  margin-bottom: 14px;
}
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .btn { flex: 1; }
.btn-primary { background: var(--accent); color: #1a1a1a; font-weight: 600; }

/* Zwei-Finger-Zoom im Zimmer-Editor */
.zoom-inner {
  position: relative;
  transform-origin: 0 0;
  will-change: transform;
}
.zoom-reset {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
}
/* Rahmen, Beschriftung und Eckpunkte beim Zoomen gleich groß halten */
.zoom-inner .zone-rect { border-width: calc(2px / var(--z, 1)); border-radius: calc(4px / var(--z, 1)); }
.zoom-inner .zone-label {
  font-size: calc(11px / var(--z, 1));
  padding: calc(2px / var(--z, 1)) calc(6px / var(--z, 1));
  border-radius: 0 0 calc(6px / var(--z, 1)) 0;
}
.zoom-inner .zone-handle {
  width: calc(22px / var(--z, 1));
  height: calc(22px / var(--z, 1));
  margin: calc(-11px / var(--z, 1));
  border-width: calc(2px / var(--z, 1));
}

/* Arbeitsort: Gebäude → Stockwerk → Zimmer */
.location-panel {
  margin: 12px 16px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px 12px;
}
.location-title { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.location-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.location-bar .loc-room, .location-bar .loc-other { grid-column: 1 / -1; }
.location-bar select, .location-bar input, .fp-building {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.location-bar .loc-room { font-weight: 600; }
.fp-building { margin-top: 6px; padding: 6px 10px; font-size: 14px; width: auto; }
/* System-Pfeil der Auswahlfelder behalten, damit sie als Dropdown erkennbar sind */
.location-bar select, .fp-building { -webkit-appearance: menulist; appearance: auto; }

.pin-floor-tabs { margin-top: 10px; }

/* Statistik / Filter */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 16px 0;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text);
  font-family: inherit;
}
.stat-num { font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--text-dim); }
.stat.active { border-color: var(--accent); background: var(--surface-2); }
.stat.active .stat-label { color: var(--accent); font-weight: 600; }

/* Abhaken */
.entry-check {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--text-dim);
  background: transparent;
  color: #1a1a1a;
  font-size: 16px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  align-self: center;
}
.entry-check.checked { background: var(--ok); border-color: var(--ok); }
.entry-check:disabled { opacity: 0.3; }
.entry-card.is-done .entry-room,
.entry-card.is-done .entry-note { text-decoration: line-through; color: var(--text-dim); }
.entry-card.is-done canvas { opacity: 0.5; }
.entry-card.is-deleted { opacity: 0.6; }

/* Pin-Marker im Zoom gleich groß halten */
.zoom-inner .pin-marker { font-size: calc(26px / var(--z, 1)); }
#pin-map { touch-action: pan-y; }

/* Darstellung: Segment-Schalter */
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.segmented button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  border-radius: 8px;
  padding: 9px 4px;
  font-size: 14px;
  font-family: inherit;
}
.segmented button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
:root[data-theme="light"] .chip-btn, :root[data-theme="light"] .link-btn { color: #9a6f00; }
:root[data-theme="light"] .toast { box-shadow: 0 4px 14px rgba(0,0,0,.15); }

/* Logo: schwarz im Hellmodus, weiß im Dunkelmodus */
.brand { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.brand-logo { height: 56px; width: auto; display: block; margin: -4px 0 2px -4px; }
.brand-watermark {
  position: fixed;
  left: 50%;
  top: 58%;
  transform: translate(-50%, -50%);
  width: min(78vw, 420px);
  height: auto;
  opacity: 0.06;
  pointer-events: none;
  z-index: 0;
}
#view-list > *:not(.brand-watermark):not(.bottombar) { position: relative; z-index: 1; }
#view-list > .bottombar { z-index: 2; }
:root[data-theme="dark"] .brand-logo,
:root[data-theme="dark"] .brand-watermark { filter: invert(1); }
:root[data-theme="dark"] .brand-watermark { opacity: 0.07; }

.map-pin.done { background: var(--ok); }
/* Rundgang */
.route-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.route-svg polyline {
  fill: none;
  stroke: var(--danger);
  stroke-width: 2.5;
  stroke-dasharray: 6 5;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  opacity: 0.85;
}
.route-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-dim); margin: -4px 0 12px; }
.route-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Backup */
.btn-sync { flex: 0 0 auto; padding-left: 14px; padding-right: 14px; white-space: nowrap; }
.btn-sync.has-pending { background: var(--accent); color: #1a1a1a; font-weight: 700; }
.backup-key-row { display: flex; gap: 8px; margin-top: 8px; }
.backup-key-row input { flex: 1; }
#backup-drive-link a { color: var(--accent); font-weight: 600; }
