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

:root {
  /* Klinikum Lippe Farbschema */
  --primary: #6d8c2a;
  --primary-light: #b1cd4d;
  --primary-lighter: #e8f2cc;
  --primary-dark: #4a6518;
  --accent: #0693e3;
  --text: #515e66;
  --text-light: #7a8890;
  --text-dark: #2c3539;
  --success: #4CAF50;
  --warning: #FF9800;
  --danger: #e53935;
  --night: #3F51B5;
  --bereitschaft: #9C27B0;
  --bg: #f4f6f0;
  --bg-card: #ffffff;
  --gray-50: #f8faf5;
  --gray-100: #f0f2ec;
  --gray-200: #e2e5dc;
  --gray-300: #cfd3c8;
  --gray-500: #9E9E9E;
  --gray-700: #616161;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 6px 20px rgba(0,0,0,.12);
}

body {
  font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3, h4 {
  font-family: 'Exo', 'Open Sans', sans-serif;
  color: var(--text-dark);
}

a { color: var(--primary); }
a:hover { color: var(--primary-dark); }

.container { max-width: 1280px; margin: 0 auto; padding: 0 1.25rem; }

/* === Navigation === */
.navbar {
  background: #fff;
  border-bottom: 3px solid var(--primary-light);
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  text-decoration: none;
  color: var(--text-dark);
  font-family: 'Exo', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
}
.nav-brand img {
  height: 40px;
  width: auto;
}
.nav-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.nav-brand-title { font-size: 1rem; font-weight: 700; color: var(--text-dark); }
.nav-brand-sub { font-size: .7rem; font-weight: 400; color: var(--primary); letter-spacing: .02em; }

.nav-links {
  list-style: none;
  display: flex;
  gap: 0;
  margin: 0;
}
.nav-links li { position: relative; }
.nav-links a {
  display: block;
  padding: 1.25rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 600;
  transition: color .2s, background .2s;
  border-bottom: 3px solid transparent;
  margin-bottom: -3px;
}
.nav-links a:hover,
.nav-links a.active {
  color: var(--primary);
  border-bottom-color: var(--primary-light);
  background: var(--gray-50);
}

/* Mobile nav toggle */
.nav-toggle { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); padding: .5rem; }

/* === Flash Messages === */
.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin: 1rem 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .9rem;
  border-left: 4px solid;
}
.flash-success { background: #e8f5e9; color: #2e7d32; border-left-color: var(--success); }
.flash-error { background: #ffebee; color: #c62828; border-left-color: var(--danger); }
.flash-warning { background: #fff3e0; color: #e65100; border-left-color: var(--warning); }
.flash-info { background: var(--primary-lighter); color: var(--primary-dark); border-left-color: var(--primary-light); }
.flash-close { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: inherit; opacity: .6; }
.flash-close:hover { opacity: 1; }

/* === Cards === */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  border: 1px solid var(--gray-200);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: .75rem;
  border-bottom: 2px solid var(--primary-lighter);
}
.card-header h2 {
  font-size: 1.15rem;
  color: var(--primary-dark);
}

/* === Stats Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  text-align: center;
  border: 1px solid var(--gray-200);
  border-top: 3px solid var(--primary-light);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.stat-value { font-size: 2rem; font-weight: 900; color: var(--primary); font-family: 'Exo', sans-serif; }
.stat-label { font-size: .8rem; color: var(--text-light); margin-top: .25rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }

/* === Tables === */
table { width: 100%; border-collapse: collapse; }
th, td { padding: .625rem .75rem; text-align: left; border-bottom: 1px solid var(--gray-200); }
th {
  background: var(--primary-lighter);
  font-weight: 600;
  font-size: .8rem;
  color: var(--primary-dark);
  text-transform: uppercase;
  letter-spacing: .04em;
}
tr:hover { background: var(--gray-50); }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .5rem 1.125rem;
  border: none;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: 'Open Sans', sans-serif;
  transition: all .2s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--gray-300);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

/* === Forms === */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: .35rem;
  font-size: .85rem;
  color: var(--text-dark);
}
.form-control {
  width: 100%;
  padding: .55rem .75rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .2s, box-shadow .2s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(177, 205, 77, .25);
}
select.form-control { appearance: auto; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: .5rem; margin-top: 1.25rem; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-success { background: #e8f5e9; color: #2e7d32; }
.badge-warning { background: #fff3e0; color: #e65100; }
.badge-danger { background: #ffebee; color: #c62828; }
.badge-info { background: var(--primary-lighter); color: var(--primary-dark); }

/* === Schedule Grid === */
.schedule-container { overflow-x: auto; }
.schedule-grid {
  display: grid;
  font-size: .8rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  min-width: fit-content;
}
.schedule-grid .header-cell {
  background: var(--primary-lighter);
  font-weight: 700;
  padding: .4rem .3rem;
  text-align: center;
  border-bottom: 2px solid var(--primary-light);
  border-right: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--primary-dark);
  font-size: .75rem;
}
.schedule-grid .name-cell {
  padding: .4rem .5rem;
  font-weight: 600;
  background: #fff;
  border-right: 2px solid var(--primary-light);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
  position: sticky;
  left: 0;
  z-index: 1;
  color: var(--text-dark);
}
.schedule-grid .day-cell {
  padding: .25rem;
  text-align: center;
  border-right: 1px solid var(--gray-200);
  border-bottom: 1px solid var(--gray-200);
  cursor: pointer;
  min-width: 2.2rem;
  font-weight: 700;
  transition: background .1s, transform .1s;
}
.day-cell:hover { filter: brightness(.92); }
.day-cell.weekend { background: #faf6e8; }
.day-cell.absence { background: #ffebee; cursor: not-allowed; }
.day-cell.shift-F { background: #e8f5e9; color: #2e7d32; }
.day-cell.shift-S { background: #fff3e0; color: #e65100; }
.day-cell.shift-N { background: #e8eaf6; color: #283593; }
.day-cell.shift-B { background: #f3e5f5; color: #6a1b9a; }
.header-cell.weekend { background: #f5efc8; }
.header-cell.holiday { background: #ffcdd2; color: #c62828; }
.day-cell.holiday { background: #fff0f0; }

/* Grid dropdown editor */
.cell-editor {
  position: absolute;
  z-index: 50;
  background: #fff;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: .25rem;
}
.cell-editor button {
  display: block;
  width: 100%;
  padding: .35rem .75rem;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  font-size: .85rem;
  border-radius: 4px;
  font-weight: 600;
}
.cell-editor button:hover { background: var(--primary-lighter); color: var(--primary-dark); }

/* === Loading Spinner === */
.spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--gray-300);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

/* === Metrics Panel (Plan-Qualität) === */
.metrics-panel { padding: 1rem 1.25rem; border-left: 4px solid var(--primary-light); }
.metrics-box {
  flex: 1 1 160px;
  min-width: 160px;
  padding: .5rem .75rem;
  background: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}
.metrics-label { font-size: .7rem; color: var(--text-light); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.metrics-value { font-size: 1.4rem; font-weight: 700; font-family: 'Exo', sans-serif; margin-top: .15rem; }
.metrics-value small { font-size: .85rem; font-weight: 400; color: var(--text-light); }
.metrics-warn { font-size: .75rem; color: var(--danger); margin-top: .15rem; font-weight: 600; }

/* === Warnings List === */
.warnings { list-style: none; padding: 0; }
.warnings li {
  padding: .5rem .75rem;
  background: #fff3e0;
  border-left: 3px solid var(--warning);
  margin-bottom: .5rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .85rem;
}

/* === Footer === */
.footer {
  text-align: center;
  padding: 2rem 0 1rem;
  color: var(--text-light);
  font-size: .8rem;
}
.footer-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
}
.footer img { height: 24px; opacity: .6; }

/* === Page Header === */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1.5rem 0 1rem;
}
.page-header h1 {
  font-size: 1.5rem;
  font-family: 'Exo', sans-serif;
  color: var(--text-dark);
}

/* === Responsive === */
@media (max-width: 768px) {
  .nav-links { display: none; flex-direction: column; position: absolute; top: 64px; left: 0; right: 0; background: #fff; border-bottom: 3px solid var(--primary-light); box-shadow: var(--shadow-lg); }
  .nav-links.open { display: flex; }
  .nav-links a { padding: 1rem 1.25rem; border-bottom: 1px solid var(--gray-200); margin-bottom: 0; }
  .nav-toggle { display: block; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .nav-brand-text { display: none; }
}

/* === Print === */
@media print {
  .navbar, .btn, .flash, .footer, .cell-editor { display: none !important; }
  .schedule-grid { font-size: .7rem; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
