/* ========================================
   FAMILIENSTAMMBAUM - Mobile-First CSS
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ========================================
   CSS Variables (Design Tokens)
   ======================================== */
:root {
  /* Colors - Light Mode */
  --color-bg: #f8fafc;
  --color-bg-card: #ffffff;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-border: #e5e7eb;
  --color-header: #1f2937;
  --color-header-text: #ffffff;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);

  /* Safe areas for notched devices */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* Header height */
  --header-height: 56px;
}

/* Dark Mode Colors */
html.dark {
  --color-bg: #121212;
  --color-bg-card: #1e1e1e;
  --color-text: #e5e7eb;
  --color-text-muted: #9ca3af;
  --color-primary: #60a5fa;
  --color-primary-hover: #3b82f6;
  --color-border: #374151;
  --color-header: #0f172a;
  --color-header-text: #ffffff;
}

/* ========================================
   Reset & Base
   ======================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  transition: background-color 0.3s, color 0.3s;
}

/* ========================================
   App Header (Mobile-First)
   ======================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--color-header);
  padding-top: var(--safe-top);
  box-shadow: var(--shadow-md);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 var(--space-md);
  max-width: 1200px;
  margin: 0 auto;
}

.header-title {
  color: var(--color-header-text);
  font-size: 1.125rem;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Icon Buttons */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: var(--color-header-text);
  font-size: 1.25rem;
  cursor: pointer;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.2);
}

.icon-btn:active {
  transform: scale(0.95);
}

/* Hamburger Menu Icon */
.hamburger {
  flex-direction: column;
  gap: 4px;
  padding: 10px;
}

.hamburger-line {
  display: block;
  width: 20px;
  height: 2px;
  background-color: var(--color-header-text);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}

/* ========================================
   Mobile Navigation (Slide-in)
   ======================================== */
.mobile-nav {
  position: fixed;
  top: 0;
  right: -280px;
  width: 280px;
  height: 100%;
  height: 100dvh;
  background-color: var(--color-bg-card);
  z-index: 200;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.mobile-nav.open {
  right: 0;
}

.mobile-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  padding-top: calc(var(--safe-top) + var(--space-md));
  border-bottom: 1px solid var(--color-border);
}

.mobile-nav-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.close-icon {
  font-size: 1.75rem;
  line-height: 1;
}

.mobile-nav-links {
  flex: 1;
  padding: var(--space-md);
  overflow-y: auto;
}

.mobile-nav .nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  color: var(--color-text);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: background 0.2s;
}

.mobile-nav .nav-link:hover,
.mobile-nav .nav-link:active {
  background-color: var(--color-border);
}

.nav-icon {
  font-size: 1.25rem;
  width: 28px;
  text-align: center;
}

/* Overlay */
.nav-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.nav-overlay.visible {
  opacity: 1;
  visibility: visible;
}

/* Desktop Navigation (hidden on mobile) */
.desktop-nav {
  display: none;
}

/* ========================================
   Main Content
   ======================================== */
main {
  flex: 1;
  padding: var(--space-md);
  padding-bottom: calc(var(--space-xl) + var(--safe-bottom));
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* Cards / Sections */
.card, .section {
  background: var(--color-bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
  box-shadow: var(--shadow-sm);
}

.section {
  border-top: none;
}

.section h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: var(--space-md);
  color: var(--color-text);
}

/* ========================================
   Typography
   ======================================== */
h1, h2, h3, h4, h5, h6 {
  line-height: 1.3;
  font-weight: 600;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.125rem; }

.text-muted {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* ========================================
   Buttons
   ======================================== */
.btn, button, .btn-main {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 500;
  font-family: inherit;
  color: #ffffff;
  background-color: var(--color-primary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background-color 0.2s, transform 0.1s;
  -webkit-appearance: none;
  appearance: none;
}

.btn:hover, button:hover, .btn-main:hover {
  background-color: var(--color-primary-hover);
}

.btn:active, button:active, .btn-main:active {
  transform: scale(0.98);
}

.btn-secondary {
  background-color: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}

.btn-secondary:hover {
  background-color: var(--color-primary);
  color: #ffffff;
}

/* Full width button on mobile */
.btn-block {
  width: 100%;
}

/* ========================================
   Forms
   ======================================== */
input[type="text"],
input[type="search"],
input[type="date"],
input[type="email"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background-color: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

input::placeholder {
  color: var(--color-text-muted);
}

/* Search form specific */
.search-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.search-form input {
  flex: 1;
}

/* ========================================
   Links
   ======================================== */
a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.person-link {
  color: var(--color-primary);
  font-weight: 500;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s;
}

.person-link:hover {
  background-color: rgba(59, 130, 246, 0.1);
  text-decoration: none;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--color-primary);
  font-weight: 500;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all 0.2s;
}

.back-link:hover {
  background-color: var(--color-primary);
  color: #ffffff;
  text-decoration: none;
}

/* ========================================
   Lists
   ======================================== */
ul, ol {
  padding-left: var(--space-lg);
}

li {
  margin: var(--space-sm) 0;
}

/* Clean list (no bullets) */
.list-clean {
  list-style: none;
  padding-left: 0;
}

.list-clean li {
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border);
}

.list-clean li:last-child {
  border-bottom: none;
}

/* ========================================
   Footer
   ======================================== */
footer {
  background-color: var(--color-header);
  color: var(--color-header-text);
  padding: var(--space-lg);
  padding-bottom: calc(var(--space-lg) + var(--safe-bottom));
  text-align: center;
  font-size: 0.875rem;
  margin-top: auto;
}

/* ========================================
   Page-Specific: Index/Home
   ======================================== */
.hero {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
}

.hero-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-md);
  line-height: 1.3;
}

.hero-subtitle {
  color: var(--color-text-muted);
  font-size: 1rem;
  margin-bottom: var(--space-xl);
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.hero-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  max-width: 300px;
  margin: 0 auto;
}

/* Intro heading (legacy support) */
.intro-heading {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-md);
  line-height: 1.3;
}

/* ========================================
   Page-Specific: Person Detail
   ======================================== */
.person-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.person-name {
  font-size: 1.5rem;
  font-weight: 700;
}

.person-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.info-list {
  list-style: none;
  padding: 0;
}

.info-list li {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border);
}

.info-list li:last-child {
  border-bottom: none;
}

.info-list strong {
  min-width: 120px;
}

/* ========================================
   Page-Specific: Statistiken
   ======================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.stat-card {
  background: var(--color-bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chart-card {
  background: var(--color-bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  box-shadow: var(--shadow-sm);
}

.chart-card h4 {
  font-size: 1rem;
  margin-bottom: var(--space-md);
  text-align: center;
}

.chart-card canvas {
  max-height: 250px;
}

/* ========================================
   Page-Specific: Stammbaum
   ======================================== */
.stammbaum-titel {
  margin-bottom: var(--space-lg);
}

.knoten {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin: var(--space-sm) 0;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.3s, border-color 0.3s;
}

.knoten.paar {
  background: linear-gradient(135deg, var(--color-bg-card), var(--color-bg));
}

.toggle-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(59, 130, 246, 0.1);
  border-radius: var(--radius-sm);
  margin-right: var(--space-sm);
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-arrow:hover {
  background: rgba(59, 130, 246, 0.2);
}

.generation {
  margin-left: var(--space-lg);
  padding-left: var(--space-md);
  border-left: 2px solid var(--color-border);
}

/* ========================================
   Accordion
   ======================================== */
.accordion-toggle {
  width: 100%;
  text-align: left;
  padding: var(--space-md);
  background: var(--color-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}

.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.accordion-content.open {
  max-height: 2000px;
  margin-top: var(--space-md);
}

.accordion-block {
  margin: var(--space-lg) 0;
}

.accordion-block h4 {
  margin-bottom: var(--space-sm);
  font-size: 1.1rem;
}

.accordion-block ul {
  list-style-position: inside;
  padding-left: 0;
}

.accordion-block li {
  margin: var(--space-xs) 0;
}

/* ========================================
   Info Cards (for stats)
   ======================================== */
.info-card {
  background: var(--color-bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.info-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
}

.info-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* ========================================
   Tables (responsive)
   ======================================== */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

th {
  font-weight: 600;
  background: var(--color-bg);
}

/* Bootstrap overrides for dark mode */
html.dark .table {
  color: var(--color-text);
}

html.dark .table-striped tbody tr:nth-of-type(odd) {
  background-color: rgba(255, 255, 255, 0.05);
}

/* ========================================
   Legacy classes (backward compatibility)
   ======================================== */
.link-button, .btn-small {
  color: var(--color-primary);
  font-size: 1rem;
  font-weight: 500;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
}

.link-button:hover, .btn-small:hover {
  text-decoration: underline;
}

.today-section {
  margin-top: var(--space-xl);
  text-align: center;
}

.button-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  margin-top: var(--space-xl);
}

/* ========================================
   Utilities
   ======================================== */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mt-1 { margin-top: var(--space-sm); }
.mt-2 { margin-top: var(--space-md); }
.mt-3 { margin-top: var(--space-lg); }
.mt-4 { margin-top: var(--space-xl); }

.mb-1 { margin-bottom: var(--space-sm); }
.mb-2 { margin-bottom: var(--space-md); }
.mb-3 { margin-bottom: var(--space-lg); }
.mb-4 { margin-bottom: var(--space-xl); }

.py-2 { padding-top: var(--space-md); padding-bottom: var(--space-md); }
.py-3 { padding-top: var(--space-lg); padding-bottom: var(--space-lg); }
.py-4 { padding-top: var(--space-xl); padding-bottom: var(--space-xl); }

.gap-1 { gap: var(--space-sm); }
.gap-2 { gap: var(--space-md); }
.gap-3 { gap: var(--space-lg); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

.hidden { display: none !important; }

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

/* Row/Col Grid (Bootstrap-like) */
.row {
  display: flex;
  flex-wrap: wrap;
  margin: 0 calc(-1 * var(--space-sm));
}

.row > * {
  padding: 0 var(--space-sm);
  margin-bottom: var(--space-md);
}

.col-12 { width: 100%; }

.g-3, .g-4 {
  gap: var(--space-md);
}

/* ========================================
   Desktop Styles (min-width: 768px)
   ======================================== */
@media (min-width: 768px) {
  :root {
    --header-height: 64px;
  }

  /* Hide mobile hamburger, show desktop nav */
  .hamburger {
    display: none;
  }

  .desktop-nav {
    display: flex;
    justify-content: center;
    gap: var(--space-lg);
    background-color: var(--color-header);
    padding: var(--space-sm) var(--space-md);
  }

  .desktop-nav a {
    color: var(--color-header-text);
    font-weight: 500;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background 0.2s;
  }

  .desktop-nav a:hover {
    background: rgba(255, 255, 255, 0.1);
    text-decoration: none;
  }

  /* Header title larger */
  .header-title {
    font-size: 1.25rem;
  }

  /* Main content with more padding */
  main {
    padding: var(--space-xl);
  }

  /* Typography adjustments */
  h1 { font-size: 2rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.25rem; }

  .hero-title, .intro-heading {
    font-size: 2rem;
  }

  .hero-subtitle {
    font-size: 1.125rem;
  }

  /* Search form horizontal */
  .search-form {
    flex-direction: row;
    max-width: 500px;
    margin: 0 auto;
  }

  .search-form input {
    flex: 1;
  }

  .search-form button {
    flex-shrink: 0;
  }

  /* Hero buttons horizontal */
  .hero-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    max-width: none;
  }

  /* Stats grid 4 columns */
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Person header horizontal */
  .person-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  /* Charts side by side */
  .chart-card canvas {
    max-height: 300px;
  }

  /* Bootstrap-like columns */
  .col-md-3 { width: 25%; }
  .col-md-4 { width: 33.333%; }
  .col-md-6 { width: 50%; }

  .col-sm-6 { width: 50%; }
}

/* ========================================
   Large Desktop (min-width: 1024px)
   ======================================== */
@media (min-width: 1024px) {
  main {
    padding: var(--space-2xl);
  }

  .hero {
    padding: var(--space-2xl);
  }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
  .app-header,
  .mobile-nav,
  .nav-overlay,
  .desktop-nav,
  footer,
  .btn,
  button {
    display: none !important;
  }

  main {
    padding: 0;
    margin: 0;
  }

  .card, .section {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}
