:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --header: #202c33;
  --border: #2a3942;
  --text: #e9edef;
  --muted: #8696a0;
  --green: #005c4b;
  --green-bright: #25d366;
  --in: #202c33;
  --accent-marcus: #53bdeb;
  --accent-peter: #e0a458;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }

/* --- Login --- */
.login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-box {
  background: var(--panel); padding: 32px; border-radius: 12px; width: 320px;
  display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--border);
}
.login-box h1 { margin: 0; font-size: 20px; }
.login-box p { margin: 0; color: var(--muted); font-size: 14px; }
.login-box input, .login-box button {
  padding: 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 15px;
}
.login-box button { background: var(--green); border: none; font-weight: 600; }
.login-error { color: #f15c6d; font-size: 13px; min-height: 16px; }

/* --- Layout --- */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 360px; min-width: 300px; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sidebar-head {
  height: 60px; padding: 0 16px; background: var(--header);
  display: flex; align-items: center; justify-content: space-between;
}
.logo { font-weight: 700; }
.head-actions button {
  background: transparent; border: none; color: var(--muted); font-size: 20px;
  padding: 6px 8px; border-radius: 6px;
}
.head-actions button:hover { background: var(--panel-2); color: var(--text); }

.filters { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.filters button {
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  padding: 5px 12px; border-radius: 999px; font-size: 13px;
}
.filters button.active { background: var(--panel-2); color: var(--text); border-color: var(--green-bright); }

.label-filters { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 12px 8px; }
.label-filters:empty { display: none; }
.lchip {
  border: 1px solid var(--lc, var(--border)); color: var(--lc, var(--muted));
  background: transparent; padding: 3px 9px; border-radius: 999px; font-size: 12px;
}
.lchip.active { background: var(--lc); color: #000; font-weight: 600; }
.lchip-sm {
  display: inline-block; border: 1px solid var(--lc); color: var(--lc);
  padding: 1px 7px; border-radius: 999px; font-size: 11px; margin-right: 4px;
}
.chat-dots { display: inline-flex; gap: 3px; align-items: center; margin-left: auto; }
.ldot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.chat-labels { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 4px; }
.chat-labels .label-btn { padding: 2px 8px; }

.label-picker { padding: 8px 12px; }
.label-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
.label-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.label-new { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); }
.label-new input[type=text] { flex: 1; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.label-new input[type=color] { width: 38px; border: none; background: none; padding: 0; }

.tpl-btn { background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); width: 40px; height: 40px; border-radius: 50%; font-size: 18px; flex-shrink: 0; }
.tpl-btn:hover { color: var(--text); }
.tpl-list { overflow-y: auto; padding: 8px; max-height: 60vh; }
.tpl-row { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.tpl-main { flex: 1; min-width: 0; cursor: pointer; }
.tpl-main:hover .tpl-title { color: var(--green-bright); }
.tpl-title { font-weight: 600; }
.tpl-body { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: pre-wrap; }
.tpl-actions { display: flex; gap: 4px; flex-shrink: 0; }

.auto-list { padding: 10px 14px; }
.auto-row { padding: 12px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.auto-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.auto-ai { font-size: 10px; background: var(--panel-2); color: var(--accent-marcus); padding: 1px 6px; border-radius: 4px; }
.auto-action { color: var(--muted); font-size: 13px; padding-left: 26px; display: flex; align-items: center; gap: 6px; }
.auto-action select { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; }
.auto-note { color: var(--accent-peter); font-size: 12px; padding: 12px 0 0; }

/* --- Statistik --- */
.modal-wide .stats-body { padding: 14px 16px; overflow-y: auto; }
.modal-box.modal-wide { width: min(680px, 95vw); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.stat-tile { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; text-align: center; }
.stat-num { font-size: 26px; font-weight: 700; color: var(--text); }
.stat-lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.stat-chip { background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--muted); }
.stat-h { margin: 18px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.barchart { width: 100%; height: auto; }
.barchart .bar { fill: var(--accent-marcus); }
.barchart .bar:hover { fill: var(--green-bright); }
.barchart .axis { stroke: var(--border); stroke-width: 2; }
.barchart .bar-val { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.barchart .bar-x { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.stat-labels { display: flex; flex-direction: column; gap: 6px; }
.stat-lrow { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }

.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex; gap: 12px; padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--panel-2); }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2); font-size: 18px; position: relative;
}
.avatar .badge {
  position: absolute; bottom: -2px; right: -2px; width: 16px; height: 16px;
  border-radius: 50%; border: 2px solid var(--panel); font-size: 9px;
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: #000;
}
.chat-main { flex: 1; min-width: 0; }
.chat-row1 { display: flex; justify-content: space-between; gap: 8px; }
.chat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.chat-row2 { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; }
.chat-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-dot {
  background: var(--green-bright); color: #000; border-radius: 999px; min-width: 18px;
  height: 18px; padding: 0 5px; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.acct-tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; margin-left: 6px; }

/* --- Chat panel --- */
.chat { flex: 1; display: flex; flex-direction: column; background:
  linear-gradient(rgba(11,20,26,0.95), rgba(11,20,26,0.95)); }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.chat-empty .big { font-size: 60px; text-align: center; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  height: 60px; background: var(--header); padding: 0 18px; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; border-left: 1px solid var(--border);
}
.chat-head-main { min-width: 0; }
.chat-title { font-weight: 600; }
.chat-sub { font-size: 12px; color: var(--muted); }
.person-area { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }
.person-line { display: flex; align-items: center; gap: 6px; }
.person-mega { font-size: 11px; color: var(--muted); max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.person-mega:hover { text-decoration: underline; }
.person-mega.warn { color: var(--accent-peter); }
.msg-filed { font-size: 11px; color: var(--green-bright); margin-top: 4px; }
.person-link {
  color: var(--green-bright); text-decoration: none; font-weight: 600; font-size: 14px;
  background: rgba(37,211,102,0.1); padding: 5px 10px; border-radius: 8px;
}
.person-link:hover { text-decoration: underline; }

/* Person-Modal */
.person-search { padding: 12px 16px 4px; }
#person-input {
  width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: 15px;
}
.person-current { font-size: 13px; color: var(--muted); margin-top: 8px; display: flex; gap: 8px; align-items: center; }
.person-results { overflow-y: auto; padding: 6px 8px 12px; max-height: 52vh; }
.person-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
}
.person-row:hover { background: var(--panel-2); }
.person-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages { flex: 1; overflow-y: auto; padding: 18px 8%; display: flex; flex-direction: column; gap: 4px; }
.bubble {
  max-width: 68%; padding: 7px 10px 5px; border-radius: 8px; position: relative;
  font-size: 14px; line-height: 1.35; word-wrap: break-word; white-space: pre-wrap;
}
.bubble.in { background: var(--in); align-self: flex-start; border-top-left-radius: 0; }
.bubble.out { background: var(--green); align-self: flex-end; border-top-right-radius: 0; }
.bubble .meta { font-size: 10px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg-img { display: block; max-width: 260px; max-height: 320px; border-radius: 6px; cursor: pointer; }
.msg-cap { margin-top: 4px; }
.daysep { align-self: center; background: var(--panel-2); color: var(--muted); font-size: 12px;
  padding: 4px 12px; border-radius: 8px; margin: 8px 0; }

/* --- Composer --- */
.composer { background: var(--header); padding: 10px 16px; border-top: 1px solid var(--border); }
.ai-box {
  background: rgba(37,211,102,0.08); border: 1px solid rgba(37,211,102,0.35);
  border-radius: 10px; padding: 8px 12px; margin-bottom: 8px;
}
.ai-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--green-bright); font-weight: 600; }
.ai-actions button {
  background: transparent; border: 1px solid rgba(37,211,102,0.4); color: var(--green-bright);
  border-radius: 6px; padding: 2px 8px; font-size: 12px; margin-left: 4px;
}
.ai-text { margin-top: 6px; font-size: 14px; color: var(--text); white-space: pre-wrap; }
.ai-text.loading { color: var(--muted); font-style: italic; }
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
textarea#reply {
  flex: 1; resize: none; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 20px; padding: 11px 16px; font-size: 15px;
  max-height: 140px; font-family: inherit; line-height: 1.3;
}
.send {
  background: var(--green-bright); border: none; color: #000; width: 46px; height: 46px;
  border-radius: 50%; font-size: 18px; flex-shrink: 0;
}
.send:disabled { opacity: 0.5; cursor: default; }

/* --- Codes button + badge --- */
.codes-btn { position: relative; }
.codes-badge {
  position: absolute; top: -2px; right: -2px; background: var(--green-bright); color: #000;
  font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 999px;
  padding: 0 4px; display: flex; align-items: center; justify-content: center;
}

/* --- Modal (Codes) --- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex;
  align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  background: var(--panel); width: min(640px, 94vw); max-height: 82vh; border-radius: 12px;
  border: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; background: var(--header); font-weight: 600;
}
.modal-head-actions { display: flex; gap: 6px; }
.mini {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 4px 10px; font-size: 12px;
}
.mini.done-btn { background: var(--green); border-color: var(--green); }
.codes-list { overflow-y: auto; padding: 8px; }
.codes-empty { color: var(--muted); text-align: center; padding: 30px; }
.code-row {
  display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border);
  align-items: center;
}
.code-row.done { opacity: 0.5; }
.code-main { flex: 1; min-width: 0; }
.code-top { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.code-sender { font-weight: 600; color: var(--text); }
.code-badge { background: var(--panel-2); border-radius: 4px; padding: 0 6px; }
.code-value {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 24px; font-weight: 700;
  letter-spacing: 3px; color: var(--green-bright); margin: 2px 0;
}
.code-ctx { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }

/* --- Passwort + Admin --- */
.pw-form { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.pw-form input { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.pw-msg { font-size: 13px; min-height: 16px; }
.admin-tabs { display: flex; gap: 6px; padding: 8px 14px 0; border-bottom: 1px solid var(--border); }
.admin-tab { background: transparent; border: none; color: var(--muted); padding: 8px 12px; border-bottom: 2px solid transparent; font-size: 14px; }
.admin-tab.active { color: var(--text); border-bottom-color: var(--green-bright); }
.admin-body { padding: 12px 14px; overflow-y: auto; max-height: 66vh; }
.admin-new { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.admin-new input, .admin-new select { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; }
.admin-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.admin-row-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.admin-row-head input, .admin-row-head select { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; }
.admin-id { font-size: 11px; color: var(--muted); }
.admin-sub { margin-top: 8px; font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.admin-sub input[type=text], .admin-sub input:not([type]) { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
.acc-cb { display: inline-flex; align-items: center; gap: 4px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; cursor: pointer; }

.back-btn { display: none; background: transparent; border: none; color: var(--text);
  font-size: 30px; line-height: 1; padding: 0 8px 0 0; cursor: pointer; flex-shrink: 0; }

@media (max-width: 720px) {
  .sidebar { width: 100%; min-width: 0; border-right: none; }
  .chat { display: none; }                 /* Standard: nur die Liste */
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .chat { display: flex; }  /* Chat offen: nur der Chat */
  .back-btn { display: block; }
  .messages { padding: 14px 5%; }
  .bubble { max-width: 82%; }
  .person-mega { max-width: 150px; }
  .chat-head { padding: 0 10px; }
  .sidebar-head { padding: 0 12px; }
  .head-actions button { font-size: 18px; padding: 6px 5px; }
  .composer { padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .barchart { min-width: 480px; }
  .modal-wide .stats-body { overflow-x: auto; }
}
