* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #222;
  background: #f6f7f9;
  -webkit-text-size-adjust: 100%;
}

header {
  background: #1f3a5f;
  color: #fff;
  padding: 0.75rem 1.5rem 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  margin: 0 0 0.5rem 0;
  font-size: 1.3rem;
  font-weight: 600;
}

nav#tabnav {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
nav#tabnav::-webkit-scrollbar { display: none; }

nav#tabnav button {
  background: transparent;
  color: #cfd9e6;
  border: 0;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  white-space: nowrap;
  flex-shrink: 0;
}

nav#tabnav button:hover { background: rgba(255,255,255,0.08); color: #fff; }

nav#tabnav button.active {
  background: #f6f7f9;
  color: #1f3a5f;
  font-weight: 600;
}

main {
  padding: 1.25rem 1.5rem;
  max-width: 1300px;
  margin: 0 auto;
}

.tab { display: none; }
.tab.active { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

button {
  background: #fff;
  color: #222;
  border: 1px solid #c4ccd6;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 40px;
}

button:hover { background: #eef1f5; }

button.primary {
  background: #1f3a5f;
  color: #fff;
  border-color: #1f3a5f;
}
button.primary:hover { background: #2a4d7c; }

button.danger {
  background: #b33;
  color: #fff;
  border-color: #b33;
}
button.danger:hover { background: #d44; }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th, td {
  border: 1px solid #e1e5eb;
  padding: 0.45rem 0.6rem;
  text-align: left;
  font-size: 0.92rem;
  vertical-align: middle;
}

th {
  background: #eef1f5;
  font-weight: 600;
  white-space: nowrap;
}

input[type=text], input[type=number], input[type=time], select {
  padding: 0.4rem 0.5rem;
  border: 1px solid #c4ccd6;
  border-radius: 4px;
  font-size: 1rem;
  min-height: 36px;
  background: #fff;
}

input[type=number] { width: 5rem; }
input[type=text] { min-width: 8rem; }

textarea {
  width: 100%;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.85rem;
  padding: 0.6rem;
  border: 1px solid #c4ccd6;
  border-radius: 6px;
}

.hint { color: #667; font-size: 0.85rem; }
.info { color: #1f3a5f; font-size: 0.9rem; font-style: italic; }

.empty-hint {
  background: #fff;
  border: 1px dashed #c4ccd6;
  padding: 1.25rem;
  border-radius: 6px;
  color: #667;
  text-align: center;
}

footer {
  text-align: center;
  padding: 1rem;
  color: #889;
}

/* ---------- Plan: Desktop-Grid ---------- */
.plan-grid {
  display: grid;
  grid-template-columns: 140px repeat(5, 1fr);
  gap: 4px;
  background: #fff;
  padding: 8px;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.plan-grid .pg-head,
.plan-grid .pg-row-label {
  font-weight: 600;
  text-align: center;
  padding: 0.5rem;
  background: #eef1f5;
  border-radius: 4px;
}

.plan-grid .pg-row-label {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
}

.plan-cell {
  background: #f6f7f9;
  padding: 0.55rem;
  border-radius: 4px;
  min-height: 60px;
}

.plan-cell.empty {
  background: #fafbfc;
  color: #aab;
  font-style: italic;
  text-align: center;
}

.plan-cell.understaffed {
  background: #fde9e9;
  border: 1px solid #d99;
}

.plan-cell .time {
  font-size: 0.75rem;
  color: #667;
  display: block;
  margin-bottom: 4px;
}

.person {
  display: inline-block;
  background: #1f3a5f;
  color: #fff;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.85rem;
  margin: 2px 4px 2px 0;
}

.person.parttime { background: #6a4e1f; }

.stats-table { margin-top: 1rem; max-width: 700px; }

.legend {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.8rem;
  margin: 0 0.2rem;
}
.legend.yes { background: #c8e6c9; color: #1a4d1f; }
.legend.no  { background: #fbd1d1; color: #6b1a1a; }

/* ---------- Plan: Mobile-Liste ---------- */
.plan-mobile { display: none; margin-bottom: 1rem; }

.plan-mobile .day-card {
  background: #fff;
  border-radius: 6px;
  margin-bottom: 0.6rem;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.plan-mobile .day-card h3 {
  margin: 0;
  background: #1f3a5f;
  color: #fff;
  padding: 0.5rem 0.9rem;
  font-size: 1rem;
}

.plan-mobile .shift-item {
  padding: 0.6rem 0.9rem;
  border-top: 1px solid #eef1f5;
}
.plan-mobile .shift-item:first-of-type { border-top: 0; }

.plan-mobile .shift-item.understaffed { background: #fde9e9; }

.plan-mobile .shift-meta {
  font-size: 0.85rem;
  color: #667;
  margin-bottom: 0.35rem;
}

.plan-mobile .shift-staff { line-height: 1.8; }

/* ---------- Präferenz-Matrix ---------- */
#prefs-table { min-width: max-content; }

#prefs-table th, #prefs-table td {
  text-align: center;
  padding: 0.25rem;
}

#prefs-table td.pref-cell {
  cursor: pointer;
  user-select: none;
  min-width: 56px;
  min-height: 44px;
  font-weight: 600;
  font-size: 1rem;
}

#prefs-table td.pref-cell.yes { background: #c8e6c9; color: #1a4d1f; }
#prefs-table td.pref-cell.no  { background: #fbd1d1; color: #6b1a1a; }

#prefs-table td.name-cell {
  text-align: left;
  font-weight: 600;
  background: #eef1f5;
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 8rem;
}
#prefs-table thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
}

.warning { color: #b33; font-weight: 600; }

/* ---------- Mobile-Breakpoints ---------- */
@media (max-width: 760px) {
  header { padding: 0.5rem 0.75rem 0; }
  header h1 { font-size: 1.05rem; }

  main { padding: 0.75rem; }

  nav#tabnav button { font-size: 0.85rem; padding: 0.5rem 0.7rem; }

  .toolbar { gap: 0.5rem; }
  .toolbar > button { flex: 1 1 auto; }

  th, td { padding: 0.4rem 0.5rem; font-size: 0.9rem; }

  input[type=number] { width: 4.5rem; }
  input[type=text] { min-width: 6rem; width: 100%; }

  .plan-grid { display: none; }
  .plan-mobile { display: block; }

  .stats-table th, .stats-table td { font-size: 0.85rem; }
}

@media (max-width: 480px) {
  main { padding: 0.5rem; }
  header { padding: 0.4rem 0.5rem 0; }
  h3 { font-size: 1rem; }
  .toolbar { gap: 0.4rem; }
  .toolbar > * { width: 100%; }
  .toolbar > input[type=number], .toolbar > label { width: auto; }
  .toolbar label { display: flex; align-items: center; gap: 0.4rem; }
}

/* ---------- Druckansicht ---------- */
@media print {
  header nav, footer, .toolbar, .empty-hint { display: none; }
  body { background: #fff; }
  .tab { display: block !important; }
  #tab-employees, #tab-shifts, #tab-preferences, #tab-data { display: none !important; }
  .plan-grid { display: grid; }
  .plan-mobile { display: none; }
}
