:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f0f1f7;
  --line: #e3e5ee;
  --text: #121826;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #f59e0b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(17, 24, 39, .12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1018;
    --surface: #151b26;
    --surface-2: #1c2431;
    --line: #273042;
    --text: #e8ebf2;
    --muted: #9aa3b5;
    --accent: #818cf8;
    --accent-soft: #232a4a;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0; font-size: 14px; }
.spacer { flex: 1; }

/* ---------- Splash ---------- */
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 100; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons & Inputs ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger.filled { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 12px; font-size: 26px; line-height: 1;
  display: grid; place-items: center; color: var(--text);
}
.icon-btn:active, .chip-btn:active, .title-btn:active { background: var(--surface-2); }
.chip-btn { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; }
label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 12px 0 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { min-height: 110px; resize: vertical; }
input[type="color"] { padding: 4px; height: 44px; width: 64px; }
input[type="checkbox"] { width: auto; display: inline; margin: 0; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; padding-top: calc(24px + var(--safe-top)); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); padding: 28px 22px; border-radius: 22px; box-shadow: var(--shadow); }
.login-card h1 { margin: 8px 0 0; font-size: 24px; }
.login-card .btn { margin-top: 16px; padding: 13px; }
.login-logo { width: 56px; height: 56px; }

/* ---------- Topbar ---------- */
.app { min-height: 100%; padding-bottom: calc(90px + var(--safe-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: calc(6px + var(--safe-top)) 8px 6px; border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; gap: 4px; }
.topbar-row.second { gap: 10px; padding: 4px 4px 2px; }
.title-btn { border: 0; background: transparent; font-size: 19px; font-weight: 700; padding: 6px 8px; border-radius: 10px; display: flex; align-items: center; gap: 8px; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; transition: background .3s; }
.live.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.live.wait { background: var(--warn); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; flex: none; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.legend { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.legend::-webkit-scrollbar { display: none; }
.legend button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 10px 4px 8px;
  font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.legend button.off { opacity: .4; text-decoration: line-through; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- Monatsansicht ---------- */
.view { max-width: 900px; margin: 0 auto; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); padding: 8px 4px 4px; font-size: 12px; color: var(--muted); font-weight: 600; text-align: center; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; padding: 0 4px; touch-action: pan-y; }
.cell {
  min-height: 74px; background: var(--surface); border-radius: 8px; padding: 3px 2px 2px; border: 0; text-align: left;
  display: flex; flex-direction: column; gap: 2px; overflow: hidden; position: relative;
}
.cell.other { opacity: .45; }
.cell.weekend { background: color-mix(in srgb, var(--surface) 85%, var(--surface-2)); }
.cell.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell .num { font-size: 13px; font-weight: 600; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; margin: 0 auto 1px; }
.cell.today .num { background: var(--accent); color: #fff; }
.bar {
  font-size: 10.5px; line-height: 15px; height: 15px; border-radius: 4px; padding: 0 3px; color: #fff; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; font-weight: 600;
}
.bar.timed { background: transparent !important; color: var(--text); padding-left: 2px; display: flex; align-items: center; gap: 3px; }
.bar.timed::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); flex: none; }
.more { font-size: 10px; color: var(--muted); padding-left: 3px; font-weight: 600; }
@media (min-width: 700px) { .cell { min-height: 110px; padding: 4px; } .bar { font-size: 12px; line-height: 18px; height: 18px; } }

.day-panel { padding: 14px 12px 0; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 4px 8px; }
.day-head h2 { font-size: 17px; margin: 0; }
.empty { text-align: center; padding: 22px 12px; color: var(--muted); background: var(--surface); border-radius: var(--radius); border: 1px dashed var(--line); }

/* ---------- Terminkarten ---------- */
.card {
  display: flex; gap: 12px; width: 100%; text-align: left; border: 0; background: var(--surface); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05); align-items: stretch;
}
.card .stripe { width: 5px; border-radius: 4px; flex: none; background: var(--c); }
.card .time { width: 52px; flex: none; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card .time small { display: block; font-weight: 500; color: var(--muted); }
.card .main { flex: 1; min-width: 0; }
.card .ttl { font-weight: 700; overflow-wrap: anywhere; }
.card .sub { font-size: 13px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.badges { display: inline-flex; gap: 4px; margin-left: 4px; font-size: 12px; opacity: .8; }

.agenda { padding: 10px 12px; }
.agenda-day { margin: 14px 4px 6px; font-weight: 700; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.agenda-day .muted { font-weight: 500; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(20px + var(--safe-bottom)); width: 58px; height: 58px; border-radius: 18px;
  border: 0; background: var(--accent); color: #fff; font-size: 32px; line-height: 1; box-shadow: var(--shadow); z-index: 20;
}
.fab:active { transform: scale(.96); }

/* ---------- Sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(10, 12, 20, .45); z-index: 40; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--surface); border-radius: 22px 22px 0 0;
  max-height: calc(100% - 28px - var(--safe-top)); display: flex; flex-direction: column; box-shadow: var(--shadow);
  animation: up .25s cubic-bezier(.2, .9, .3, 1); max-width: 640px; margin: 0 auto;
}
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet-body { overflow-y: auto; padding: 8px 18px calc(22px + var(--safe-bottom)); -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(40%); opacity: .3; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
.sheet-top { display: flex; align-items: center; gap: 8px; position: sticky; top: -8px; background: var(--surface); padding: 8px 0; z-index: 2; }
.sheet-top h2 { flex: 1; margin: 0; font-size: 18px; }
.sheet-top .btn { padding: 8px 14px; }

.who { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.who button {
  border: 2px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px;
}
.who button.active { border-color: var(--c); background: color-mix(in srgb, var(--c) 14%, var(--surface)); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0 2px; font-weight: 600; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chips button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 6px 11px; font-size: 13px; font-weight: 600; }
.chips button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.banner { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent); padding: 10px 12px; border-radius: 12px; margin: 8px 0; font-size: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.form-actions .btn { flex: 1; padding: 13px; }

/* Termin-Details */
.detail-title { font-size: 22px; font-weight: 800; margin: 4px 0 6px; overflow-wrap: anywhere; }
.owner-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-weight: 600; font-size: 13px; background: color-mix(in srgb, var(--c) 15%, var(--surface)); color: var(--text); }
.dl { margin: 14px 0; display: grid; gap: 12px; }
.dl > div { display: flex; gap: 12px; align-items: flex-start; }
.dl .ic { width: 22px; text-align: center; flex: none; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); padding: 12px; border-radius: 12px; }
.notes a, .dl a { color: var(--accent); }
.meta { font-size: 12px; color: var(--muted); margin-top: 14px; }

/* Einstellungen */
.section { margin-top: 22px; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.box { background: var(--surface-2); border-radius: var(--radius); padding: 12px 14px; }
.box + .box { margin-top: 8px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.swatches button { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; }
.swatches button.active { border-color: var(--text); }
.qr { background: #fff; padding: 8px; border-radius: 12px; width: 200px; height: 200px; display: block; margin: 10px auto; }
code.secret { display: block; word-break: break-all; background: var(--surface); padding: 8px; border-radius: 8px; font-size: 13px; user-select: all; }

/* ---------- Modal & Toast ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(10, 12, 20, .5); padding: 20px; animation: fade .15s; }
.modal-card { background: var(--surface); border-radius: 20px; padding: 20px; width: 100%; max-width: 360px; box-shadow: var(--shadow); }
.modal-card h3 { margin: 0 0 6px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.modal-actions .btn { padding: 12px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + var(--safe-bottom)); z-index: 70;
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow);
  max-width: calc(100% - 32px); animation: fade .2s;
}
