/* ============ Grundlagen ============ */
:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --ink: #1f2933;
  --ink-soft: #5b6b78;
  --line: #e2ddd2;
  --brand: #0f766e;
  --brand-dark: #0b5750;
  --brand-soft: #d7efe9;
  --danger: #c0392b;
  --shadow: 0 10px 30px rgba(31, 41, 51, 0.12);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

/* ============ Buttons ============ */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform .05s ease, background .15s ease;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: rgba(0,0,0,.05); }
.btn-icon {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  width: 44px; height: 44px;
  font-size: 22px; line-height: 1;
  padding: 0;
  border-radius: 10px;
}
.btn-icon:hover { background: var(--brand-soft); }

/* ============ Login ============ */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #d7efe9 0%, transparent 60%), var(--bg);
}
.login-card {
  background: var(--surface);
  padding: 36px 30px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 380px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-emoji { font-size: 54px; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-sub { margin: 0; color: var(--ink-soft); font-size: 14px; }
.login-card input {
  font: inherit; font-size: 16px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
}
.login-card input:focus { outline: 2px solid var(--brand); border-color: transparent; }
.login-error { color: var(--danger); font-size: 14px; margin: 0; }

/* ============ Topbar ============ */
.topbar {
  background: var(--brand);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; min-width: 0; }
.brand-emoji { font-size: 22px; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.role-badge {
  background: #fff; color: var(--brand-dark);
  padding: 5px 12px; border-radius: 999px;
  font-weight: 700; font-size: 13px; white-space: nowrap;
}
.year-badge {
  background: rgba(255,255,255,.18);
  padding: 5px 12px; border-radius: 999px;
  font-weight: 700; font-size: 14px;
}
.topbar .btn-ghost { color: #fff; padding: 8px 12px; }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.15); }

/* ============ Gruppen-Tabs ============ */
.group-tabs {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 16px 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.group-tab {
  font: inherit; font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
}
.group-tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ============ Wohnungs-Chips ============ */
.apt-chips {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.apt-chip {
  font: inherit; font-weight: 600; font-size: 14px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.apt-chip.active { background: var(--brand-soft); color: var(--brand-dark); }

/* ============ Wohnungs-Foto-Banner ============ */
.apt-hero {
  max-width: 1100px;
  margin: 14px auto 0;
  height: 170px;
  border-radius: var(--radius);
  background-size: cover;
  background-position: center;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-end;
  position: relative;
  overflow: hidden;
}
/* seitlicher Außenabstand wie der restliche Inhalt */
.apt-hero { width: auto; margin-left: 16px; margin-right: 16px; }
.apt-hero-cap {
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  padding: 14px 18px;
  text-shadow: 0 2px 8px rgba(0,0,0,.5);
}

/* ============ Toolbar ============ */
.toolbar {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-label { font-size: 18px; font-weight: 700; min-width: 140px; text-align: center; }

/* ============ Monatskalender ============ */
.calendar-wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px 60px; }
.calendar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
}
.month-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.wd-head {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 2px 0;
}
.wd-head.weekend { color: var(--brand); }
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.mcell {
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 74px;
  padding: 5px 5px 6px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  background: var(--surface);
  transition: background .12s ease;
}
.mcell:hover { background: var(--brand-soft); }
.mcell.out { visibility: hidden; }
.mcell.weekend { background: #faf8f2; }
.mcell.weekend:hover { background: var(--brand-soft); }
.dn { font-size: 13px; font-weight: 700; color: var(--ink); line-height: 1; }
.mcell.today .dn {
  background: var(--brand); color: #fff;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
}

/* Buchungs-Segmente */
.segs {
  flex: 1;
  display: flex;
  align-items: stretch;
  gap: 3px;
  margin-top: 5px;
  min-height: 22px;
}
.seg {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .3px;
  border-radius: 6px;
  overflow: hidden;
}
.seg-full { flex: 1; }
.seg-half { flex: 1; }
.seg-empty { background: transparent !important; }

.legend {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin: 14px 4px 0;
  font-size: 13px;
  color: var(--ink-soft);
}
.legend-item { display: flex; align-items: center; gap: 7px; }
.legend-swatch { width: 26px; height: 16px; border-radius: 5px; background: var(--brand); display: inline-block; }
.legend-swatch.half { width: 13px; }
.legend-hint { margin-left: auto; font-style: italic; }

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 31, .5);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: 18px;
  width: 100%;
  max-width: 460px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 6px;
}
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-close { background: none; border: none; font-size: 30px; line-height: 1; color: var(--ink-soft); cursor: pointer; padding: 0 4px; }
.modal-body { padding: 8px 20px 4px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 20px 20px; display: flex; justify-content: flex-end; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.field span em { font-weight: 400; color: var(--ink-soft); font-style: normal; }
.field input, .field select {
  font: inherit; font-size: 16px; font-weight: 500;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.field input:focus, .field select:focus { outline: 2px solid var(--brand); border-color: transparent; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.field-time { max-width: 130px; }
.field-check { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; cursor: pointer; }
.field-check input { width: 20px; height: 20px; accent-color: var(--brand); }
.form-error { color: var(--danger); font-size: 14px; margin: 0; }

/* ============ Detail-Liste ============ */
.detail-empty { color: var(--ink-soft); font-style: italic; }
.detail-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.detail-card-head { display: flex; align-items: center; gap: 10px; }
.detail-badge { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.detail-name { font-weight: 700; }
.detail-meta { font-size: 13px; color: var(--ink-soft); line-height: 1.5; }
.detail-meta .row { display: flex; gap: 6px; }
.detail-meta .ico { width: 18px; text-align: center; }
.cleaning-yes { color: var(--brand); font-weight: 600; }
.cleaning-no { color: var(--danger); font-weight: 600; }
.detail-del { align-self: flex-start; background: none; border: none; color: var(--danger); font: inherit; font-size: 13px; cursor: pointer; padding: 2px 0; text-decoration: underline; }

/* ============ Mobil ============ */
@media (max-width: 600px) {
  .brand { font-size: 16px; }
  .brand span:last-child { max-width: 38vw; }
  .topbar .btn-ghost { font-size: 0; padding: 8px; }       /* "Abmelden" -> nur Icon-Fläche */
  .topbar .btn-ghost::before { content: "⎋"; font-size: 18px; }
  .role-badge { font-size: 12px; padding: 4px 10px; }
  .year-badge { display: none; }                           /* Platz sparen */
  .apt-hero { height: 130px; margin-top: 12px; }
  .apt-hero-cap { font-size: 18px; padding: 12px 14px; }
  .toolbar { gap: 10px; }
  .month-nav { flex: 1; justify-content: center; }
  #new-booking-btn { width: 100%; }
  .calendar { padding: 7px; }
  .month-head, .month-grid { gap: 4px; }
  .mcell { min-height: 60px; border-radius: 8px; padding: 3px; }
  .dn { font-size: 12px; }
  .seg { font-size: 10px; border-radius: 5px; }
  .segs { min-height: 18px; margin-top: 3px; }
  .legend-hint { margin-left: 0; width: 100%; }
  .field-row { flex-direction: column; }
  .field-time { max-width: none; }
}
