/* ============================================
   Mein Nestwerk - Main Styles
   Base, Layout, Typography, Cards, Grids
   ============================================
   Version: 2.1 - Theme-Namen modernisiert
   Datum: 2025-11-24
   ============================================ */

/* ===== CI & Theme-Variablen ===== */
:root {
  --ci-white: #F4F1F1;
  --ci-black: #2E2D2C;
  --ci-gray: #6F6E6E;
  --photo-h: 150px;
}

/* Theme-spezifische Farben */
:root.theme-man {
  --accent-strong: #539CD5;
  --accent-soft: #80BDE8;
  --logo-url: url('/assets/img/mlogo.svg');
}

:root.theme-woman {
  --accent-strong: #E65D9D;
  --accent-soft: #F3A7C3;
  --logo-url: url('/assets/img/wlogo.svg');
}

:root.theme-neutral {
  --accent-strong: #53AE32;
  --accent-soft: #A7D19F;
  --logo-url: url('/assets/img/logo.svg');
}

/* Abgeleitete Variablen (für alle Themes) */
:root.theme-man,
:root.theme-woman,
:root.theme-neutral {
  --bg: var(--ci-white);
  --fg: var(--ci-black);
  --surface: #FFFFFF;
  --muted: var(--ci-gray);
  --border: #DDDDDD;
  --accent: var(--accent-strong);
  --accent-contrast: var(--accent-soft);
  
  /* Live-Save Feedback Farben */
  --accent-mid: var(--accent-soft);
  --accent-shadow: rgba(83, 156, 213, 0.2);
}

/* Theme-spezifische Shadow-Farben */
:root.theme-man {
  --accent-shadow: rgba(83, 156, 213, 0.2);
}

:root.theme-woman {
  --accent-shadow: rgba(230, 93, 157, 0.2);
}

:root.theme-neutral {
  --accent-shadow: rgba(83, 174, 50, 0.2);
}

/* ===== Base & Reset ===== */
* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.45;
}

img {
  max-height: 100%;
  width: auto;
  display: block;
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 0.8rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.2px;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.2rem;
}

h4 {
  font-size: 1.1rem;
}

p {
  margin: 0 0 1rem;
}

/* ===== Layout ===== */
header, footer, main {
  width: 100%;
}

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 clamp(12px, 4vw, 20px);
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: grid;
  padding-left: 16px;
  grid-template-columns: calc(var(--photo-h) * 0.77) 1fr auto;
  align-items: end;          /* alles an der Unterkante ausrichten */
  column-gap: 16px;
  justify-items: center;
}

.brand .logo {
  width: calc(var(--photo-h) * 0.77);
  aspect-ratio: 1/1;
  margin: 12px 0 0;          /* nur oben Abstand, unten bündig */
  background-image: var(--logo-url);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  justify-self: center;
}

.brand .title {
  color: var(--accent-soft);
  font-weight: 700;
  font-size: 2.2rem;
  letter-spacing: 0.2px;
  text-align: center;
  justify-self: center;  /* horizontal zentriert in der mittleren Spalte */
  align-self: center;   /* vertikale Zentrierung innerhalb der Gridzelle */
  padding-bottom: 12px;  /* gleicht die 12px Logo-Margin aus */
}

.brand .title h1 {
  margin: 0;
  font-size: 2.2rem;
}

.brand .title p {
  margin: 3px 0 0 0;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 400;
}

/* neuer Block für die Buttons rechts */
.header-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 8px 0 0;
  padding-bottom: 12px;   /* gleiche Referenz wie Titel + Logo */
  align-self: end;
}

.header-actions .card-btn {
  margin: 0;
}

main {
  padding: 12px 0;
}

footer {
  margin-top: 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
}

footer .footer-text {
  color: var(--ci-gray);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

/* ===== Cards & Sections ===== */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* Kontakt-, Details- & Owner-Card mit schwebendem Titel */
.contact-card,
.owner-card,
.details-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-top: 2.0rem;
  padding: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  position: relative;
  padding-top: 1.5rem;
}

/* Header-Container für Title + Buttons */
.contact-card-header {
  position: absolute;
  top: -1.3em;
  left: 0.95rem;
  right: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 2;
}

.card-title {
  background: #fff;
  border: 2px solid var(--accent-soft);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
  color: var(--accent-strong);
  font-weight: 700;
  line-height: 1.2;
  display: inline-block;
  white-space: nowrap;
  transform: translateY(5px);    /* hier feinjustieren */
}

/* Button-Container rechts */
.card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  transform: translateY(-3px);    /* hier feinjustieren */
}

/* Badge-Style Buttons (wie card-title) */
.card-btn {
  background: #fff;
  border: 2px solid var(--accent-soft);
  border-radius: 8px;
  padding: 0px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
}

.card-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.card-btn:active {
  transform: translateY(0);
}

/* Primärkontakt-Button (Stern) */
.card-btn--primary {
  color: var(--accent-strong);
  border-color: var(--accent-soft);
}

.card-btn--primary:hover {
  background: var(--accent-soft);
  border-color: var(--accent-strong);
  color: #fff;
}

.card-btn--primary.active {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

/* Löschen-Button (Mülleimer) */
.card-btn--delete {
  color: #dc3545;
  border-color: #ffc1c7;
}

.card-btn--delete:hover {
  background: #dc3545;
  border-color: #dc3545;
  color: #fff;
}

.card-btn--login {
  position: relative;
  padding: 0; /* wenn nötig */
}

.card-btn--login::before {
  content: "";
  width: 16px;
  height: 16px;
  display: block;

  background-color: var(--accent-strong);
  mask: url(/assets/img/login.svg) no-repeat center / contain;
  -webkit-mask: url(/assets/img/login.svg) no-repeat center / contain;

  transition: background-color 0.2s ease;
}

/* Hover → Icon weiß */
.card-btn--login:hover::before {
  background-color: white;
}

/* Dashboard-Button (wie Login-Button, nur anderes SVG) */
.card-btn--dashboard {
  position: relative;
  padding: 0;
  width: calc(var(--photo-h) * 0.58 / 2);
  height: calc(var(--photo-h) * 0.58 / 2);
  min-width: auto;
  align-self: end;
  justify-self: center;
  margin-bottom: 20px;
}

.card-btn--dashboard::before {
  content: "";
  width: 70%;
  height: 70%;
  display: block;
  background-color: var(--accent-strong);
  mask: url(/assets/img/dashboard.svg) no-repeat center / contain;
  -webkit-mask: url(/assets/img/dashboard.svg) no-repeat center / contain;
  transition: background-color 0.2s ease;
  margin: auto;
}

.card-btn--dashboard:hover {
  background: transparent;
}

.card-btn--logout:dashboard::before {
  background-color: var(--accent-soft);
}

/* Logout-Button (wie Login-Button, nur anderes SVG) */
.card-btn--logout {
  position: relative;
  padding: 0;
  width: calc(var(--photo-h) * 0.58 / 2);
  height: calc(var(--photo-h) * 0.58 / 2);
  min-width: auto;
  align-self: end;
  justify-self: center;
  margin-bottom: 20px;
}

.card-btn--logout::before {
  content: "";
  width: 70%;
  height: 70%;
  display: block;
  background-color: var(--accent-strong);
  mask: url(/assets/img/logout.svg) no-repeat center / contain;
  -webkit-mask: url(/assets/img/logout.svg) no-repeat center / contain;
  transition: background-color 0.2s ease;
  margin: auto;
}

.card-btn--logout:hover {
  background: transparent;
}

.card-btn--logout:hover::before {
  background-color: var(--accent-soft);
}

/* Icon-Größe in Buttons */
.card-btn img,
.card-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* Stern-Symbol für Primärkontakt */
.card-btn--primary::before {
  content: "★";
  font-size: 16px;
}

.card-btn--primary.active::before {
  content: "★";
}

/* Löschen-Symbol (Kreuz) */
.card-btn--delete::before {
  content: "✕";
  font-size: 18px;
  font-weight: bold;
}

/* Responsive: Mobile */
@media (max-width: 600px) {
  .contact-card-header {
    left: 0.7rem;
    right: 0.7rem;
  }
  
  .card-btn {
    min-width: 28px;
    height: 28px;
    padding: 4px 8px;
  }
  
  .card-title {
    font-size: 0.8rem;
    padding: 5px 8px;
  }
}

.section {
  display: grid;
  gap: 6px;
  margin: 6px 0;
}

.section h2,
.section h3 {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 1.1rem;
  letter-spacing: 0.2px;
}

/* ===== Grids ===== */
.grid {
  display: grid;
  gap: 12px;
}

.grid-2 {
  grid-template-columns: 1fr;
}

.grid-3 {
  grid-template-columns: 1fr 1fr;
}

.grid-contacts {
  display: grid;
  gap: 12px;
}

@media (min-width: 600px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }

  .grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .grid-contacts {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ===== Foto/Avatar Preview ===== */
.photo-preview {
  height: 342px;
  aspect-ratio: 3/4;
  border-radius: 16px;
  overflow: hidden;
  background: #f9f9f9;
  border: 2px solid var(--accent-soft);
  flex-shrink: 0;
  text-align: center;
  margin: 13px 0 0 0;
  align-self: flex-start;
}

.photo-preview img {
  height: 100%;
  width: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.photo-preview img:hover {
  transform: scale(1.05);
}

/* ===== Avatar Picker ===== */
.avatar-picker {
  display: grid;
  grid-template-columns: 1fr;
  position: relative;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}

.avatar-picker .strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding: 10px 0;
  border-radius: 0.5rem;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.avatar-thumb {
  height: 150px;
  aspect-ratio: 3 / 4;
  border-radius: 0.4rem;
  cursor: pointer;
  border: 2px solid transparent;
  flex: 0 0 auto;
  transition: border-color 0.15s ease, transform 0.2s ease;
  background: #fff;
}

.avatar-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-thumb:hover {
  transform: scale(1.05);
  border-color: var(--accent-strong);
}

.avatar-thumb.selected {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(83, 174, 50, 0.3);
}

/* Pfeile als Overlay */
.avatar-picker .nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--accent-strong);
  font-size: 20px;
  font-weight: bold;
  border: 2px solid var(--accent-strong);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  z-index: 5;
}

.avatar-picker .nav:hover {
  background: var(--accent-strong);
  color: #fff;
  transform: translateY(-50%) scale(1.1);
}

.avatar-picker .nav.left {
  left: 0;
}

.avatar-picker .nav.right {
  right: 0;
}

/* ===== Utility Classes ===== */
.hidden {
  display: none !important;
}

.space-top {
  margin-top: 15px;
}

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--muted);
}

/* ===== Messenger Items ===== */
.ms-row,
.msrow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 520px) {
  .ms-row,
  .msrow {
    grid-template-columns: 1fr;
  }
}

.ms-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ===== Responsive Helpers ===== */
@media (max-width: 600px) {
  .container {
    padding: 0 12px;
  }

  .brand .title {
    font-size: 1.8rem;
  }

  .photo-preview {
    height: 240px;
  }
}

/* ===== Accessibility ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus Styles */
*:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

/* ===== Admin-spezifische Styles ===== */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

/* ===== Alert Boxen ===== */
.alert {
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.alert-success {
  background: #efe;
  border: 1px solid #cfc;
  color: #3a3;
}

.alert-error {
  background: #fee;
  border: 1px solid #fcc;
  color: #c33;
}

.alert ul {
  margin: 5px 0 0;
  padding-left: 20px;
}

/* ===== Card Inner ===== */
.card.inner {
  margin-top: 2.0rem;
  position: relative;
  padding-top: 1.5rem;
}

/* ===== Avatar Section ===== */
.avatar-section {
  margin-top: 25px;
}

/* ===== Owner Cards Spacing ===== */
.owner-cards-spacing {
  margin-top: 16px;
}

/* ===== Contact Actions ===== */
.contact-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  flex-wrap: wrap;
}

.contact-actions .btn {
  flex: 1;
  min-width: 120px;
}

/* ===== SOS ID Display ===== */
.sos-id {
  color: var(--fg);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.sos-id-text {
  color: var(--ci-black);
  font-weight: 500;
}

/* ===== Section Divider ===== */
.section-divider {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 2px dashed var(--border);
}

/* Verstecke Divider wenn nachfolgendes Element .hidden hat */
.section-divider:has(+ .hidden),
.section-divider:has(+ * .hidden) {
  display: none;
}

/* ===== Pregnancy Week Display ===== */
.pregnancy-week-info {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--accent-soft);
  color: #fff;
  border-radius: 6px;
  font-weight: 600;
  text-align: center;
}

/* ===== Popup Overlay ===== */
#popup-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.popup-box {
  background: white;
  border-radius: 12px;
  padding: 40px;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.popup-box h2 {
  color: var(--accent);
  margin: 0 0 20px;
  font-size: 24px;
}

.popup-box p {
  color: var(--text);
  margin: 0 0 20px;
  line-height: 1.6;
}

.popup-box .sos-id-display {
  background: var(--bg-soft);
  padding: 15px;
  border-radius: 8px;
  margin: 20px 0;
  font-family: monospace;
  font-size: 20px;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 2px;
}

.popup-box .email-display {
  background: var(--bg-soft);
  padding: 15px;
  border-radius: 8px;
  margin: 20px 0;
  font-size: 16px;
  color: var(--text);
}

.popup-box form {
  display: flex;
  gap: 15px;
  margin-top: 30px;
}

.popup-box button {
  flex: 1;
}

.popup-box .btn {
  margin: 6px;
}

.banned-date {
  font-weight: 600;
  color: var(--danger);
  font-size: 15px;
}

/* ===== OVERLAY (für Info-Badges & Medical) ===== */
#overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

#overlay.visible {
  display: flex;
}

.overlay-box {
  background: white;
  border-radius: 16px;
  max-width: 500px;  /* Schmaler als vorher (war 600px) */
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  animation: overlaySlideIn 0.3s ease;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 2px solid #e0e0e0;
  position: sticky;
  top: 0;
  background: white;
  z-index: 10;
  border-radius: 16px 16px 0 0;
}

.overlay-close {
  background: none;
  border: none;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  color: #666;
  padding: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.overlay-close:hover {
  background: #f5f5f5;
  color: #333;
}

.overlay-content {
  padding: 24px;
}

@keyframes overlaySlideIn {
  from {
    opacity: 0;
    transform: translateY(-30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Mobile */
@media (max-width: 768px) {
  .overlay-box {
    max-width: 100%;
    margin: 0;
    border-radius: 12px;
  }
  
  .overlay-header {
    padding: 16px 20px;
  }
  
  .overlay-content {
    padding: 20px;
  }
}
