:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1a2332;
  --muted: #5c6b7a;
  --border: #d8e0e8;
  --primary: #1f6feb;
  --primary-dark: #1558c0;
  --danger: #c62828;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
  --topbar-height: 3.75rem;
  --mobile-image-height: min(36vh, 260px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100vh;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(420px, calc(100% - 2rem));
  margin: 10vh auto 2rem;
  padding: 1.5rem;
}

.login-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.login-tab {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
  font: inherit;
}

.login-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

h1, h2 {
  margin: 0 0 0.75rem;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.9rem;
}

label {
  display: block;
  margin: 1rem 0 0.35rem;
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
}

textarea {
  resize: vertical;
  min-height: 3.2rem;
}

.kommentar-label {
  margin-top: 1rem;
}

button {
  border: none;
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  font-size: 0.9rem;
  cursor: pointer;
}

button.primary {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

button.primary:hover {
  background: var(--primary-dark);
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button.danger {
  background: var(--danger);
  color: #fff;
}

button.outline {
  background: #fff;
  font-weight: 600;
}

button.block-btn {
  width: 100%;
  margin-top: 0.5rem;
}

button.danger.outline {
  color: var(--danger);
  border: 2px solid var(--danger);
}

button.secondary.outline {
  color: var(--primary);
  border: 2px solid var(--primary);
}

button.secondary.outline.active {
  background: var(--primary);
  color: #fff;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.error {
  color: var(--danger);
  margin-top: 0.75rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
}

.label-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1rem;
  max-width: 1800px;
  margin: 0 auto;
  align-items: start;
}

.image-panel {
  position: sticky;
  top: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
  align-self: start;
  padding: 0.75rem;
  min-height: 0;
  max-height: calc(100vh - var(--topbar-height) - 1.25rem);
  z-index: 5;
}

#label-image {
  display: block;
  width: 100%;
  height: min(calc(100vh - 7rem), 780px);
  max-height: calc(100vh - 7rem);
  object-fit: contain;
  background: #111;
  border-radius: 10px;
}

.image-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.form-panel {
  padding: 1rem 1.1rem 1.25rem;
  min-width: 0;
}

.form-body {
  width: 100%;
}

.form-body label,
.form-body select,
.form-body #rating-extra,
.form-body .actions,
.form-body #btn-kriterien-start,
.form-body .gesamt-block,
.form-body #kriterien-section {
  width: 100%;
}

.form-body select {
  display: block;
}

#gesamt-buttons {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
}

#gesamt-buttons .chip {
  flex: 1 1 0;
  min-width: 0;
  padding: 0.32rem 0.35rem;
  font-size: 0.74rem;
  white-space: nowrap;
  text-align: center;
  line-height: 1.15;
}

.section {
  margin-top: 1rem;
}

.section-title {
  display: block;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

#rating-extra.disabled-block,
.gesamt-block.locked,
#bereich-block.locked {
  opacity: 0.45;
  pointer-events: none;
  user-select: none;
}

#irrelevant-hint {
  margin: 0.75rem 0 0;
  padding: 0.65rem 0.75rem;
  background: #eef3fb;
  border-radius: 8px;
}

.btn-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.btn-grid .chip {
  padding: 0.32rem 0.48rem;
  font-size: 0.82rem;
  line-height: 1.2;
}

.chip {
  background: #eef3fb;
  color: var(--text);
  border: 1px solid transparent;
}

.chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
}

.chip-nicht-bewohnbar {
  background: #fff5f5;
  border: 1px solid #e57373;
}

.chip-nicht-bewohnbar.active {
  background: var(--danger);
  color: #fff;
  border-color: #9e1f1f;
}

button.unsicher.outline {
  color: #9a7b00;
  border: 2px solid #e6c200;
  padding: 0.5rem 0.65rem;
  font-weight: 600;
}

button.unsicher.outline.active {
  background: #c9a000;
  color: #fff;
  border-color: #9a7b00;
}

.kriterium {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.55rem;
}

.kriterium-title {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.45rem;
}

.kriterium.locked {
  opacity: 0.45;
}

.kriterium.locked .btn-grid {
  pointer-events: none;
}

.kriterium.locked .chip {
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 1rem;
}

.actions .ghost {
  flex: 1 1 52%;
  min-width: 0;
  font-size: 0.8rem;
  line-height: 1.25;
  padding: 0.5rem 0.55rem;
  text-align: center;
}

.actions .primary {
  flex: 1 1 48%;
  min-width: 0;
}

#done-panel {
  margin: 2rem auto;
  width: min(520px, calc(100% - 2rem));
  padding: 1.5rem;
  text-align: center;
}

#btn-login {
  width: 100%;
  margin-top: 1rem;
}

@media (max-width: 960px) {
  .login-card {
    margin: 6vh auto 1.5rem;
    padding: 1.15rem;
  }

  .topbar {
    padding: 0.55rem 0.75rem;
    align-items: flex-start;
  }

  .topbar > div {
    min-width: 0;
    flex: 1;
    line-height: 1.3;
  }

  #stats-display {
    display: block;
    font-size: 0.76rem;
    margin-top: 0.15rem;
  }

  #btn-logout {
    flex-shrink: 0;
    padding: 0.5rem 0.65rem;
    min-height: 2.5rem;
  }

  .label-layout {
    grid-template-columns: 1fr;
    padding: 0.5rem;
    gap: 0.65rem;
  }

  /* Bild bleibt unter der Topbar sichtbar beim Scrollen im Formular */
  .image-panel {
    position: sticky;
    top: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
    z-index: 8;
    max-height: none;
    padding: 0.45rem 0.5rem 0.5rem;
    box-shadow: 0 6px 18px rgba(16, 24, 40, 0.14);
  }

  #label-image {
    height: var(--mobile-image-height);
    max-height: var(--mobile-image-height);
    border-radius: 8px;
  }

  .image-meta {
    font-size: 0.78rem;
    margin-top: 0.35rem;
  }

  .form-panel {
    padding: 0.85rem 0.9rem 1rem;
  }

  .form-panel h2 {
    font-size: 1.15rem;
  }

  #gesamt-buttons {
    flex-wrap: wrap;
  }

  #gesamt-buttons .chip {
    flex: 0 1 auto;
    min-width: auto;
  }

  .btn-grid .chip {
    min-height: 2.35rem;
  }

  button.block-btn,
  .actions button {
    min-height: 2.75rem;
    font-size: 0.92rem;
  }

  .actions {
    flex-direction: column;
    position: sticky;
    bottom: 0;
    z-index: 9;
    margin-top: 1.25rem;
    padding: 0.65rem 0 calc(0.35rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, var(--card) 78%, rgba(255, 255, 255, 0));
  }

  .actions .ghost,
  .actions .primary {
    flex: 1 1 auto;
    width: 100%;
  }
}

/* Desktop unverändert ab 961px — sticky Bild links neben Formular */
@media (min-width: 961px) {
  .actions {
    position: static;
    background: transparent;
    padding-bottom: 0;
  }
}
