/* Catnip – Oberfläche. Mobil zuerst, Hell/Dunkel automatisch. */
:root {
  --bg: #f7f4fc;
  --bg2: #ffffff;
  --bg3: #efe9f8;
  --fg: #22192f;
  --muted: #7a6e8a;
  --line: #e4dcef;
  --accent: #7c5cbf;
  --accent-fg: #ffffff;
  --green: #3fa56f;
  --danger: #d0443e;
  --mine: #7c5cbf;
  --mine-fg: #ffffff;
  --theirs: #ffffff;
  --theirs-fg: #22192f;
  --shadow: 0 1px 2px rgba(40, 20, 70, .08), 0 4px 14px rgba(40, 20, 70, .06);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15121c;
    --bg2: #1f1a29;
    --bg3: #2a2337;
    --fg: #eee8f7;
    --muted: #a397b4;
    --line: #342b44;
    --accent: #9d7fe0;
    --theirs: #2a2337;
    --theirs-fg: #eee8f7;
    --mine: #7c5cbf;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg);
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, textarea, select { font: inherit; color: var(--fg); }
.muted { color: var(--muted); }
.center { text-align: center; }
.small-text { font-size: 13px; }
.error { color: var(--danger); }

/* Knöpfe */
.primary, .ghost, .danger {
  border-radius: 12px; padding: 11px 16px; font-weight: 600;
}
.primary { background: var(--accent); color: var(--accent-fg); }
.ghost { background: var(--bg3); color: var(--fg); }
.danger { background: transparent; color: var(--danger); border: 1.5px solid var(--danger); }
.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.primary:active, .ghost:active, .danger:active, .icon-btn:active, .send-btn:active { transform: scale(.97); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 20px; flex: none;
}
.icon-btn:hover { background: var(--bg3); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Anmeldung */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 96px; height: 96px; }
.login h1 { margin: 8px 0 4px; font-size: 32px; }
.login form { display: grid; gap: 10px; text-align: left; margin-top: 24px; }
.login input { padding: 13px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg2); }

/* App-Rahmen */
.app { height: 100dvh; display: flex; flex-direction: column; padding-top: var(--safe-top); }
main { flex: 1; min-height: 0; position: relative; }
.view { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--green); color: #fff; padding: 8px 12px; font-weight: 600;
}
.banner button { background: rgba(255, 255, 255, .25); color: #fff; }

/* Reiter */
.tabs {
  display: flex; border-top: 1px solid var(--line); background: var(--bg2);
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 0 8px; font-size: 12px; color: var(--muted); position: relative;
}
.tab-ico { font-size: 21px; filter: grayscale(1); opacity: .7; }
.tab.active { color: var(--accent); font-weight: 600; }
.tab.active .tab-ico { filter: none; opacity: 1; }
.badge {
  position: absolute; top: 3px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; font-weight: 700;
}

/* Chat */
.chat-head, .cal-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
.chat-head { justify-content: space-between; }
.peer { display: flex; align-items: center; gap: 10px; min-width: 0; }
.peer-name { font-weight: 700; }
.peer-status { font-size: 13px; }
.peer-status.online { color: var(--green); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-size: 22px; background: var(--bg3); flex: none; border: 2px solid transparent;
}
.avatar.big { width: 64px; height: 64px; font-size: 36px; }
.messages { flex: 1; overflow-y: auto; padding: 10px 10px 4px; -webkit-overflow-scrolling: touch; }
.older { display: block; margin: 4px auto 10px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.day-sep { text-align: center; margin: 14px 0 8px; }
.day-sep span { background: var(--bg3); color: var(--muted); font-size: 12px; padding: 3px 10px; border-radius: 10px; }
.msg { display: flex; margin: 2px 0; }
.msg.mine { justify-content: flex-end; }
.bubble {
  max-width: min(78%, 520px); padding: 7px 11px 5px; border-radius: var(--radius);
  background: var(--theirs); color: var(--theirs-fg); box-shadow: var(--shadow);
  white-space: pre-wrap; overflow-wrap: anywhere; position: relative;
}
.msg.mine .bubble { background: var(--mine); color: var(--mine-fg); border-bottom-right-radius: 6px; }
.msg:not(.mine) .bubble { border-bottom-left-radius: 6px; }
.msg.cont .bubble { border-radius: var(--radius); }
.msg.gap { margin-top: 8px; }
.bubble.deleted { font-style: italic; opacity: .7; }
.bubble .meta { font-size: 11px; opacity: .75; text-align: right; margin-top: 2px; user-select: none; white-space: nowrap; }
.bubble .ticks.read { color: #a6f3c8; opacity: 1; }
.bubble img.photo {
  display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin: 2px -4px 4px; min-height: 60px; background: var(--bg3);
}
.quote {
  border-left: 3px solid currentColor; padding: 3px 8px; margin: 2px 0 5px; border-radius: 6px;
  background: rgba(127, 127, 127, .15); font-size: 14px; opacity: .9;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.quote b { display: block; font-size: 12px; }
.composer { background: var(--bg2); border-top: 1px solid var(--line); padding: 6px 8px; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1; resize: none; border: 1.5px solid var(--line); background: var(--bg); border-radius: 20px;
  padding: 9px 14px; max-height: 140px; line-height: 1.35; outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 18px; flex: none;
}
.send-btn:disabled { opacity: .45; }
.attach { cursor: pointer; }
.reply-bar {
  display: flex; align-items: center; gap: 8px; border-left: 3px solid var(--accent);
  background: var(--bg3); border-radius: 8px; padding: 4px 4px 4px 10px; margin-bottom: 6px;
}
.reply-bar-text { flex: 1; min-width: 0; font-size: 14px; }
.reply-bar-text b { display: block; font-size: 12px; color: var(--accent); }
.reply-bar-text span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg.flash .bubble { outline: 3px solid var(--green); }

/* Kalender */
.cal-head { flex-wrap: wrap; }
.cal-title { font-weight: 700; font-size: 17px; flex: 1; text-align: left; padding: 6px 4px; }
.seg { display: inline-flex; background: var(--bg3); border-radius: 10px; padding: 2px; }
.seg-btn { padding: 5px 10px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.seg-btn.active { background: var(--bg2); color: var(--fg); font-weight: 600; box-shadow: var(--shadow); }
#cal-month, #cal-list { overflow-y: auto; flex: 1; padding-bottom: 90px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; padding: 0 6px; }
.cal-weekdays { padding-top: 8px; padding-bottom: 4px; }
.cal-weekdays span { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; }
.cal-day {
  aspect-ratio: 1 / .92; border-radius: 12px; display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start; padding-top: 6px; position: relative; font-size: 15px;
}
.cal-day.out { opacity: .35; }
.cal-day.today .num { background: var(--accent); color: #fff; }
.cal-day.sel { background: var(--bg3); }
.cal-day .num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; }
.cal-day .dots { display: flex; gap: 3px; margin-top: 3px; flex-wrap: wrap; justify-content: center; max-width: 34px; }
.cal-day .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.day-title { margin: 14px 14px 6px; font-size: 16px; }
.ev-list { padding: 0 10px; }
.ev-group { margin: 14px 4px 6px; font-weight: 700; font-size: 15px; }
.ev {
  display: flex; gap: 10px; align-items: stretch; background: var(--bg2); border-radius: 14px; padding: 10px 12px;
  margin-bottom: 8px; box-shadow: var(--shadow); width: 100%; text-align: left;
}
.ev .bar { width: 4px; border-radius: 2px; background: var(--accent); flex: none; }
.ev .when { font-size: 13px; color: var(--muted); }
.ev .t { font-weight: 600; }
.ev .who { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ev-empty { color: var(--muted); padding: 6px 6px 12px; }
.fab {
  position: absolute; right: 18px; bottom: 18px; width: 56px; height: 56px; border-radius: 18px;
  background: var(--accent); color: #fff; font-size: 30px; box-shadow: 0 6px 20px rgba(80, 40, 140, .35);
}

/* Mehr */
.more { overflow-y: auto; height: 100%; padding: 12px; }
.card { background: var(--bg2); border-radius: 16px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 8px; font-size: 17px; }
.card p { margin: 0 0 10px; }
.profile-row { display: flex; align-items: center; gap: 14px; }

/* Blatt / Dialoge */
.backdrop { position: fixed; inset: 0; background: rgba(15, 8, 30, .45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--bg2);
  border-radius: 20px 20px 0 0; max-height: 92dvh; overflow-y: auto;
  padding: 8px 16px calc(16px + var(--safe-bottom)); box-shadow: 0 -8px 30px rgba(0, 0, 0, .2);
  max-width: 640px; margin: 0 auto; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 2px auto 10px; }
.sheet h3 { margin: 4px 0 12px; }
.sheet .actions { display: grid; gap: 4px; }
.sheet .actions button { text-align: left; padding: 13px 10px; border-radius: 12px; font-size: 16px; }
.sheet .actions button:hover { background: var(--bg3); }
.sheet .actions .danger-text { color: var(--danger); }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 5px; font-size: 14px; color: var(--muted); font-weight: 600; }
.form input[type=text], .form input[type=date], .form input[type=time], .form select, .form textarea {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--bg); color: var(--fg);
}
.form textarea { min-height: 70px; resize: vertical; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .switch { display: flex; align-items: center; justify-content: space-between; color: var(--fg); font-weight: 500; font-size: 16px; }
.form .switch input { width: 22px; height: 22px; accent-color: var(--accent); }
.form .hint { font-size: 13px; color: var(--muted); margin: -4px 0 0; }
.form-buttons { display: flex; gap: 8px; justify-content: space-between; margin-top: 6px; }
.form-buttons .primary { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-width: 42px; height: 42px; border-radius: 12px; background: var(--bg3); font-size: 22px; display: grid; place-items: center; border: 2px solid transparent; }
.chip.sel { border-color: var(--accent); }
.chip.color { width: 34px; min-width: 34px; height: 34px; border-radius: 50%; }

/* Bildbetrachter */
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .92); display: grid; place-items: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translateX(-50%); z-index: 60;
  background: #2b2236; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
}

@media (min-width: 720px) {
  .app { max-width: 720px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg:not(.mine) .bubble a { color: var(--accent); }
