/**
 * Belegungszahlen-Portal
 * Stiftungsamt Aschaffenburg
 * Design inspiriert von stiftungsamt.de
 */

:root {
  /* Farbpalette - würdevoll, behördlich */
  --color-primary: #1a365d;
  --color-primary-light: #2c5282;
  --color-primary-dark: #0f2744;
  --color-accent: #b8860b;
  --color-accent-light: #d4a84b;
  --color-accent-muted: rgba(184, 134, 11, 0.15);
  
  --color-bg: #f8f7f4;
  --color-bg-card: #ffffff;
  --color-bg-header: #1a365d;
  
  --color-text: #2d3748;
  --color-text-muted: #718096;
  --color-text-light: #e2e8f0;
  
  --color-border: #e2e8f0;
  --color-border-focus: #2c5282;
  
  --color-success: #276749;
  --color-success-bg: #c6f6d5;
  --color-error: #c53030;
  --color-error-bg: #fed7d7;
  
  --shadow-sm: 0 1px 2px rgba(26, 54, 93, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(26, 54, 93, 0.08), 0 2px 4px -2px rgba(26, 54, 93, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(26, 54, 93, 0.08), 0 4px 6px -4px rgba(26, 54, 93, 0.04);
  
  --radius: 6px;
  --radius-lg: 10px;
  --font-sans: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: 'Cormorant Garamond', Georgia, serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
}

/* ========== Login Page ========== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

.login-bg-pattern {
  position: absolute;
  inset: 0;
  background: 
    linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%),
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 40px,
      rgba(255,255,255,0.02) 40px,
      rgba(255,255,255,0.02) 80px
    );
  z-index: 0;
}

.login-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  margin: 2rem;
  background: var(--color-bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.login-header {
  background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  color: white;
  padding: 2.5rem 2rem;
  text-align: center;
}

.logo-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  background: var(--color-accent);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.login-header h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 600;
}

.login-header .subtitle {
  margin: 0.5rem 0 0;
  font-size: 0.95rem;
  opacity: 0.9;
}

.login-form-wrapper {
  padding: 2rem;
}

.login-form .form-group {
  margin-bottom: 1.25rem;
}

.login-form label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  font-size: 0.9rem;
}

.login-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color 0.2s;
}

.login-form input:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px var(--color-accent-muted);
}

.login-form .btn {
  margin-top: 0.5rem;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--color-error-bg);
  color: var(--color-error);
}

.alert-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

/* ========== Main Layout ========== */
.main-header {
  background: var(--color-bg-header);
  color: white;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: white;
  font-weight: 600;
  font-size: 1.1rem;
}

.logo-mark {
  width: 36px;
  height: 36px;
  background: var(--color-accent);
  border-radius: 6px;
}

.main-nav {
  display: flex;
  gap: 0.5rem;
  flex: 1;
}

.main-nav a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  transition: all 0.2s;
}

.main-nav a:hover {
  color: white;
  background: rgba(255,255,255,0.1);
}

.main-nav a.active {
  color: white;
  background: var(--color-accent);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
}

.user-name {
  font-weight: 500;
}

.user-role {
  opacity: 0.8;
  font-size: 0.85rem;
}

.main-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.dashboard-subnav {
  background: #f1f5f9;
  border-bottom: 1px solid var(--color-border);
}

.subnav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.5rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.dashboard-subnav a {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  color: var(--color-primary);
  text-decoration: none;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.dashboard-subnav a:hover {
  background: rgba(26, 54, 93, 0.08);
}

.dashboard-subnav a.active {
  background: var(--color-primary);
  color: white;
}

.main-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--color-border);
  margin-top: 3rem;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-light);
}

.btn-outline {
  background: transparent;
  color: white;
  border: 1px solid rgba(255,255,255,0.6);
}

.btn-outline:hover {
  background: rgba(255,255,255,0.1);
  border-color: white;
}

.main-content .btn-outline {
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.main-content .btn-outline:hover {
  background: var(--color-accent-muted);
}

.btn-danger {
  background: var(--color-error);
  color: white;
}

.btn-danger:hover {
  background: #9b2c2c;
}

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1.05rem; }
.btn-block { width: 100%; }

/* ========== Page Header ========== */
.page-header {
  margin-bottom: 2rem;
}

.page-header h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 600;
  color: var(--color-primary);
}

.page-header .lead {
  margin: 0.5rem 0 0;
  color: var(--color-text-muted);
  font-size: 1.05rem;
}

/* ========== Cards ========== */
.card {
  background: var(--color-bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.card-header {
  padding: 1.25rem 1.5rem;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.card-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--color-primary);
}

.card-body {
  padding: 1.5rem;
}

.badge {
  background: var(--color-primary);
  color: white;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
}

/* ========== Dashboard ========== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.card-stat .card-body {
  padding: 1.25rem;
}

.card-stat h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

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

.stat-unit {
  font-size: 1rem;
  font-weight: 400;
  color: var(--color-text-muted);
}

.stat-bar {
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  margin: 0.75rem 0 0.25rem;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.stat-meta, .stat-date {
  margin: 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

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

.chart-section {
  margin-bottom: 1.5rem;
}

.chart-container {
  position: relative;
  height: 320px;
}

.chart-container.chart-bar {
  height: 280px;
}

.chart-container.chart-wohnbereich {
  height: auto;
  min-height: 200px;
}

.section-title {
  margin: 1.5rem 0 0.75rem;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--color-primary);
}

.wohnbereich-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.wohnbereich-card .card-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.wohnbereich-stats {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.wohnbereich-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.wohnbereich-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.95rem;
}

.wohnbereich-name {
  font-weight: 500;
}

.wohnbereich-zahl {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.wohnbereich-bar {
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
}

.wohnbereich-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.stichtag-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stichtag-cards-5 {
  grid-template-columns: repeat(5, 1fr);
}

@media (max-width: 1200px) {
  .stichtag-cards-5 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .stichtag-cards-5 { grid-template-columns: 1fr; }
}

.section-link {
  margin: -0.5rem 0 1rem;
  font-size: 0.95rem;
}

.section-link a {
  color: var(--color-primary);
  text-decoration: none;
}

.section-link a:hover {
  text-decoration: underline;
}

.stichtag-card .card-header h3 {
  margin: 0;
  font-size: 1rem;
}

.stichtag-stats {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stichtag-row {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--color-border);
}

.stichtag-row.stichtag-subsection {
  font-weight: 600;
  color: var(--color-primary);
  margin-top: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

.stichtag-row.stichtag-subsection:first-of-type {
  margin-top: 0;
}

.stichtag-row.stichtag-gesamt {
  border-bottom: none;
  font-size: 1.1rem;
  color: var(--color-primary);
  margin-top: 0.25rem;
}

/* Stichtagsbelegung: Einrichtung als Karte mit Tabelle – kompakt */
.stichtag-einrichtung-card {
  margin-bottom: 1.25rem;
}

.stichtag-einrichtung-card:last-child {
  margin-bottom: 0;
}

.stichtag-einrichtung-card .card-header {
  padding: 0.6rem 1rem;
}

.stichtag-einrichtung-card .card-header h3 {
  font-size: 1rem;
  margin: 0;
}

.stichtag-einrichtung-card .card-body {
  padding: 0.75rem 1rem;
}

.stichtag-einrichtung-table {
  font-size: 0.8rem;
}

.stichtag-einrichtung-table th,
.stichtag-einrichtung-table td {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

.stichtag-einrichtung-table th:not(:first-child),
.stichtag-einrichtung-table td:not(:first-child) {
  text-align: center;
  min-width: 2.5rem;
}

.stichtag-einrichtung-table th {
  font-weight: 600;
  font-size: 0.75rem;
  white-space: nowrap;
}

.stichtag-einrichtung-table .stichtag-label {
  font-weight: 500;
  color: var(--color-text);
  min-width: 100px;
  font-size: 0.8rem;
}

.stichtag-einrichtung-table tr.stichtag-gesamt td {
  font-weight: 600;
  color: var(--color-primary);
  border-top: 1px solid var(--color-border);
  padding-top: 0.35rem;
}

/* Optische Trennung: 2 Tabellenbereiche */
.stichtag-tbody-1 {
  background: #fafbfc;
}

.stichtag-tbody-2 {
  background: #fff;
}

.stichtag-tbody-2 tr:first-child td {
  border-top: 2px solid var(--color-primary);
  padding-top: 0.5rem;
}

/* ========== Forms ========== */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  font-size: 0.9rem;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-border-focus);
}

.form-group input:disabled {
  background: #f1f5f9;
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.form-hint {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.form-inline input,
.form-inline select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.form-inline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  align-items: end;
}

.form-group-full {
  grid-column: 1 / -1;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  cursor: pointer;
}

.form-actions {
  margin-top: 2rem;
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ========== Data Table ========== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.data-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--color-primary);
}

.data-table tr:hover {
  background: #f8fafc;
}

.data-table tr.disabled {
  opacity: 0.6;
}

.data-table .actions {
  white-space: nowrap;
}

.data-table .actions form {
  display: inline;
}

.data-table .actions .btn {
  margin-right: 0.25rem;
}

/* ========== Einrichtungen Admin ========== */
.einrichtung-card {
  margin-bottom: 1.5rem;
}

.wohnbereich-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
}

.wohnbereich-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

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

.wohnbereich-list .form-inline input[type="text"] {
  min-width: 180px;
}

.mb-3 { margin-bottom: 1rem; }

/* ========== Belegung ========== */
.belegung-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.belegung-row.belegung-gesamt {
  font-weight: 600;
  background: #f8fafc;
  margin: 0 -1.5rem;
  padding: 0.75rem 1.5rem;
  border-bottom-color: var(--color-border);
}

.belegung-inputs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.belegung-inputs input {
  width: 80px;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  text-align: center;
}

.belegung-card h4 {
  margin: 1.5rem 0 0.75rem;
  font-size: 0.95rem;
  color: var(--color-text-muted);
}

/* ========== Modal ========== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.modal.open {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-muted);
  line-height: 1;
  padding: 0 0.25rem;
}

.modal-close:hover {
  color: var(--color-text);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: stretch;
  }
  
  .main-nav {
    flex-wrap: wrap;
  }
  
  .cards-grid {
    grid-template-columns: 1fr;
  }
  
  .form-inline {
    flex-direction: column;
    align-items: stretch;
  }
  
  .form-inline input {
    width: 100%;
  }
}

/* ========== Print Button ========== */
.page-header-with-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn-print {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-print:hover {
  background: var(--color-primary-light);
}

.btn-print svg {
  flex-shrink: 0;
}

/* ========== Druckansicht (A4) ========== */
@media screen {
  .print-only {
    display: none !important;
  }
}

@media print {
  .print-only {
    display: block !important;
  }

  .no-print,
  .main-header,
  .dashboard-subnav,
  .main-footer,
  .btn-print {
    display: none !important;
  }

  body {
    background: white;
    font-size: 11pt;
  }

  .main-content {
    max-width: none;
    padding: 0;
  }

  @page {
    size: A4;
    margin: 15mm;
  }

  .dashboard {
    padding: 0;
  }

  .page-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #1a365d;
  }

  .page-header h1 {
    font-size: 18pt;
    margin: 0 0 0.25rem;
  }

  .page-header .lead {
    font-size: 10pt;
    margin: 0;
    color: #333;
  }

  .print-meta {
    font-size: 9pt;
    color: #666;
    margin-top: 0.5rem;
  }

  .card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
    margin-bottom: 1rem;
  }

  .card-header {
    background: #f5f5f5 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .card-stat {
    break-inside: avoid;
  }

  .stat-bar-fill,
  .wohnbereich-bar-fill {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .chart-container {
    height: 200px !important;
    page-break-inside: avoid;
  }

  .wohnbereich-cards {
    display: block;
  }

  .wohnbereich-card {
    break-inside: avoid;
    margin-bottom: 1rem;
  }

  .section-title {
    font-size: 14pt;
    margin: 1.5rem 0 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid #ddd;
  }
}
