/* ── 1. Backdrop ── */
.profile-panel-backdrop {
  visibility: hidden;
  pointer-events: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 10000;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}
.profile-panel-backdrop.open {
  visibility: visible;
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.2s ease, visibility 0s linear 0s;
}

/* ── 2. Modal (zentriert) ── */
.profile-panel {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: 760px; max-width: 94vw;
  max-height: 90vh;
  background: var(--rb-surface-card, #fff);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08);
  z-index: 10001;
  display: flex; flex-direction: column;
  opacity: 0;
  overflow: hidden;
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1),
              opacity   0.25s cubic-bezier(0.4,0,0.2,1);
}
.profile-panel.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

/* ── 3. Header (volle Breite) ── */
.profile-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--rb-border, rgba(0,0,0,0.08));
  flex-shrink: 0;
  min-height: 0;
}
.profile-panel-title {
  font-size: 1rem; font-weight: 700;
  color: var(--rb-text-primary, #1d1d1f); margin: 0;
}
.profile-panel-close {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: var(--rb-surface-2, #f5f5f7);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--rb-text-secondary, #6e6e73); font-size: 1.1rem;
  transition: background 0.15s; flex-shrink: 0;
}
.profile-panel-close:hover { background: var(--rb-surface-3, #e8e8ed); }

/* ── 4. Zweispaltiges Grid ── */
.profile-modal-inner {
  display: grid;
  grid-template-columns: 200px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── 5. Linke Spalte (Avatar-Karte) ── */
.profile-left-col {
  background: var(--rb-surface-2, #f5f5f7);
  border-right: 1px solid var(--rb-border, rgba(0,0,0,0.07));
  display: flex; flex-direction: column;
  align-items: center;
  /* FIX: war "center" → Inhalte wurden bei kleinen Höhen oben/unten abgeschnitten */
  justify-content: flex-start;
  padding: 28px 16px 24px;
  gap: 10px;
  text-align: center;
  /* FIX: Scrollen aktiviert, damit bei kleinen Viewports nichts verlorengeht */
  overflow-y: auto;
  overflow-x: hidden;
}
.profile-left-name {
  font-size: 0.95rem; font-weight: 700;
  color: var(--rb-text-primary, #1d1d1f);
  word-break: break-word;
}
.profile-left-role {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 20px;
  background: rgba(0,113,227,0.1); color: var(--rb-primary, #0071e3);
  font-size: 0.72rem; font-weight: 600;
}
.profile-left-company {
  font-size: 0.78rem; color: var(--rb-text-secondary, #6e6e73);
  word-break: break-word;
}
.profile-left-email {
  font-size: 0.72rem; color: var(--rb-text-tertiary, #aeaeb2);
  word-break: break-all;
}

/* ── 6. Rechte Spalte (Formular) ── */
.profile-panel-body {
  /* FIX: min-height: 0 ist kritisch für korrekte Scrollable-Flex-Items */
  flex: 1; min-height: 0; overflow-y: auto; padding: 24px;
  display: flex; flex-direction: column;
}

/* ── 7. Avatar ── */
.profile-avatar-wrapper {
  position: relative; width: 84px; height: 84px; flex-shrink: 0;
}
.profile-avatar-img { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; }
.profile-avatar-initials {
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--rb-primary, #0071e3); color: #fff;
  font-size: 1.7rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.profile-avatar-edit-btn {
  position: absolute; bottom: 0; right: 0;
  width: 27px; height: 27px; border-radius: 50%;
  background: var(--rb-primary, #0071e3);
  border: 2px solid var(--rb-surface-2, #f5f5f7);
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; transition: background 0.15s;
}
.profile-avatar-edit-btn:hover { background: var(--rb-primary-dark, #005ac2); }
.profile-avatar-remove-btn {
  background: none; border: none; cursor: pointer;
  color: var(--rb-danger, #ef4444); font-size: 0.72rem;
  padding: 0; text-decoration: underline;
}
.profile-avatar-input { display: none; }

/* ── 8. Formular-Abschnitte ── */
.profile-section { margin-bottom: 20px; }
.profile-section:last-child { margin-bottom: 0; }
.profile-section-title {
  font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--rb-text-secondary, #6e6e73);
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid var(--rb-border, rgba(0,0,0,0.07));
}
.profile-form-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px;
}
.profile-form-row.full { grid-template-columns: 1fr; }
.profile-form-group { display: flex; flex-direction: column; gap: 4px; }
.profile-form-label { font-size: 0.75rem; font-weight: 600; color: var(--rb-text-secondary, #6e6e73); }
.profile-form-label.readonly { color: var(--rb-text-tertiary, #aeaeb2); }
.profile-form-input, .profile-form-textarea {
  padding: 8px 11px;
  border: 1px solid var(--rb-border, rgba(0,0,0,0.12));
  border-radius: 8px;
  background: var(--rb-surface-input, #fff);
  color: var(--rb-text-primary, #1d1d1f);
  font-size: 0.875rem; font-family: inherit;
  /* FIX: box-sizing verhindert, dass padding die Breite überschreitet */
  box-sizing: border-box;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.profile-form-input:focus, .profile-form-textarea:focus {
  outline: none;
  border-color: var(--rb-primary, #0071e3);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.12);
}
.profile-form-input[disabled] {
  background: var(--rb-surface-2, #f5f5f7);
  color: var(--rb-text-tertiary, #aeaeb2); cursor: not-allowed;
}
.profile-form-textarea { resize: vertical; min-height: 76px; }
.profile-form-hint { font-size: 0.7rem; color: var(--rb-text-tertiary, #aeaeb2); margin-top: 2px; }

/* ── 9. Passwort-Toggle ── */
.profile-pw-toggle {
  display: flex; align-items: center; gap: 8px;
  background: none; border: 1px dashed var(--rb-border, rgba(0,0,0,0.15));
  border-radius: 8px; padding: 10px 14px; cursor: pointer;
  color: var(--rb-text-secondary, #6e6e73); font-size: 0.82rem; font-weight: 600;
  /* FIX: box-sizing + width verhindert Überlappen mit Padding */
  width: 100%; box-sizing: border-box;
  text-align: left; transition: border-color 0.15s, color 0.15s;
}
.profile-pw-toggle:hover { border-color: var(--rb-primary, #0071e3); color: var(--rb-primary, #0071e3); }
.profile-pw-fields { display: none; margin-top: 10px; }
.profile-pw-fields.open { display: block; }

/* ── 10. Footer (volle Breite) ── */
.profile-panel-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--rb-border, rgba(0,0,0,0.08));
  flex-shrink: 0;
}
.profile-btn {
  padding: 8px 18px; border-radius: 8px;
  font-size: 0.875rem; font-weight: 600;
  border: none; cursor: pointer; transition: all 0.15s;
  white-space: nowrap;
}
.profile-btn-secondary { background: var(--rb-surface-2, #f5f5f7); color: var(--rb-text-primary, #1d1d1f); }
.profile-btn-secondary:hover { background: var(--rb-surface-3, #e8e8ed); }
.profile-btn-primary { background: var(--rb-primary, #0071e3); color: #fff; }
.profile-btn-primary:hover { background: var(--rb-primary-dark, #005ac2); }
.profile-btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── 11. Dark Mode ── */
[data-theme="dark"] .profile-panel {
  background: var(--rb-surface-card, #1c1c1e);
}
[data-theme="dark"] .profile-left-col {
  background: var(--rb-surface-3, #2c2c2e);
  border-right-color: var(--rb-border, rgba(255,255,255,0.06));
}
[data-theme="dark"] .profile-form-input,
[data-theme="dark"] .profile-form-textarea {
  background: var(--rb-surface-2, #2c2c2e);
  color: var(--rb-text-primary, #f5f5f7);
  border-color: var(--rb-border, rgba(255,255,255,0.1));
}
[data-theme="dark"] .profile-btn-secondary {
  background: var(--rb-surface-2, #2c2c2e);
  color: var(--rb-text-primary, #f5f5f7);
}

/* ── 12. Schmale Viewports (600–760px) — schmalere linke Spalte ── */
@media (max-width: 760px) and (min-width: 601px) {
  .profile-modal-inner {
    grid-template-columns: 170px 1fr;
  }
  .profile-left-col {
    padding: 20px 12px;
  }
}

/* ── 13. Mobile (≤ 600px) ── */
@media (max-width: 600px) {
  .profile-panel {
    width: 100%; max-width: 100%;
    /* FIX: 100dvh für korrekte Höhe auf iOS, 100vh als Fallback */
    max-height: 100vh; max-height: 100dvh;
    border-radius: 0;
    top: 0; left: 0;
    /* FIX: kein translate nötig da top:0 left:0; slide-up statt scale */
    transform: translateY(3%);
  }
  .profile-panel.open {
    transform: translateY(0);
  }
  .profile-modal-inner {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .profile-left-col {
    border-right: none;
    border-bottom: 1px solid var(--rb-border, rgba(0,0,0,0.07));
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    padding: 14px 18px;
    gap: 14px;
    text-align: left;
    /* FIX: auf Mobile kein vertikales Scroll, horizontales Abschneiden verhindern */
    overflow-y: visible;
    overflow-x: hidden;
    /* FIX: Höhe nicht fixieren — Inhalt bestimmt Höhe */
    flex-shrink: 0;
  }
  .profile-left-col > .profile-avatar-wrapper { flex-shrink: 0; }
  /* FIX: Texte in linker Spalte dürfen umbrechen und nicht abgeschnitten werden */
  .profile-left-col > :not(.profile-avatar-wrapper) {
    min-width: 0;
    word-break: break-word;
  }
  .profile-form-row { grid-template-columns: 1fr; }
  .profile-panel-header { padding: 16px 18px; }
  .profile-panel-body { padding: 18px; }
  .profile-panel-footer { padding: 12px 18px; }
}
