:root {
  --bg: #ffffff; --bg2: #f4f4f5; --fg: #000000; --muted: #707579; --line: #e4e4e7;
  --accent: #3390ec; --accent-fg: #ffffff; --chat-bg: #dfe7d4; --bubble: #ffffff; --bubble-fg: #000000;
  --service: rgba(0,0,0,.28); --link: #2f80d0; --hl: #fff2a8; --danger: #d93a3a; --ok: #2e9e4f;
  --shadow: 0 1px 2px rgba(0,0,0,.15); --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17212b; --bg2: #0e1621; --fg: #f5f5f5; --muted: #8b98a5; --line: #2b3946;
    --accent: #5eb5f7; --accent-fg: #0e1621; --chat-bg: #0e1621; --bubble: #182533; --bubble-fg: #f5f5f5;
    --service: rgba(255,255,255,.12); --link: #6ab3f3; --hl: #5a4b1c; --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17212b; --bg2: #0e1621; --fg: #f5f5f5; --muted: #8b98a5; --line: #2b3946;
  --accent: #5eb5f7; --accent-fg: #0e1621; --chat-bg: #0e1621; --bubble: #182533; --bubble-fg: #f5f5f5;
  --service: rgba(255,255,255,.12); --link: #6ab3f3; --hl: #5a4b1c; --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--link); }
.muted { color: var(--muted); }
.center { display: flex; align-items: center; justify-content: center; min-height: 60vh; padding: 16px; text-align: center; }
[hidden] { display: none !important; }

/* Grundgerüst */
#app { height: 100%; display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--bg); border-bottom: 1px solid var(--line);
       min-height: 56px; position: sticky; top: 0; z-index: 5; }
.bar .title { flex: 1; min-width: 0; }
.bar .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .title small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center;
            justify-content: center; cursor: pointer; color: var(--muted); flex: none; }
.icon-btn:hover, .icon-btn:focus-visible { background: var(--bg2); color: var(--fg); }
.icon-btn svg { width: 22px; height: 22px; }
.btn { background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 600; }
.btn.secondary { background: var(--bg2); color: var(--fg); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=url] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.err { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 18px 16px 24px; }

/* Anmelden */
.login { max-width: 380px; margin: 10vh auto 0; padding: 0 16px; text-align: center; }
.login .logo { width: 72px; height: 72px; margin-bottom: 12px; }
.login h1 { font-size: 22px; margin: 0 0 6px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.login form { display: grid; gap: 10px; }

/* Archivliste */
.list { max-width: 720px; width: 100%; margin: 0 auto; }
.item { display: flex; gap: 12px; align-items: center; padding: 10px 16px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); }
.item:hover { background: var(--bg2); }
.avatar { width: 48px; height: 48px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center;
          font-weight: 600; flex: none; font-size: 17px; }
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.item .t { flex: 1; min-width: 0; }
.item .t b, .item .t span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .t span { color: var(--muted); font-size: 14px; }
.list-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; padding: 20px 16px; }

/* Chat */
.chat { flex: 1; overflow-y: auto; background: var(--chat-bg); padding: 8px 8px 16px; overscroll-behavior: contain; }
.chat-inner { max-width: 760px; margin: 0 auto; }
.day { text-align: center; margin: 12px 0 6px; position: sticky; top: 4px; z-index: 2; pointer-events: none; }
.day span, .service span { background: var(--service); color: #fff; border-radius: 12px; padding: 3px 10px; font-size: 13px; display: inline-block; }
.service { text-align: center; margin: 6px 0; }
.service span { max-width: 90%; }
.service img { display: block; margin: 6px auto 0; width: 96px; height: 96px; border-radius: 50%; object-fit: cover; }
.msg { display: flex; gap: 8px; align-items: flex-end; margin: 2px 0; }
.msg .avatar { visibility: hidden; }
.msg.last .avatar { visibility: visible; }
.msg.cont { margin-top: 1px; }
.bubble { background: var(--bubble); color: var(--bubble-fg); border-radius: var(--radius); padding: 6px 10px 6px; max-width: min(520px, 82%);
          box-shadow: var(--shadow); position: relative; min-width: 80px; overflow-wrap: anywhere; }
.msg.flash .bubble { animation: flash 2s ease-out; }
@keyframes flash { 0%, 40% { background: var(--hl); } 100% { background: var(--bubble); } }
.who { font-weight: 600; font-size: 14px; margin-bottom: 2px; background: none; border: 0; padding: 0; cursor: pointer; display: block; text-align: left; }
.who:hover { text-decoration: underline; }
.avatar.clickable { cursor: pointer; }
.lb-who { background: none; border: 0; color: inherit; text-align: left; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.lb-who:hover { background: rgba(255,255,255,.12); }
.lb-body { overflow: hidden; }
.lb-body img { transition: transform .15s ease-out; transform-origin: center center; cursor: zoom-in; user-select: none; -webkit-user-select: none; }
.lb-body.zoomed img { cursor: grab; transition: none; }
.lb-body.zoomed img.grabbing { cursor: grabbing; }
.lb-body.zoomed .lb-nav { display: none; }
.msg.cont .who { display: none; }
.fwd { font-size: 13px; color: var(--link); margin-bottom: 3px; }
.text { white-space: pre-wrap; }
.meta { float: right; font-size: 12px; color: var(--muted); margin: 6px 0 -4px 10px; white-space: nowrap; }
.reply { border-left: 3px solid var(--accent); padding: 2px 8px; margin: 2px 0 6px; border-radius: 4px; background: var(--bg2);
         cursor: pointer; display: flex; gap: 8px; align-items: center; font-size: 13px; max-width: 100%; }
.reply img { width: 34px; height: 34px; object-fit: cover; border-radius: 4px; }
.reply b { color: var(--accent); display: block; }
.reply span { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }
.media { margin: 2px -6px 4px; }
.media img, .media video { display: block; max-width: 100%; height: auto; max-height: 420px; object-fit: cover; border-radius: 8px; cursor: zoom-in; background: var(--bg2); }
.media video.round { width: 220px; height: 220px; border-radius: 50%; object-fit: cover; cursor: pointer; }
.media .sticker { max-width: 180px; max-height: 180px; background: none; cursor: default; }
.media.gif { position: relative; display: inline-block; }
.badge { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 1px 6px; border-radius: 6px; pointer-events: none; }
.file { display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; padding: 4px 0; }
.file .ico { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); display: flex;
             align-items: center; justify-content: center; flex: none; overflow: hidden; }
.file .ico img { width: 100%; height: 100%; object-fit: cover; }
.file .ico svg { width: 22px; height: 22px; }
.file > span:last-child { min-width: 0; }
.file b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.row .file b { max-width: 100%; }
.file small { color: var(--muted); }
audio { width: 260px; max-width: 100%; height: 40px; }
.miss { font-size: 13px; color: var(--muted); font-style: italic; padding: 4px 0; }
.poll b { display: block; margin-bottom: 6px; }
.poll .opt { margin: 4px 0; font-size: 14px; }
.poll .opt .barline { height: 4px; background: var(--accent); border-radius: 2px; margin-top: 2px; }
.mention, .hashtag { color: var(--link); }
.spoiler { background: var(--muted); color: transparent; border-radius: 3px; cursor: pointer; }
.spoiler.open { background: none; color: inherit; }
code, pre { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--bg2); border-radius: 4px; padding: 0 3px; }
pre { padding: 6px; overflow-x: auto; white-space: pre-wrap; }
blockquote { margin: 4px 0; padding-left: 8px; border-left: 3px solid var(--accent); }
.loader { text-align: center; color: var(--muted); padding: 10px; font-size: 13px; }
.jump-end { position: absolute; right: 16px; bottom: 20px; width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--bg);
            box-shadow: 0 2px 6px rgba(0,0,0,.25); cursor: pointer; color: var(--muted); z-index: 6; }
.jump-end.top { bottom: 76px; }
.cal-wrap { position: relative; display: inline-flex; }
.native-date { position: absolute; right: 0; top: 100%; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.bar-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; background: none; border: 0; padding: 4px 6px; margin: -4px 0;
            text-align: left; cursor: pointer; border-radius: 10px; color: inherit; }
.bar-info:hover, .bar-info:focus-visible { background: var(--bg2); }
.cal-pop { position: fixed; z-index: 40; width: 320px; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 14px;
           box-shadow: 0 8px 28px rgba(0,0,0,.22); padding: 10px; }
.cal-head { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.cal-head select { flex: 1; min-width: 0; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.cal-head .icon-btn { width: 34px; height: 34px; }
.cal-head .icon-btn:disabled { opacity: .3; cursor: default; background: none; }
.icon-btn.flip svg { transform: scaleX(-1); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid .wd { font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-day { border: 0; background: none; height: 36px; border-radius: 50%; cursor: default; color: var(--muted); opacity: .45; font-size: 14px; }
.cal-day.has { color: var(--fg); opacity: 1; font-weight: 600; cursor: pointer; position: relative; }
.cal-day.has::after { content: ""; position: absolute; left: 50%; bottom: 4px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent); }
.cal-day.has:hover { background: var(--bg2); }
.cal-day.cur { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; }
.linkbtn { background: none; border: 0; color: var(--link); cursor: pointer; padding: 4px; font-size: 13px; white-space: nowrap; }
.cal-foot .muted { text-align: center; }
.info { max-width: 760px; margin: 0 auto; }
.info-head { text-align: center; padding: 24px 16px 10px; }
.info-head .avatar { margin: 0 auto 10px; }
.info-head h1 { font-size: 22px; margin: 0 0 4px; }
.avatar.lg { width: 96px; height: 96px; font-size: 34px; }
.info-media { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 10px 16px 16px; }
.info-chip { display: flex; flex-direction: column; align-items: center; min-width: 76px; padding: 8px 10px; border-radius: 12px; background: var(--bg2);
             text-decoration: none; color: inherit; }
.info-chip b { font-size: 17px; }
.info-chip span { font-size: 13px; color: var(--muted); }
.info-sec { padding: 12px 16px 4px; border-top: 8px solid var(--bg2); }
.info-sec p { font-size: 13px; margin: 4px 0 6px; }
.item .t span.small { font-size: 13px; }
.info-sec input { margin: 4px 0 6px; }
.facts { max-width: 520px; margin: 6px auto 0; padding: 0 16px; }
.fact { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.fact span:last-child { text-align: right; overflow-wrap: anywhere; }
.chat-wrap { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* Suche */
.searchbar { padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.searchbar form { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; }
.results { flex: 1; overflow-y: auto; }
.result { display: flex; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer; max-width: 760px; margin: 0 auto; }
.result:hover { background: var(--bg2); }
.result .t { flex: 1; min-width: 0; }
.result .top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.result .top small { color: var(--muted); white-space: nowrap; }
.result .snip { color: var(--muted); font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.result mark { background: var(--hl); color: inherit; border-radius: 2px; }
.result img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }

/* Medien */
.tabs { display: flex; gap: 2px; overflow-x: auto; background: var(--bg); border-bottom: 1px solid var(--line); padding: 0 8px; scrollbar-width: none; }
.tab { background: none; border: 0; padding: 12px 12px 10px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 600; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.tab small { font-weight: 400; }
.mediapane { flex: 1; overflow-y: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 2px; max-width: 900px; margin: 0 auto; }
.cell { position: relative; aspect-ratio: 1; background: var(--bg2); cursor: pointer; overflow: hidden; border: 0; padding: 0; }
.cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cell .dur { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 5px; border-radius: 5px; }
.month { grid-column: 1 / -1; padding: 10px 8px 4px; font-weight: 600; color: var(--muted); font-size: 14px; }
.rows { max-width: 760px; margin: 0 auto; }
.row { display: flex; gap: 12px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.row .t { flex: 1; min-width: 0; }
.row .t a.u { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .t small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .go { flex: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* Großansicht */
.lightbox { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; flex-direction: column; color: #fff; }
.lb-top { display: flex; align-items: center; gap: 6px; padding: 8px 10px; }
.lb-top .title { flex: 1; min-width: 0; }
.lb-top small { color: #aaa; display: block; }
.lb-top .icon-btn { color: #ddd; }
.lb-top .icon-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.lb-body { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; position: relative; touch-action: none; }
.lb-body img, .lb-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.12); border: 0; color: #fff; width: 44px; height: 64px;
          cursor: pointer; border-radius: 8px; }
.lb-nav.prev { left: 8px; } .lb-nav.next { right: 8px; }
.lb-cap { padding: 8px 16px 14px; text-align: center; color: #ddd; max-height: 20vh; overflow-y: auto; white-space: pre-wrap; }
.lb-actions { display: flex; gap: 8px; justify-content: center; padding: 0 16px 16px; flex-wrap: wrap; }
.lb-actions .btn.secondary { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }

/* Verwaltung */
.admin { max-width: 860px; margin: 0 auto; padding: 16px; width: 100%; }
.admin h1 { font-size: 22px; margin: 6px 0 4px; }
.admin h2 { font-size: 18px; margin: 28px 0 10px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 10px 0; background: var(--bg); }
.card .head { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.card .head b { font-size: 16px; }
.card .sub { color: var(--muted); font-size: 14px; }
.fields { display: grid; gap: 10px; margin-top: 10px; }
.fields label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline > input { flex: 1; min-width: 180px; }
.checks { display: grid; gap: 6px; }
.checks label { display: flex; gap: 8px; align-items: center; color: var(--fg); font-size: 15px; }
.progress { height: 8px; background: var(--bg2); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.progress div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.share { background: var(--bg2); border-radius: 8px; padding: 10px; font-size: 14px; white-space: pre-wrap; margin-top: 8px; overflow-wrap: anywhere; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 22px 16px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--accent); color: var(--accent); }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--bg2); color: var(--muted); }
.tag.ok { color: var(--ok); } .tag.err { color: var(--danger); }
.help { color: var(--muted); font-size: 14px; }
.help ol { padding-left: 20px; margin: 6px 0; }

@media (max-width: 520px) {
  .bubble { max-width: 88%; }
  .grid { grid-template-columns: repeat(3, 1fr); }
  .lb-nav { display: none; }
}
