:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --border: #e2e4e9;
  --text: #17181c;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  --header-h: 56px;
  --sidebar-w: 264px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101114; --surface: #17181c; --surface-2: #1e2026; --border: #2b2e36;
    --text: #e8e9ec; --muted: #9aa1ad; --primary-soft: #1e3a8a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.hidden { display: none !important; }

/* ---------------- Buttons & Felder ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); cursor: pointer; font-size: 14px; font-weight: 500;
  min-height: 40px; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: #fee2e2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.icon { padding: 0; width: 40px; min-height: 40px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=time], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 9px; cursor: pointer; padding: 6px 0; font-size: 14px; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex: none; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--danger); font-size: 14px; margin: 8px 0; min-height: 1em; }

/* ---------------- Anmeldung ---------------- */
#login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 20px;
  background: var(--bg); z-index: 100;
}
#login .card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
#login h1 { font-size: 21px; margin: 0 0 4px; }
#login p.sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }

/* ---------------- Grundgeruest ---------------- */
#app { display: flex; flex-direction: column; height: 100dvh; }
header.top {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border); height: var(--header-h); flex: none;
}
header.top h2 { font-size: 17px; margin: 0; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: none; background: transparent; padding: 6px 12px; border-radius: 8px;
  cursor: pointer; font-size: 13px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.body { display: flex; flex: 1; min-height: 0; }
aside {
  width: var(--sidebar-w); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 14px;
}
aside h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 18px 0 8px; }
aside h3:first-child { margin-top: 0; }
main { flex: 1; min-width: 0; overflow: auto; position: relative; }

/* ---------------- Mini-Monat ---------------- */
.mini { user-select: none; }
.mini-head { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.mini-head strong { flex: 1; font-size: 14px; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.mini-grid span { text-align: center; font-size: 11px; color: var(--muted); padding: 3px 0; }
.mini-grid button { border: none; background: transparent; padding: 5px 0; border-radius: 7px;
  cursor: pointer; font-size: 12.5px; }
.mini-grid button:hover { background: var(--surface-2); }
.mini-grid button.other { color: var(--muted); opacity: .55; }
.mini-grid button.today { color: var(--primary); font-weight: 700; }
.mini-grid button.sel { background: var(--primary); color: #fff; }

/* ---------------- Kategorie-/Kalenderliste ---------------- */
.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.legend-item { display: flex; align-items: center; gap: 9px; padding: 6px 4px; border-radius: 8px; cursor: pointer; }
.legend-item:hover { background: var(--surface-2); }
.legend-item .name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-item.off { opacity: .4; }

/* ---------------- Monatsansicht ---------------- */
.month { display: flex; flex-direction: column; min-height: 100%; }
.month-head { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 3; }
.month-head div { padding: 7px 6px; font-size: 12px; color: var(--muted); text-align: center; font-weight: 600; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: minmax(96px, 1fr);
  flex: 1; background: var(--border); gap: 1px; }
.day-cell { background: var(--bg); padding: 3px; overflow: hidden; display: flex; flex-direction: column; cursor: pointer; }
.day-cell.other { background: var(--surface-2); }
.day-cell.today .num { background: var(--primary); color: #fff; }
.day-cell .num { align-self: flex-start; font-size: 12.5px; padding: 2px 6px; border-radius: 999px;
  margin-bottom: 2px; font-weight: 600; }
.day-cell.other .num { color: var(--muted); font-weight: 400; }
.chip {
  display: flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 5px;
  border-radius: 6px; margin-bottom: 2px; cursor: pointer; background: var(--surface);
  border-left: 3px solid var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip:hover { filter: brightness(.96); }
.chip .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.chip .h { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; }
.chip.allday { color: #fff; border-left: none; }
.more { font-size: 11px; color: var(--muted); padding-left: 4px; cursor: pointer; }

/* ---------------- Wochen-/Tagesansicht ---------------- */
.tt { display: grid; grid-template-columns: 54px 1fr; min-height: 100%; }
.tt-times { border-right: 1px solid var(--border); }
.tt-times .slot { height: 48px; font-size: 11px; color: var(--muted); text-align: right;
  padding-right: 6px; transform: translateY(-7px); }
.tt-cols { display: grid; position: relative; }
.tt-daycol { border-right: 1px solid var(--border); position: relative; }
.tt-daycol .slot { height: 48px; border-bottom: 1px solid var(--border); }
.tt-daycol.today { background: color-mix(in srgb, var(--primary) 5%, transparent); }
.tt-header { display: grid; position: sticky; top: 0; background: var(--surface); z-index: 3;
  border-bottom: 1px solid var(--border); }
.tt-header .th { padding: 6px 4px; text-align: center; font-size: 12px; color: var(--muted); cursor: pointer; }
.tt-header .th b { display: block; font-size: 17px; color: var(--text); }
.tt-header .th.today b { color: var(--primary); }
.tt-wrap { display: grid; grid-template-columns: 54px 1fr; }
.tev {
  position: absolute; left: 2px; right: 4px; border-radius: 7px; padding: 3px 6px; overflow: hidden;
  font-size: 12px; color: #fff; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.2); z-index: 1;
}
.tev b { display: block; font-weight: 600; font-size: 12px; }
.tev small { opacity: .9; font-size: 11px; }
.allday-row { display: grid; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; z-index: 2; }
.allday-row .cell { padding: 2px; min-height: 24px; border-right: 1px solid var(--border); }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; }
.now-line::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--danger); }

/* ---------------- Liste ---------------- */
.agenda { padding: 8px 12px 100px; max-width: 760px; margin: 0 auto; }
.agenda .day { display: grid; grid-template-columns: 62px 1fr; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--border); }
.agenda .dh { text-align: right; }
.agenda .dh .d { font-size: 22px; font-weight: 600; line-height: 1.1; }
.agenda .dh .w { font-size: 12px; color: var(--muted); }
.agenda .day.today .dh .d { color: var(--primary); }
.agenda .item { display: flex; gap: 10px; align-items: flex-start; padding: 7px 8px;
  border-radius: 10px; cursor: pointer; }
.agenda .item:hover { background: var(--surface-2); }
.agenda .item .bar { width: 4px; align-self: stretch; border-radius: 3px; flex: none; min-height: 32px; }
.agenda .item .ttl { font-weight: 500; }
.agenda .empty { color: var(--muted); font-size: 14px; padding: 7px 8px; }

/* ---------------- Dialoge ---------------- */
dialog {
  border: none; border-radius: 16px; padding: 0; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); width: min(560px, calc(100vw - 24px)); max-height: 88dvh;
}
dialog::backdrop { background: rgba(0,0,0,.45); backdrop-filter: blur(2px); }
dialog .dlg-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 10px; }
dialog .dlg-head h3 { margin: 0; font-size: 17px; flex: 1; }
dialog .dlg-body { padding: 4px 18px 8px; overflow-y: auto; max-height: calc(88dvh - 132px); }
dialog .dlg-foot { display: flex; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--border);
  background: var(--surface); }
dialog .dlg-foot .spacer { flex: 1; }

.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--border); }
.tabs button { border: none; background: transparent; padding: 10px 12px; cursor: pointer;
  font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 8px 6px; border-bottom: 1px solid var(--border); }
table.list td { padding: 9px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); }
.badge.admin { background: var(--primary-soft); color: var(--primary); }

.colors { display: flex; flex-wrap: wrap; gap: 7px; }
.colors button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.colors button.on { border-color: var(--text); }

.copybox { display: flex; gap: 6px; align-items: center; }
.copybox input { font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.fab { position: fixed; right: 18px; bottom: 22px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none; font-size: 28px; line-height: 1;
  box-shadow: 0 6px 20px rgba(37,99,235,.45); cursor: pointer; z-index: 20; display: none; }

.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #17181c; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px;
  z-index: 200; box-shadow: var(--shadow); max-width: 90vw; }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; display: none; }

/* Auf dem Desktop laesst sich die Seitenleiste einklappen */
@media (min-width: 821px) {
  aside.collapsed { display: none; }
}

/* ---------------- Mobil ---------------- */
@media (max-width: 820px) {
  aside {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: var(--shadow); padding-top: 16px;
  }
  aside.open { transform: none; }
  .scrim.on { display: block; }
  .fab { display: block; }
  #btn-new { display: none; }
  .month-grid { grid-auto-rows: minmax(74px, 1fr); }
  .chip .h { display: none; }
  header.top h2 { font-size: 15px; }
  .seg button { padding: 6px 9px; font-size: 12px; }
  dialog { width: 100vw; max-width: 100vw; max-height: 92dvh; border-radius: 16px 16px 0 0;
    margin: auto auto 0; }
  .tt { grid-template-columns: 44px 1fr; }
  .tt-wrap { grid-template-columns: 44px 1fr; }
}
@media (max-width: 480px) {
  .month-grid { grid-auto-rows: minmax(64px, 1fr); }
  .chip { font-size: 11px; padding: 1px 4px; }
}
