:root {
  --bg: #f6f4f1;
  --surface: #fffdf9;
  --surface-2: #f1ede6;
  --border: #e4ded4;
  --border-strong: #c9c1b3;
  --text: #1d3557;
  --text-muted: #6b7286;
  --primary: #1d3557;
  --primary-hover: #15294a;
  --sun: #f2c94c;
  --sage: #b7c9a3;
  --danger: #c53c3c;
  --success: #3e7a3a;
  --warn: #a86a00;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(29, 53, 87, .06), 0 4px 16px rgba(29, 53, 87, .07);
  --shadow-lg: 0 20px 50px rgba(29, 53, 87, .25);
  --font: "Jost", "Futura", "Avenir Next", system-ui, sans-serif;
  --bar-h: 22px;
  --lane-gap: 3px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
p { margin: 0; }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }

input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="time"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 53, 87, .15);
}
textarea { resize: vertical; min-height: 60px; line-height: 1.45; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
label > input, label > select, label > textarea { font-weight: 400; color: var(--text); font-size: 14px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); border-color: #94a3b8; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: #fecaca; background: #fff5f5; }
.btn-danger:hover { background: #fee2e2; border-color: #fca5a5; }
.btn-success { color: #166534; border-color: #bbf7d0; background: #f0fdf4; }
.btn-success:hover { background: #dcfce7; }
.btn-warn { color: #92400e; border-color: #fde68a; background: #fffbeb; }
.btn-warn:hover { background: #fef3c7; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: rgba(15, 23, 42, .06); border-color: transparent; }
.btn-icon { padding: 6px 10px; font-size: 18px; line-height: 1; }
.btn-small { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-close { font-size: 22px; padding: 2px 8px; }

/* Brand */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 44px; width: auto; flex: none; }
.login-card .brand-logo { height: 72px; }
.brand h1 { font-size: 22px; }
.brand p { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* Login */
.login-view { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 32px;
  display: flex; flex-direction: column; gap: 16px;
}
.form-error { color: var(--danger); font-size: 13px; }

/* App shell */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.client-switch { display: flex; align-items: center; gap: 10px; }
.client-switch select { width: auto; min-width: 200px; padding: 6px 10px; }
.client-switch a { color: inherit; }
.portal-badge { display: inline-flex; align-items: center; gap: 8px; align-self: flex-start; margin-top: -4px; }
.admin-client-list li > span:not(.client-dot) { line-height: 1.25; }
.client-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 600;
}
.client-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.user-menu { position: relative; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--sun); color: var(--primary); font-size: 12px; font-weight: 700;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); min-width: 220px; padding: 6px; z-index: 30;
}
.menu-info { padding: 8px 10px; font-size: 12px; color: var(--text-muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-info strong { display: block; color: var(--text); font-size: 13px; }
.menu-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px;
}
.toolbar-left { display: flex; align-items: center; gap: 6px; }
.toolbar-right { margin-left: auto; }
.month-title { font-size: 20px; margin-left: 10px; min-width: 190px; }
.toolbar-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface); cursor: pointer; font-size: 12.5px; font-weight: 500; user-select: none;
}
.filter-chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.filter-chip.off { opacity: .45; }
.filter-chip:hover { background: var(--surface-2); }

/* Layout */
.layout { display: flex; gap: 16px; padding: 0 20px 20px; flex: 1; align-items: flex-start; }
.calendar { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.sidebar { width: 290px; flex: none; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 72px; }

/* Calendar grid */
.weekdays { display: grid; grid-template-columns: 40px repeat(7, minmax(0, 1fr)); background: var(--surface-2); border-bottom: 1px solid var(--border); }
.weekdays > div { padding: 8px 10px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.weekdays > div:first-child { text-align: center; padding-inline: 0; }
.week { display: grid; grid-template-columns: 40px repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--border); position: relative; min-height: 112px; }
.week:last-child { border-bottom: 0; }
.kw { display: flex; align-items: flex-start; justify-content: center; padding-top: 8px; font-size: 11px; color: var(--text-muted); background: var(--surface-2); border-right: 1px solid var(--border); }
.day {
  min-width: 0;
  border-right: 1px solid var(--border);
  padding: 6px 6px 8px;
  min-height: 112px;
  display: flex; flex-direction: column; gap: 3px;
  transition: background .12s;
  cursor: pointer;
}
.day:last-child { border-right: 0; }
.day:hover { background: #fbfcfe; }
.day.outside { background: #fafbfd; color: var(--text-muted); }
.day.outside .day-num { color: #94a3b8; }
.day.weekend { background: #fafbfd; }
.day.drop-target { background: #fbf1cf; box-shadow: inset 0 0 0 2px var(--sun); }
.day-head { display: flex; align-items: center; justify-content: space-between; height: 24px; }
.day-num { font-size: 13px; font-weight: 600; width: 24px; height: 24px; display: inline-grid; place-items: center; border-radius: 50%; }
.day.today .day-num { background: var(--sun); color: var(--primary); }
.day-add { opacity: 0; font-size: 16px; line-height: 1; color: var(--text-muted); background: transparent; border: 0; cursor: pointer; padding: 0 4px; }
.day:hover .day-add { opacity: 1; }
.bars-space { flex: none; }
.chips { display: flex; flex-direction: column; gap: 3px; }

.chip {
  display: block;
  padding: 3px 6px 4px;
  border-radius: 6px;
  font-size: 12px; line-height: 1.25;
  background: var(--chip-bg);
  border-left: 3px solid var(--chip-color);
  cursor: pointer;
  overflow: hidden;
  user-select: none;
  min-width: 0;
}
.chip:hover { filter: brightness(.96); }
.chip.dragging { opacity: .4; }
.chip-meta { display: flex; align-items: center; gap: 5px; min-height: 14px; }
.chip .chip-title {
  margin-top: 2px; font-weight: 500;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: break-word;
}
.chip .chip-time { color: var(--text-muted); font-size: 11px; }
.chip .chip-channel {
  font-size: 9.5px; font-weight: 700; letter-spacing: .02em;
  padding: 1px 4px; border-radius: 4px; background: var(--chip-color); color: var(--chip-fg, #fff);
}
.chip.published .chip-title { text-decoration: line-through; opacity: .7; }
.chip-badges { margin-left: auto; display: inline-flex; gap: 3px; color: var(--text-muted); font-size: 10.5px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--status-color, #94a3b8); box-shadow: 0 0 0 1.5px #fff; }

.bars { position: absolute; left: 40px; right: 0; top: 30px; pointer-events: none; }
.bar {
  position: absolute; height: var(--bar-h);
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px; border-radius: 6px;
  background: var(--bar-color); color: var(--bar-fg, #fff);
  font-size: 12px; font-weight: 600; line-height: 1;
  overflow: hidden; white-space: nowrap;
  pointer-events: auto; cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .15);
}
.bar:hover { filter: brightness(1.08); }
.bar .bar-title { overflow: hidden; text-overflow: ellipsis; }
.bar .status-dot { box-shadow: 0 0 0 1.5px rgba(255,255,255,.7); }
.bar.continues-left { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.continues-right { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.bar.published { opacity: .75; }

/* Sidebar cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 14px 16px; }
.card h4 { margin-bottom: 10px; }
.legend { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.legend-item { display: flex; align-items: center; gap: 8px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.legend-sub { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; }
.legend-sub .legend-item { gap: 5px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.list-item:hover { background: var(--surface-2); border-color: var(--border); }
.list-item .legend-swatch { margin-top: 3px; }
.list-item strong { display: block; font-size: 13px; font-weight: 600; }
.list-item span { font-size: 12px; color: var(--text-muted); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 11.5px; color: var(--text-muted); }
.empty { color: var(--text-muted); font-size: 13px; padding: 4px 0; }

/* Dialogs */
.dialog {
  border: 0; border-radius: 16px; padding: 0;
  width: min(560px, calc(100vw - 32px));
  box-shadow: var(--shadow-lg);
  background: var(--surface); color: var(--text);
}
.dialog-wide { width: min(1040px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
.dialog-body { display: flex; flex-direction: column; gap: 14px; padding: 20px 22px; max-height: calc(100vh - 64px); overflow: auto; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h3 { font-size: 18px; }
.dialog-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 6px; border-top: 1px solid var(--border); }
.foot-right { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.entry-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 22px; }
.entry-main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.entry-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; border-left: 1px solid var(--border); padding-left: 22px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.swatch.selected { border-color: var(--text); }
.swatch.auto { background: repeating-linear-gradient(45deg, #e2e8f0 0 4px, #fff 4px 8px); position: relative; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.upload-label { cursor: pointer; }
.dropzone { border: 1.5px dashed var(--border-strong); border-radius: 10px; padding: 10px; min-height: 70px; transition: background .12s, border-color .12s; }
.dropzone.over { background: #fbf1cf; border-color: var(--sun); }
.dropzone-hint { font-size: 12px; color: var(--text-muted); text-align: center; padding: 6px; }
.attachment-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.attachment-list:empty { display: none; }
.attachment { position: relative; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.attachment a { display: block; color: inherit; text-decoration: none; }
.attachment img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.attachment .file-icon { display: grid; place-items: center; aspect-ratio: 1; font-size: 11px; font-weight: 700; color: var(--text-muted); background: #e2e8f0; text-transform: uppercase; }
.attachment .att-name { font-size: 11px; padding: 5px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .att-del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(15,23,42,.65); color: #fff; cursor: pointer; font-size: 14px; line-height: 1; display: none; }
.attachment:hover .att-del { display: block; }
.disabled-note { font-size: 12px; color: var(--text-muted); padding: 8px; background: var(--surface-2); border-radius: 8px; }

.comments { display: flex; flex-direction: column; gap: 10px; }
.comment-list { display: flex; flex-direction: column; gap: 8px; max-height: 360px; overflow: auto; }
.comment { padding: 8px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; position: relative; }
.comment.mine { background: #fbf1cf; border-color: #f2e3a8; }
.comment-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 12px; color: var(--text-muted); }
.comment-head strong { color: var(--text); }
.comment-role { font-size: 10px; padding: 1px 5px; border-radius: 4px; background: #e2e8f0; text-transform: uppercase; letter-spacing: .04em; }
.comment-role.admin { background: var(--sun); color: var(--primary); }
.comment-body { white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.comment-del { position: absolute; top: 6px; right: 8px; border: 0; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 13px; opacity: 0; }
.comment:hover .comment-del { opacity: 1; }
.comment-compose { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.comment-compose textarea { width: 100%; }
.meta { font-size: 11.5px; color: var(--text-muted); line-height: 1.5; }

/* Admin */
.admin-grid { display: grid; grid-template-columns: 300px 1fr; gap: 22px; }
.admin-clients { display: flex; flex-direction: column; gap: 12px; }
.admin-client-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow: auto; }
.admin-client-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.admin-client-list li:hover { background: var(--surface-2); }
.admin-client-list li.active { background: #fbf1cf; border-color: #f2e3a8; }
.admin-client-list li span.count { margin-left: auto; font-size: 11px; color: var(--text-muted); }
.admin-detail { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.admin-detail h5, .admin-clients h5 { font-size: 13px; }
.user-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.user-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.user-table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.user-table td:last-child { text-align: right; white-space: nowrap; }
.admin-box { padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }

/* Übersicht & Aufgaben */
.chip-client { display: flex; align-items: center; gap: 4px; margin-top: 3px; font-size: 10.5px; color: var(--text-muted); }
.chip-client .client-dot { width: 7px; height: 7px; }
.bar-client { opacity: .85; font-weight: 500; }
.client-dot-all { background: conic-gradient(var(--primary), var(--sun), var(--sage), var(--primary)) !important; }
.count-pill { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; background: var(--sun); color: var(--primary); font-size: 11px; text-align: center; margin-left: 6px; letter-spacing: 0; }
.todo-group { margin-bottom: 8px; }
.todo-kind { font-size: 11.5px; font-weight: 600; color: var(--text-muted); margin: 6px 0 2px; }
.mcp-url { display: flex; gap: 6px; }
.mcp-url input { font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Wochenansicht & Checkliste */
.view-switch { display: inline-flex; margin-left: 10px; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.view-switch button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; font-weight: 500; font-size: 13px; }
.view-switch button + button { border-left: 1px solid var(--border-strong); }
.view-switch button.active { background: var(--primary); color: #fff; }
.calendar.week-view .day { min-height: 420px; }
.calendar.week-view .week { min-height: 420px; }
.calendar.week-view .chip { font-size: 12.5px; }
.calendar.week-view .chip-title { -webkit-line-clamp: 4; }
.todo-item { display: flex; flex-direction: row; align-items: flex-start; gap: 8px; padding: 6px 6px; border-radius: 8px; cursor: pointer; font-weight: 400; color: var(--text); }
.todo-item:hover { background: var(--surface-2); }
.todo-item input { margin: 3px 0 0; accent-color: var(--primary); flex: none; cursor: pointer; }
.todo-item .swatch-sm { margin-top: 4px; }
.todo-text { display: block; min-width: 0; }
.todo-text strong { display: block; font-size: 13px; font-weight: 600; }
.todo-text span { font-size: 12px; color: var(--text-muted); }
.todo-item.done .todo-text strong { text-decoration: line-through; opacity: .6; }
.todo-done { margin-top: 6px; }
.todo-done summary { cursor: pointer; font-size: 12px; color: var(--text-muted); font-weight: 600; }
@media (max-width: 820px) { .calendar.week-view .day { min-height: 200px; } .calendar.week-view .week { min-height: 200px; } }

/* Toasts */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 13px; box-shadow: var(--shadow-lg); animation: toast-in .2s ease-out; max-width: 360px; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Responsive */
@media (max-width: 1100px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; position: static; flex-direction: row; flex-wrap: wrap; }
  .sidebar .card { flex: 1 1 260px; }
}
@media (max-width: 820px) {
  .entry-grid, .admin-grid { grid-template-columns: 1fr; }
  .entry-side { border-left: 0; padding-left: 0; border-top: 1px solid var(--border); padding-top: 16px; }
  .topbar { flex-wrap: wrap; }
  .client-switch { order: 3; width: 100%; }
  .month-title { font-size: 17px; min-width: 0; }
  .week, .weekdays { grid-template-columns: 28px repeat(7, minmax(0, 1fr)); }
  .bars { left: 28px; }
  .day { padding: 4px; min-height: 90px; }
  .chip .chip-channel, .chip .chip-time { display: none; }
  .row { flex-direction: column; }
}

@media print {
  .topbar, .toolbar-right, .toolbar-filters, .sidebar, .day-add, .toasts { display: none !important; }
  .layout { padding: 0; }
  .calendar { border: 0; box-shadow: none; }
  body { background: #fff; }
}
