/* ============================================================
   Mitarbeiter-Login (Header-Popover) + oeffentliches Chat-Widget
   ============================================================ */

/* ---------- Login-Popover im Header ---------- */
.header-login { position: relative; margin-left: 0.25rem; }

.header-login-btn {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.header-login-btn:hover { border-color: var(--blue); color: #fff; }
.header-login-btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.header-login-btn[aria-expanded="true"] { border-color: var(--blue); color: #fff; }

.header-staff-link { white-space: nowrap; }

.login-panel {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  z-index: 30;
  width: min(300px, calc(100vw - 2.5rem));
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.7);
  padding: 1.25rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity var(--dur) var(--ease), visibility var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.login-panel.open { opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(0); }

.login-panel h3 {
  margin: 0 0 1rem;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  color: var(--text);
}

.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-submit { justify-content: center; width: 100%; }

@media (max-width: 900px) {
  .login-panel { right: -0.5rem; }
}

/* ---------- Oeffentliches Chat-Widget ---------- */
.chat-bubble {
  position: fixed;
  right: clamp(1rem, 2vw, 2rem);
  bottom: clamp(1rem, 2vw, 2rem);
  z-index: 500;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--blue-600));
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: 0 16px 40px -12px var(--blue-glow);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.chat-bubble:hover { transform: translateY(-3px); }
.chat-bubble:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.chat-bubble.open { transform: scale(0.94); }

.chat-bubble-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid var(--bg);
}
.chat-bubble-badge[hidden] { display: none; }

.chat-bubble-status {
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--text-dim);
}
.chat-bubble-status.online { background: #4ade80; }

.chat-panel {
  position: fixed;
  right: clamp(1rem, 2vw, 2rem);
  bottom: calc(clamp(1rem, 2vw, 2rem) + 76px);
  z-index: 500;
  width: min(360px, calc(100vw - 2rem));
  height: min(480px, calc(100vh - 8rem));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.8);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity var(--dur) var(--ease), visibility var(--dur) var(--ease), transform var(--dur) var(--ease);
  overflow: hidden;
}
.chat-panel.open { opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(0); }

.chat-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.chat-panel-head-text { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.chat-panel-head h3 {
  margin: 0;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  color: var(--text);
}
.chat-status-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.chat-status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.chat-status-line.online .chat-status-dot { background: #4ade80; }

.chat-offline-hint {
  margin: 0.85rem 1.15rem 0;
  padding: 0.75rem 0.9rem;
  background: rgba(224, 50, 45, 0.12);
  border: 1px solid rgba(224, 50, 45, 0.3);
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-muted);
}
.chat-offline-hint a { color: var(--red); font-weight: 600; }
.chat-offline-hint[hidden] { display: none; }

.chat-panel-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}
.chat-panel-close:hover { color: #fff; }
.chat-panel-close:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.chat-messages:empty::before {
  content: "Schreiben Sie uns eine Nachricht — wir antworten so schnell wie möglich.";
  color: var(--text-muted);
  font-size: 0.92rem;
}

.chat-msg {
  max-width: 82%;
  padding: 0.55rem 0.85rem;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.4;
  word-wrap: break-word;
}
.chat-msg-visitor {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--blue), var(--blue-600));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg-employee {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.85rem;
  border-top: 1px solid var(--border);
}
.chat-form-field {
  padding: 0.6rem 0.8rem;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
}
.chat-form-field:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-glow); }
.chat-form-field[hidden] { display: none; }
.chat-form-row { display: flex; gap: 0.6rem; }
.chat-form textarea {
  flex: 1;
  resize: vertical;
  height: 76px;
  max-height: 200px;
  padding: 0.6rem 0.8rem;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
}
.chat-form textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-glow); }
.chat-form .btn { width: auto; flex-shrink: 0; padding: 0.6rem 1rem; align-self: flex-end; }

.chat-status { margin: 0 1.15rem 0.6rem; font-size: 0.85rem; }

/* Vollflaechiges Chat-Fenster auf Smartphones: feste vh-Werte fuer Position/
   Hoehe funktionieren nicht zuverlaessig, sobald die Bildschirmtastatur
   aufklappt (der Layout-Viewport schrumpft je nach Browser nicht mit) -
   dadurch wurde nur ein schmaler Streifen des Formulars sichtbar. */
@media (max-width: 640px) {
  .chat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }
}
