/* ==========================================================================
   Float – Ressourcenplanung
   ========================================================================== */

:root {
  --bg:            #ffffff;
  --bg-sunken:     #f6f7f9;
  --bg-raised:     #ffffff;
  --bg-hover:      #f1f3f6;
  --bg-active:     #e8ebf0;
  --border:        #e2e5ea;
  --border-subtle: #eef0f3;
  --border-strong: #cbd2dc;
  --fg:            #101828;
  --fg-muted:      #667085;
  --fg-subtle:     #98a2b3;
  --fg-invert:     #ffffff;
  --accent:        #4f46e5;
  --accent-hover:  #4338ca;
  --accent-soft:   #eef2ff;
  --accent-border: #c7d2fe;
  --ok:            #059669;
  --ok-soft:       #ecfdf5;
  --warn:          #d97706;
  --warn-soft:     #fffbeb;
  --danger:        #dc2626;
  --danger-soft:   #fef2f2;
  --weekend:       #f8f9fb;
  --holiday:       #fff7ed;
  --today:         #eef2ff;
  --shadow-sm:     0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md:     0 4px 12px -2px rgba(16, 24, 40, .12), 0 2px 4px -2px rgba(16, 24, 40, .06);
  --shadow-lg:     0 20px 40px -12px rgba(16, 24, 40, .25), 0 4px 10px -4px rgba(16, 24, 40, .1);
  --radius:        8px;
  --radius-lg:     14px;
  /* Mischverhältnisse für die getönten Aufgabenbalken. Der Balken bekommt in
     JavaScript nur seine Grundfarbe (--bar-farbe); Grund, Schrift und Kante
     entstehen hier daraus. So stimmt der Kontrast in beiden Themen, ohne dass
     die Farbe zweimal gepflegt werden muss. */
  --bar-grund:     13%;
  --bar-schrift:   58%;
  --bar-kante:     78%;
  --sidebar-w:     216px;
  --people-w:      248px;
  --day-w:         38px;
  --row-h:         84px;
  --bar-h:         26px;
  --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono:          ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #16181d;
    --bg-sunken:     #0f1115;
    --bg-raised:     #1c1f26;
    --bg-hover:      #23272f;
    --bg-active:     #2b3038;
    --border:        #2a2f38;
    --border-subtle: #22262d;
    --border-strong: #3a4149;
    --fg:            #e7eaf0;
    --fg-muted:      #98a2b3;
    --fg-subtle:     #6b7480;
    --bar-grund:     30%;
    --bar-schrift:   45%;
    --bar-kante:     92%;
    --accent:        #7c74f2;
    --accent-hover:  #8f88f5;
    --accent-soft:   #21214a;
    --accent-border: #3d3a80;
    --ok-soft:       #0f2a22;
    --warn-soft:     #2b2110;
    --danger-soft:   #2c1517;
    --weekend:       #12141a;
    --holiday:       #241a10;
    --today:         #1d1e40;
    --shadow-lg:     0 20px 40px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body.app-body { overflow: hidden; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--fg-subtle); }
::-webkit-scrollbar-corner { background: transparent; }

/* ------------------------------------------------------------------ Buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 13px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-raised); color: var(--fg);
  font-size: 13px; font-weight: 550; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s, transform .06s;
  text-decoration: none;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12px; }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }
.btn-block { width: 100%; }
.btn svg { flex: none; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 11px;
  background: var(--bg-active); color: var(--fg-muted);
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.chip-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* ----------------------------------------------------------- Formularfelder */

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; margin-bottom: 5px;
  font-size: 12px; font-weight: 600; color: var(--fg-muted);
}
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="number"], .field input[type="date"], .field input[type="time"],
.field input:not([type]), .field select, .field textarea, input.inp, select.inp, textarea.inp {
  width: 100%; height: 36px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--fg);
  transition: border-color .12s, box-shadow .12s;
}
.field textarea, textarea.inp { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus,
input.inp:focus, select.inp:focus, textarea.inp:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input[type="color"] { width: 46px; height: 36px; padding: 2px; cursor: pointer; }
.field-error input, .field-error select { border-color: var(--danger); }
.field-msg { margin-top: 4px; font-size: 11px; color: var(--danger); }
.field-hint { margin-top: 4px; font-size: 11px; color: var(--fg-subtle); }

/* Hinweis mitten in einer Ansicht – etwa wenn eine Liste nicht geladen werden
   konnte. Bewusst kein flüchtiger Toast: Der Grund muss stehen bleiben. */
.msg-inline {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: 9px; font-size: 12.5px; line-height: 1.5;
  background: var(--bg-sunken); border: 1px solid var(--border);
}
.msg-inline.err { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.check { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 12px; cursor: pointer; font-size: 13px; }
.check input { margin: 2px 0 0; width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; flex: none; }
.check span { line-height: 1.45; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }
.span2 { grid-column: span 2; }
@media (max-width: 640px) {
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}

/* ------------------------------------------------------------------- Login */

.login-body { display: grid; place-items: center; background: var(--bg-sunken); }
.login-wrap { width: 100%; padding: 24px; display: grid; place-items: center; }
.login-card {
  width: 100%; max-width: 380px; padding: 34px 32px 30px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-md);
}
.login-logo { margin-bottom: 16px; }
.login-card h1 { font-size: 22px; margin-bottom: 3px; }
.login-sub { margin: 0 0 24px; color: var(--fg-muted); font-size: 13px; }
.login-error {
  margin-bottom: 16px; padding: 10px 12px;
  background: var(--danger-soft); border: 1px solid #fecaca;
  border-radius: var(--radius); color: var(--danger); font-size: 13px;
}
.login-card .btn { margin-top: 8px; height: 38px; }

/* -------------------------------------------------------------- App-Gerüst */

.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; height: 100dvh; }
.boot { display: grid; place-content: center; justify-items: center; gap: 14px; height: 100vh; grid-column: 1 / -1; color: var(--fg-muted); }
.boot-spinner {
  width: 26px; height: 26px; border: 2.5px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Sidebar */
.sidebar {
  display: flex; flex-direction: column;
  background: var(--bg-sunken); border-right: 1px solid var(--border);
  overflow: hidden;
}
.sidebar-head { display: flex; align-items: center; gap: 9px; padding: 14px 16px; }
.sidebar-head .logo { flex: none; border-radius: 7px; }
.sidebar-head strong { font-size: 14px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin-bottom: 1px;
  border: none; border-radius: var(--radius);
  background: transparent; color: var(--fg-muted);
  font-size: 13.5px; font-weight: 550; cursor: pointer; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--bg-hover); color: var(--fg); }
.nav-item.on { background: var(--bg-active); color: var(--fg); font-weight: 650; }
.nav-item svg { flex: none; opacity: .8; }
.nav-item.on svg { opacity: 1; color: var(--accent); }
.nav-label {
  padding: 16px 12px 6px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase; color: var(--fg-subtle);
}
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px; }
.user-box { display: flex; align-items: center; gap: 9px; padding: 6px; border-radius: var(--radius); }
.user-box:hover { background: var(--bg-hover); }
.user-box .meta { min-width: 0; flex: 1; }
.user-box .meta b { display: block; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-box .meta span { font-size: 11px; color: var(--fg-subtle); }

/* Personen tragen bewusst keine eigene Farbe – Farbe kennzeichnet den Kunden. */
.avatar {
  display: grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg-active); color: var(--fg-muted);
  border: 1px solid var(--border);
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
}
.user-box .avatar { background: var(--accent); color: #fff; border-color: transparent; }
.avatar-sm { width: 24px; height: 24px; font-size: 9.5px; }
.avatar-lg { width: 38px; height: 38px; font-size: 13px; }
/* Im Zeitplan trägt das Kürzel die Farbe der Person – das verbindet Zeile und
   Balken, ohne dass die Spalte bunt wird. */
.tl-person .avatar {
  width: 34px; height: 34px; font-size: 11.5px; border: none;
  background: color-mix(in srgb, var(--avatar-farbe, var(--accent)) 16%, var(--bg));
  color: color-mix(in srgb, var(--avatar-farbe, var(--accent)) 62%, var(--fg));
}

/* Hauptbereich */
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 10px;
  height: 54px; padding: 0 16px; flex: none;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin-right: 4px; }
.topbar .spacer { flex: 1; }
.view-body { flex: 1; overflow: auto; min-height: 0; }
.view-pad { padding: 20px 22px 60px; max-width: 1240px; }

.seg { display: inline-flex; padding: 2px; background: var(--bg-active); border-radius: var(--radius); }
.seg button {
  border: none; background: transparent; color: var(--fg-muted);
  padding: 5px 11px; border-radius: 6px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.seg button.on { background: var(--bg-raised); color: var(--fg); box-shadow: var(--shadow-sm); }

.hamburger { display: none; }

/* ================================================================ Zeitplan */

.schedule {
  display: flex; flex-direction: column; height: 100%; min-height: 0;
  /* Die Zeitachse liegt als Karte auf einem ruhigen Grund – so hört sie nach
     der letzten Person sichtbar auf, statt als Raster ins Leere zu laufen. */
  background: var(--bg-sunken);
}

.tl-toolbar {
  display: flex; align-items: center; gap: 9px;
  padding: 14px 16px; flex: none;
  flex-wrap: wrap;
}
.tl-range { font-size: 14px; font-weight: 700; min-width: 168px; letter-spacing: -.01em; }
.tl-toolbar .spacer { flex: 1; }

.tl-scroll {
  /* Nicht strecken: Bei wenigen Personen hört die Karte nach der letzten Zeile
     auf, statt einen Bildschirm voll leeres Raster zu zeigen. */
  flex: 0 1 auto; min-height: 0; overflow: auto; position: relative;
  margin: 0 16px 16px; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--bg);
  overscroll-behavior-x: contain;
  /* Der Platz des senkrechten Scrollbalkens bleibt dauerhaft reserviert.
     Sonst taucht er auf, sobald eine Zeile durch mehr Stunden höher wird,
     verschmälert die Spalten – und die Höhe eines Balkens veränderte seine
     Breite. Genau diese Kopplung soll es nicht geben. */
  scrollbar-gutter: stable;
}
.tl-inner {
  position: relative; min-width: max-content;
  display: flex; flex-direction: column;
}

/* Kopfzeile */
/* Über den Ziehwerten der Balken (bis 61): Sonst malte ein gezogener Balken
   oder die Kapazitätslinie über die klebende Kopf- und Personenspalte. */
.tl-head {
  position: sticky; top: 0; z-index: 80; flex: none;
  display: flex; background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
}
.tl-head-left {
  position: sticky; left: 0; z-index: 5; flex: none;
  width: var(--people-w); background: var(--bg-sunken);
  border-right: 1px solid var(--border);
  display: flex; align-items: flex-end; padding: 0 14px 8px;
}
.tl-head-left .tl-total {
  font-size: 11.5px; color: var(--fg-muted); font-weight: 500; line-height: 1.5;
}
.tl-head-left .tl-total b { display: block; color: var(--fg); font-weight: 700; font-size: 12.5px; }
.tl-head-days { flex: none; }
.tl-months { display: flex; height: 24px; }
.tl-month {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding-left: 7px; font-size: 11px; font-weight: 700; color: var(--fg-muted);
  border-left: 1px solid var(--border); overflow: hidden; white-space: nowrap;
  letter-spacing: .02em;
}
.tl-weeks { display: flex; height: 26px; }
.tl-week {
  flex: none; display: flex; align-items: center; gap: 8px; padding-left: 10px;
  font-size: 11px; color: var(--fg-subtle);
  border-left: 1px solid var(--border);
  overflow: hidden; white-space: nowrap;
}
.tl-week b { font-weight: 700; color: var(--fg-muted); }
.tl-month { border-left: 2px solid var(--fg-subtle); }
.tl-dates { display: flex; height: 26px; }
.tl-date {
  width: var(--day-w); flex: none;
  display: grid; place-items: center;
  font-size: 11px; color: var(--fg-subtle);
  border-left: 1px solid var(--border-subtle);
}
.tl-date.we { color: var(--fg-subtle); opacity: .65; }
.tl-date.hol { color: var(--warn); }
/* Heute: nur die Zahl im Kreis, nicht die ganze Spalte einfärben – so bleibt
   der Blick auf den Balken und nicht auf dem Datum. */
.tl-date .num {
  display: inline-flex; min-width: 20px; height: 20px; padding: 0 5px;
  align-items: center; justify-content: center; border-radius: 999px;
}
.tl-date.today .num { background: var(--accent); color: var(--fg-invert); font-weight: 700; }
.tl-date .dow { display: none; }
.tl-mode-days .tl-date { flex-direction: column; gap: 0; line-height: 1.1; }
.tl-mode-days .tl-date .dow { display: block; font-size: 8.5px; text-transform: uppercase; opacity: .7; }
.tl-mode-days .tl-dates { height: 30px; }

/* Zeilen */
.tl-rows { position: relative; flex: none; display: flex; flex-direction: column; }
.tl-row { display: flex; border-bottom: 1px solid var(--border-subtle); position: relative; }
.tl-row:last-child { border-bottom: none; }
.tl-row:hover .tl-person { background: var(--bg-hover); }
.tl-row.drop-target .tl-track { background: var(--accent-soft); }
/* Zeile einer inaktiven Person: Sie erscheint nur, weil dort noch Aufgaben
   liegen. Gedämpft, damit sie sich von den geplanten Zeilen abhebt. */
.tl-row.tl-inactive .tl-person { opacity: .62; }
.tl-row.tl-inactive .tl-track { background: repeating-linear-gradient(135deg,
  color-mix(in srgb, var(--fg-subtle) 5%, transparent) 0 6px, transparent 6px 12px); }

.tl-person {
  position: sticky; left: 0; z-index: 70; flex: none;
  width: var(--people-w); padding: 13px 14px;
  background: var(--bg); border-right: 1px solid var(--border);
  /* Auslastung unter den Namen statt daneben: In der schmalen Spalte bleibt so
     für beides Platz, und die Zahl steht dort, wo man sie sucht. */
  display: grid; grid-template-columns: 34px 1fr; gap: 4px 10px;
  align-content: start;
  transition: background .1s;
}
.tl-person .who { min-width: 0; }
.tl-person .tl-load { grid-column: 2; justify-self: start; }
.tl-person .who b { display: block; font-size: 13px; font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-person .who small { display: block; font-size: 11px; color: var(--fg-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-person .who .pen { font-size: 10px; color: var(--fg-subtle); }
.tl-load {
  flex: none; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
  font-variant-numeric: tabular-nums;
  background: var(--bg-active); color: var(--fg-muted);
}
.tl-load.warn { background: var(--warn-soft); color: var(--warn); }
.tl-load.over { background: var(--danger-soft); color: var(--danger); }
.tl-load.free { background: var(--ok-soft); color: var(--ok); }

/* touch-action: none, damit sich auf dem Tablet auch auf leerer Fläche eine
   Aufgabe aufziehen lässt – sonst übernimmt der Browser die Geste zum
   Scrollen und bricht sie mit pointercancel ab. */
.tl-track { position: relative; flex: none; min-height: var(--row-h); touch-action: none; }
.tl-track-bg { position: absolute; inset: 0; display: flex; pointer-events: none; }
.tl-cell { width: var(--day-w); flex: none; border-left: 1px solid var(--border-subtle); }

/* Wochen- und Monatsanfänge deutlich abheben – das gliedert die Fläche. */
.tl-cell.week-start,
.tl-date.week-start,
.tl-foot-day.week-start { border-left: 1px solid var(--border-strong); }
.tl-cell.month-start,
.tl-date.month-start,
.tl-foot-day.month-start { border-left: 2px solid var(--fg-subtle); }
.tl-cell.we { background: var(--weekend); }
.tl-cell { border-left: 1px solid var(--border-subtle); }
.tl-cell.hol { background: var(--holiday); }
.tl-cell.today { background: var(--today); }
.tl-cell.nowork {
  background-image: repeating-linear-gradient(45deg,
    transparent 0 5px, var(--border-subtle) 5px 6px);
}

.tl-absence {
  position: absolute; top: 4px; bottom: 4px; z-index: 1;
  border-radius: 8px; pointer-events: auto; cursor: pointer;
  border: 1.5px dashed currentColor;
  display: flex; align-items: center; padding: 0 6px; overflow: hidden;
  font-size: 10.5px; font-weight: 650;
  background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.35) 0 5px, transparent 5px 10px);
}
.tl-absence span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Aufgabenbalken */
.bar {
  --ton: var(--bar-farbe, #64748b);
  position: absolute; z-index: 5;
  /* Netz gegen 0 px hohe Balken: Die Höhe kommt sonst ausschliesslich aus
     dem Stil am Element (siehe barHeightFor in schedule.js). */
  min-height: 22px;
  border-radius: 7px; cursor: grab;
  overflow: hidden;
  display: flex; align-items: center;
  padding: 0 8px; gap: 6px;
  font-size: 11.5px; font-weight: 600; line-height: 1.25;
  /* Getönt statt vollflächig: Der Grund bleibt hell, die Schrift dunkel und
     lesbar, und die kräftige Kante links ordnet den Balken dem Kunden zu.
     Bei vielen Balken nebeneinander beruhigt das den ganzen Plan spürbar. */
  background: color-mix(in srgb, var(--ton) var(--bar-grund), var(--bg));
  color: color-mix(in srgb, var(--ton) var(--bar-schrift), var(--fg));
  /* Die kräftige Kante links als Innenschatten, nicht als Rahmen: Ein echter
     Rahmen verkleinert den Inhaltsbereich, und der untere Anfasser – der über
     left/right aufgespannt wird – verlöre genau diese 3 px Trefferfläche. */
  box-shadow:
    inset 3px 0 0 0 color-mix(in srgb, var(--ton) var(--bar-kante), var(--bg)),
    inset 0 0 0 1px color-mix(in srgb, var(--ton) 22%, transparent);
  user-select: none; -webkit-user-select: none;
  transition: box-shadow .12s, background .12s;
  touch-action: none;
}
.bar:hover {
  background: color-mix(in srgb, var(--ton) calc(var(--bar-grund) + 7%), var(--bg));
  box-shadow:
    inset 3px 0 0 0 color-mix(in srgb, var(--ton) var(--bar-kante), var(--bg)),
    inset 0 0 0 1px color-mix(in srgb, var(--ton) 34%, transparent), var(--shadow-md);
  z-index: 8;
}
.bar:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }
.bar.dragging {
  z-index: 60 !important; cursor: grabbing; opacity: .95;
  box-shadow:
    inset 3px 0 0 0 color-mix(in srgb, var(--ton) var(--bar-kante), var(--bg)),
    inset 0 0 0 1px color-mix(in srgb, var(--ton) 45%, transparent), var(--shadow-lg);
}
.bar.resizing {
  z-index: 60 !important;
  box-shadow:
    inset 3px 0 0 0 color-mix(in srgb, var(--ton) var(--bar-kante), var(--bg)),
    inset 0 0 0 1px color-mix(in srgb, var(--ton) 45%, transparent), var(--shadow-lg);
}
.bar.resizing-h { cursor: ns-resize; }
.bar.ghost {
  pointer-events: none;
  box-shadow: inset 0 0 0 2px var(--accent);
}
.bar.selected {
  box-shadow:
    inset 3px 0 0 0 color-mix(in srgb, var(--ton) var(--bar-kante), var(--bg)),
    inset 0 0 0 2px color-mix(in srgb, var(--ton) 80%, var(--fg)), var(--shadow-md);
  z-index: 9;
}
.bar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
/* Die Stundenzahl als Plakette: Sie ist die zweite Zahl, um die es geht, und
   hebt sich so vom Titel ab, statt mit ihm zu verschwimmen. */
.bar-hours {
  flex: none; font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 1px 6px; border-radius: 999px; margin-left: auto;
  background: color-mix(in srgb, var(--ton) 22%, transparent);
}
.bar-status {
  flex: none; width: 6px; height: 6px; border-radius: 50%;
  background: color-mix(in srgb, var(--ton) 75%, var(--fg));
}
/* Überlastung eines Tages: rote Linie auf Höhe der Tageskapazität,
   darunter die Zone für die Stunden, die darüber hinausgehen. */
.tl-over {
  position: absolute; z-index: 2; pointer-events: none;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}
/* Die Kapazitätsgrenze liegt über den Balken – sonst verschwände sie,
   sobald ein einzelner Balken die Grenze allein überschreitet. */
.tl-over-line {
  position: absolute; height: 0;
  border-top: 2px solid var(--danger);
  pointer-events: none;
  /* Über allen Balkenzuständen – auch über einem markierten (9), einem
     überfahrenen (8) und einem gerade gezogenen (60). Nur so bleibt beim
     Ziehen sichtbar, wo die Tageskapazität endet. */
  z-index: 61;
}
.bar.done { opacity: .62; }
.bar.done .bar-title { text-decoration: line-through; }
.bar.narrow { padding: 0 4px; }
.bar.narrow .bar-hours { display: none; }
.bar.tiny .bar-title { display: none; }
.bar.tiny { padding: 0; }
.bar-people { display: flex; gap: 2px; flex: none; }
.bar-people i {
  width: 5px; height: 5px; border-radius: 50%; display: block;
  background: color-mix(in srgb, var(--ton) 70%, var(--fg));
}

/* Ab einer gewissen Höhe steht der Titel oben und die Stunden unten rechts,
   damit die Fläche die reservierte Zeit sichtbar macht. */
.bar.tall {
  align-items: flex-start;
  flex-wrap: wrap;
  align-content: flex-start;
  padding-top: 5px;
  padding-bottom: 4px;
  line-height: 1.25;
}
.bar.tall .bar-title { white-space: normal; overflow: hidden; flex: 1 1 100%; }
/* Höhere Spezifität als .bar.narrow .bar-hours { display: none } – sonst
   verschwände die Stundenzahl genau dort, wo man sie beim Stundenziehen
   braucht. Sehr schmale Balken bleiben ausgenommen, dort passt sie nicht hin. */
.bar.tall:not(.tiny) .bar-hours { display: block; position: absolute; right: 7px; bottom: 4px; }
.bar.tall .bar-people { position: absolute; left: 7px; bottom: 5px; }

/* Anfasser links/rechts */
.bar-handle {
  position: absolute; top: 0; bottom: 0; width: 9px;
  cursor: ew-resize; z-index: 3;
  display: grid; place-items: center;
  opacity: 0; transition: opacity .12s;
  touch-action: none;
}
/* Die seitlichen Anfasser enden oberhalb des unteren Bandes. Sonst liegen in
   den Ecken zwei Anfasser übereinander und eine schräge Handbewegung ändert
   ungewollt die Dauer, obwohl man die Stunden ziehen wollte. */
/* Anteilig, damit auf schmalen oder flachen Balken beide Gesten erreichbar
   bleiben und keine die andere verdrängt. */
/* Nie breiter als eine Tagesspalte und nie mehr als ein Drittel des Balkens –
   sonst liegt der Griffpunkt in einer anderen Spalte als die Kante. */
.bar-handle.l { left: 0; bottom: clamp(9px, 40%, 12px); width: min(9px, 30%, var(--day-w)); }
.bar-handle.r { right: 0; bottom: clamp(9px, 40%, 12px); width: min(9px, 30%, var(--day-w)); }
.bar-handle::after {
  content: ''; width: 3px; height: 12px; border-radius: 2px;
  /* Aus der Balkenfarbe gemischt statt fest weiss – sonst verschwinden die
     Griffe auf einem hellen Balken. */
  background: color-mix(in srgb, var(--ton) 65%, var(--fg));
  opacity: .75;
}

/* Unterkante: Stunden pro Tag ändern */
.bar-handle.b {
  left: 0; right: 0; width: auto; top: auto;
  height: clamp(9px, 40%, 12px); bottom: 0; cursor: ns-resize;
  z-index: 4;
}
.bar-handle.b::after {
  width: 26px; height: 3px;
}
.bar:hover .bar-handle, .bar.resizing .bar-handle, .bar.selected .bar-handle { opacity: 1; }
/* Nur die seitlichen Anfasser verschmälern. Traf die Regel auch den unteren,
   schrumpfte das Stundenband auf ein 6-px-Kästchen unten links – ein
   senkrechter Zug galt dann als Verschieben und ordnete die Aufgabe einer
   anderen Person zu. */
.bar.tiny .bar-handle.l, .bar.tiny .bar-handle.r { width: 6px; }

/* Auslastungs-Fussleiste */
.tl-foot {
  display: flex; position: sticky; bottom: 0; z-index: 75; flex: none;
  background: var(--bg); border-top: 1px solid var(--border);
}
.tl-foot-left {
  position: sticky; left: 0; z-index: 3; flex: none; width: var(--people-w);
  padding: 6px 12px; background: var(--bg); border-right: 1px solid var(--border);
  font-size: 11px; font-weight: 650; color: var(--fg-muted);
}
.tl-foot-days { display: flex; flex: none; }
.tl-foot-day {
  width: var(--day-w); flex: none; height: 30px;
  border-left: 1px solid var(--border-subtle);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 2px;
  position: relative;
}
.tl-foot-day .fill {
  position: absolute; left: 2px; right: 2px; bottom: 0;
  background: var(--accent); opacity: .35; border-radius: 2px 2px 0 0;
  min-height: 1px;
}
.tl-foot-day.over .fill { background: var(--danger); opacity: .5; }
.tl-foot-day span { position: relative; font-size: 8.5px; color: var(--fg-subtle); font-variant-numeric: tabular-nums; }
.tl-foot-day.we { background: var(--weekend); }

/* Nicht zugewiesene Aufgaben */
.tl-unassigned .tl-person { background: var(--bg-sunken); }
.tl-unassigned .tl-person .who b { color: var(--fg-muted); font-style: italic; }

.tl-empty { padding: 60px 24px; text-align: center; color: var(--fg-muted); }
.tl-empty h3 { margin-bottom: 6px; font-size: 15px; color: var(--fg); }
.tl-empty p { margin: 0 0 16px; font-size: 13px; }

/* Live-Hinweis beim Ziehen */
.drag-tip {
  position: fixed; z-index: 200; pointer-events: none;
  padding: 5px 9px; border-radius: 6px;
  background: var(--fg); color: var(--bg);
  font-size: 11.5px; font-weight: 650; white-space: nowrap;
  box-shadow: var(--shadow-md);
  font-variant-numeric: tabular-nums;
}

/* ================================================================= Tabellen */

.panel {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 20px;
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 14px; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 16px; }

table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th {
  text-align: left; padding: 9px 14px;
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--fg-subtle); background: var(--bg-sunken);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--border-subtle); font-size: 13px; vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--bg-hover); }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl .actions { text-align: right; white-space: nowrap; }
table.tbl .actions .btn { opacity: .35; }
table.tbl tr:hover .actions .btn { opacity: 1; }
.tbl-wrap { overflow-x: auto; }

.cell-person { display: flex; align-items: center; gap: 9px; }
.cell-person b { font-weight: 600; }
.cell-person small { display: block; color: var(--fg-subtle); font-size: 11px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; display: inline-block; vertical-align: middle; }
.inactive-row { opacity: .55; }

.empty-state { padding: 48px 20px; text-align: center; color: var(--fg-muted); }
.empty-state svg { opacity: .3; margin-bottom: 12px; }
.empty-state h3 { font-size: 15px; color: var(--fg); margin-bottom: 5px; }
.empty-state p { margin: 0 0 18px; font-size: 13px; }

/* Statistik-Karten */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat {
  padding: 14px 16px; background: var(--bg-raised);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.stat .k { font-size: 11px; font-weight: 650; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .s { font-size: 11.5px; color: var(--fg-subtle); margin-top: 2px; }
.stat.accent .v { color: var(--accent); }
.stat.ok .v { color: var(--ok); }
.stat.warn .v { color: var(--warn); }
.stat.danger .v { color: var(--danger); }

.meter { height: 6px; border-radius: 3px; background: var(--bg-active); overflow: hidden; min-width: 60px; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width .3s; }
.meter.over i { background: var(--danger); }
.meter.warn i { background: var(--warn); }
.meter.ok i { background: var(--ok); }

.bar-h-list { display: flex; flex-direction: column; gap: 9px; }
.bar-h-row { display: grid; grid-template-columns: 150px 1fr 74px; align-items: center; gap: 10px; font-size: 12.5px; }
.bar-h-row .lbl { display: flex; align-items: center; gap: 7px; overflow: hidden; }
.bar-h-row .lbl span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-h-row .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.bar-h-track { height: 20px; background: var(--bg-sunken); border-radius: 4px; overflow: hidden; }
.bar-h-track i { display: block; height: 100%; border-radius: 4px; }

/* ================================================================== Dialoge */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 24, 40, .45);
  display: grid; place-items: center; padding: 20px;
  animation: fade .14s ease-out;
  overflow-y: auto;
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } }
.modal {
  width: 100%; max-width: 540px; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  background: var(--bg-raised); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); animation: pop .16s ease-out;
  margin: auto;
}
.modal-lg { max-width: 760px; }
.modal-sm { max-width: 420px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--border); flex: none;
}
.modal-head h2 { font-size: 15.5px; flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; align-items: center; gap: 9px;
  padding: 13px 18px; border-top: 1px solid var(--border); flex: none;
}
.modal-foot .spacer { flex: 1; }

/* Personen-Auswahl */
.picker { border: 1px solid var(--border); border-radius: var(--radius); max-height: 208px; overflow-y: auto; }
.picker-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--border-subtle);
}
.picker-item:last-child { border-bottom: none; }
.picker-item:hover { background: var(--bg-hover); }
.picker-item.on { background: var(--accent-soft); }
.picker-item input { width: 15px; height: 15px; accent-color: var(--accent); flex: none; }
.picker-item .who { flex: 1; min-width: 0; }
.picker-item .who b { display: block; font-size: 12.5px; font-weight: 600; }
.picker-item .who small { font-size: 11px; color: var(--fg-subtle); }
.picker-item .hrs { width: 66px; flex: none; }
.picker-item .hrs input { height: 28px; text-align: right; font-size: 12px; }
.picker-search { padding: 7px 9px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-raised); z-index: 1; }
.picker-search input { height: 30px; }

/* Kopfblock im Aufgaben-Dialog: die Zahlen auf einen Blick */
.alloc-head {
  display: grid;
  grid-template-columns: 108px 116px 1fr;
  gap: 10px 18px;
  align-items: start;
  padding: 14px 16px 12px;
  margin-bottom: 18px;
  background: var(--bg-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.alloc-label {
  display: block; margin-bottom: 4px;
  font-size: 11.5px; font-weight: 600; color: var(--fg-muted);
}
.alloc-value {
  font-size: 20px; font-weight: 650; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums; line-height: 1.4;
}
.alloc-duration { white-space: nowrap; }
.alloc-cell input[type="number"] { height: 34px; font-size: 17px; font-weight: 650; }
.alloc-dates { grid-column: 3; min-width: 0; }
.alloc-dates .row { gap: 6px; }
.alloc-dates input { height: 34px; }
.alloc-foot { grid-column: 1 / -1; }
.alloc-foot .field-hint { margin-top: 0; }
@media (max-width: 620px) {
  .alloc-head { grid-template-columns: 1fr 1fr; }
  .alloc-dates { grid-column: 1 / -1; }
}

/* Status als Schaltflächenreihe */
.status-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.status-chip {
  padding: 7px 13px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--fg-muted);
  font-size: 13px; font-weight: 550; cursor: pointer;
}
.status-chip:hover { background: var(--bg-hover); }
.status-chip.on {
  background: var(--accent-soft); border-color: var(--accent-border);
  color: var(--accent); font-weight: 650;
}

/* Farbwähler */
.colors { display: flex; flex-wrap: wrap; gap: 6px; }
.colors button {
  width: 26px; height: 26px; border-radius: 6px; border: 2px solid transparent;
  cursor: pointer; padding: 0; position: relative;
}
.colors button.on { border-color: var(--fg); }
.colors button.on::after {
  content: '✓'; position: absolute; inset: 0;
  display: grid; place-items: center; color: #fff;
  font-size: 13px; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.4);
}

/* Wochentagswähler */
.days-pick { display: flex; gap: 4px; }
.days-pick button {
  width: 34px; height: 32px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--bg); cursor: pointer;
  font-size: 11px; font-weight: 650; color: var(--fg-muted);
}
.days-pick button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------------------------------------------------------------- Toasts */

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 11px 13px; border-radius: var(--radius);
  background: var(--fg); color: var(--bg);
  font-size: 13px; box-shadow: var(--shadow-lg);
  animation: slideIn .18s ease-out; line-height: 1.4;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.toast button { background: none; border: none; color: inherit; opacity: .7; cursor: pointer; padding: 0; font-size: 15px; line-height: 1; }
.toast .undo { text-decoration: underline; font-weight: 650; opacity: 1; font-size: 12.5px; }

/* --------------------------------------------------------------- Kontextmenü */

.ctx {
  position: fixed; z-index: 250; min-width: 186px; padding: 5px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: pop .1s ease-out;
}
.ctx button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 9px; border: none; border-radius: 5px;
  background: none; text-align: left; font-size: 13px; cursor: pointer; color: var(--fg);
}
.ctx button:hover { background: var(--bg-hover); }
.ctx button.danger { color: var(--danger); }
.ctx hr { border: none; border-top: 1px solid var(--border-subtle); margin: 4px 2px; }
.ctx .hint { padding: 4px 9px 6px; font-size: 10.5px; color: var(--fg-subtle); }

/* --------------------------------------------------------------- Hilfsklassen */

.muted { color: var(--fg-muted); }
.subtle { color: var(--fg-subtle); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12px; }
.tabnum { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { flex-wrap: wrap; }
.mt0 { margin-top: 0; } .mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mt24 { margin-top: 24px; }
.mb0 { margin-bottom: 0; } .mb8 { margin-bottom: 8px; } .mb16 { margin-bottom: 16px; }
.hide { display: none !important; }
.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ------------------------------------------------------------------ Responsive */

@media (max-width: 900px) {
  :root { --people-w: 168px; --sidebar-w: 0px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 244px; z-index: 90;
    transform: translateX(-100%); transition: transform .2s ease-out;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 89; background: rgba(16,24,40,.4); }
  .hamburger { display: inline-flex; }
  .view-pad { padding: 14px; }
  .tl-person { padding: 8px; }
  .tl-person .avatar { display: none; }
  .topbar { padding: 0 10px; }
  .topbar h1 { font-size: 15px; }
  .tl-toolbar { padding: 8px 10px; }
}

@media print {
  .sidebar, .topbar, .tl-toolbar, .btn { display: none !important; }
  .app-shell { display: block; height: auto; }
  body.app-body { overflow: visible; }

  /* Farben erzwingen: Der Balkenhintergrund wird in JavaScript gesetzt, die
     Schriftfarbe passend dazu. Lässt der Browser den Hintergrund weg, bliebe
     weisse Schrift auf weissem Grund – der Ausdruck wäre leer. */
  .bar, .tl-cell, .tl-cell.we, .tl-cell.hol, .tl-cell.today, .tl-cell.nowork,
  .tl-absence, .tl-over, .tl-over-line, .tl-foot-day .fill, .tl-load, .avatar,
  .chip, .status-chip, .meter, .meter i {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  /* Anfasser haben auf Papier keinen Sinn und würden nur Striche hinterlassen. */
  .bar-handle { display: none !important; }
  /* Die Zeitachse darf über mehrere Seiten laufen, statt abgeschnitten zu werden. */
  .tl-scroll { overflow: visible !important; height: auto !important; }
  .tl-row { break-inside: avoid; }
}
