:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #6b7584;
  --line: #e3e7ec;
  --line-strong: #cfd5dc;
  --accent: #2563eb;
  --accent-soft: #e6eeff;
  --offhours: #f1f3f6;
  --green: #16a34a;
  --yellow: #eab308;
  --red: #dc2626;
  --red-soft: #fde8e8;
  --orange: #ea580c;
  --orange-soft: #ffedd5;
  --amber-soft: #fef3c7;
  --block: #dbe7ff;
  --block-border: #7aa2f7;
  --shadow: 0 8px 28px rgba(20, 30, 50, 0.16);
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --panel: #1a1e25;
    --text: #e6e9ee;
    --muted: #9099a6;
    --line: #2a303a;
    --line-strong: #3a4250;
    --accent: #6d9bff;
    --accent-soft: #1f2b45;
    --offhours: #15181e;
    --red-soft: #3d1c1c;
    --orange-soft: #3b2412;
    --amber-soft: #352d10;
    --block: #22345a;
    --block-border: #4f74c4;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--red); }
input, textarea, select {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 6px 8px;
  width: 100%;
}
input.invalid { border-color: var(--red); }
code { background: var(--offhours); padding: 1px 4px; border-radius: 4px; }

/* ---------- Kopfzeile ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; }
.mode { color: var(--orange); font-size: 12px; }
.sync { margin-left: auto; font-size: 12px; color: var(--muted); max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync::before { content: "●"; margin-right: 5px; color: var(--green); }
.sync.syncing::before { color: var(--accent); }
.sync.offline::before { color: var(--muted); }
.sync.error::before { color: var(--red); }
.icon-btn { padding: 2px 8px; font-size: 15px; }

/* ---------- Verbinden ---------- */

.connect { flex: 1; display: grid; place-items: center; padding: 16px; }
.connect-card {
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  text-align: center;
}
.connect-card h1 { margin: 0 0 8px; }
.connect-card .primary { padding: 10px 18px; margin-top: 8px; }
.hint { color: var(--muted); font-size: 13px; }
.fatal { position: fixed; bottom: 16px; left: 16px; right: 16px; background: var(--red-soft); color: var(--red); padding: 12px; border-radius: var(--radius); }

/* ---------- Layout ---------- */

.app {
  flex: 1;
  min-height: 0;
  display: grid;
  /* Liste | Trenner | Kalender; --list-w setzt der Trenner, sonst ein Drittel */
  grid-template-columns: var(--list-w, minmax(280px, 1fr)) 12px var(--cal-w, 2fr);
  padding: 12px;
}
.splitter { cursor: col-resize; position: relative; touch-action: none; }
.splitter::after { content: ""; position: absolute; top: 50%; left: 4px; width: 4px; height: 36px; margin-top: -18px; border-radius: 2px; background: var(--line-strong); }
.splitter:hover::after, .splitter.active::after { background: var(--accent); }
body.resizing, body.resizing * { cursor: col-resize !important; user-select: none; }

/* Liste eingeklappt: nur eine schmale Spalte bleibt */
.strip { display: none; }
.app.collapsed { grid-template-columns: 40px 12px 1fr; }
.app.collapsed .splitter { pointer-events: none; }
.app.collapsed .splitter::after { display: none; }
.app.collapsed .tasks > :not(.strip) { display: none; }
.app.collapsed .strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex: 1;
  border: none;
  border-radius: 0;
  padding: 10px 0;
  background: none;
}
.strip:hover { background: var(--bg); }
.strip .chevron { font-size: 18px; line-height: 1; }
.strip-label { writing-mode: vertical-rl; color: var(--muted); font-size: 13px; letter-spacing: 0.5px; }
.chevron-btn { padding: 0 9px; font-size: 18px; line-height: 1; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(180px, 38vh) 1fr; padding: 8px; gap: 8px; }
  .splitter { display: none; }
  .app.collapsed { grid-template-columns: 1fr; grid-template-rows: 40px 1fr; }
  .app.collapsed .strip { flex-direction: row; justify-content: center; padding: 0; }
  .app.collapsed .strip .chevron { transform: rotate(90deg); }
  .app.collapsed .strip-label { writing-mode: horizontal-tb; }
  .chevron-btn { transform: rotate(90deg); }
  .topbar { padding: 8px 12px; }
}

/* ---------- Aufgabenliste ---------- */

.new-task { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.new-task .primary { width: 38px; font-size: 18px; padding: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.filters:empty { display: none; }
.filter-spacer { flex: 1; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 999px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .state-dot { width: 8px; height: 8px; margin: 0 5px 0 0; vertical-align: 0; }
.chip.on .state-dot { border-color: #fff; }
.chip.on .state-dot.on { background: #fff; }

.task-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; position: relative; }
.task-list .empty { color: var(--muted); padding: 16px; text-align: center; }
.task {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 12px 9px 10px;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--line);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.task:hover { background: var(--bg); }
.task.active { border-left-color: var(--task, var(--accent)); }
.task.passive.colored { border-left-color: color-mix(in srgb, var(--task) 45%, transparent); }
.task.passive.colored .state-dot { border-color: var(--task); }
.task.active .task-title { font-weight: 600; }
.task.archived { opacity: 0.6; }
.task-main { min-width: 0; flex: 1; }
/* Archivieren / Löschen in der Zeile: erscheint beim Darüberfahren, auf Touch-Geräten immer */
.task-acts { display: flex; gap: 2px; flex: none; margin: -2px -4px 0 0; visibility: hidden; }
.task:hover .task-acts, .task-acts:has(.armed) { visibility: visible; }
@media (hover: none) { .task-acts { visibility: visible; } }
.task-act {
  width: 26px;
  height: 26px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
}
.task-act:hover { background: var(--offhours); color: var(--text); border-color: transparent; }
.task-act.delete:hover { color: var(--red); }
.task-act.armed { color: #fff; background: var(--accent); }
.task-act.delete.armed { background: var(--red); }
.task-title { overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 4px; font-size: 12px; color: var(--muted); align-items: center; }
.planned { color: var(--accent); }
/* Eingeplant im Vergleich zur Schätzung */
.est-g { background: color-mix(in srgb, var(--green) 15%, var(--panel)); color: var(--green); font-weight: 600; }
.est-y { background: var(--amber-soft); color: #a16207; font-weight: 600; }
.est-r { background: var(--red-soft); color: var(--red); font-weight: 600; }
.new-task .estimate-input { width: 58px; flex: none; text-align: center; }

.state-dot {
  flex: none;
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  display: inline-block;
}
.task.active .state-dot, .state-dot.on { background: var(--task, var(--accent)); border-color: var(--task, var(--accent)); }

.badge { padding: 1px 7px; border-radius: 999px; font-size: 11.5px; white-space: nowrap; }
.dl-later { background: var(--offhours); color: var(--muted); }
.dl-week { background: var(--amber-soft); color: #92400e; }
.dl-soon { background: var(--orange-soft); color: var(--orange); font-weight: 600; }
.dl-today, .dl-over { background: var(--red); color: #fff; font-weight: 600; }
.wv-later { background: var(--offhours); color: var(--muted); }
.wv-due { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
@media (prefers-color-scheme: dark) { .dl-week { color: #fcd34d; } }

/* ---------- Kalender ---------- */

.cal-toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.cal-toolbar h2 { font-size: 15px; margin: 0 0 0 8px; font-weight: 600; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; border-left: none; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.cal-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Auslastungsbalken */
.bar { height: 7px; border-radius: 4px; background: var(--offhours); border: 1px solid var(--line); overflow: hidden; }
.bar-fill { height: 100%; }
.bar-fill.g { background: var(--green); }
.bar-fill.y { background: var(--yellow); }
.bar-fill.r { background: var(--red); }
.bar-fill.over { background: repeating-linear-gradient(-45deg, var(--red) 0 5px, #8f1414 5px 9px); }
.overtime { color: var(--red); font-weight: 700; }

/* Monat */
.month { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 8px; overflow: auto; }
.month-head, .month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.month-head div { text-align: center; color: var(--muted); font-size: 12px; padding-bottom: 4px; }
.month-grid { flex: 1; grid-auto-rows: minmax(84px, 1fr); }
.mday {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
}
.mday:hover { border-color: var(--line-strong); }
.mday.other { opacity: 0.45; }
.mday.weekend { background: var(--offhours); }
/* Heute: dünner blauer Rahmen + blaue Fläche · ausgewählter Tag: kräftiger dunkler Rahmen */
.mday.today { background: var(--accent-soft); border-color: var(--accent); }
.mday.selected { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.mday-top { display: flex; justify-content: space-between; gap: 4px; align-items: baseline; }
.mday-num { font-weight: 600; }
.mday.today .mday-num { color: var(--accent); }
.mday-count { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mday-hours { font-size: 11.5px; }
.mday-pct { font-size: 11px; color: var(--muted); }
@media (max-width: 600px) {
  .month { padding: 4px; }
  .month-grid { grid-auto-rows: minmax(64px, 1fr); gap: 2px; }
  .mday { padding: 3px; }
  .mday-count, .mday-pct { display: none; }
  .mday-hours { font-size: 10px; }
}

/* Woche: zeigt nur den eingestellten Zeitraum und füllt die verfügbare Höhe */
.week-scroll {
  flex: 1;
  overflow: auto;
  position: relative;
  display: flex;
  flex-direction: column;
  scroll-snap-type: x mandatory;
  scroll-padding-left: 52px; /* Stundenspalte steht davor */
}
.wday-head { scroll-snap-align: start; }
/* beim Ziehen frei scrollen, eingerastet wird danach */
.panning .week-scroll, body.dragging .week-scroll { scroll-snap-type: none; }
.wday-head.monday, .wday-grid.monday { border-left: 2px solid var(--line-strong); }
.kw { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.week {
  flex: 1;
  display: grid;
  grid-template-columns: 52px repeat(var(--days), var(--colw, 120px));
  grid-template-rows: auto minmax(calc(var(--hours) * 30px), 1fr);
  min-width: min-content;
}
.corner, .wday-head {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--panel);
  border-bottom: 1px solid var(--line-strong);
}
.corner { left: 0; z-index: 4; }
.wday-head { padding: 6px 6px 8px; border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 5px; }
.wday-title { font-size: 13px; display: flex; gap: 5px; align-items: baseline; }
.wday-load { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); gap: 4px; }
.wday-load span:first-child { color: var(--text); }
.cap { padding: 0 4px; border: 1px dashed var(--line-strong); font-size: 12px; }
.reserved { display: flex; flex-direction: column; gap: 3px; min-height: 26px; max-height: 150px; overflow-y: auto; }
.reserved-hint {
  height: 22px;
  display: grid;
  place-items: center;
  color: color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 5px;
  background: color-mix(in srgb, var(--accent) 9%, var(--panel));
}
.wday-head:hover .reserved-hint { color: var(--accent); }
.drop-hover .reserved-hint { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--panel)); }
.reserved:has(.chip-placeholder) .reserved-hint { display: none; }
.chip-booking {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  background: color-mix(in srgb, var(--task, var(--accent)) 12%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--task, var(--accent)) 50%, var(--panel));
  border-left: 3px solid var(--task, var(--accent));
  border-radius: 5px;
  padding: 2px 6px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.cb-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cb-dur { color: var(--muted); white-space: nowrap; }

.hours { position: sticky; left: 0; z-index: 2; background: var(--panel); border-right: 1px solid var(--line); }
.hlabel { position: absolute; right: 6px; font-size: 11px; color: var(--muted); transform: translateY(-50%); }
.hlabel:first-child { transform: none; }
.wday-grid {
  position: relative;
  overflow: hidden;
  border-left: 1px solid var(--line);
  /* Stundenlinien (kräftig) und halbe Stunden (zart) */
  background-image:
    linear-gradient(to bottom, var(--line-strong) 1px, transparent 1px),
    linear-gradient(to bottom, transparent 50%, var(--line) 50%, var(--line) calc(50% + 1px), transparent calc(50% + 1px));
  background-size: 100% calc(100% / var(--hours));
}
.wday-grid.weekend, .wday-head.weekend { background-color: var(--offhours); }
/* Tag ohne Kapazität: Schraffur (über Grau am Wochenende, über Weiß an Werktagen) */
.wday-head.nocap, .mday.nocap {
  background-image: repeating-linear-gradient(-45deg, transparent 0 6px, var(--line-strong) 6px 7px);
}
.wday-grid.nocap {
  background-image:
    linear-gradient(to bottom, var(--line-strong) 1px, transparent 1px),
    repeating-linear-gradient(-45deg, transparent 0 8px, var(--line) 8px 9px);
  background-size: 100% calc(100% / var(--hours)), auto;
}
.now { position: absolute; left: 0; right: 0; height: 2px; background: var(--red); z-index: 2; pointer-events: none; }
.block {
  position: absolute;
  z-index: 1;
  min-height: 16px;
  background: color-mix(in srgb, var(--task, var(--accent)) 17%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--task, var(--accent)) 50%, var(--panel));
  border-left: 3px solid var(--task, var(--accent));
  border-radius: 5px;
  padding: 2px 6px;
  font-size: 12px;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.block.outside { border-style: dashed; }
.block-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.block-time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.resize { position: absolute; left: 0; right: 0; bottom: 0; height: 10px; cursor: ns-resize; touch-action: none; }
.resize::after { content: ""; position: absolute; left: 50%; bottom: 3px; width: 22px; margin-left: -11px; height: 3px; border-radius: 2px; background: color-mix(in srgb, var(--task, var(--accent)) 45%, var(--panel)); }
.block:hover .resize::after, .block.resizing .resize::after { background: var(--task, var(--accent)); }
.block.resizing { z-index: 4; box-shadow: var(--shadow); }
body.resizing-block, body.resizing-block * { cursor: ns-resize !important; user-select: none; }

/* Heute: farbig hinterlegt · angeklickter Tag: umrandet */
.today-tag { font-size: 10.5px; font-weight: 600; color: #fff; background: var(--accent); border-radius: 999px; padding: 0 6px; }
.wday-head.today { background: var(--accent-soft); }
.wday-head.today .wday-title b { color: var(--accent); }
.wday-grid.today { background-color: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.wday-head.today { box-shadow: inset 1px 0 0 var(--accent), inset -1px 0 0 var(--accent), inset 0 1px 0 var(--accent); }
.wday-grid.today { box-shadow: inset 1px 0 0 var(--accent), inset -1px 0 0 var(--accent), inset 0 -1px 0 var(--accent); }
.wday-head.selected { box-shadow: inset 2px 0 0 var(--text), inset -2px 0 0 var(--text), inset 0 2px 0 var(--text); }
.wday-grid.selected { box-shadow: inset 2px 0 0 var(--text), inset -2px 0 0 var(--text), inset 0 -2px 0 var(--text); }

/* Blättern */
.cal-body { position: relative; user-select: none; -webkit-user-select: none; }
.cal-body.pannable { touch-action: pan-y; }
.cal-body.panning, .cal-body.panning * { cursor: grabbing !important; }
.cal-body.flip-prev::before, .cal-body.flip-next::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 28px;
  z-index: 10;
  pointer-events: none;
}
.cal-body.flip-prev::before { left: 0; background: linear-gradient(to right, color-mix(in srgb, var(--accent) 45%, transparent), transparent); }
.cal-body.flip-next::after { right: 0; background: linear-gradient(to left, color-mix(in srgb, var(--accent) 45%, transparent), transparent); }

/* ---------- Ziehen ---------- */

body.dragging, body.dragging * { cursor: grabbing !important; }
body.dragging { user-select: none; -webkit-user-select: none; }
.drag-source { opacity: 0.4; }
.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 5px 9px;
  box-shadow: var(--shadow);
  font-size: 12.5px;
  max-width: 260px;
}
.drag-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drag-where { color: var(--accent); font-size: 12px; }
.drag-where:empty { display: none; }
.drop-hover.mday, .drop-hover.wday-head { background: var(--accent-soft); }
.drop-hover.wday-grid { background-color: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.task-list.drop-hover { background: none; }

/* Einfügemarken */
.insert-line {
  position: absolute;
  left: 6px;
  right: 6px;
  height: 3px;
  margin-top: -1px;
  border-radius: 2px;
  background: var(--accent);
  pointer-events: none;
  z-index: 5;
}
.insert-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.drop-preview {
  position: absolute;
  left: 2px;
  right: 2px;
  min-height: 16px;
  z-index: 3;
  border: 2px dashed var(--accent);
  border-top: 3px solid var(--accent);
  border-radius: 5px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
  padding: 1px 6px;
  pointer-events: none;
}
.chip-placeholder {
  font-size: 12px;
  border: 2px dashed var(--accent);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--accent);
  font-weight: 600;
  pointer-events: none;
}

/* ---------- Popover & Dialoge ---------- */

.popover {
  position: fixed;
  z-index: 50;
  width: 290px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pop-title { font-weight: 600; }
.pop-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pop-row { display: flex; gap: 6px; align-items: center; }
.quick { display: flex; flex-wrap: wrap; gap: 4px; }
.quick button { font-size: 12px; padding: 2px 7px; }
.quick button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.pop-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

dialog {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 18px;
  width: min(520px, calc(100vw - 24px));
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 15, 25, 0.35); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog h3 { margin: 0; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog label small { font-size: 11.5px; }
.title-input { font-size: 17px; font-weight: 600; }
.status-line { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.status-line .state-dot { margin-top: 0; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.task-bookings ul { list-style: none; padding: 0; margin: 4px 0 0; font-size: 13px; }
.task-bookings li { padding: 3px 0; cursor: pointer; color: var(--accent); }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 10px; }
legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.weekday-caps { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.weekday-caps input { padding: 5px 4px; text-align: center; }

/* Schließen-Knopf oben rechts in Dialogen und Popovers */
.close-x {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}
.close-x:hover { background: var(--offhours); color: var(--text); }
dialog form { position: relative; }
dialog form > .close-x { top: -8px; right: -8px; } /* in die Ecke des Dialogs */
dialog .title-input { width: calc(100% - 28px); }
dialog h3 { margin-right: 28px; }
.popover { padding-right: 36px; }
.popover .close-x { top: 6px; right: 6px; }

/* ---------- Externe Kalender (Google, iCal) ---------- */

/* Status oben rechts */
.cal-status { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.cal-status:not([hidden]) + .sync { margin-left: 12px; }
.cal-status a { color: var(--accent); }
.cal-error { color: var(--orange); }
#btn-cal-refresh { padding: 0 7px; font-size: 14px; line-height: 22px; }
#btn-cal-refresh.spinning { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Anteil der Kalendertermine im Auslastungsbalken */
.bar-fill { position: relative; }
.bar-ext {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.55) 0 2px, transparent 2px 5px);
}

/* Ganztägige Termine im Tageskopf */
.ext-allday-list { display: flex; flex-direction: column; gap: 2px; }
.ext-allday {
  font-size: 11px;
  line-height: 16px;
  padding: 0 5px;
  border-radius: 4px;
  border-left: 3px solid color-mix(in srgb, var(--cal) 60%, var(--panel));
  background: color-mix(in srgb, var(--cal) 8%, var(--panel));
  color: color-mix(in srgb, var(--cal) 45%, var(--muted));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ext-allday.free { background: var(--panel); border-left-style: dashed; color: var(--muted); }
.ext-more { font-size: 11px; color: var(--muted); padding-left: 5px; }

/* Kalendertermine im Stundenraster: blass, aber deckend und vor Raster, Wochenend-Grau und Schraffur */
.ext-event {
  position: absolute;
  z-index: 1;
  min-height: 14px;
  box-sizing: border-box;
  border-left: 3px solid color-mix(in srgb, var(--cal) 55%, var(--panel));
  background: color-mix(in srgb, var(--cal) 8%, var(--panel));
  border-radius: 3px;
  overflow: hidden;
  padding: 1px 4px;
  font-size: 10.5px;
  line-height: 1.25;
  color: color-mix(in srgb, var(--cal) 45%, var(--muted));
}
.ext-event span, .ext-event small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ext-event span { font-weight: 600; }
.ext-event small { font-size: 10px; opacity: 0.8; }
.ext-event.free {
  background: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--cal) 7%, var(--panel)) 0 4px, var(--panel) 4px 8px);
  border-left-style: dashed;
}

/* Termine in der Monatsansicht als Punkte */
.mday-ext { display: flex; gap: 3px; align-items: center; margin-top: auto; }
.mday-ext i { width: 7px; height: 7px; border-radius: 50%; background: var(--cal); }
.mday-ext i.allday { width: 12px; border-radius: 3px; }
.mday-ext span { font-size: 10px; color: var(--muted); }

/* Einstellungen: Kalender */
dialog { max-height: calc(100vh - 32px); overflow-y: auto; }
dialog label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
dialog label.inline input { width: 70px; }
dialog label.check { flex-direction: row; align-items: center; gap: 5px; color: var(--text); font-size: 13px; white-space: nowrap; }
dialog label.check input { width: auto; }
.cal-settings { display: flex; flex-direction: column; gap: 10px; }
.cal-source { display: flex; flex-direction: column; gap: 6px; }
.cal-source-body { display: flex; flex-direction: column; gap: 6px; padding-left: 22px; }
.cal-source-body .hint { margin: 0; font-size: 12px; }
.cal-status-line { font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cal-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.cal-row-main { display: flex; align-items: center; gap: 6px; flex: 1 1 220px; min-width: 0; }
.cal-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.cal-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-row input[type="color"] { width: 28px; height: 26px; padding: 1px; flex: none; }
.cal-name-input { flex: 0 1 130px; }
.cal-url-input { flex: 1 1 160px; min-width: 0; }
.close-x.inline-x { position: static; flex: none; }
.cal-row-error { flex-basis: 100%; font-size: 12px; color: var(--orange); }

/* Aufgabe direkt im Kalender anlegen */
.quick-add { display: flex; flex-direction: column; gap: 8px; }
.quick-add input[name="dur"] { width: 64px; text-align: center; }
.wday-grid { cursor: cell; }
.wday-head .reserved { cursor: cell; }
.wday-head .reserved .chip-booking { cursor: grab; }
.ext-event { cursor: default; }

/* Farbauswahl im Aufgabendialog */
.color-pick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.color-pick button {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--panel);
  background: var(--swatch);
  box-shadow: 0 0 0 1px var(--line-strong);
}
.color-pick button.on { box-shadow: 0 0 0 2px var(--text); }
.color-pick button:hover { transform: scale(1.12); }
dialog .field { display: flex; flex-direction: column; gap: 6px; }
dialog .field-label { font-size: 13px; color: var(--muted); }
