:root {
  --navy: #575756;            /* RMG-Grau */
  --navy-2: #6b6b6a;
  --accent: #1baaa0;          /* RMG-Grün (Logo) */
  --accent-hover: #169489;
  --accent-ink: #ffffff;       /* Schrift auf Grün */
  --accent-strong: #11786f;    /* dunkleres Grün für Links/Text */
  --accent-soft: #dcf3f1;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --danger: #dc2626;
  --ok: #15803d;
  --wait: #b45309;
  --radius: 12px;
  --top-h: 56px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .05);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
body.modal-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-strong); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.warn { color: var(--danger); font-weight: 600; }
.icon { flex: none; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text);
  font-weight: 600; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-small { min-height: 34px; padding: 6px 10px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-call { background: #ecfdf3; border-color: #bbf7d0; color: var(--ok); }
.btn-call:hover { background: #dcfce7; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; cursor: pointer; color: inherit;
}
.icon-btn:hover { background: rgba(127, 127, 127, .12); }
.icon-btn.danger { color: var(--danger); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 28px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25); display: flex; flex-direction: column; gap: 8px;
}
.login-card h1 { font-size: 24px; }
.login-card label { font-weight: 600; font-size: 14px; margin-top: 6px; }
.login-card .btn { margin-top: 10px; min-height: 46px; }
.login-logo { width: 170px; height: auto; border-radius: 10px; margin: 0 auto 8px; display: block; }
.login-card h1 { text-align: center; }
.login-card > p.muted:first-of-type { text-align: center; }

input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px;
  border: 1px solid #cbd5e1; border-radius: 10px; background: #fff;
  font-size: 16px; /* verhindert Zoom auf iPhone */
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible, .card:focus-visible {
  outline: 3px solid rgba(27, 170, 160, .4); outline-offset: 1px; border-color: var(--accent-strong);
}
input:disabled, select:disabled { background: #f1f5f9; color: var(--muted); }
textarea { resize: vertical; min-height: 80px; }
.form-error { color: var(--danger); font-weight: 600; min-height: 0; }
.form-error:empty { display: none; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 10px 0;
  display: flex; align-items: center; gap: 10px;
  background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand-logo { height: 38px; width: auto; border-radius: 6px; display: block; }
.tabs { display: flex; gap: 4px; margin-left: 6px; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px;
  border: 0; border-radius: 9px; background: transparent; color: rgba(255, 255, 255, .75); cursor: pointer; font-weight: 600;
}
.tab.active { background: var(--accent); color: #fff; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.user-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px;
  border: 0; border-radius: 9px; background: transparent; color: #fff; cursor: pointer; max-width: 200px;
}
.user-btn:hover { background: rgba(255, 255, 255, .1); }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(255, 255, 255, .6); }

/* ---------- Werkzeugleiste ---------- */
.toolbar {
  position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top)); z-index: 20;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 8px 12px; display: flex; flex-direction: column; gap: 8px;
}
.toolbar:empty { display: none; }
.nav-row { display: flex; align-items: center; gap: 10px; }
.nav-btns { display: flex; align-items: center; gap: 2px; }
.view-title { font-size: 16px; font-weight: 700; }
.view-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.segmented { display: inline-flex; background: #eef2f6; border-radius: 10px; padding: 3px; }
.segmented button {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted);
}
.segmented button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.filter { width: auto; min-width: 170px; min-height: 38px; padding: 6px 10px; font-size: 15px; }

/* ---------- Inhalt ---------- */
.content { max-width: 1280px; margin: 0 auto; padding: 12px 12px 110px; transition: opacity .15s; }
.content.is-loading { opacity: .55; }
.empty { padding: 40px 10px; text-align: center; color: var(--muted); }
.empty.small { padding: 16px 4px; }
.empty.tiny { padding: 6px 4px; font-size: 13px; }

.day-block { margin-bottom: 18px; }
.day-head { display: flex; align-items: baseline; gap: 8px; padding: 4px 2px 8px; flex-wrap: wrap; }
.day-name { font-weight: 700; font-size: 16px; }
.day-date { color: var(--muted); }
.day-count { margin-left: auto; color: var(--muted); font-size: 13px; }
.day-head.today .day-name { color: var(--accent-strong); }
.day-link { display: block; width: 100%; border: 0; background: transparent; padding: 0; text-align: left; cursor: pointer; }

/* ---------- Fahrt-Karte ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border-left: 5px solid var(--c, #94a3b8);
  padding: 12px 12px 12px 14px; margin-bottom: 10px; cursor: pointer;
  display: flex; flex-direction: column; gap: 8px;
}
.card:hover { box-shadow: 0 2px 4px rgba(15, 23, 42, .08), 0 6px 16px rgba(15, 23, 42, .08); }
.card-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.time { font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }
.kunde { font-weight: 600; }
.driver {
  margin-left: auto; font-size: 13px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 14%, white); color: color-mix(in srgb, var(--c) 75%, black);
}
.driver.unassigned { background: #fef2f2; color: var(--danger); }
.route { display: flex; flex-direction: column; gap: 4px; }
.route-row { display: flex; gap: 8px; align-items: flex-start; }
.route-ico { color: var(--muted); padding-top: 2px; }
.addr { color: var(--text); text-decoration: underline; text-decoration-color: #cbd5e1; text-underline-offset: 3px; word-break: break-word; }
.addr:hover { text-decoration-color: var(--accent-strong); color: var(--accent-strong); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; background: var(--info-soft); color: var(--info);
}
.pill-wait { background: #fff7ed; color: var(--wait); }
.pill-today { background: var(--accent); color: var(--accent-ink); font-size: 12px; padding: 1px 8px; }
.pill-soft { background: #f1f5f9; color: var(--muted); }
.pill-off { background: #fef2f2; color: var(--danger); }
.note-preview {
  display: flex; gap: 6px; align-items: flex-start; font-size: 14px; color: var(--muted);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.note-preview .icon { display: inline; vertical-align: -2px; margin-right: 4px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card.compact { padding: 9px 10px 9px 11px; gap: 5px; margin-bottom: 8px; }
.card.compact .time { font-size: 15px; }
.card.compact .route-row { font-size: 14px; }

/* ---------- Woche ---------- */
.week-grid { display: flex; flex-direction: column; }
.week-day.is-empty .day-head { opacity: .6; }

@media (min-width: 1000px) {
  .week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; align-items: start; }
  .week-day { background: #e9edf2; border-radius: var(--radius); padding: 8px; min-height: 200px; margin: 0; }
  .week-day .day-head { flex-direction: column; gap: 0; align-items: flex-start; }
  .week-day .day-count { margin-left: 0; }
  .week-day .card.compact .driver { margin-left: 0; }
  .week-day .card.compact .badges .pill { font-size: 12px; }
}

/* ---------- Monat ---------- */
.month { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.month-head { display: grid; grid-template-columns: repeat(7, 1fr); background: #f8fafc; border-bottom: 1px solid var(--line); }
.month-head div { padding: 8px 4px; text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); }
.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.month-cell {
  min-height: 64px; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: #fff; padding: 5px; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; align-items: stretch;
}
.month-cell:nth-child(7n) { border-right: 0; }
.month-cell:hover { background: #f8fafc; }
.month-cell.other { background: #fafbfc; color: #a0aec0; }
.month-num { font-weight: 700; font-size: 14px; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.month-cell.today .month-num { background: var(--accent); color: var(--accent-ink); }
.month-chips { display: none; flex-direction: column; gap: 2px; }
.chip {
  font-size: 12px; padding: 2px 5px; border-radius: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: color-mix(in srgb, var(--c) 14%, white); border-left: 3px solid var(--c);
}
.chip.more { background: transparent; border: 0; color: var(--muted); }
.month-dots { display: flex; gap: 3px; flex-wrap: wrap; align-items: center; }
.month-dots i { width: 8px; height: 8px; border-radius: 50%; display: block; }
.month-dots small { font-size: 11px; color: var(--muted); }
@media (min-width: 760px) {
  .month-cell { min-height: 112px; }
  .month-chips { display: flex; }
  .month-dots { display: none; }
}

/* ---------- Termine ---------- */
.card.termin { border-left-style: dashed; background: #fbfcff; }
.pill-termin { background: #f3e8ff; color: #7e22ce; font-size: 12px; padding: 2px 8px; }
.chip-termin { border-left-style: dashed; font-style: italic; }
.typ-switch { width: 100%; }
.typ-switch button { flex: 1; padding: 9px; font-size: 15px; }

/* ---------- Adress-Eingabe ---------- */
.addr-input { display: flex; flex-direction: column; gap: 6px; }
.addr-row { display: grid; grid-template-columns: 96px 1fr; gap: 6px; }

/* ---------- Zeitleiste ---------- */
.tl-wrap {
  overflow: auto; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: calc(100vh - 210px); max-height: calc(100dvh - 210px); position: relative;
}
.tl-grid { display: grid; position: relative; min-width: min-content; }
.tl-corner, .tl-colhead { position: sticky; top: 0; z-index: 3; background: #f8fafc; border-bottom: 1px solid var(--line); }
.tl-corner { left: 0; z-index: 4; }
.tl-colhead {
  display: flex; align-items: center; gap: 6px; padding: 10px 8px; font-weight: 700; font-size: 14px;
  border-left: 1px solid var(--line); min-width: 0;
}
.tl-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.tl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-n { margin-left: auto; font-size: 12px; background: #e2e8f0; color: var(--muted); border-radius: 999px; padding: 0 7px; }
.tl-times { position: sticky; left: 0; z-index: 2; background: #fff; border-right: 1px solid var(--line); }
.tl-hour { position: absolute; right: 6px; transform: translateY(-50%); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-hour:first-child { transform: none; }
.tl-col {
  position: relative; border-left: 1px solid var(--line);
  background-image:
    linear-gradient(to bottom, #e5e9f0 1px, transparent 1px),
    linear-gradient(to bottom, #f3f5f8 1px, transparent 1px);
  background-size: 100% var(--slot), 100% calc(var(--slot) / 2);
}
.tl-block {
  position: absolute; border: 0; text-align: left; cursor: pointer; overflow: hidden;
  border-radius: 7px; padding: 4px 6px; display: flex; flex-direction: column; gap: 1px;
  background: color-mix(in srgb, var(--c) 16%, white); border-left: 4px solid var(--c);
  color: var(--text); font-size: 12px; line-height: 1.25; box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}
.tl-block:hover { z-index: 1; box-shadow: 0 3px 10px rgba(0, 0, 0, .15); }
.tl-block.termin { border-left-style: dashed; background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--c) 12%, white) 0 8px, color-mix(in srgb, var(--c) 18%, white) 8px 16px); }
.tl-block.conflict { outline: 2px solid var(--danger); outline-offset: -2px; }
.tl-block.conflict::after { content: "!"; position: absolute; top: 3px; right: 5px; width: 16px; height: 16px; border-radius: 50%; background: var(--danger); color: #fff; font-weight: 800; font-size: 11px; display: flex; align-items: center; justify-content: center; }
.tl-time { font-weight: 800; font-variant-numeric: tabular-nums; }
.tl-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-sub { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-block.short { flex-direction: row; gap: 6px; align-items: center; }
.tl-block.short .tl-sub { display: none; }
.tl-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; pointer-events: none; }
.tl-now::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }

/* ---------- Mitarbeiter ---------- */
.staff-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 14px; flex-wrap: wrap; }
.staff-list { display: flex; flex-direction: column; gap: 8px; }
.staff-card {
  display: flex; align-items: center; gap: 12px; background: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px;
}
.staff-card.inactive { opacity: .6; }
.staff-color { width: 14px; height: 40px; border-radius: 6px; flex: none; }
.staff-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.staff-name { font-weight: 700; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.staff-actions { display: flex; gap: 2px; }
.hint { margin-top: 16px; }
.tel { color: var(--accent-strong); }

/* ---------- Formulare ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-weight: 600; font-size: 14px; }
.grid-2, .grid-3 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1.3fr 1fr 1fr; }
}
.check { display: flex; gap: 10px; align-items: center; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent-strong); flex: none; }
.wait-box { display: grid; gap: 12px; grid-template-columns: 1fr; padding: 12px; background: #fff7ed; border-radius: 10px; }
.wait-box[hidden] { display: none; }
@media (min-width: 560px) { .wait-box { grid-template-columns: 1fr 2fr; } }
.inline { display: flex; gap: 8px; align-items: center; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.color { width: 32px; height: 32px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.color.active { box-shadow: 0 0 0 3px var(--text); }

/* ---------- Detail ---------- */
.detail dl { margin: 0; display: flex; flex-direction: column; }
.dl-row { display: grid; grid-template-columns: 120px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.dl-row:last-child { border-bottom: 0; }
.dl-row dt { color: var(--muted); font-size: 14px; }
.dl-row dd { margin: 0; display: flex; flex-direction: column; gap: 6px; word-break: break-word; }
.nav-choices { display: flex; gap: 6px; flex-wrap: wrap; }
.pre { white-space: pre-wrap; }
@media (max-width: 420px) { .dl-row { grid-template-columns: 1fr; gap: 3px; } }

/* ---------- Modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.modal {
  background: #fff; width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column; box-shadow: 0 -10px 40px rgba(0, 0, 0, .2);
  animation: up .2s ease-out;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
}
@media (min-width: 640px) {
  .overlay { align-items: center; padding: 20px; }
  .modal { max-width: 620px; border-radius: 16px; max-height: 90vh; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 40;
  height: 56px; min-width: 56px; padding: 0 18px; border-radius: 28px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 8px 24px rgba(17, 120, 111, .35);
}
.fab:hover { background: var(--accent-hover); }

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600;
  opacity: 0; transform: translateY(10px); transition: all .25s; max-width: 90vw;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }

/* ---------- Handy ---------- */
@media (max-width: 640px) {
  .tab span, .user-name { display: none; }
  .brand-logo { height: 34px; }
  .tab { padding: 0 10px; }
  .brand-text { display: none; }
  .segmented { flex: 1; }
  .segmented button { flex: 1; padding: 7px 2px; font-size: 13px; }
  .filter { flex: 1 1 100%; }
  .view-title { font-size: 15px; }
  .dot { display: none; }
  .modal-foot .btn { flex: 1 1 40%; }
}
@media (min-width: 641px) { .user-btn .icon { display: none; } }
@media (min-width: 1304px) {
  .toolbar { padding-left: calc((100% - 1280px) / 2 + 12px); padding-right: calc((100% - 1280px) / 2 + 12px); }
}
@media (max-width: 380px) {
  .fab span { display: none; }
  .fab { padding: 0; }
}

/* ---------- Feiertage ---------- */
.pill-holiday { background: #fdecec; color: #b42318; font-size: 12px; padding: 2px 9px; }
.day-head.holiday .day-name { color: #b42318; }
.day-block.holiday-only { margin-bottom: 10px; opacity: .9; }
.week-day.holiday .day-head { opacity: 1; }
@media (min-width: 1000px) { .week-day.holiday { background: #fbe9e8; } }
.month-top { display: flex; align-items: center; gap: 4px; min-width: 0; }
.month-holiday {
  font-size: 11px; font-weight: 600; color: #b42318; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.month-cell.holiday { background: #fdf2f1; }
.month-cell.holiday .month-num { color: #b42318; }
.month-cell.today.holiday .month-num { color: var(--accent-ink); }
@media (max-width: 759px) { .month-holiday { display: none; } .month-cell.holiday .month-num { box-shadow: inset 0 0 0 2px #f3b8b3; } }
.holiday-banner {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px; padding: 10px 14px;
  background: #fdecec; color: #b42318; border-radius: 10px; font-weight: 700;
}
