* { box-sizing: border-box; }
:root {
  --blue: #2b5b8c;
  --blue-dark: #1f4368;
  --bg: #f4f6f9;
  --border: #d7dde5;
  --green: #3aa655;
  --green-light: #bfe3c8;
  --amber: #e7b53c;
  --red: #e06464;
  --purple: #9b6dc4;
  --arbeitstag: #22c55e; /* leuchtendes Grün für erfasste Arbeitstage (z. B. Samstagsarbeit) */
}
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: #233;
}
.hidden { display: none !important; }
button {
  cursor: pointer;
  border: none;
  background: var(--blue);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
}
button:hover { background: var(--blue-dark); }
button.ghost { background: transparent; color: var(--blue); border: 1px solid var(--border); }
button.ghost:hover { background: #eef2f7; }
/* Inline-Icons (z. B. Lösch-Icon) mittig in Buttons ausrichten */
button svg { vertical-align: middle; }
input, select { padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.error { color: var(--red); min-height: 18px; font-size: 13px; margin: 6px 0 0; }
.muted, .spacer { color: #889; }
.spacer { flex: 1; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: #fff; padding: 32px; border-radius: 12px; width: 340px;
  box-shadow: 0 8px 30px rgba(0,0,0,.08); display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; color: var(--blue); }
.login-card .sub { margin: 0 0 8px; color: #889; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.login-card label input { font-weight: 400; }
.demo { margin-top: 8px; font-size: 12px; color: #667; }
.demo code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; }
.linkbtn { background: none; border: none; color: var(--blue); padding: 0; font-size: 13px;
  text-decoration: underline; cursor: pointer; align-self: center; }
.linkbtn:hover { background: none; color: var(--blue-dark); }
.msg-ok { color: var(--green); }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--blue); color: #fff; padding: 10px 18px;
}
.topbar nav { display: flex; gap: 4px; }
.tab { background: rgba(255,255,255,.12); }
.tab.active { background: #fff; color: var(--blue); font-weight: 600; }
.whoami { font-size: 13px; opacity: .9; }
/* Abmelden-Button liegt in der blauen Topbar: heller Text + heller Rand,
   sonst wäre die (blaue) .ghost-Schrift auf blauem Grund unsichtbar. */
.topbar button.ghost { color: #fff; background: transparent; border-color: rgba(255,255,255,.55); }
.topbar button.ghost:hover { background: rgba(255,255,255,.16); color: #fff; }
main { max-width: 1100px; margin: 22px auto; padding: 0 18px; }

/* ---- Toolbar ---- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.toolbar h2 { margin: 0; font-size: 18px; min-width: 180px; text-align: center; }

/* ---- Kalender ---- */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
/* Kalenderwoche als schmale Spalte links neben jeder Zeile (Klasse setzt app.js) */
.calendar-grid.mit-kw { grid-template-columns: 34px repeat(7, minmax(0, 1fr)); } /* alle Tage gleich breit, lange Einträge werden gekürzt */
.cal-kw {
  display: flex; justify-content: center; align-items: flex-start;
  padding-top: 6px; border-radius: 6px; background: #e8edf3;
  font-size: 11px; font-weight: 600; color: #5d6876; font-variant-numeric: tabular-nums;
}
.cal-kw.aktuell { background: var(--blue); color: #fff; }
.cal-head { text-align: center; font-weight: 600; font-size: 12px; color: #778; padding: 4px; }
.cal-cell {
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  min-height: 84px; padding: 4px 6px; font-size: 12px;
  cursor: pointer; transition: background .12s, box-shadow .12s;
}
.cal-cell:hover { background: #eef4fb; box-shadow: 0 0 0 1px var(--blue) inset; }
/* Tage aus dem Vor-/Folgemonat: dezent kleinere Nummer, aber voll auswählbar */
.cal-cell.other .daynum { color: #9aa4b1; }
.cal-cell.weekend { background: #f0f3f7; }
.cal-cell.today { border: 2px solid var(--blue); box-shadow: 0 0 0 2px var(--blue) inset; }
.cal-cell.today .daynum { color: var(--blue); }
.cal-cell .daynum { font-weight: 600; }
.entry { margin-top: 3px; padding: 1px 5px; border-radius: 4px; color: #fff; font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry.urlaub-approved { background: var(--green); }
.entry.urlaub-pending  { background: var(--amber); }
.entry.krankheit       { background: var(--red); }
.entry.sonderurlaub    { background: var(--purple); }
.entry.arbeitstag      { background: var(--arbeitstag); box-shadow: 0 0 5px rgba(34,197,94,.8); }

.legend { display: flex; gap: 18px; margin-top: 14px; font-size: 13px; color: #556; flex-wrap: wrap; }
.legend .dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.dot.urlaub-approved { background: var(--green); }
.dot.urlaub-pending  { background: var(--amber); }
.dot.krankheit       { background: var(--red); }
.dot.sonderurlaub    { background: var(--purple); }
.dot.arbeitstag      { background: var(--arbeitstag); box-shadow: 0 0 4px rgba(34,197,94,.75); }

/* Halber Tag: gestreift, damit er auch am Handy (dort nur Farbbalken) erkennbar ist.
   Steht hinter den Farbklassen und setzt nur das Muster, die Farbe bleibt die des Typs. */
.entry.halb, .dot.halb { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.2) 0 4px, transparent 4px 8px); }
.entry.halb { text-shadow: 0 0 2px rgba(0,0,0,.6); }
.legend .dot.halb { background-color: #8896a6; }
.modal-card label.check { flex-direction: row; align-items: center; gap: 8px; }
.modal-card label.check input { width: 18px; height: 18px; margin: 0; }

/* ---- Tabellen ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 8px; }
.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; }
.data-table th, .data-table td { padding: 9px 12px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--border); }
.data-table th { background: #eef2f7; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: #667; }
.badge { padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.approved { background: var(--green-light); color: #1c6b32; }
.badge.pending  { background: #fae7bd; color: #8a6311; }
.badge.rejected { background: #f6cccc; color: #9a2b2b; }
.badge.cancel   { background: #ffe0c2; color: #9a5512; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: flex-end; }
.inline-form input { width: 130px; }

/* Beschriftetes Urlaubstage-Feld im Anlegen-Formular */
.inline-form .nu-days-field { display: flex; flex-direction: column; gap: 3px; width: 130px; font-size: 11px; font-weight: 600; color: #667; }
.inline-form .nu-days-field input { width: 100%; font-weight: 400; }

/* Genommene Tage je Typ (Mitarbeiter-Reiter) */
.table-note { margin: 0 0 12px; font-size: 12px; color: #778; }
/* Admin-Werkzeugleiste (z. B. Backup-Download) über der Mitarbeiter-Tabelle */
.admin-toolbar { margin: 0 0 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.daycount {
  display: inline-block; min-width: 28px; text-align: center;
  padding: 2px 8px; border-radius: 99px; font-size: 13px; font-weight: 600;
}
.daycount.urlaub       { background: var(--green-light); color: #1c6b32; }
.daycount.krankheit    { background: #f6cccc; color: #9a2b2b; }
.daycount.sonderurlaub { background: #e7ddf3; color: #5e3d86; }
.daycount.arbeitstag   { background: #c6f6d5; color: #12813a; }
.daycount.zero         { background: #eef2f7; color: #aab2bd; font-weight: 500; }

/* ---- Mitarbeiter-Tabelle: am Desktop OHNE Links-Rechts-Scroll ----
   Die 11 Spalten werden mit table-layout:fixed fest auf 100% Breite eingepasst;
   lange Texte (Name/E-Mail/Standort) brechen um, statt die Tabelle zu verbreitern.
   Auf Mobil (<=640px) greift dieser Block NICHT -> dort bleibt das horizontale
   Scrollen wie bei den anderen Tabellen erhalten. */
@media (min-width: 641px) {
  #tab-employees .data-table { table-layout: fixed; width: 100%; }
  #tab-employees .data-table th,
  #tab-employees .data-table td { padding: 8px 8px; overflow-wrap: anywhere; }
  #tab-employees .data-table th { font-size: 11px; letter-spacing: 0; }
  /* Kompakte Zahlen-/Zähler-Spalten (Anspruch … Arbeitstag): keine Großbuchstaben
     -> schmalere Header, die einzeilig in die engen Spalten passen; zentriert. */
  #tab-employees .data-table th:nth-child(n+5):nth-child(-n+10) { text-transform: none; font-size: 10px; }
  #tab-employees .data-table th:nth-child(n+5):nth-child(-n+10),
  #tab-employees .data-table td:nth-child(n+5):nth-child(-n+10) { text-align: center; }
  /* Spaltenbreiten – Summe = 100% */
  #tab-employees .data-table th:nth-child(1)  { width: 13%; } /* Name */
  #tab-employees .data-table th:nth-child(2)  { width: 15%; } /* E-Mail */
  #tab-employees .data-table th:nth-child(3)  { width: 9%;  } /* Rolle */
  #tab-employees .data-table th:nth-child(4)  { width: 11%; } /* Standort */
  #tab-employees .data-table th:nth-child(5)  { width: 8%;  } /* Anspruch */
  #tab-employees .data-table th:nth-child(6)  { width: 5%;  } /* Rest */
  #tab-employees .data-table th:nth-child(7)  { width: 6%;  } /* Urlaub */
  #tab-employees .data-table th:nth-child(8)  { width: 6%;  } /* Krank */
  #tab-employees .data-table th:nth-child(9)  { width: 9%;  } /* Sonderurlaub */
  #tab-employees .data-table th:nth-child(10) { width: 8%;  } /* Arbeitstag */
  #tab-employees .data-table th:nth-child(11) { width: 10%; } /* Aktionen */
  /* Aktions-Buttons kompakt, damit die Icons in die schmale Spalte passen (notfalls umbrechen) */
  #tab-employees .data-table td:last-child button { padding: 4px 7px; }
}

/* ---- Anträge: "Beantragt am" + Archiv ---- */
.created-date { display: inline-block; padding: 2px 8px; border-radius: 6px; background: #e8eff7; color: var(--blue-dark); font-weight: 600; font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.requests-table th:nth-child(2) { white-space: nowrap; }
.rq-badges { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.archive { margin-top: 22px; }
.archive > summary {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  list-style: none; cursor: pointer; user-select: none;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; font-size: 15px;
}
.archive > summary::-webkit-details-marker { display: none; }
/* Pfeil, der sich beim Öffnen dreht */
.archive > summary::before {
  content: ""; width: 8px; height: 8px; flex-shrink: 0;
  border-right: 2px solid var(--blue); border-bottom: 2px solid var(--blue);
  transform: rotate(-45deg); transition: transform .15s; margin: 0 4px 0 2px;
}
.archive[open] > summary::before { transform: rotate(45deg); }
.archive > summary:hover { background: #eef4fb; }
.archive[open] > summary { border-radius: 8px 8px 0 0; border-bottom-color: transparent; }
.archive-title { font-weight: 700; color: var(--blue); }
.archive-count { background: var(--blue); color: #fff; border-radius: 99px; padding: 1px 9px; font-size: 12px; font-weight: 700; }
.archive-sub { color: #889; font-size: 13px; }
.archive[open] .table-wrap { border: 1px solid var(--border); border-top: none; border-radius: 0 0 8px 8px; }
.archive .data-table { border-radius: 0; }

/* ---- Modal ---- */
/* z-index über der (auf Mobil klebenden) Topbar (z-index 20), damit das Pop-up
   den kompletten Bildschirm überdeckt und der Titel nicht verdeckt wird. */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: #fff; padding: 24px; border-radius: 12px; width: min(420px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-card h3 { margin: 0 0 4px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.modal-card label input, .modal-card label select { font-weight: 400; }
.modal-card .row { display: flex; gap: 12px; }
.modal-card .row label { flex: 1; }
.modal-card .hint { margin: -4px 0 0; font-size: 12px; color: #667; font-weight: 400; }
/* Nachunternehmer: Häkchen, wessen Kalender und VPN er sehen darf */
.sicht-feld { border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px 12px; margin: 0; min-width: 0; }
.sicht-feld legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.sicht-feld .hint { margin: 0 0 8px; }
.sicht-liste { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px 14px; max-height: 260px; overflow-y: auto; }
.sicht-liste label.check { font-weight: 400; }

/* Tag-Detail-Modal: Liste der Einträge eines Tages */
.day-list { display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; }
.day-list .muted { font-size: 13px; margin: 4px 0; }
.day-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }
.day-item-main { flex: 1; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.day-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.day-item .dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---- VPN (Verpflegungsnachweis) ---- */
.modal-card.wide { width: min(1040px, 100%); }
.vpn-name .muted { display: block; font-size: 12px; }
.vpn-aktionen { white-space: nowrap; text-align: right; }
.vpn-aktionen button { padding: 6px 10px; }
.vpn-table td:nth-child(n+3):nth-child(-n+5), .vpn-table th:nth-child(n+3):nth-child(-n+5) { text-align: center; }
.vpn-ohne td { color: #889; }
.vpn-summe { margin: 0; font-weight: 600; }
.vpn-hinweise { margin: 0; padding: 8px 10px 8px 26px; background: #fdf3dc; border-radius: 6px; font-size: 13px; color: #6f5010; }
.vpn-hinweise:empty { display: none; }
.vpn-monat th, .vpn-monat td { padding: 4px 7px; font-size: 12px; white-space: nowrap; }
.vpn-monat .vpn-we td { background: #f0f3f7; }
.vpn-vorlage th, .vpn-vorlage td { padding: 5px; font-size: 12px; }
.vpn-vorlage tbody th { background: none; color: #233; text-transform: none; letter-spacing: 0; white-space: nowrap; }
.vpn-vorlage input { width: 100%; min-width: 96px; }
.vpn-vorlage input.vv-zeit { min-width: 64px; width: 64px; }

/* =====================================================================
   Mobile / Responsive  (Smartphones & schmale Tablets)
   ===================================================================== */
@media (max-width: 640px) {
  /* Größere, fingerfreundliche Touch-Flächen */
  button { padding: 11px 14px; font-size: 15px; }
  /* 16px verhindert das automatische Zoomen von iOS beim Fokus */
  input, select { font-size: 16px; padding: 11px; }

  /* ---- Topbar: umbrechen, Tabs horizontal scrollbar, klebt oben ---- */
  .topbar {
    position: sticky; top: 0; z-index: 20;
    flex-wrap: wrap; gap: 8px 10px; padding: 10px 12px;
  }
  .topbar > strong { font-size: 15px; }
  .topbar nav {
    order: 3; width: 100%;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    gap: 6px; padding-bottom: 2px;
  }
  .topbar nav .tab { flex: 0 0 auto; white-space: nowrap; }
  .topbar .spacer { display: none; }
  .whoami { font-size: 12px; margin-left: auto; }

  main { margin: 14px auto; padding: 0 12px; }

  /* ---- Toolbar: Monatswahl in einer Reihe, Button voll breit ---- */
  .toolbar { flex-wrap: wrap; gap: 8px; }
  .toolbar .spacer { display: none; }
  .toolbar h2 { min-width: 0; flex: 1; font-size: 16px; }
  #newRequestBtn { width: 100%; }

  /* ---- Kalender: kompakt, Einträge als farbige Balken ---- */
  .calendar-grid { gap: 3px; }
  .calendar-grid.mit-kw { grid-template-columns: 24px repeat(7, minmax(0, 1fr)); }
  .cal-kw { padding-top: 4px; border-radius: 5px; font-size: 10px; }
  .cal-head { font-size: 11px; padding: 2px 0; }
  .cal-cell { min-height: 52px; padding: 3px; border-radius: 5px; }
  .cal-cell .daynum { font-size: 12px; }
  /* Text der Einträge ausblenden -> schmale Farbbalken; Details per Tap im Tag-Modal */
  .cal-cell .entry {
    font-size: 0; line-height: 0; height: 6px;
    padding: 0; margin-top: 2px; border-radius: 2px;
  }
  .cal-cell .entry.halb { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.5) 0 4px, transparent 4px 8px); }
  .legend { gap: 10px 14px; font-size: 12px; }

  /* ---- Tabellen: horizontal scrollen statt überlaufen ---- */
  .data-table th, .data-table td { padding: 9px 10px; white-space: nowrap; }

  /* ---- Neuer-Mitarbeiter-Formular: gestapelt, volle Breite ---- */
  .inline-form { flex-direction: column; gap: 10px; align-items: stretch; }
  .inline-form input, .inline-form select, .inline-form button { width: 100%; }
  .inline-form .nu-days-field { width: 100%; }

  /* ---- Modals / Pop-ups: volle Breite, gut erreichbar, sauber gestapelt ---- */
  .modal { align-items: flex-start; padding: 8px; }
  .modal-card {
    width: 100%; padding: 16px; gap: 12px; border-radius: 14px;
    max-height: calc(100dvh - 16px); /* dvh berücksichtigt die Handy-Browserleiste */
  }
  .modal-card h3 { font-size: 17px; }
  .modal-card .row { flex-direction: column; gap: 10px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }

  /* Tag-Detail-Pop-up: Einträge stapeln, Aktionen volle Breite DARUNTER
     (statt gequetscht neben dem Text). Nur ein Scrollbereich (die Karte). */
  .day-list { max-height: none; }
  .day-item { flex-wrap: wrap; padding: 10px; }
  .day-item-main { font-size: 14px; }
  .day-item-actions { flex-basis: 100%; margin-top: 2px; }
  .day-item-actions button { flex: 1; }

  /* ---- Anträge (aktiv + Archiv): jede Zeile als Karte, alle Spalten
     inkl. "Beantragt am" ohne Seitwärts-Scrollen sichtbar ---- */
  .requests-table, .requests-table tbody, .requests-table tr, .requests-table td { display: block; width: 100%; }
  .requests-table { background: transparent; }
  .requests-table thead { display: none; }
  .requests-table tr { background: #fff; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 4px 0; }
  .requests-table td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    white-space: normal; border-bottom: none; padding: 6px 12px; text-align: right;
  }
  .requests-table td::before {
    content: attr(data-label); flex-shrink: 0; text-align: left;
    font-size: 12px; font-weight: 600; color: #667; text-transform: uppercase; letter-spacing: .03em;
  }
  .requests-table td.rq-name { font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 2px; }
  .requests-table td.rq-empty { display: none; }
  .rq-badges { justify-content: flex-end; }
  .requests-table td.rq-actions { justify-content: flex-end; flex-wrap: wrap; gap: 6px; padding-top: 8px; }
  .requests-table td.rq-actions::before { display: none; }
  .requests-table td[colspan] { justify-content: center; }
  .requests-table td[colspan]::before { display: none; }
  .archive[open] .table-wrap { border: none; padding-top: 10px; }
  .archive[open] > summary { border-radius: 8px; border-bottom-color: var(--border); }

  /* VPN: größere Knöpfe, Eingaben behalten ihre Breite (die Tabelle scrollt seitlich) */
  .vpn-aktionen { white-space: normal; }
  .vpn-aktionen button { padding: 8px 10px; font-size: 14px; }
  .vpn-name.rq-name { display: block; text-align: left; }
  .vpn-table td[colspan] { justify-content: flex-start; }
  .vpn-vorlage input.vv-zeit { width: 84px; min-width: 84px; }
  .vpn-vorlage input { min-width: 130px; }

  /* Login-Karte randlos auf kleinen Screens */
  .login-card { width: 100%; max-width: 360px; }
}
