:root {
  --red: #FF2800;
  --red-dark: #D40000;
  --bg: #f3f3f3;
  --panel: #ffffff;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --border: #e3e3e3;
  --chat-bg: #fbeceb;
  --bubble-me: #ffd9d3;
  --bubble-other: #ffffff;
  --input-bg: #ffffff;
  --hover: #f6f6f6;
  --active: #fde8e5;
  --shadow: 0 2px 12px rgba(0, 0, 0, .18);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --red-dark: #FF6a52;
    --bg: #111111; --panel: #1b1b1b; --text: #ececec; --muted: #9a9a9a; --border: #2c2c2c;
    --chat-bg: #181212; --bubble-me: #6b1a10; --bubble-other: #2a2a2a; --input-bg: #262626;
    --hover: #242424; --active: #3a1a16; --shadow: 0 2px 12px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  --red-dark: #FF6a52;
  --bg: #111111; --panel: #1b1b1b; --text: #ececec; --muted: #9a9a9a; --border: #2c2c2c;
  --chat-bg: #181212; --bubble-me: #6b1a10; --bubble-other: #2a2a2a; --input-bg: #262626;
  --hover: #242424; --active: #3a1a16; --shadow: 0 2px 12px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
  overscroll-behavior: none;
}
#app { height: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--red-dark); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* Buttons & Formulare */
.btn {
  background: var(--red); color: #fff; border: 0; border-radius: 8px; padding: 10px 16px;
  cursor: pointer; font-weight: 600;
}
.btn:hover { filter: brightness(.94); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--red-dark); border: 1px solid var(--red); }
.btn.block { width: 100%; }
.link-btn { background: none; border: 0; color: var(--red-dark); cursor: pointer; padding: 4px 0; text-decoration: underline; }
.icon-btn {
  background: transparent; border: 0; cursor: pointer; font-size: 20px; line-height: 1;
  width: 38px; height: 38px; border-radius: 50%; color: inherit; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(127, 127, 127, .2); }
input[type=text], input[type=password], input[type=search], input[type=number], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--input-bg); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--red); box-shadow: 0 0 0 2px rgba(255, 40, 0, .18); }
label.field { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); }
label.field > input, label.field > textarea { margin-top: 4px; color: var(--text); }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.row.between { justify-content: space-between; }
.error { color: var(--red-dark); font-weight: 600; margin: 8px 0; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }

/* Auth */
.auth-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, var(--red) 0 38%, var(--bg) 38%); overflow: auto; }
.auth-card { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 420px; padding: 24px; }
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.auth-logo img { width: 44px; height: 44px; }
.auth-logo h1 { margin: 0; color: var(--red-dark); font-size: 26px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); margin: 12px 0; }
.tabs button { flex: 1; background: none; border: 0; padding: 10px; cursor: pointer; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.on { color: var(--red-dark); border-bottom-color: var(--red); }
.notice-big {
  background: #fff; color: #000; border: 2px solid #000; border-radius: 8px; padding: 12px 14px;
  font-size: 17px; font-weight: 700; line-height: 1.4; margin: 14px 0;
}
.recovery-code {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 34px; font-weight: 800; letter-spacing: 3px;
  text-align: center; padding: 16px 8px; border: 2px dashed var(--red); border-radius: 10px; color: var(--red-dark); margin: 12px 0; user-select: all;
}

/* Hauptlayout */
#main { display: flex; height: 100%; max-width: 1600px; margin: 0 auto; background: var(--panel); }
#sidebar { width: 380px; max-width: 100%; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--panel); flex-shrink: 0; }
#chatpane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); position: relative; }
.topbar {
  background: var(--red); color: #fff; display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); min-height: 56px;
}
.topbar .title { font-weight: 700; font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .team-tag, .topbar .verified { color: #fff; }
.searchbar { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.searchbar input { border-radius: 20px; }
#chatlist { flex: 1; overflow-y: auto; }
.chat-item { display: flex; gap: 12px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--border); align-items: center; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; background: var(--red); color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 19px; flex-shrink: 0; overflow: hidden;
}
.avatar.sm { width: 36px; height: 36px; font-size: 15px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-main { flex: 1; min-width: 0; }
.chat-line { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chat-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.chat-time.unread { color: var(--red-dark); font-weight: 700; }
.chat-last { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.badge { background: var(--red); color: #fff; border-radius: 12px; min-width: 22px; padding: 1px 7px; font-size: 12px; font-weight: 700; text-align: center; }
.team-tag { font-weight: 700; }
.team-owner { color: #D40000; }
.team-admin { color: #1a73e8; }
.team-mod { color: #1e8e3e; }
.verified { color: var(--red-dark); font-size: .8em; font-weight: 700; }
.empty { padding: 30px 16px; text-align: center; color: var(--muted); }
.empty-pane { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.empty-pane img { width: 90px; opacity: .85; }

/* Menü-Dropdown */
.dropdown { position: absolute; right: 8px; top: 54px; background: var(--panel); color: var(--text); border-radius: 10px; box-shadow: var(--shadow); min-width: 210px; z-index: 40; overflow: hidden; }
.dropdown button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 12px 16px; cursor: pointer; }
.dropdown button:hover { background: var(--hover); }
#sidebar { position: relative; }

/* Chat */
.chat-head { background: var(--red); color: #fff; display: flex; align-items: center; gap: 10px; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); min-height: 56px; }
.chat-head .info { flex: 1; min-width: 0; cursor: pointer; }
.chat-head .t1 { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .t2 { font-size: 12.5px; opacity: .92; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .team-tag, .chat-head .verified { color: #fff; }
.back-btn { display: none; color: #fff; }
.msgs { flex: 1; overflow-y: auto; padding: 12px 8%; display: flex; flex-direction: column; gap: 3px; }
.day-sep { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 3px 10px; border-radius: 10px; margin: 8px 0; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.msg { max-width: min(75%, 560px); padding: 6px 9px 4px; border-radius: 10px; background: var(--bubble-other); box-shadow: 0 1px 1px rgba(0, 0, 0, .14); align-self: flex-start; position: relative; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--bubble-me); }
.msg .who { font-size: 12.5px; font-weight: 700; color: var(--red-dark); margin-bottom: 1px; }
.msg .body { white-space: pre-wrap; }
.msg.deleted .body { font-style: italic; color: var(--muted); }
.msg .meta { display: flex; gap: 5px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--muted); margin-top: 1px; }
.msg .ticks.read { color: #1a73e8; }
.msg .menu-btn { position: absolute; top: 1px; right: 3px; opacity: 0; background: none; border: 0; cursor: pointer; font-size: 14px; color: var(--muted); padding: 0 4px; }
.msg:hover .menu-btn { opacity: 1; }
@media (hover: none) { .msg .menu-btn { opacity: .55; } }
.msg img.pic { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; margin-bottom: 4px; cursor: zoom-in; background: rgba(127, 127, 127, .15); min-height: 60px; }
.quote { border-left: 4px solid var(--red); background: rgba(127, 127, 127, .14); border-radius: 4px; padding: 3px 7px; margin-bottom: 4px; font-size: 13px; cursor: pointer; }
.quote .qn { font-weight: 700; color: var(--red-dark); font-size: 12px; }
.quote .qt { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.flash { animation: flash 1.2s; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--red); } 100% { box-shadow: 0 0 0 0 transparent; } }
.composer-wrap { background: var(--panel); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.composer { display: flex; gap: 6px; padding: 8px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 120px; border-radius: 20px; padding: 10px 14px; }
.composer .send { background: var(--red); color: #fff; }
.composer .send:hover { background: var(--red-dark); }
.ctx-bar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-left: 4px solid var(--red); background: var(--hover); margin: 6px 8px 0; border-radius: 6px; }
.ctx-bar .txt { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.load-more { align-self: center; }

.pin-note { background: var(--hover); border-radius: 8px; padding: 10px; font-size: 13px; margin: 8px 0; }

/* Modal & Toast */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 12px; }
.modal { background: var(--panel); color: var(--text); border-radius: 12px; width: 100%; max-width: 440px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 10px 18px; background: var(--red); color: #fff; border-radius: 12px 12px 0 0; }
.modal-body { padding: 16px; overflow-y: auto; }
.menu-list button { display: block; width: 100%; text-align: left; padding: 12px; background: none; border: 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.menu-list button:hover { background: var(--hover); }
.menu-list button.danger { color: var(--red-dark); }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 6px; align-items: center; width: max-content; max-width: 92vw; }
.toast { background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); }
.user-hit { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; }
.user-hit:hover { background: var(--hover); }

/* PIN-Sperre */
#pinlock { position: fixed; inset: 0; z-index: 500; background: var(--red); display: flex; align-items: center; justify-content: center; padding: 16px; }
#pinlock .box { background: var(--panel); border-radius: 14px; padding: 24px; width: 100%; max-width: 320px; text-align: center; }
#pinlock input { text-align: center; font-size: 26px; letter-spacing: 8px; margin: 12px 0; }

/* Mobil */
@media (max-width: 760px) {
  #sidebar { width: 100%; border-right: 0; }
  #chatpane { position: fixed; inset: 0; z-index: 20; transform: translateX(100%); transition: transform .2s; }
  body.chat-open #chatpane { transform: none; }
  .back-btn { display: inline-flex; }
  .msgs { padding: 10px 10px; }
  .msg { max-width: 86%; }
  .modal { max-height: 96vh; }
}
.dashbar { display: flex; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.dashbar .btn { flex: 1; padding: 8px 6px; font-size: 14px; }
.dashbar .btn.dark { background: #222; color: #fff; }
