:root {
  /* Helles Design */
  --ink: #1f3a5f;
  --ink-soft: #4b5f7a;
  --paper: #f5f6f2;
  --card: #ffffff;
  --line: #e2e4dd;
  --sun: #f0a830;
  --sun-deep: #c9831a;
  --danger: #c2413a;
  --text: #1c2430;
  --muted: #6b7482;
  --due: #1f3a5f;
  --btn-bg: #1f3a5f;
  --btn-fg: #ffffff;
  --repeat-off: rgba(107, 116, 130, .45);
  --radius: 14px;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  /* Dunkles Design: dunkles Grau statt Schwarz */
  --ink: #d6dee8;
  --ink-soft: #aeb8c5;
  --paper: #202327;
  --card: #2b2f34;
  --line: #3b4047;
  --sun: #e2a74a;
  --sun-deep: #ebb865;
  --danger: #f0897f;
  --text: #e8eaed;
  --muted: #9ba3ae;
  --due: #cfd4da;
  --btn-bg: #4d6687;
  --btn-fg: #ffffff;
  --repeat-off: rgba(155, 163, 174, .4);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: inherit; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, .big-title { font-family: ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", Roboto, sans-serif; }
.muted { color: var(--muted); margin: 0; font-size: 14px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

button { font: inherit; cursor: pointer; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--sun) 60%, transparent); outline-offset: 2px;
}
label { display: block; font-size: 14px; color: var(--muted); }
label > input, label > textarea { margin-top: 4px; }

.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; background: var(--line); color: var(--text); }
.btn.primary { background: var(--btn-bg); color: var(--btn-fg); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 14px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; text-align: left; }
.login-card h1 { margin: 0; font-size: 34px; color: var(--ink); }
.login-icon { width: 64px; height: 64px; border-radius: 16px; }

/* Hauptansicht */
#main { max-width: 720px; margin: 0 auto; padding: 16px 16px 48px; }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.big-title { font-size: 36px; line-height: 1.1; margin: 8px 0 4px; color: var(--ink); letter-spacing: -0.01em; }
.icon-btn { border: 0; background: var(--card); color: var(--ink); width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 0 0 1px var(--line); }

.toolbar { display: grid; gap: 12px; margin: 18px 0 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600;
  background: var(--card); color: var(--text); box-shadow: inset 0 0 0 1px var(--line);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip .count { color: var(--muted); font-weight: 500; }
.chip[aria-selected="true"] { background: var(--btn-bg); color: var(--btn-fg); box-shadow: none; }
.chip[aria-selected="true"] .count { color: inherit; opacity: .75; }
.switch-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.switch-row input { width: auto; }

/* Liste */
.list { list-style: none; margin: 8px 0 0; padding: 0; background: var(--card); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--line); overflow: hidden; }
.list:empty { display: none; }
.row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; padding: 14px 14px 14px 12px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.check {
  width: 26px; height: 26px; margin-top: 1px; border-radius: 50%; border: 2px solid var(--muted);
  background: transparent; display: grid; place-items: center; padding: 0; color: transparent;
  transition: background .15s, border-color .15s;
}
.check svg { width: 14px; height: 14px; }
.row.done .check { background: var(--sun); border-color: var(--sun); color: #fff; }
.row-body { min-width: 0; cursor: pointer; }
.row-title { font-weight: 600; word-wrap: break-word; }
.row.done .row-title { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.row-notes { color: var(--muted); font-size: 14px; margin-top: 2px; white-space: pre-wrap; word-wrap: break-word; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.topic-tag { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
.topic-tag .dot { width: 8px; height: 8px; border-radius: 50%; }
.repeat-btn {
  border: 0; background: transparent; color: var(--repeat-off); width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; padding: 0;
}
.repeat-btn svg { width: 20px; height: 20px; }
.repeat-btn[aria-pressed="true"] { color: var(--sun-deep); background: color-mix(in srgb, var(--sun) 16%, transparent); }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }


/* Sheet */
.backdrop { position: fixed; inset: 0; background: rgba(15, 20, 28, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet {
  background: var(--paper); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(24px + env(safe-area-inset-bottom, 0px));
  animation: up .22s ease-out;
}
@media (min-width: 640px) { .backdrop { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .check { transition: none; } }
.sheet h2 { margin: 0 0 16px; font-size: 22px; color: var(--ink); font-family: ui-rounded, "SF Pro Rounded", -apple-system, sans-serif; }
.sheet form, .sheet .stack { display: grid; gap: 14px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.sheet-actions .spacer { flex: 1; }
.toggle-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--text); font-size: 16px; }
.toggle-line input { width: 22px; height: 22px; accent-color: var(--sun-deep); }
.info { font-size: 13px; color: var(--muted); margin: 0; }
.menu-list { display: grid; gap: 8px; }
.menu-list .btn { text-align: left; background: var(--card); box-shadow: inset 0 0 0 1px var(--line); }
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.user-row:first-child { border-top: 0; }
.user-row small { color: var(--muted); display: block; }
.user-actions { display: flex; gap: 4px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; margin: 0; }
legend { padding: 0 6px; color: var(--muted); font-size: 14px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--text); color: var(--paper); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20;
}
.menu-sub { margin: -10px 0 16px; }

/* Termine */
.due { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; color: var(--ink-soft); }
.due svg { width: 13px; height: 13px; }
.due.overdue { color: var(--danger); }
.time-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type="date"], input[type="time"] { min-height: 44px; -webkit-appearance: none; appearance: none; }
.cal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn.cal { display: flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); font-size: 14px; padding: 11px 8px; text-align: center; }
.btn.cal svg { width: 16px; height: 16px; flex: none; }
.schedule-actions { display: flex; justify-content: flex-start; }

/* Kopfbereich */
.top { align-items: center; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { height: 44px; width: auto; flex: none; display: block; }
.brand .big-title { font-size: 30px; margin: 0; line-height: 1.05; }
.subtitle { font-size: 15px; font-weight: 600; color: var(--ink-soft); margin-top: 2px; white-space: nowrap; }
.summary { margin-top: 10px; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.btn-new {
  border: 0; border-radius: 999px; padding: 8px 14px; background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn-new .short { display: none; }
@media (max-width: 520px) {
  .btn-new .long { display: none; }
  .btn-new .short { display: inline; }
  .brand { gap: 9px; }
  .logo { height: 38px; }
  .brand .big-title { font-size: 24px; }
  .subtitle { font-size: 13.5px; }
  .icon-btn { width: 38px; height: 38px; }
}

/* Listeneintrag: Termin prominent, Meta klein */
.due-line { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 700; color: var(--due); margin-bottom: 3px; }
.due-line svg { width: 15px; height: 15px; flex: none; }
.due-line.today { color: var(--sun-deep); }
.due-line.overdue { color: var(--danger); }
.row.done .due-line { color: var(--muted); }
.loc { display: inline-flex; align-items: center; gap: 5px; font-size: 13.5px; color: var(--ink-soft); text-decoration: none; margin-top: 4px; max-width: 100%; }
.loc span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--ink-soft) 35%, transparent); text-underline-offset: 2px; }
.loc svg { width: 14px; height: 14px; flex: none; }
.row-meta { font-size: 11.5px; margin-top: 5px; gap: 3px 10px; }
.row-meta .topic-tag .dot { width: 7px; height: 7px; }

/* Formular Termin */
.dt-row { display: grid; grid-template-columns: 52px minmax(0, 1fr) 112px; gap: 8px; align-items: center; }
.dt-label { font-size: 14px; color: var(--muted); }
.schedule-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.link-btn { display: inline-flex; align-items: center; gap: 5px; text-decoration: none; background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.link-btn svg { width: 14px; height: 14px; }

/* Design-Schalter */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .2s; pointer-events: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + .track { background: var(--btn-bg); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid color-mix(in srgb, var(--sun) 60%, transparent); outline-offset: 2px; }
.theme-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--card); border-radius: 12px; padding: 10px 14px; box-shadow: inset 0 0 0 1px var(--line); font-weight: 600; }
.theme-line small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
@media (prefers-reduced-motion: reduce) { .switch .track, .switch .track::after { transition: none; } }

/* iPhone: Datums-/Zeitfelder dürfen das Fenster nicht verbreitern */
fieldset { min-width: 0; }
.sheet { overflow-x: hidden; }
.sheet form, .sheet .stack, .sheet label { min-width: 0; }
input[type="date"], input[type="time"] {
  display: block; width: 100%; min-width: 0; max-width: 100%;
  text-align: left; line-height: 1.3;
}
input::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type="date"]::-webkit-calendar-picker-indicator, input[type="time"]::-webkit-calendar-picker-indicator { margin-left: 4px; }
.dt-row > * { min-width: 0; }
@media (max-width: 400px) {
  .dt-row { grid-template-columns: 46px minmax(0, 1.35fr) minmax(0, 1fr); gap: 6px; }
  .dt-row input { padding-left: 8px; padding-right: 8px; }
}
select {
  -webkit-appearance: none; appearance: none; min-height: 44px; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%239ba3ae' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
}
label > select { margin-top: 4px; }

/* Profilbilder */
.avatar { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; flex: none; display: inline-block; vertical-align: middle; }
.avatar.initial { display: inline-grid; place-items: center; color: #fff; font-size: 10px; font-weight: 700; }
.avatar.mid { width: 34px; height: 34px; font-size: 15px; }
.avatar.big { width: 52px; height: 52px; font-size: 22px; box-shadow: 0 0 0 2px var(--card); }
.by { display: inline-flex; align-items: center; gap: 5px; }
.row-meta .by .avatar { width: 20px; height: 20px; }
.info-by { display: flex; align-items: center; gap: 8px; }
.info-by .avatar { width: 24px; height: 24px; font-size: 11px; }
.menu-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.menu-head h2 { margin: 0; }
.user-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.menu-head { margin-bottom: 8px; }
.menu-sub { margin: 0 0 16px; }

/* Verlauf */
.history h3 { margin: 4px 0 10px; font-size: 15px; color: var(--ink-soft); font-weight: 700; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 13px; top: 8px; bottom: 8px; width: 2px; background: var(--line); border-radius: 2px; }
.h-entry { position: relative; display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; padding: 6px 0; font-size: 13.5px; color: var(--text); }
.h-entry .h-avatar { width: 28px; height: 28px; font-size: 12px; box-shadow: 0 0 0 3px var(--paper); position: relative; }
.h-entry time { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.h-entry strong { font-weight: 700; }
.h-done strong + * , .h-done span { color: var(--text); }
.h-more { padding: 4px 0 4px 38px; }

/* Kategorien verwalten */
.cat-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.cat-row { background: var(--card); border-radius: 12px; box-shadow: inset 0 0 0 1px var(--line); padding: 10px 12px; }
.cat-main { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px; }
.cat-name { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 0; padding: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.swatch.big { width: 26px; height: 26px; }
.swatch.current { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--text); }
.palette { display: grid; grid-template-columns: repeat(8, 30px); justify-content: space-between; gap: 10px 0; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
@media (max-width: 360px) { .palette { grid-template-columns: repeat(8, 26px); } .palette .swatch { width: 26px; height: 26px; } }
