/* Web-Kalender – Layout und Design */

:root {
  --bg: #ffffff;
  --bg-soft: #f4f6fb;
  --surface: #ffffff;
  --text: #1d2433;
  --muted: #5f6878;
  --line: #e3e7ef;
  --line-strong: #cfd5e1;
  --accent: #3d5afe;
  --accent-soft: #e6eaff;
  --accent-text: #ffffff;
  --today: #3d5afe;
  --now: #e53935;
  --danger: #d32f2f;
  --shadow: 0 1px 2px rgba(20, 30, 60, .08), 0 4px 16px rgba(20, 30, 60, .10);
  --radius: 12px;
  --hour: 48px;
  --sidebar: 256px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171f;
    --bg-soft: #1b1f2a;
    --surface: #1e2330;
    --text: #e7eaf1;
    --muted: #9aa3b5;
    --line: #2b3242;
    --line-strong: #3a4357;
    --accent: #8c9eff;
    --accent-soft: #283056;
    --accent-text: #10142a;
    --today: #8c9eff;
    --now: #ff6b6b;
    --danger: #ff6b6b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.noscript { padding: 2rem; text-align: center; }

/* Icons (lokale SVG-Dateien als Maske) */
.i { display: inline-block; width: 20px; height: 20px; background: currentColor; mask: center / contain no-repeat; -webkit-mask: center / contain no-repeat; flex: none; }
.i-menu { mask-image: url(icons/menu.svg); -webkit-mask-image: url(icons/menu.svg); }
.i-left { mask-image: url(icons/left.svg); -webkit-mask-image: url(icons/left.svg); }
.i-right { mask-image: url(icons/right.svg); -webkit-mask-image: url(icons/right.svg); }
.i-plus { mask-image: url(icons/plus.svg); -webkit-mask-image: url(icons/plus.svg); }
.i-close { mask-image: url(icons/close.svg); -webkit-mask-image: url(icons/close.svg); }
.i-refresh { mask-image: url(icons/refresh.svg); -webkit-mask-image: url(icons/refresh.svg); }
.i-share { mask-image: url(icons/share.svg); -webkit-mask-image: url(icons/share.svg); }
.i-back { mask-image: url(icons/back.svg); -webkit-mask-image: url(icons/back.svg); }
.i-camera { mask-image: url(icons/camera.svg); -webkit-mask-image: url(icons/camera.svg); width: 18px; height: 18px; }
.i-repeat { mask-image: url(icons/repeat.svg); -webkit-mask-image: url(icons/repeat.svg); width: 12px; height: 12px; }

.logo-mark { display: inline-block; width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, #5c7cfa, #3d5afe 55%, #2a3eb1); position: relative; }
.logo-mark::after { content: ""; position: absolute; inset: 35% 22% 22% 22%; border-radius: 4px; background: rgba(255, 255, 255, .9); }
.logo-mark.small { width: 28px; height: 28px; border-radius: 8px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 16px; border-radius: 18px; border: 1px solid transparent; background: none; font-weight: 500; white-space: nowrap; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-outline { border-color: var(--line-strong); }
.btn-outline:hover, .btn-text:hover { background: var(--bg-soft); }
.btn-text { color: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--line-strong); }
.btn-danger.confirm { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-block { width: 100%; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: none; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm .i { width: 16px; height: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Formularfelder */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; flex: 1; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { resize: vertical; }
.field.time { flex: 0 0 120px; }
.row { display: flex; gap: 10px; }
.check { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 12px; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.error { color: var(--danger); margin: 0 0 12px; }
.note { background: var(--accent-soft); padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--bg-soft); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 32px 28px; }
.login-card h1 { margin: 12px 0 4px; font-size: 24px; }
.login-card > .muted { margin: 0 0 20px; }
.login-card .small { margin: 16px 0 0; line-height: 1.4; }

/* App-Rahmen */
.app { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: 16px; font-size: 20px; }
.nav-arrows { display: flex; }
.title { font-size: 20px; font-weight: 500; margin: 0 0 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loading { color: var(--muted); font-size: 12px; }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 18px; overflow: hidden; }
.segmented button { border: 0; background: none; padding: 0 14px; height: 34px; }
.segmented button + button { border-left: 1px solid var(--line-strong); }
.segmented button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.body { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar { width: var(--sidebar); flex: none; padding: 12px 12px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.app.collapsed .sidebar { display: none; }
.view { flex: 1; min-width: 0; display: flex; flex-direction: column; border-left: 1px solid var(--line); }

.create-btn { display: inline-flex; align-items: center; gap: 12px; align-self: flex-start; height: 52px; padding: 0 22px 0 16px; border-radius: 16px; border: 0; background: var(--surface); box-shadow: var(--shadow); font-weight: 500; font-size: 15px; }
.create-btn .i { width: 24px; height: 24px; color: var(--accent); }
.create-btn:hover { background: var(--bg-soft); }

/* Mini-Monat */
.mini-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 4px 8px; font-weight: 500; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 11px; }
.mini-grid .dow { color: var(--muted); padding: 4px 0; }
.mini-grid button { border: 0; background: none; width: 28px; height: 28px; margin: 1px auto; border-radius: 50%; font-size: 11px; }
.mini-grid button:hover { background: var(--bg-soft); }
.mini-grid button.other { color: var(--muted); }
.mini-grid button.sel { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.mini-grid button.today { background: var(--today); color: var(--accent-text); font-weight: 600; }

/* Kalenderliste */
.cal-list h3 { font-size: 14px; font-weight: 500; margin: 0 0 6px 8px; }
.cal-list ul { list-style: none; margin: 0; padding: 0; }
.cal-list li label { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.cal-list li label:hover { background: var(--bg-soft); }
.cal-list input { appearance: none; -webkit-appearance: none; width: 18px; height: 18px; border-radius: 4px; border: 2px solid var(--cal); margin: 0; flex: none; display: grid; place-content: center; cursor: pointer; }
.cal-list input:checked { background: var(--cal); }
.cal-list input:checked::after { content: ""; width: 9px; height: 5px; border: solid #fff; border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.cal-list li { display: flex; align-items: center; }
.cal-list li label { flex: 1; min-width: 0; }
.cal-list .cal-text { display: flex; flex-direction: column; min-width: 0; }
.cal-list .ro { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-btn { opacity: .55; }
.cal-list li:hover .share-btn, .share-btn:focus-visible { opacity: 1; }
.cal-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-box { margin-top: auto; padding-left: 8px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.user-box p { margin: 0; }
#btn-logout2 { display: none; }

/* Monatsansicht */
.month { flex: 1; display: grid; grid-template-rows: auto 1fr; min-height: 0; }
.month-head { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); }
.month-head div { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); padding: 6px 0; text-transform: uppercase; letter-spacing: .04em; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: 1fr; min-height: 0; }
.mcell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px 4px 2px; min-width: 0; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.mcell:nth-child(7n) { border-right: 0; }
.mcell.other { background: var(--bg-soft); }
.mcell .dnum { align-self: center; border: 0; background: none; width: 26px; height: 26px; border-radius: 50%; font-size: 12px; font-weight: 500; flex: none; }
.mcell .dnum:hover { background: var(--line); }
.mcell.other .dnum { color: var(--muted); }
.mcell.today .dnum { background: var(--today); color: var(--accent-text); }
.more { border: 0; background: none; text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 1px 6px; border-radius: 4px; }
.more:hover { background: var(--line); color: var(--text); }

/* Termin-Chips */
.chip { display: flex; align-items: center; gap: 4px; border: 0; width: 100%; text-align: left; font-size: 12px; line-height: 18px; padding: 0 6px; border-radius: 4px; background: none; overflow: hidden; white-space: nowrap; flex: none; }
.chip:hover { background: var(--bg-soft); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ev); flex: none; }
.chip .t { color: var(--muted); flex: none; }
.chip .s { overflow: hidden; text-overflow: ellipsis; }
.chip.solid { background: var(--ev); color: var(--ev-fg); font-weight: 500; }
.chip.solid:hover { filter: brightness(.95); }

/* Wochen- und Tagesansicht */
.tgrid { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.tg-head, .tg-allday { display: grid; grid-template-columns: 56px repeat(var(--days), 1fr); border-bottom: 1px solid var(--line); }
.tg-head > div { text-align: center; padding: 6px 2px 4px; min-width: 0; }
.tg-head .dname { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tg-head .dnum { border: 0; background: none; width: 44px; height: 44px; border-radius: 50%; font-size: 22px; }
.tg-head .dnum:hover { background: var(--bg-soft); }
.tg-head .today .dname { color: var(--today); }
.tg-head .today .dnum { background: var(--today); color: var(--accent-text); }
.tg-allday > div { border-left: 1px solid var(--line); padding: 2px; display: flex; flex-direction: column; gap: 2px; min-width: 0; min-height: 24px; }
.tg-allday > .lbl { border-left: 0; font-size: 10px; color: var(--muted); align-items: flex-end; justify-content: center; padding-right: 6px; }
.tg-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.tg-body { display: grid; grid-template-columns: 56px repeat(var(--days), 1fr); position: relative; height: calc(var(--hour) * 24); }
.tg-hours { position: relative; }
.tg-hours span { position: absolute; right: 8px; font-size: 10px; color: var(--muted); transform: translateY(-50%); }
.tg-col { position: relative; border-left: 1px solid var(--line); background-image: linear-gradient(var(--line) 1px, transparent 1px); background-size: 100% var(--hour); cursor: pointer; min-width: 0; }
.tg-col.today { background-color: color-mix(in srgb, var(--accent-soft) 35%, transparent); }
.tev { position: absolute; border: 0; border-radius: 6px; padding: 2px 6px; text-align: left; overflow: hidden; background: var(--ev); color: var(--ev-fg); font-size: 12px; line-height: 15px; box-shadow: 0 0 0 1px var(--bg); display: flex; flex-direction: column; }
.tev:hover { filter: brightness(.95); z-index: 3; }
.tev .s { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.tev .t { opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tev.short { flex-direction: row; gap: 4px; white-space: nowrap; align-items: center; }
.rep { opacity: .85; vertical-align: -1px; }
.nowline { position: absolute; left: 0; right: 0; height: 2px; background: var(--now); z-index: 4; pointer-events: none; }
.nowline::before { content: ""; position: absolute; left: -6px; top: -5px; width: 12px; height: 12px; border-radius: 50%; background: var(--now); }

/* Dialog */
.dlg { border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(10, 15, 30, .45); }
.dlg form { padding: 16px 20px 20px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dlg-head h2 { font-size: 18px; margin: 0; font-weight: 500; }
.dlg-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.dlg #f-title { font-size: 18px; }

/* Bereichs-Umschalter */
.mode-tabs { display: inline-flex; background: var(--bg-soft); border-radius: 18px; padding: 3px; margin-right: 8px; }
.mode-tabs button { border: 0; background: none; height: 30px; padding: 0 14px; border-radius: 15px; font-weight: 500; color: var(--muted); }
.mode-tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(20, 30, 60, .15); }
.app.mode-contacts #btn-today, .app.mode-contacts .nav-arrows, .app.mode-contacts .segmented,
.app.mode-contacts #btn-menu, .app.mode-contacts .sidebar, .app.mode-contacts #view, .app.mode-contacts .fab, .app.mode-contacts .scrim { display: none !important; }

/* Teilen-Dialog */
.share-list { list-style: none; margin: 0 0 12px; padding: 0; border: 1px solid var(--line); border-radius: 10px; }
.share-list li { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; }
.share-list li + li { border-top: 1px solid var(--line); }
.share-list li.muted { padding: 10px 12px; }
.share-user { font-weight: 500; flex: 1; }

/* Kontakte */
.contacts { flex: 1; display: flex; min-height: 0; border-top: 0; }
.c-listpane { width: 340px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
.c-tools { display: flex; gap: 8px; padding: 12px 12px 4px; }
.c-tools input { flex: 1; min-width: 0; padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: 18px; background: var(--surface); }
.c-tools input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.c-tools .btn { padding: 0 14px 0 10px; }
.c-count { margin: 4px 16px 6px; }
.c-list { list-style: none; margin: 0; padding: 0 6px 16px; overflow-y: auto; flex: 1; }
.c-letter { font-size: 12px; font-weight: 600; color: var(--accent); padding: 10px 10px 4px; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.c-item { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; text-align: left; padding: 6px 10px; border-radius: 10px; }
.c-item:hover { background: var(--bg-soft); }
.c-item.sel { background: var(--accent-soft); }
.c-item-text { display: flex; flex-direction: column; min-width: 0; }
.c-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-empty { padding: 16px; }
.avatar { flex: none; border-radius: 50%; object-fit: cover; display: inline-grid; place-items: center; background: var(--av, var(--accent)); color: #fff; font-weight: 600; overflow: hidden; }
.avatar.sm { width: 36px; height: 36px; font-size: 13px; }
.avatar.lg { width: 112px; height: 112px; font-size: 38px; }
.c-detail { flex: 1; min-width: 0; overflow-y: auto; padding: 24px 32px 48px; }
.c-placeholder { height: 100%; display: grid; place-items: center; text-align: center; }
.c-head { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; position: relative; margin-bottom: 12px; }
.c-head h2 { margin: 6px 0 0; font-size: 24px; font-weight: 500; word-break: break-word; }
.c-head p { margin: 0; }
.c-back { position: absolute; left: -8px; top: -8px; display: none; }
.c-actions { display: flex; justify-content: center; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.c-body { max-width: 560px; margin: 0 auto; border: 1px solid var(--line); border-radius: 14px; padding: 6px 18px; }
.c-row { display: grid; grid-template-columns: 140px 1fr; gap: 12px; padding: 10px 0; }
.c-row + .c-row { border-top: 1px solid var(--line); }
.c-label { color: var(--muted); font-size: 13px; }
.c-row a { color: var(--accent); text-decoration: none; word-break: break-all; }
.c-row a:hover { text-decoration: underline; }
.pre { white-space: pre-wrap; word-break: break-word; }
.c-form { max-width: 620px; margin: 0 auto; }
.c-form .c-head { margin-bottom: 4px; }
.c-photo-row { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.c-photo-btns { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.c-multi { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 4px; margin: 0 0 12px; }
.c-multi legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.c-editrow { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; }
.c-editrow + .c-editrow { border-top: 1px dashed var(--line); }
.c-typecol { display: flex; flex-direction: column; gap: 6px; width: 130px; flex: none; }
.c-editrow input, .c-editrow select { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); min-width: 0; }
.c-editrow > input { flex: 1; }
.c-adr { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.c-adr-line { display: flex; gap: 6px; }
.c-adr-line .plz { flex: 0 0 90px; }
.c-editrow .icon-btn { margin-top: 4px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2b2f3a; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); }

.fab { display: none; }
.scrim { display: none; }

/* Handy / schmale Fenster */
@media (max-width: 860px) {
  .brand-text, .brand { display: none; }
  .topbar { gap: 4px; padding: 6px 6px; min-height: 56px; flex-wrap: wrap; }
  .title { font-size: 17px; margin-left: 2px; }
  #btn-today { padding: 0 12px; }
  .segmented { order: 10; width: 100%; }
  .segmented button { flex: 1; }
  #btn-logout { display: none; }
  #btn-logout2 { display: inline-flex; }
  .sidebar { position: absolute; z-index: 20; top: 0; bottom: 0; left: 0; background: var(--surface); box-shadow: var(--shadow); }
  .app:not(.drawer-open) .sidebar { display: none; }
  .app.drawer-open .scrim { display: block; position: absolute; inset: 0; z-index: 15; background: rgba(10, 15, 30, .35); }
  .app.collapsed.drawer-open .sidebar { display: flex; }
  .view { border-left: 0; }
  .create-btn { display: none; }
  .fab { display: inline-flex; align-items: center; justify-content: center; position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 16px; border: 0; background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow); z-index: 10; }
  .fab .i { width: 26px; height: 26px; }
  .tg-head, .tg-allday, .tg-body { grid-template-columns: 40px repeat(var(--days), 1fr); }
  .tg-head .dnum { width: 34px; height: 34px; font-size: 17px; }
  .tev { padding: 1px 3px; font-size: 11px; }
  .chip { font-size: 11px; padding: 0 3px; }
  .chip .t { display: none; }
  .mcell { padding: 2px 1px; }
  .row { flex-wrap: wrap; }
  .row .field { min-width: 150px; }
  .field.time { flex: 1 0 110px; }
  .mode-tabs { margin-right: 2px; padding: 2px; }
  .mode-tabs button { padding: 0 10px; height: 30px; }
  .app.mode-contacts .topbar { flex-wrap: nowrap; }
  .app.mode-contacts #btn-logout { display: inline-flex; }
  .c-listpane { width: 100%; border-right: 0; }
  .contacts.show-detail .c-listpane { display: none; }
  .contacts:not(.show-detail) .c-detail { display: none; }
  .c-detail { padding: 16px 16px 40px; }
  .c-back { display: inline-flex; }
  .c-row { grid-template-columns: 1fr; gap: 2px; }
  .c-typecol { width: 104px; }
}
