/* ───────────────────────── Farben & Grundlagen ───────────────────────── */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --border: #e4e6eb;
  --text: #16181d;
  --muted: #6b7080;
  --accent: #5b5bd6;
  --accent-hover: #4b4bc4;
  --accent-fg: #ffffff;
  --accent-soft: #ededfc;
  --danger: #dc3e42;
  --success: #2b9a66;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 20px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 60px rgba(16, 24, 40, .22);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2a2f39;
    --text: #eceef2;
    --muted: #9198a8;
    --accent: #8d8df2;
    --accent-hover: #a2a2f6;
    --accent-fg: #0e1014;
    --accent-soft: #24254a;
    --danger: #ff6369;
    --success: #3dd68c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ───────────────────────── Buttons ───────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--surface-2); font-weight: 600; font-size: 14px;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.danger-text { color: var(--danger) !important; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--border); background: transparent;
}
.icon-btn:hover { background: var(--surface-2); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ───────────────────────── Demo / Boot ───────────────────────── */
.demo-banner {
  background: #fff4d6; color: #6b4e00; text-align: center;
  padding: 8px 16px; font-size: 13px; border-bottom: 1px solid #f2dc9b;
}
@media (prefers-color-scheme: dark) {
  .demo-banner { background: #2e2511; color: #f5d68a; border-color: #4a3b17; }
}
.boot { min-height: 70vh; display: grid; place-items: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────────────────── Login ───────────────────────── */
.login {
  min-height: calc(100vh - 40px);
  display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(600px 300px at 20% 0%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    radial-gradient(500px 300px at 90% 100%, color-mix(in srgb, #e5484d 10%, transparent), transparent 70%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow); padding: 32px 28px;
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-card h1 { font-size: 28px; font-weight: 700; }
.login-card .muted { margin: -8px 0 8px; }
.login-card .field { text-align: left; }
.login-logo {
  width: 56px; height: 56px; margin: 0 auto 4px; border-radius: 16px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-fg);
}
.login-logo svg { width: 28px; height: 28px; }

/* ───────────────────────── Formulare ───────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field textarea, .cat-list input[type=text], .cat-add input[type=text], .search input {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 80px; }
.field input:focus, .field textarea:focus, .cat-list input[type=text]:focus, .cat-add input[type=text]:focus, .search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--danger); font-size: 14px; margin: 0; }
.hint { font-size: 13px; color: var(--muted); margin: 0; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius-sm); }

.cat-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-opt input { position: absolute; opacity: 0; pointer-events: none; }
.cat-opt span {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); cursor: pointer; font-weight: 500; font-size: 14px;
  transition: all .15s;
}
.cat-opt input:checked + span {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, var(--surface));
  box-shadow: inset 0 0 0 1px var(--c);
}
.cat-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex-shrink: 0; }

/* ───────────────────────── Kopfzeile ───────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; flex: 1; min-width: 0; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: var(--accent-fg); }
.role-badge {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.is-admin .role-badge { background: var(--accent-soft); color: var(--accent); }
.view-toggle { display: flex; background: var(--surface-2); padding: 3px; border-radius: 11px; gap: 2px; }
.view-toggle button {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent; height: 32px; padding: 0 12px; border-radius: 8px;
  font-weight: 600; font-size: 14px; color: var(--muted);
}
.view-toggle button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.topbar-actions { display: flex; gap: 8px; flex: 1; justify-content: flex-end; }
.admin-only { display: none !important; }
.is-admin .admin-only { display: inline-flex !important; }

/* ───────────────────────── Inhalt ───────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 20px 20px 60px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.filters { display: flex; gap: 8px; overflow-x: auto; flex: 1; padding: 2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 7px; flex-shrink: 0;
  height: 34px; padding: 0 13px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; font-weight: 500; color: var(--muted);
  transition: all .15s;
}
.filter-chip:hover { color: var(--text); }
.filter-chip.on { color: var(--text); border-color: var(--c, var(--text)); background: color-mix(in srgb, var(--c, var(--text)) 12%, var(--surface)); }
.filter-chip.all.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ───────────────────────── Kalender ───────────────────────── */
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.cal-card { overflow: hidden; }
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; gap: 12px; }
.cal-head h2 { font-size: 20px; font-weight: 700; text-transform: capitalize; }
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-weekdays { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.cal-weekdays span { padding: 8px 10px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.day {
  position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 4px;
  min-height: 112px; padding: 6px; text-align: left;
  border: 0; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: var(--surface); transition: background .12s;
  min-width: 0;
}
.day:nth-child(7n) { border-right: 0; }
.day:hover { background: var(--surface-2); }
.day.weekend { background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
.day.weekend:hover { background: var(--surface-2); }
.day.other .num { color: color-mix(in srgb, var(--muted) 55%, transparent); }
.day.other .chips { opacity: .55; }
.num {
  display: inline-grid; place-items: center; align-self: flex-start;
  min-width: 26px; height: 26px; padding: 0 4px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
}
.day.today .num { background: var(--accent); color: var(--accent-fg); }
.chips { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.chip {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px; font-weight: 500; line-height: 1.35;
  padding: 2px 6px; border-radius: 5px;
  background: color-mix(in srgb, var(--c) 15%, var(--surface));
  border-left: 3px solid var(--c);
}
.chip b { font-weight: 600; opacity: .7; }
.more { font-size: 11px; color: var(--muted); padding-left: 6px; font-weight: 500; }
.dots { display: none; }

/* Demnächst */
.upcoming { padding: 16px; position: sticky; top: 76px; }
.upcoming h3 { font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.up-item, .day-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px; border: 0; background: transparent; border-radius: var(--radius-sm);
  text-align: left;
}
.up-item:hover, .day-item:hover { background: var(--surface-2); }
.up-bar { width: 4px; align-self: stretch; border-radius: 4px; background: var(--c); flex-shrink: 0; }
.up-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.up-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-meta { font-size: 12.5px; color: var(--muted); }
.up-rel, .li-rel {
  font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap;
  padding: 3px 8px; border-radius: 999px; background: var(--surface-2);
}
.up-rel.soon, .li-rel.soon { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
.empty-small { color: var(--muted); font-size: 14px; margin: 8px 0; }

/* ───────────────────────── Liste ───────────────────────── */
.list-tools { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; }
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.month-head { font-size: 14px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 24px 4px 10px; }
.list-card { overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: 16px; width: 100%;
  padding: 14px 18px; border: 0; border-bottom: 1px solid var(--border);
  background: transparent; text-align: left; transition: background .12s;
}
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }
.list-item.past { opacity: .55; }
.li-date {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 52px; height: 56px; border-radius: 12px; flex-shrink: 0;
  background: color-mix(in srgb, var(--c) 13%, var(--surface));
  color: color-mix(in srgb, var(--c) 80%, var(--text));
}
.li-wd { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.li-day { font-size: 21px; font-weight: 700; line-height: 1.1; }
.li-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.li-title { font-weight: 600; font-size: 15.5px; }
.li-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.li-note { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 14%, var(--surface));
  color: color-mix(in srgb, var(--c) 75%, var(--text));
}
.badge.lg { font-size: 13px; padding: 4px 11px; }

.empty { text-align: center; padding: 48px 20px; margin-top: 16px; }
.empty p { margin: 4px 0; }
.empty-icon { font-size: 40px; margin-bottom: 8px; }

/* ───────────────────────── Modal ───────────────────────── */
.modal {
  width: min(520px, calc(100% - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.modal.small { width: min(400px, calc(100% - 32px)); }
.modal::backdrop { background: rgba(10, 12, 18, .45); backdrop-filter: blur(3px); }
.modal[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-body { position: relative; padding: 24px; }
.modal-body > h2 { font-size: 20px; font-weight: 700; padding-right: 40px; }
.modal-close { position: absolute; top: 16px; right: 16px; border: 0; }
.eyebrow { font-size: 12px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 4px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.day-list { margin-top: 14px; display: flex; flex-direction: column; gap: 2px; }
.chev { color: var(--muted); }

.detail-title { font-size: 22px !important; margin-top: 12px; }
.detail { margin: 18px 0 0; display: flex; flex-direction: column; gap: 12px; }
.detail div { display: grid; grid-template-columns: 70px 1fr; gap: 12px; }
.detail dt { font-size: 13px; font-weight: 600; color: var(--muted); padding-top: 1px; }
.detail dd { margin: 0; }
.detail .note { white-space: pre-wrap; }
.meta-line { font-size: 12.5px; color: var(--muted); margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--border); }
#confirm p { margin: 0; font-size: 15px; }

/* Kategorien-Verwaltung */
.cat-list { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-direction: column; gap: 8px; }
.cat-list li { display: flex; align-items: center; gap: 8px; }
.cat-list .count {
  min-width: 28px; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border-radius: 999px; padding: 2px 6px;
}
.cat-list .icon-btn { border: 0; }
input[type=color] {
  width: 42px; height: 42px; padding: 4px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: 0; border-radius: 6px; }
input[type=color]::-moz-color-swatch { border: 0; border-radius: 6px; }
.cat-add { display: flex; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border); }

/* ───────────────────────── Toasts ───────────────────────── */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; width: max-content; max-width: calc(100% - 32px); }
.toast {
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(10px); transition: all .25s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); color: #fff; }

/* ───────────────────────── Responsive ───────────────────────── */
@media (max-width: 960px) {
  .cal-layout { grid-template-columns: 1fr; }
  .upcoming { position: static; }
}

@media (max-width: 720px) {
  .topbar-inner { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .brand { order: 1; }
  .topbar-actions { order: 2; flex: 0; }
  .view-toggle { order: 3; width: 100%; }
  .view-toggle button { flex: 1; justify-content: center; }
  .hide-sm { display: none; }
  .topbar-actions .btn { width: 38px; padding: 0; }
  .container { padding: 14px 16px 90px; }
  .toolbar #btn-add {
    position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 20;
    height: 52px; padding: 0 20px; border-radius: 999px; box-shadow: var(--shadow-lg);
  }
  .cal-head { padding: 12px 12px; }
  .cal-head h2 { font-size: 17px; }
  .cal-weekdays span { padding: 6px 0; text-align: center; font-size: 11px; }
  .day { min-height: 58px; padding: 4px 2px; align-items: center; }
  .num { align-self: center; font-size: 13px; min-width: 28px; height: 28px; border-radius: 50%; }
  .chips { display: none; }
  .dots { display: flex; gap: 3px; justify-content: center; }
  .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }
  .list-item { padding: 12px 14px; gap: 12px; }
  .li-date { width: 46px; height: 50px; }
  .li-day { font-size: 18px; }
  .li-rel { display: none; }
  .search { max-width: none; }
  .form .row { grid-template-columns: 1fr; }
  .modal { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92vh; }
  .modal.small { width: calc(100% - 32px); margin: auto; border-radius: 18px; }
  .modal-body { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
  .cat-add { flex-wrap: wrap; }
  .cat-add input[type=text] { flex: 1; min-width: 0; }
  .cat-add .btn { width: 100%; }
}
