:root {
  --bg: #f4f5f4; --panel: #ffffff; --panel2: #f9faf9; --line: #e3e6e4; --text: #18201d; --muted: #66726d;
  --accent: #0f766e; --accent-soft: #e0f2ef; --accent-text: #fff;
  --bubble-in: #ffffff; --bubble-out: #d9f6e6; --chat-bg: #ece8e1; --quote: rgba(0,0,0,.05);
  --warn: #b45309; --warn-soft: #fef3c7; --err: #b91c1c; --err-soft: #fee2e2; --ok: #15803d; --ok-soft: #dcfce7;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --r: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1412; --panel: #151d1a; --panel2: #1a2420; --line: #26322d; --text: #e6ece9; --muted: #92a19a;
    --accent: #2dd4bf; --accent-soft: #123a35; --accent-text: #04201c;
    --bubble-in: #1f2a26; --bubble-out: #11463b; --chat-bg: #0b1210; --quote: rgba(255,255,255,.06);
    --warn: #fbbf24; --warn-soft: #3a2a08; --err: #f87171; --err-soft: #3b1414; --ok: #4ade80; --ok-soft: #0f2e1b;
    --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(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--err); min-height: 1.2em; font-size: 14px; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 9px 14px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--err); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: grid; gap: 12px; text-align: center; box-shadow: var(--shadow); }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 800; }
.brand-mark.big { width: 56px; height: 56px; border-radius: 16px; font-size: 26px; margin: 0 auto 4px; }

/* Layout */
.app { display: flex; height: 100%; }
.sidebar { width: 220px; flex: none; background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 8px 16px; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--text); }
.sidebar a:hover { background: var(--panel2); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ico { width: 22px; text-align: center; }
.view { flex: 1; min-width: 0; overflow: auto; }
.page { max-width: 1100px; margin: 0 auto; padding: 24px 24px 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

@media (max-width: 760px) {
  .app { flex-direction: column-reverse; }
  .sidebar { width: 100%; flex-direction: row; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); gap: 0; }
  .brand, .sidebar a[data-nav="medien"], .sidebar a[data-nav="einstellungen"] { display: none; }
  .sidebar a { flex-direction: column; gap: 0; font-size: 11px; padding: 6px 4px; flex: 1; text-align: center; }
  .ico { font-size: 18px; }
  .page { padding: 16px 16px 32px; }
  h1 { font-size: 21px; }
}

/* Karten */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat b { display: block; font-size: 24px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.notice { border-radius: var(--r); padding: 12px 14px; margin-bottom: 14px; display: flex; gap: 10px; align-items: flex-start; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice a { font-weight: 600; text-decoration: underline; }

/* Listen */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px; color: var(--text); cursor: pointer; min-width: 0; }
.row:hover { background: var(--panel2); }
.row.active { background: var(--accent-soft); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { color: var(--muted); font-size: 12px; text-align: right; flex: none; }
.letter { position: sticky; top: 0; background: var(--bg); color: var(--accent); font-weight: 700; padding: 8px 8px 4px; font-size: 13px; z-index: 1; }
.avatar { width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; color: #fff; overflow: hidden; font-size: 15px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 96px; height: 96px; font-size: 34px; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.searchbar { position: sticky; top: 0; z-index: 2; background: var(--bg); padding-bottom: 10px; }

/* Kontakt */
.contact-head { display: flex; gap: 18px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.field { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field .lbl { width: 100px; flex: none; color: var(--muted); font-size: 13px; padding-top: 1px; }
.field .val { flex: 1; min-width: 0; word-break: break-word; white-space: pre-line; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.thumbs a, .thumbs div { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--panel2); display: block; position: relative; cursor: pointer; }
.thumbs img, .thumbs video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs .vid::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 22px; text-shadow: 0 1px 4px rgba(0,0,0,.6); }

/* Chats – zwei Spalten */
.chats { display: flex; height: 100%; }
.chatlist { width: 360px; flex: none; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.chatlist .head { padding: 16px 14px 10px; }
.chatlist .list { overflow: auto; padding: 0 6px 12px; flex: 1; }
.convo { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); min-height: 0; }
.convo-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.convo-head .main { flex: 1; min-width: 120px; }
.convo-head .title { font-weight: 700; }
.convo-head .tools { display: flex; gap: 6px; flex-wrap: wrap; }
.convo-head input[type=date] { width: auto; padding: 5px 8px; font-size: 13px; }
.back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 12px 6% 18px; display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain; }
.empty-convo { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 4px 10px; border-radius: 8px; margin: 10px 0 6px; box-shadow: var(--shadow); }
.sys { align-self: center; color: var(--muted); font-size: 12px; max-width: 80%; text-align: center; margin: 4px 0; }
.msg { max-width: min(75%, 620px); padding: 6px 9px 4px; border-radius: 10px; background: var(--bubble-in); align-self: flex-start; box-shadow: var(--shadow); position: relative; word-wrap: break-word; overflow-wrap: anywhere; margin-top: 2px; }
.msg.me { background: var(--bubble-out); align-self: flex-end; }
.msg.first { margin-top: 8px; }
.msg.hl { outline: 3px solid var(--accent); animation: pulse 1.8s ease-out 1; }
@keyframes pulse { from { outline-color: var(--accent); } to { outline-color: transparent; } }
.msg .who { font-size: 12.5px; font-weight: 700; margin-bottom: 1px; }
.msg .txt { white-space: pre-wrap; }
.msg .time { font-size: 11px; color: var(--muted); float: right; margin: 6px 0 -2px 10px; }
.msg .quote { background: var(--quote); border-left: 3px solid var(--accent); border-radius: 6px; padding: 4px 8px; font-size: 13px; margin-bottom: 4px; color: var(--muted); max-height: 4.5em; overflow: hidden; white-space: pre-wrap; }
.msg img.m, .msg video.m { display: block; max-width: 100%; max-height: 360px; border-radius: 6px; margin: 2px 0 4px; cursor: pointer; }
.msg img.sticker { max-width: 140px; max-height: 140px; }
.msg audio { width: 260px; max-width: 100%; margin: 4px 0; display: block; }
.msg .doc { display: flex; gap: 8px; align-items: center; background: var(--quote); border-radius: 8px; padding: 8px 10px; margin: 2px 0 4px; color: var(--text); }
.msg .missing { color: var(--muted); font-style: italic; font-size: 13px; }
.msg.deleted .txt { color: var(--muted); font-style: italic; }
.loadmore { align-self: center; margin: 6px 0; }

@media (max-width: 760px) {
  .chatlist { width: 100%; border-right: 0; }
  .chats.open .chatlist { display: none; }
  .chats:not(.open) .convo { display: none; }
  .back { display: inline-flex; }
  .msgs { padding: 10px 10px 16px; }
  .msg { max-width: 86%; }
}

/* Suche */
.snip { color: var(--muted); font-size: 14px; white-space: normal; }
.snip mark { background: var(--warn-soft); color: inherit; border-radius: 3px; padding: 0 2px; }

/* Medien */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; font: inherit; font-size: 14px; }
.tab.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.gallery .g { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--panel2); position: relative; cursor: pointer; }
.gallery img, .gallery video { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .vid::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 26px; text-shadow: 0 1px 4px rgba(0,0,0,.6); }

/* Tresor */
.drop { display: block; border: 2px dashed var(--line); border-radius: var(--r); padding: 18px; text-align: center; cursor: pointer; transition: .15s; }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
.howto { font-size: 14px; color: var(--muted); margin: 10px 0 0; padding-left: 18px; }
.howto li { margin: 3px 0; }
.howto code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.bar { height: 8px; background: var(--panel2); border-radius: 99px; overflow: hidden; margin: 6px 0; }
.bar > div { height: 100%; background: var(--accent); transition: width .3s; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); }
.badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.error { background: var(--err-soft); color: var(--err); }
.badge.needs_key, .badge.processing, .badge.queued, .badge.uploading { background: var(--warn-soft); color: var(--warn); }
.vault-row { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.vault-row:last-child { border-bottom: 0; }
.vault-row .main { flex: 1; min-width: 200px; }
.vault-row .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Lightbox, Toast */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50; display: grid; place-items: center; padding: 20px; }
.lb-body { max-width: 100%; max-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; color: #ddd; }
.lb-body img, .lb-body video { max-width: 94vw; max-height: 82vh; border-radius: 6px; }
.lb-body a { color: #9ee; }
.lb-close { position: absolute; top: 12px; right: 14px; background: none; border: 0; color: #fff; font-size: 26px; cursor: pointer; }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: 14px; max-width: calc(100% - 32px); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 40px; margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv span:nth-child(odd) { color: var(--muted); }
.form-row { display: grid; gap: 6px; margin-bottom: 12px; }
.form-row label { font-size: 13px; color: var(--muted); font-weight: 600; }
.inline { display: flex; gap: 8px; }
