:root {
  --background: #f4f7fc;
  --card: #ffffff;
  --foreground: #1c2540;
  --muted-foreground: #5b6685;
  --primary: #1b2a52;
  --primary-foreground: #f7f9fd;
  --secondary: #dbe6fa;
  --secondary-hover: #c7d8f5;
  --accent: #b9d0f2;
  --border: #cdd8ef;
  --input-bg: #dbe6fa;
  --destructive: #c0362c;
  --destructive-bg: #fbe4e2;
  --ring: #4667c9;
  --green-bg: #dcf5e3;
  --green-border: #8fd1a4;
  --yellow-bg: #fdf1b8;
  --yellow-border: #e8cf6a;
  --red-bg: #fbe4e2;
  --red-border: #e8a49c;
  --radius: 10px;
  --font-sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--foreground);
}

a { color: inherit; }

h1, h2, h3 { margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.card-title { font-size: 1.25rem; font-weight: 600; margin: 0; }
.card-desc { color: var(--muted-foreground); margin: 0.15rem 0 0; font-size: 0.9rem; }

.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.85rem; font-weight: 600; }

input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--foreground);
}

select { background: var(--input-bg); cursor: pointer; }
select:hover { background: var(--secondary-hover); }

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(70, 103, 201, 0.25);
}

textarea { resize: vertical; min-height: 4rem; line-height: 1.4; }

.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--foreground);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn:hover { background: var(--secondary); }
.btn-block { width: 100%; justify-content: center; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); border-color: var(--primary); }
.btn-primary:hover { background: #263a70; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--secondary); }
.btn-sm { font-size: 0.8rem; padding: 0.3rem 0.6rem; }
.btn-icon { padding: 0.35rem; line-height: 1; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--secondary);
}
.badge-destructive { background: var(--destructive-bg); color: var(--destructive); }
.badge-success { background: var(--green-bg); color: #1a7a3d; }
.badge-warning { background: var(--yellow-bg); color: #7a5b00; }
/* Hinweis (z.B. Feiertag) unter dem Datum statt daneben, damit die Datumsspalte schmal bleibt */
.badge-below { display: table; margin-top: 0.15rem; }

.form-error {
  background: var(--destructive-bg);
  color: var(--destructive);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  margin: 0;
}

.toast-success { color: #1a7a3d; }
.form-notice { background: var(--green-bg); color: #1a7a3d; border-radius: 8px; padding: 0.5rem 0.75rem; font-size: 0.9rem; margin: 0; }

.btn-danger { color: var(--destructive); border-color: var(--red-border); background: #fff; }
.btn-danger:hover { background: var(--destructive-bg); }
.danger-zone { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
tr.row-archived td { color: var(--muted-foreground); }

/* ---- Ordner-Auswahl (Einstellungen) ---- */
dialog.folder-dialog { max-width: 40rem; }
.folder-shortcuts { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.folder-current { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; min-width: 0; }
.folder-current code { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.folder-current code span { unicode-bidi: isolate; }
.folder-list { list-style: none; margin: 0; padding: 0.25rem; border: 1px solid var(--border); border-radius: 8px; height: 18rem; overflow-y: auto; }
.folder-item { width: 100%; text-align: left; background: none; border: none; border-radius: 6px; padding: 0.4rem 0.5rem; font: inherit; font-size: 0.9rem; color: var(--foreground); cursor: pointer; }
.folder-item:hover { background: var(--secondary); }
.folder-empty { padding: 0.5rem; font-size: 0.85rem; }

/* ---- Login page ---- */
.login-body { display: flex; min-height: 100vh; }
.login-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 1rem; }
.login-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; }
.lang-switcher { padding: 0.3rem 0.5rem; font-size: 0.85rem; }

/* ---- App layout ---- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.app-header { background: var(--primary); color: var(--primary-foreground); }
.app-header-inner {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.app-header nav { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; flex-wrap: wrap; }
.app-header nav a { color: rgba(247, 249, 253, 0.75); text-decoration: none; }
.app-header nav a:hover { color: var(--primary-foreground); }
.app-header .brand { font-weight: 700; letter-spacing: 0.02em; }
.app-header .user-info { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
.app-header .user-info span { color: var(--primary-foreground); }
.app-header .user-info .btn { color: rgba(247, 249, 253, 0.85); }
.app-header .user-info .btn:hover { color: var(--primary-foreground); background: rgba(255, 255, 255, 0.12); }
.app-main { max-width: 72rem; margin: 0 auto; width: 100%; padding: 1.5rem 1rem; flex: 1; display: flex; flex-direction: column; gap: 1rem; }
.app-main-narrow { max-width: 42rem; }
/* Breite Tabellen-Seiten (Admin-Stundenliste) */
.app-main-wide { max-width: 84rem; }
.app-shell:has(.app-main-wide) .app-header-inner { max-width: 84rem; }

/* ---- Day cards (driver view) ---- */
.day-card { display: flex; flex-direction: column; gap: 0.75rem; }
.day-card.filled { background: var(--green-bg); border-color: var(--green-border); }
.day-card.missing { background: var(--red-bg); border-color: var(--red-border); }
.day-card.sunday:not(.filled):not(.missing) { border-color: var(--muted-foreground); }
/* Datum links, Tagestyp + Symbole rechts. Reicht der Platz nicht (z. B. erste Karte mit ?-Hilfen
   am Handy), rutschen die Bedienelemente in eine eigene Zeile – das Datum wird nie überdeckt. */
.day-card-header { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem 0.5rem; flex-wrap: wrap; }
.day-card-header .date { font-weight: 600; white-space: nowrap; flex: 0 0 auto; }
.day-card-controls { display: flex; align-items: center; gap: 0.25rem; flex: 0 1 auto; margin-left: auto; min-width: 0; }
.day-card-controls select { width: auto; max-width: 11rem; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
/* Felder unten ausrichten: bricht eine Beschriftung um, bleiben die Eingabefelder trotzdem auf einer Linie. */
.day-card .grid-2, .day-card .grid-3 { align-items: end; }
.day-card .field input, .day-card .field select, .day-card .field textarea { width: 100%; min-width: 0; }
.day-card .field label { display: flex; align-items: center; flex-wrap: wrap; }

/* "Änderungen seit dem Öffnen rückgängig": schwebt unten, sobald es Änderungen gibt */
.revert-session { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 0.3rem;
  background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 0.3rem 0.5rem 0.3rem 0.3rem; box-shadow: 0 6px 24px rgba(0,0,0,0.15); max-width: calc(100vw - 1.5rem); }
.revert-session[hidden] { display: none; }
.revert-session .btn { border-radius: 999px; white-space: normal; text-align: center; justify-content: center; }
@media (max-width: 520px) {
  .revert-session { left: 0.75rem; right: 0.75rem; transform: none; justify-content: center; border-radius: 14px; }
  .revert-session .btn { flex: 1; border-radius: 10px; }
}
#day-cards { padding-bottom: 3.5rem; }

/* Monatsleiste: Pfeil – Monat – Pfeil in einer Zeile */
.month-nav { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.5rem; }
.month-nav-title { text-align: center; }

@media (max-width: 520px) {
  .app-main { padding: 1rem 0.75rem; gap: 0.75rem; }
  .day-card { padding: 0.8rem; gap: 0.6rem; }
  .grid-2, .grid-3 { gap: 0.6rem; }
  /* Land Arbeit + Land Ende nebeneinander, Übernachtung in eigener Zeile */
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-3 .field-wide-mobile { grid-column: 1 / -1; }
  .month-nav .nav-text { display: none; }
  .month-nav .btn { padding: 0.5rem 0.9rem; font-size: 1.1rem; }
  .month-nav-title { font-size: 1.1rem; }
  /* iOS zoomt bei Schrift unter 16 px beim Antippen ins Feld – daher 16 px */
  input[type=text], input[type=email], input[type=password], input[type=number], textarea, select { font-size: 16px; }
  .app-header .brand { font-size: 0.95rem; }
}
/* Größere "?"-Symbole auf Touch-Geräten, damit sie gut zu treffen sind */
@media (pointer: coarse) {
  .help-btn { width: 1.4rem; height: 1.4rem; font-size: 0.8rem; }
}

/* ---- Admin dashboard month grid ---- */
.driver-card { display: flex; flex-direction: column; gap: 0.6rem; }
.month-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
@media (max-width: 480px) {
  .month-grid { grid-template-columns: repeat(3, 1fr); }
}
.month-tile-wrap { position: relative; }
.month-tile { width: 100%; text-align: center; justify-content: center; flex-direction: column; gap: 0.1rem; }
.month-tile-amount { font-size: 0.72rem; font-weight: 500; opacity: 0.85; font-variant-numeric: tabular-nums; }
.earnings-year { font-size: 0.85rem; color: var(--muted-foreground); }
.earnings-year strong { color: var(--foreground); font-variant-numeric: tabular-nums; }
.month-tile.locked { background: #4caf6f; color: #fff; border-color: #3d9459; }
.month-tile.locked:hover { background: #3d9459; }
.month-tile.current { background: var(--yellow-bg); border-color: var(--yellow-border); }
.month-hide-btn {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  background: var(--secondary); border: none; cursor: pointer; opacity: 0.7; font-size: 11px;
}
.month-hide-btn:hover { opacity: 1; }
.month-tile-wrap.hidden-month { opacity: 0.5; }

/* ---- Tables (admin timesheet) ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.4rem 0.5rem; text-align: left; vertical-align: middle; white-space: nowrap; }
thead th { border-bottom: 1px solid var(--border); font-weight: 600; }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(0,0,0,0.02); }
.text-right { text-align: right; }

/* Stundenliste: nur die Tage scrollen, Kopfbereich + Summen bleiben stehen, Spaltenköpfe fixiert. */
.table-scroll { max-height: calc(100vh - 20rem); min-height: 16rem; overflow: auto; }
.table-scroll thead th { position: sticky; top: 0; z-index: 2; background: var(--card); box-shadow: inset 0 -1px 0 var(--border); }
@media (max-height: 560px) {
  .table-scroll { max-height: none; }
}
.w-fahrzeit { width: 5.25rem; text-align: right; }
/* Pfeiltasten in den Zeitfeldern der Tabelle ausblenden – schaffen Platz für Werte wie 10,15 */
.w-fahrzeit::-webkit-outer-spin-button, .w-fahrzeit::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.w-fahrzeit[type=number] { -moz-appearance: textfield; appearance: textfield; }
.w-land { width: 6rem; }
.w-rate { width: 7.5rem; }
.w-tagestyp { width: 8.5rem; }

.summary-grid { display: flex; flex-wrap: wrap; gap: 1.5rem; }
.summary-item .label { color: var(--muted-foreground); font-size: 0.85rem; }
.summary-item .value { font-size: 1.1rem; font-weight: 600; }

/* ---- Dialog (native <dialog>) ---- */
dialog {
  border: none;
  border-radius: var(--radius);
  padding: 1rem;
  max-width: 32rem;
  width: calc(100% - 2rem);
  color: var(--foreground);
  font-family: var(--font-sans);
}
dialog::backdrop { background: rgba(0,0,0,0.15); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.75rem; }
.audit-entry { border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.75rem; background: rgba(0,0,0,0.02); font-size: 0.85rem; }
.audit-entry .meta { display: flex; justify-content: space-between; gap: 0.5rem; color: var(--muted-foreground); font-size: 0.75rem; flex-wrap: wrap; }
.audit-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: 50vh; overflow-y: auto; }

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

/* ---- Datenschutz-Dokument (Admin) ---- */
.privacy-doc { max-width: 52rem; }
.privacy-doc h3 { font-size: 1rem; margin: 0.6rem 0 0; }
.doc-title { font-size: 1.3rem; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.doc-table th, .doc-table td { border: 1px solid var(--border); padding: 0.4rem 0.55rem; vertical-align: top; white-space: normal; text-align: left; }
.doc-table th { width: 12rem; background: var(--secondary); font-weight: 600; }
.doc-table ul, .doc-checklist { margin: 0; padding-left: 1.1rem; }
.doc-checklist { list-style: none; padding-left: 0; font-size: 0.9rem; line-height: 1.7; }
.fill-in { background: var(--yellow-bg); border-bottom: 1px dashed var(--yellow-border); padding: 0 0.2rem; outline: none; }
.fill-in:focus, .fill-in-filled:focus { outline: 2px solid var(--ring); }
@media print {
  .app-header, .no-print, .help-btn { display: none !important; }
  body, .app-shell { background: #fff; }
  .app-main { padding: 0; max-width: none; }
  .privacy-doc .card { border: none; padding: 0; }
  .fill-in { background: none; border: none; }
  .doc-table th { background: #eef2f8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .doc-table tr { break-inside: avoid; }
}

/* ---- "?"-Hilfen ---- */
.help-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.05rem; height: 1.05rem; margin-left: 0.3rem; padding: 0;
  border-radius: 999px; border: 1px solid var(--accent); background: var(--secondary);
  color: var(--primary); font: 700 0.68rem/1 var(--font-sans); cursor: pointer; vertical-align: middle;
  flex: none;
}
.help-btn:hover, .help-btn[aria-expanded="true"] { background: var(--primary); color: var(--primary-foreground); border-color: var(--primary); }
.help-bubble {
  position: fixed; z-index: 1000; max-width: min(22rem, calc(100vw - 16px));
  background: var(--primary); color: var(--primary-foreground); border-radius: 8px;
  padding: 0.55rem 0.75rem; font-size: 0.82rem; font-weight: 400; line-height: 1.4; text-align: left;
  white-space: normal; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
.help-bubble p { margin: 0; }
.help-bubble p + p { margin-top: 0.35rem; }
.help-intro { font-size: 0.85rem; background: var(--secondary); border-radius: var(--radius); padding: 0.6rem 0.8rem; margin: 0; }
.help-intro summary { cursor: pointer; font-weight: 600; }
.help-intro p { margin: 0.4rem 0 0; }
.mt-0 { margin-top: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 9rem; display: inline-block; vertical-align: middle; }

.day-total { margin: -0.2rem 0 0; font-size: 0.85rem; color: var(--muted-foreground); font-weight: 600; font-variant-numeric: tabular-nums; }
.day-total:empty { display: none; }

/* ---- Anleitung (Admin) ---- */
.guide-steps { margin: 0.3rem 0 0; padding-left: 1.3rem; line-height: 1.55; font-size: 0.92rem; }
.guide-steps > li { margin-bottom: 0.55rem; }
.guide-steps ul, .guide-list { margin: 0.2rem 0 0; padding-left: 1.1rem; font-size: 0.9rem; line-height: 1.55; }
.guide-doc section h3 { border-bottom: 1px solid var(--border); padding-bottom: 0.25rem; }
.guide-doc .help-btn { cursor: default; }

.local-folder-name { background: var(--secondary); border-radius: 6px; padding: 0.3rem 0.55rem; font-size: 0.85rem; }

/* ---- Einstellungen: Abschnitte untereinander ---- */
.section-title { font-size: 1.2rem; margin: 0; }
.settings-section + .settings-section { border-top: 1px solid var(--border); padding-top: 1.5rem; margin-top: 0.5rem; }
.settings-narrow { max-width: 42rem; }
@media print {
  body.print-privacy .settings-section:not(#privacy),
  body.print-privacy .app-main > h1,
  body.print-privacy .app-main > .form-error,
  body.print-privacy .app-main > .form-notice { display: none !important; }
  body.print-privacy #privacy { border-top: none; padding-top: 0; margin-top: 0; }
}

/* ---- "?" in der Kopfzeile (Anleitung) ---- */
.nav-help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  border: 1px solid rgba(247, 249, 253, 0.5); color: var(--primary-foreground);
  font-weight: 700; font-size: 0.9rem; text-decoration: none;
}
.nav-help:hover { background: rgba(255, 255, 255, 0.12); }
