:root {
  --bg: #09090c;
  --bg-elev: #111117;
  --bg-cell: #18181f;
  --border: #252530;
  --text: #eceaf2;
  --text-dim: #7c798c;
  --accent: #f07a6a;         /* Salmon — Primärfarbe */
  --accent-text: #1a0c08;    /* Text auf Salmon-Buttons */
  --green: #1c3028;
  --green-soft: #162620;
  --red: #3a1a1e;
  --red-soft: #2c1418;
  --red-x: #f87171;
  --blue: #1a2a44;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

.view { width: 100%; min-height: 100vh; }
.hidden { display: none !important; }

/* ---------- Login ---------- */
#login-view,
#first-login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  overflow: hidden;
  position: relative;
}
.login-box::before {
  content: '';
  display: block;
  height: 2px;
  background: linear-gradient(90deg, #f07a6a 0%, #e06030 55%, #b5c71b 100%);
}
.login-box-inner {
  padding: 22px 28px 28px;
}
.login-logo {
  display: block;
  height: 40px;
  width: auto;
  margin-bottom: 16px;
}
.login-box h1 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.login-box .hint {
  margin: 0 0 20px;
  color: var(--text-dim);
  font-size: 13px;
}

#login-form,
#first-login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 4px;
}

input[type="password"],
input[type="text"] {
  background: var(--bg-cell);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 16px; /* >=16px verhindert iOS-Auto-Zoom beim Fokus */
  outline: none;
  min-height: 44px;
  width: 100%;
}
input:focus { border-color: var(--accent); }

button {
  background: var(--accent);
  color: var(--accent-text, #1a0c08);
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(1px); }

#login-form button,
#first-login-form button {
  min-height: 44px;
  font-size: 15px;
}

.error {
  color: #ff8a8a;
  font-size: 14px;
  margin-top: 12px;
  min-height: 1.2em;
}

/* ---------- App ---------- */
#app-view {
  padding: 24px;
  max-width: 720px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
  position: relative;
  padding-top: 4px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.week-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 6px;
}

.week-switch button {
  background: transparent;
  color: var(--text);
  padding: 4px 10px;
  font-size: 18px;
  border-radius: 6px;
  min-height: 36px;
  min-width: 36px;
}
.week-switch button:hover { background: var(--bg-cell); }

#week-label {
  font-size: 14px;
  min-width: 150px;
  text-align: center;
  color: var(--text-dim);
}

.logout {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}
.logout:hover { background: var(--bg-cell); }

/* ---------- Card ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 16px 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#emp-name {
  font-size: 18px;
  font-weight: 600;
}

.badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.skill-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-cell);
  color: var(--text);
  border: 1px solid var(--border);
}

.badge-soll { background: var(--bg-cell); }
.badge-max { background: var(--bg-cell); }

.badge-contract.fest { background: #c7e457; color: #1b1d22; border-color: transparent; }
.badge-contract.azubi { background: #5dbef0; color: #1b1d22; border-color: transparent; }
.badge-contract.mini { background: #b58cf0; color: #1b1d22; border-color: transparent; }

.skill {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  color: #1b1d22;
}
.skill-service { background: #ff8c2a; }
.skill-kueche { background: #4cc77a; }
.skill-fahrer { background: #5da8ff; }
.skill-fahrradfahrer { background: #2a4d7a; color: #fff; }

.status {
  font-size: 12px;
  color: var(--text-dim);
  min-height: 1.2em;
}
.status.saved { color: #7cd28b; }
.status.saving { color: var(--accent); }
.status.error { color: #ff8a8a; }

/* ---------- Tabelle ---------- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 4px;
}

thead th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  text-align: center;
  padding: 6px 4px;
}

thead th:first-child { text-align: left; padding-left: 12px; }

tbody td {
  padding: 0;
  height: 44px;
  text-align: center;
  background: var(--bg-cell);
  border-radius: 6px;
  font-weight: 500;
}

tbody td.day-name {
  text-align: left;
  padding-left: 12px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  width: 35%;
}

.day-date {
  color: var(--text-dim);
  margin-left: 5px;
}

/* Kurz-Tagname wird per Media-Query auf Mobile aktiviert */
.day-short { display: none; }

tbody td.slot {
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: filter 0.1s;
  touch-action: manipulation;
}
tbody td.slot:hover { filter: brightness(1.12); }
tbody td.slot:active { filter: brightness(0.85); }

tbody td.slot.available {
  background: #dcfce7;
  border: 1px solid #b5e6c4;
}

tbody td.slot.unavailable {
  background: #fee2e2;
  border: 1px solid #fbb4b4;
  color: #c93535;
  font-size: 18px;
  font-weight: 700;
}

tbody td.slot.unavailable::after {
  content: "✗";
}

tbody td.slot.school {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  font-size: 18px;
  font-weight: 700;
}

/* Teilverfügbar — gleicher Gelb-Ton, aber etwas heller + Uhrzeit-Text */
tbody td.slot.partial {
  background: #fde68a;
  border: 1px solid #f59e0b;
  color: #78350f;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  user-select: none;
}

tbody.locked td.slot {
  cursor: not-allowed;
  opacity: 0.55;
}
tbody.locked td.slot:hover { filter: none; }
tbody.locked td.slot:active { filter: none; }

.lock-hint {
  display: none;
  margin: 10px 4px 0;
  padding: 8px 12px;
  background: #3a2d1a;
  border: 1px solid #6e5022;
  border-radius: 6px;
  color: #f0c674;
  font-size: 13px;
}
.lock-hint.show { display: block; }

.legend {
  margin: 16px 0 4px;
  padding: 12px;
  background: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.legend-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.legend-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.legend-item[hidden] { display: none; }
.legend-text strong { font-weight: 600; }
.legend-coarse-pointer { display: none; }
@media (hover: none) and (pointer: coarse) {
  .legend-fine-pointer { display: none; }
  .legend-coarse-pointer { display: inline; }
}
.legend-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.legend-swatch.sw-available {
  background: #dcfce7;
  border: 1px solid #b5e6c4;
}
.legend-swatch.sw-unavailable {
  background: #fee2e2;
  border: 1px solid #fbb4b4;
  color: #c93535;
}
.legend-swatch.sw-school {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
}
.legend-swatch.sw-partial {
  background: #fde68a;
  border: 1px solid #f59e0b;
  color: #78350f;
  width: auto;
  min-width: 28px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- Modal: Uhrzeit für Teilverfügbarkeit ---------- */
.time-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.time-modal.hidden { display: none; }
.time-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}
.time-modal-box {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 20px 18px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.time-modal-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}
.time-modal-hint {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}
#time-modal-input {
  background: var(--bg-cell);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  outline: none;
  min-height: 50px;
  width: 100%;
  letter-spacing: 0.04em;
  /* Native Picker auf Mobile (iOS Safari, Android Chrome) verwenden */
  -webkit-appearance: none;
  appearance: none;
}
#time-modal-input:focus { border-color: var(--accent); }
.time-modal-error {
  font-size: 13px;
  color: #ff8a8a;
  min-height: 1.2em;
}
.time-modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
.tm-btn {
  border-radius: 8px;
  padding: 12px 8px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border);
  cursor: pointer;
  min-height: 46px;
  touch-action: manipulation;
}
.tm-secondary {
  background: var(--bg-cell);
  color: var(--text);
}
.tm-secondary:hover { background: var(--border); }
.tm-danger {
  background: var(--red-soft);
  color: #ff8a8a;
  border-color: var(--red);
}
.tm-danger:hover { background: var(--red); color: #fff; }
.tm-primary {
  background: var(--accent);
  color: #1b1d22;
  border-color: transparent;
}
.tm-primary:hover { filter: brightness(1.08); }

/* ---------- Tablet ---------- */
@media (max-width: 768px) {
  #app-view { padding: 16px; }
  #week-label { min-width: 130px; }
}

/* ---------- Handy (Portrait) ---------- */
@media (max-width: 480px) {
  #app-view { padding: 12px; }

  /* Topbar wird zur vertikalen Spalte */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 16px;
  }

  .topbar h1 {
    font-size: 18px;
    text-align: left;
  }

  /* Aktionen: Wochen-Switch + "Aktuelle Woche" volle Breite,
     Passwort + Abmelden in 2er-Grid */
  .topbar-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  .week-switch {
    grid-column: 1 / -1;
    justify-content: space-between;
    padding: 6px 8px;
  }

  .week-switch button {
    padding: 8px 16px;
    font-size: 22px;
    min-height: 44px;
    min-width: 44px;
  }

  #week-label {
    flex: 1;
    min-width: 0;
    font-size: 13px;
  }

  #week-today {
    grid-column: 1 / -1;
  }

  .topbar-right .logout {
    min-height: 44px;
    font-size: 14px;
    padding: 10px 12px;
  }

  /* Card: kompakter, Header gestackt */
  .card {
    padding: 12px;
  }

  .card-header {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .status {
    text-align: left;
  }

  /* Tagsnamen abkürzen (Mo, Di, ...) */
  .day-long { display: none; }
  .day-short { display: inline; }

  tbody td.day-name {
    width: 22%;
    padding-left: 8px;
    font-size: 15px;
    font-weight: 600;
  }

  /* Größere Slot-Zellen für Tap-Komfort */
  tbody td {
    height: 52px;
  }

  thead th {
    font-size: 11px;
  }

  thead th:first-child {
    padding-left: 8px;
  }

  tbody td.slot.unavailable,
  tbody td.slot.school {
    font-size: 20px;
  }

  .lock-hint {
    margin-left: 0;
    margin-right: 0;
    font-size: 13px;
  }

  /* Legende: einspaltig, kompakt, etwas mehr Luft zwischen Items */
  .legend {
    padding: 10px;
    margin-top: 14px;
  }
  .legend-items {
    flex-direction: column;
    gap: 8px;
  }
  .legend-item { font-size: 13px; }
  .legend-swatch { width: 26px; height: 26px; }

  /* Modal-Box auf Mobile: volle Breite minus Padding */
  .time-modal { padding: 12px; }
  .time-modal-box { padding: 18px 16px 14px; }
  #time-modal-input { font-size: 22px; padding: 14px; }
}

/* ---------- Sehr schmale Geräte (z. B. iPhone SE) ---------- */
@media (max-width: 360px) {
  #app-view { padding: 10px; }
  .card { padding: 10px; }

  .topbar-right { gap: 6px; }

  tbody td.day-name {
    padding-left: 6px;
    font-size: 14px;
  }

  thead th {
    font-size: 10px;
    padding: 4px 2px;
  }

  .topbar-right .logout {
    font-size: 13px;
    padding: 10px 8px;
  }

  /* Legende auf kleinstem Screen: noch kompakter */
  .legend { padding: 10px 8px; }
  .legend-title { font-size: 11px; }
  .legend-item { font-size: 12px; }
}
