/* Kindred */
:root {
  --bg: #eae6df;
  --panel: #ffffff;
  --panel-2: #f6f5f3;
  --hover: #f0efec;
  --active: #e8ebea;
  --ink: #111b21;
  --muted: #667781;
  --line: #e9edef;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #d9efe8;
  --badge: #25a37f;
  --danger: #d1394b;
  --chat-bg: #efeae2;
  --chat-dots: rgba(0, 0, 0, .035);
  --in: #ffffff;
  --out: #d6f5e7;
  --out-ink: #111b21;
  --tick: #8696a0;
  --tick-read: #2b8fd8;
  --mark: #ffe58a;
  --shadow: 0 2px 10px rgba(11, 20, 26, .12), 0 1px 2px rgba(11, 20, 26, .08);
  --radius: 10px;
  --side-w: 400px;
  color-scheme: light;
}
:root[data-theme="dark"], :root:not([data-theme="light"]) { }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1317; --panel: #111b21; --panel-2: #202c33; --hover: #202c33; --active: #2a3942;
    --ink: #e9edef; --muted: #8696a0; --line: #222d34; --accent: #3fb68f; --accent-ink: #0b1a14; --accent-soft: #163b30;
    --chat-bg: #0b141a; --chat-dots: rgba(255, 255, 255, .025); --in: #202c33; --out: #10503f; --out-ink: #e9edef;
    --tick: #8fa3ad; --tick-read: #53bdeb; --mark: #6b5a12; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1317; --panel: #111b21; --panel-2: #202c33; --hover: #202c33; --active: #2a3942;
  --ink: #e9edef; --muted: #8696a0; --line: #222d34; --accent: #3fb68f; --accent-ink: #0b1a14; --accent-soft: #163b30;
  --chat-bg: #0b141a; --chat-dots: rgba(255, 255, 255, .025); --in: #202c33; --out: #10503f; --out-ink: #e9edef;
  --tick: #8fa3ad; --tick-read: #53bdeb; --mark: #6b5a12; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--tick-read); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0; font-size: 14px; }

.icon { display: inline-flex; width: 24px; height: 24px; flex: none; }
.icon svg { width: 100%; height: 100%; fill: currentColor; }

.btn { border-radius: 24px; padding: 10px 20px; font-weight: 600; transition: filter .15s; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--panel-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.link { color: var(--accent); font-weight: 600; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); flex: none; transition: background .15s;
}
.icon-btn:hover, .icon-btn.on { background: var(--hover); }
.icon-btn.danger { color: var(--danger); }

/* ---------- Inloggning ---------- */
#auth { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; overflow: auto;
  background: linear-gradient(180deg, var(--accent) 0 220px, var(--bg) 220px); }
.auth-card { background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); padding: 32px 28px; width: min(400px, 100%); text-align: center; }
.auth-logo { width: 72px; height: 72px; border-radius: 18px; }
.auth-card h1 { margin: 12px 0 4px; font-size: 24px; }
.auth-card form { text-align: left; margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.auth-card input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); font-size: 16px; }
.auth-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
#auth:not(.register) .reg-only { display: none; }
#auth:not(.invite) .invite-only { display: none; }

/* ---------- Layout ---------- */
#app { display: flex; height: 100dvh; max-width: 1600px; margin: 0 auto; background: var(--panel); position: relative; overflow: hidden; }
@media (min-width: 1440px) { #app { height: calc(100dvh - 38px); margin-top: 19px; box-shadow: var(--shadow); } }
#sidebar { width: var(--side-w); min-width: 300px; max-width: 40%; display: flex; flex-direction: column; border-right: 1px solid var(--line); position: relative; background: var(--panel); }
#conv { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; background: var(--panel-2); }
#convView { display: flex; flex-direction: column; height: 100%; position: relative; }
.panel { width: 400px; max-width: 100%; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }

.bar { height: 60px; padding: 0 12px; display: flex; align-items: center; gap: 6px; background: var(--panel-2); flex: none;
  padding-top: env(safe-area-inset-top); box-sizing: content-box; }
#sidebar > .bar { background: var(--panel); }
.avatar-btn { border-radius: 50%; }
.avatar { border-radius: 50%; flex: none; overflow: hidden; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; background: #9aa5ab; user-select: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Sidopanel ---------- */
.prompt { margin: 0 12px 6px; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); display: flex; gap: 12px; align-items: center; font-size: 14px; }
.prompt .icon { color: var(--accent); }
.prompt b { display: block; }
.prompt .x { margin-left: auto; color: var(--muted); }
.search-wrap { padding: 4px 12px 8px; }
.search { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 10px; padding: 0 12px; height: 38px; }
.search .icon { width: 20px; height: 20px; color: var(--muted); }
.search input { flex: 1; border: 0; background: none; outline: none; min-width: 0; }
.chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.chip { padding: 6px 12px; border-radius: 16px; background: var(--panel-2); color: var(--muted); font-size: 14px; white-space: nowrap; }
.chip.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.list-label { padding: 14px 16px 6px; color: var(--accent); font-size: 14px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 13px; padding: 0 14px; min-height: 72px; cursor: pointer; position: relative; width: 100%; text-align: left; }
.row:hover { background: var(--hover); }
.row.active { background: var(--active); }
.row .body { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); align-self: stretch; display: flex; flex-direction: column; justify-content: center; gap: 2px; padding-right: 2px; }
.row:last-child .body { border-bottom: 0; }
.row .top, .row .bottom { display: flex; align-items: center; gap: 6px; min-width: 0; }
.row .name { flex: 1; font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: 12px; color: var(--muted); flex: none; }
.row.unread .time { color: var(--badge); font-weight: 600; }
.row .preview { flex: 1; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 3px; min-width: 0; }
.row .preview > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.row .preview .icon { width: 16px; height: 16px; }
.row .preview.typing { color: var(--badge); font-weight: 500; }
.row .flags { display: flex; align-items: center; gap: 4px; color: var(--muted); flex: none; }
.row .flags .icon { width: 18px; height: 18px; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--badge); color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.badge.muted-badge { background: var(--muted); }
.row .chev { position: absolute; right: 10px; bottom: 12px; opacity: 0; color: var(--muted); background: var(--hover); border-radius: 50%; }
.row:hover .chev { opacity: 1; }
@media (hover: hover) { .row:hover .flags { margin-right: 30px; } }
.row .sub { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .tag { font-size: 12px; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 1px 6px; flex: none; }
.row.check-row .checkbox { width: 22px; height: 22px; border: 2px solid var(--muted); border-radius: 5px; display: grid; place-items: center; flex: none; }
.row.check-row.checked .checkbox { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.row.check-row .checkbox .icon { width: 16px; height: 16px; visibility: hidden; }
.row.check-row.checked .checkbox .icon { visibility: visible; }
.row.action .avatar { background: var(--accent) !important; }
.row.action .name { color: var(--ink); }
.empty-list { padding: 40px 24px; text-align: center; color: var(--muted); }
.online-dot { position: absolute; left: 47px; top: 46px; width: 13px; height: 13px; border-radius: 50%; background: #25d366; border: 2px solid var(--panel); }

/* Lådor (glider in över sidopanelen) */
.drawer { position: absolute; inset: 0; background: var(--panel); z-index: 20; display: flex; flex-direction: column; animation: slideIn .2s ease-out; }
@keyframes slideIn { from { transform: translateX(-30px); opacity: 0; } }
.drawer-head { height: 108px; background: var(--accent); color: var(--accent-ink); display: flex; align-items: flex-end; gap: 20px; padding: 0 20px 18px; flex: none; padding-top: env(safe-area-inset-top); box-sizing: content-box; }
.drawer-head h2 { font-size: 19px; margin: 0; font-weight: 600; }
.drawer-head .icon-btn { color: inherit; margin-left: -8px; }
.drawer-head .icon-btn:hover { background: rgba(255, 255, 255, .15); }
.drawer-body { flex: 1; overflow-y: auto; background: var(--panel-2); }
.panel .drawer-head { height: 60px; background: var(--panel-2); color: var(--ink); align-items: center; padding-bottom: 0; }
.panel .drawer-head .icon-btn { color: var(--muted); }
.panel .drawer-head .icon-btn:hover { background: var(--hover); }
.section { background: var(--panel); padding: 14px 24px; margin-bottom: 10px; }
.section h3 { margin: 0 0 12px; color: var(--accent); font-size: 14px; font-weight: 600; }
.section.center { text-align: center; padding: 28px 24px; }
.section.center .avatar { margin: 0 auto 14px; }
.section .big-name { font-size: 22px; margin: 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.field label { font-size: 14px; color: var(--accent); }
.field .val { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.field .val span { flex: 1; overflow-wrap: anywhere; white-space: pre-wrap; }
.field input, .field textarea { flex: 1; border: 0; border-bottom: 2px solid var(--accent); background: none; padding: 6px 0; outline: none; resize: none; }
.field .hint { font-size: 13px; color: var(--muted); }
.menu-row { display: flex; align-items: center; gap: 18px; padding: 14px 24px; width: 100%; text-align: left; background: var(--panel); }
.menu-row:hover { background: var(--hover); }
.menu-row .icon { color: var(--muted); }
.menu-row .txt { flex: 1; }
.menu-row .txt small { display: block; color: var(--muted); font-size: 13px; }
.menu-row.danger, .menu-row.danger .icon { color: var(--danger); }
.toggle { width: 38px; height: 22px; border-radius: 11px; background: var(--muted); position: relative; flex: none; transition: background .15s; }
.toggle::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: transform .15s; }
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(16px); }
.avatar-edit { position: relative; display: inline-block; cursor: pointer; border-radius: 50%; }
.avatar-edit .avatar { margin: 0 auto; }
.avatar-edit .ov { position: absolute; inset: 0; border-radius: 50%; background: rgba(0, 0, 0, .45); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; opacity: 0; transition: opacity .15s; text-transform: uppercase; gap: 6px; padding: 30px; text-align: center; }
.avatar-edit:hover .ov { opacity: 1; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.media-grid .cell { aspect-ratio: 1; background: var(--panel-2); border-radius: 6px; overflow: hidden; cursor: pointer; position: relative; }
.media-grid img, .media-grid video { width: 100%; height: 100%; object-fit: cover; }
.media-grid .cell .icon { position: absolute; inset: 0; margin: auto; color: #fff; filter: drop-shadow(0 0 4px #000); }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin: -4px -24px 12px; }
.tabs button { flex: 1; padding: 10px; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600; }
.tabs button.active { color: var(--accent); border-color: var(--accent); }
.selected-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px; background: var(--panel); }
.selected-chips .sc { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border-radius: 16px; padding: 3px 4px 3px 3px; font-size: 14px; }
.selected-chips .sc .icon { width: 16px; height: 16px; color: var(--muted); }
.fab { position: absolute; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: var(--shadow); z-index: 2; }

/* ---------- Konversation ---------- */
.conv-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px; border-bottom: 6px solid var(--accent); }
.conv-empty img { width: 120px; opacity: .9; border-radius: 28px; }
.conv-empty h2 { font-weight: 300; font-size: 30px; margin: 20px 0 8px; }
.conv-empty p { max-width: 440px; }
.conv-head { border-left: 1px solid var(--line); }
.conv-head .back { display: none; }
.conv-title { flex: 1; display: flex; align-items: center; gap: 13px; min-width: 0; text-align: left; height: 100%; }
.conv-title .t { min-width: 0; }
.conv-title .n { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-title .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-title .s.typing { color: var(--badge); }

.messages {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 6% 8px; outline: none; overscroll-behavior: contain;
  background-color: var(--chat-bg);
  background-image: radial-gradient(var(--chat-dots) 1.2px, transparent 1.2px), radial-gradient(var(--chat-dots) 1.2px, transparent 1.2px);
  background-size: 22px 22px; background-position: 0 0, 11px 11px;
}
.day-sep { text-align: center; margin: 12px 0 8px; position: sticky; top: 4px; z-index: 3; pointer-events: none; }
.day-sep span { background: var(--panel); color: var(--muted); font-size: 12.5px; padding: 5px 12px; border-radius: 8px; box-shadow: 0 1px .5px rgba(11, 20, 26, .13); text-transform: uppercase; }
.unread-sep { text-align: center; margin: 10px -6%; background: color-mix(in srgb, var(--panel) 35%, transparent); padding: 4px; }
.unread-sep span { background: var(--panel); color: var(--muted); font-size: 12.5px; padding: 5px 14px; border-radius: 8px; display: inline-block; }
.sys { text-align: center; margin: 8px 0; }
.sys span { display: inline-block; background: var(--panel); color: var(--muted); font-size: 12.5px; padding: 6px 12px; border-radius: 8px; max-width: 80%; box-shadow: 0 1px .5px rgba(11, 20, 26, .13); }

.msg { display: flex; margin-top: 2px; position: relative; }
.msg.first { margin-top: 10px; }
.msg.out { justify-content: flex-end; }
.msg .av-slot { width: 36px; flex: none; margin-right: 6px; }
.msg .bubble {
  position: relative; max-width: min(65%, 560px); min-width: 80px; padding: 6px 8px 8px 9px; border-radius: 8px;
  background: var(--in); box-shadow: 0 1px .5px rgba(11, 20, 26, .13); overflow-wrap: anywhere;
}
@media (max-width: 900px) { .msg .bubble { max-width: 85%; } }
.msg.out .bubble { background: var(--out); color: var(--out-ink); }
.msg.first.in .bubble { border-top-left-radius: 0; }
.msg.first.out .bubble { border-top-right-radius: 0; }
.msg.first.in .bubble::before, .msg.first.out .bubble::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px; background: inherit;
}
.msg.first.in .bubble::before { left: -8px; clip-path: polygon(100% 0, 0 0, 100% 100%); }
.msg.first.out .bubble::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.msg .sender { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.msg .fwd { font-size: 12.5px; color: var(--muted); font-style: italic; display: flex; align-items: center; gap: 4px; margin-bottom: 2px; }
.msg .fwd .icon { width: 15px; height: 15px; }
.msg .text { white-space: pre-wrap; font-size: 14.5px; line-height: 19px; }
.msg .text.big { font-size: 42px; line-height: 1.15; }
.msg .text code { background: rgba(0, 0, 0, .06); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.msg .text mark { background: var(--mark); color: inherit; border-radius: 2px; }
.msg .meta { float: right; margin: 6px -2px -4px 10px; display: inline-flex; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); white-space: nowrap; position: relative; top: 4px; line-height: 15px; }
.msg.out .meta { color: color-mix(in srgb, var(--out-ink) 55%, transparent); }
.msg .meta .icon { width: 13px; height: 13px; }
.msg .meta .star-ico { width: 12px; height: 12px; }
.tick { display: inline-flex; width: 17px; height: 11px; color: var(--tick); }
.tick svg { width: 100%; height: 100%; fill: currentColor; }
.tick.read { color: var(--tick-read); }
.tick.sent { width: 14px; }
.tick.pending { width: 13px; height: 13px; }
.tick.failed { color: var(--danger); font-weight: 700; width: auto; }
.msg .deleted { font-style: italic; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.msg .deleted .icon { width: 16px; height: 16px; }
.msg.media-only .bubble { padding: 3px; }
.msg.media-only .meta { position: absolute; right: 8px; bottom: 7px; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .35)); padding: 0 4px; border-radius: 8px; top: auto; margin: 0; text-shadow: 0 0 2px rgba(0, 0, 0, .5); }
.msg.media-only .meta .tick:not(.read) { color: #fff; }
.media { display: block; border-radius: 6px; overflow: hidden; cursor: pointer; position: relative; background: rgba(0, 0, 0, .06); max-width: 330px; }
.media img, .media video { display: block; max-width: 100%; max-height: 360px; min-width: 120px; min-height: 80px; object-fit: cover; }
.media .play { position: absolute; inset: 0; margin: auto; width: 54px; height: 54px; border-radius: 50%; background: rgba(0, 0, 0, .5); color: #fff; display: grid; place-items: center; }
.media + .text { margin-top: 6px; padding: 0 4px; }
.progress { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .3); color: #fff; font-weight: 600; }
.file-box { display: flex; align-items: center; gap: 10px; background: rgba(0, 0, 0, .05); border-radius: 6px; padding: 10px; min-width: 240px; text-decoration: none; color: inherit; position: relative; }
.file-box .icon { width: 34px; height: 34px; color: #e56757; }
.file-box .fn { flex: 1; min-width: 0; }
.file-box .fn div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-box .fn div:last-child { font-size: 12px; color: var(--muted); }
.file-box .dl { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--muted); display: grid; place-items: center; color: var(--muted); }
.file-box .dl .icon { width: 20px; height: 20px; color: inherit; }
.file-box + .text { margin-top: 6px; }
.voice { display: flex; align-items: center; gap: 10px; min-width: 240px; padding: 4px 2px 0; }
.voice .pp { width: 34px; height: 34px; color: var(--muted); display: grid; place-items: center; }
.voice .pp .icon { width: 30px; height: 30px; }
.voice .track { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.voice input[type=range] { width: 100%; accent-color: var(--accent); height: 4px; margin: 6px 0 0; }
.voice .vt { font-size: 11px; color: var(--muted); }
.voice .spd { font-size: 12px; font-weight: 700; background: rgba(0, 0, 0, .12); color: var(--muted); border-radius: 12px; padding: 2px 7px; }
.quote {
  display: flex; gap: 8px; border-radius: 6px; background: rgba(0, 0, 0, .05); border-left: 4px solid var(--accent);
  padding: 5px 8px; margin: 0 -3px 5px; cursor: pointer; overflow: hidden; font-size: 13px; min-height: 42px; align-items: center;
}
.msg.out .quote { background: rgba(0, 0, 0, .06); }
.quote .qb { flex: 1; min-width: 0; }
.quote .qn { font-weight: 600; font-size: 12.5px; color: var(--accent); }
.quote .qt { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.quote img { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; }
.reacts { position: absolute; bottom: -18px; display: flex; gap: 2px; background: var(--panel); border-radius: 12px; padding: 2px 6px; box-shadow: 0 1px 3px rgba(0, 0, 0, .18); font-size: 14px; cursor: pointer; z-index: 2; border: 1px solid var(--line); }
.msg.in .reacts { left: 10px; }
.msg.out .reacts { right: 10px; }
.reacts .n { font-size: 12px; color: var(--muted); margin-left: 2px; align-self: center; }
.msg.has-reacts { margin-bottom: 20px; }
.msg .menu-chev { position: absolute; top: 3px; right: 3px; width: 26px; height: 22px; border-radius: 0 6px 0 12px; display: none; align-items: center; justify-content: center; color: var(--muted); z-index: 2;
  background: radial-gradient(at top right, var(--in) 60%, transparent 80%); }
.msg.out .menu-chev { background: radial-gradient(at top right, var(--out) 60%, transparent 80%); }
.msg .menu-chev .icon { width: 20px; height: 20px; }
@media (hover: hover) { .msg .bubble:hover .menu-chev { display: flex; } }
.msg .react-btn { align-self: center; margin: 0 6px; opacity: 0; color: var(--muted); width: 28px; height: 28px; border-radius: 50%; background: rgba(0, 0, 0, .1); display: grid; place-items: center; }
.msg .react-btn .icon { width: 18px; height: 18px; }
@media (hover: hover) { .msg:hover .react-btn { opacity: 1; } }
.msg.flash .bubble { animation: flash 1.6s; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 50%, transparent); } }
.msg.swiping .bubble { transition: none; }
.msg .bubble { transition: transform .2s; }
.load-more { text-align: center; padding: 8px; color: var(--muted); font-size: 13px; }

.to-bottom { position: absolute; right: 20px; bottom: 80px; width: 42px; height: 42px; border-radius: 50%; background: var(--panel); box-shadow: var(--shadow); color: var(--muted); display: grid; place-items: center; z-index: 5; }
.to-bottom .count { position: absolute; top: -8px; right: -4px; }

#composerWrap { background: var(--panel-2); flex: none; padding-bottom: env(safe-area-inset-bottom); }
.composer { display: flex; align-items: flex-end; gap: 4px; padding: 8px 12px; min-height: 62px; }
.composer textarea {
  flex: 1; resize: none; border: 0; border-radius: 10px; background: var(--panel); padding: 10px 14px; max-height: 140px; outline: none; line-height: 22px; font-size: 15px; margin: 0 4px;
}
.composer .icon-btn { margin-bottom: 2px; }
.send-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; margin-left: 4px; }
.send-btn .icon { width: 22px; height: 22px; }
.composer-notice { text-align: center; padding: 18px; color: var(--muted); font-size: 14px; }
.reply-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px 0 16px; }
.reply-bar .quote { flex: 1; margin: 0; }
.recorder { align-items: center; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; margin-left: 6px; }
@keyframes blink { 50% { opacity: .2; } }
#recTime { font-variant-numeric: tabular-nums; min-width: 40px; }
.rec-wave { flex: 1; height: 28px; display: flex; align-items: center; gap: 2px; overflow: hidden; justify-content: flex-end; }
.rec-wave i { width: 3px; border-radius: 2px; background: var(--muted); flex: none; }
.drop-zone { position: absolute; inset: 60px 0 0; background: color-mix(in srgb, var(--accent) 20%, transparent); border: 3px dashed var(--accent); display: grid; place-items: center; font-size: 22px; font-weight: 600; color: var(--accent); z-index: 30; pointer-events: none; }

/* ---------- Överlägg: menyer, dialoger, bildvisare ---------- */
#overlay > * { z-index: 100; }
.backdrop { position: fixed; inset: 0; background: rgba(11, 20, 26, .45); z-index: 99; animation: fade .15s; }
.backdrop.clear { background: transparent; }
@keyframes fade { from { opacity: 0; } }
.menu { position: fixed; background: var(--panel); border-radius: 12px; box-shadow: 0 4px 20px rgba(0, 0, 0, .22); padding: 8px 0; min-width: 210px; z-index: 101; animation: pop .12s ease-out; max-height: 80vh; overflow-y: auto; }
@keyframes pop { from { transform: scale(.95); opacity: 0; } }
.menu button { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 10px 20px; font-size: 14.5px; }
.menu button:hover { background: var(--hover); }
.menu button .icon { width: 20px; height: 20px; color: var(--muted); }
.menu button.danger { color: var(--danger); }
.menu button.danger .icon { color: var(--danger); }
.menu .quick { display: flex; gap: 2px; padding: 4px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .quick button { font-size: 24px; padding: 4px; width: 40px; height: 40px; justify-content: center; border-radius: 50%; }
.menu .quick button.mine { background: var(--accent-soft); }
.dialog { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel); border-radius: 14px; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); z-index: 101;
  width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; animation: pop .15s ease-out; }
.dialog .d-body { padding: 22px 24px 8px; overflow-y: auto; }
.dialog h3 { margin: 0 0 10px; font-size: 18px; font-weight: 600; }
.dialog p { margin: 0 0 10px; color: var(--muted); }
.dialog .d-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; flex-wrap: wrap; }
.dialog .d-actions .btn { padding: 9px 18px; }
.dialog .d-actions .btn.plain { color: var(--accent); }
.dialog .d-actions .btn.plain.danger { color: var(--danger); background: none; }
.dialog input[type=text], .dialog input[type=password], .dialog textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); outline-color: var(--accent); margin-bottom: 10px; }
.dialog .list { max-height: 50vh; margin: 0 -24px; }
.dialog.wide { width: min(720px, calc(100vw - 32px)); }
.preview-media { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); margin-bottom: 12px; }
.preview-media .pm { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--panel-2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 6px; text-align: center; font-size: 12px; color: var(--muted); }
.preview-media .pm.single { grid-column: 1 / -1; aspect-ratio: auto; max-height: 50vh; }
.preview-media img, .preview-media video { width: 100%; height: 100%; object-fit: cover; }
.preview-media .pm.single img, .preview-media .pm.single video { object-fit: contain; max-height: 50vh; }
.preview-media .pm .icon { width: 40px; height: 40px; }
.emoji-picker { position: fixed; width: 340px; max-width: calc(100vw - 16px); height: 360px; background: var(--panel); border-radius: 14px; box-shadow: 0 4px 24px rgba(0, 0, 0, .25); z-index: 101; display: flex; flex-direction: column; animation: pop .12s ease-out; overflow: hidden; }
.emoji-picker .cats { display: flex; border-bottom: 1px solid var(--line); }
.emoji-picker .cats button { flex: 1; padding: 8px 0; font-size: 18px; border-bottom: 3px solid transparent; opacity: .6; }
.emoji-picker .cats button.active { border-color: var(--accent); opacity: 1; }
.emoji-picker .grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(8, 1fr); padding: 6px; align-content: start; }
.emoji-picker .grid button { font-size: 24px; aspect-ratio: 1; border-radius: 8px; }
.emoji-picker .grid button:hover { background: var(--hover); }
.viewer { position: fixed; inset: 0; background: rgba(8, 12, 14, .96); z-index: 120; display: flex; flex-direction: column; animation: fade .15s; }
.viewer header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; color: #fff; padding-top: max(10px, env(safe-area-inset-top)); }
.viewer header .icon-btn { color: #fff; }
.viewer header .icon-btn:hover { background: rgba(255, 255, 255, .12); }
.viewer header .who { flex: 1; min-width: 0; }
.viewer header .who small { display: block; color: #aab; }
.viewer .stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 10px; min-height: 0; }
.viewer .stage img, .viewer .stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .cap { color: #fff; text-align: center; padding: 12px 16px 20px; white-space: pre-wrap; }
#toasts { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #2b3338; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: pop .15s; max-width: 90vw; }

/* ---------- Mobil ---------- */
@media (max-width: 780px) {
  #sidebar { width: 100%; max-width: none; min-width: 0; border-right: 0; }
  #conv { position: absolute; inset: 0; z-index: 30; transform: translateX(100%); transition: transform .22s ease-out; visibility: hidden; }
  #app.in-chat #conv { transform: none; visibility: visible; }
  .conv-head { border-left: 0; padding-left: 4px; }
  .conv-head .back { display: inline-flex; }
  .panel { position: absolute; inset: 0; width: 100%; z-index: 40; border-left: 0; }
  .messages { padding: 10px 10px 8px; }
  .unread-sep { margin: 10px -10px; }
  .composer { padding: 6px 6px; }
  .composer .icon-btn { width: 38px; }
  .row .chev { display: none; }
  .emoji-picker { left: 8px !important; right: 8px; width: auto; bottom: 70px !important; top: auto !important; }
}
@media (min-width: 781px) and (max-width: 1100px) {
  .panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 40; box-shadow: var(--shadow); }
}

/* ---------- Kryptering ---------- */
.sys button { display: inline-block; background: var(--panel); color: var(--muted); font-size: 12.5px; padding: 6px 12px; border-radius: 8px; max-width: 80%; box-shadow: 0 1px .5px rgba(11, 20, 26, .13); line-height: 1.4; }
.sys.e2e-note button { background: #fdf4c5; color: #54656f; }
.sys.key-change button { background: #fde2e1; color: #8a2a2a; }
:root[data-theme="dark"] .sys.e2e-note button { background: #1d2c26; color: #c4d3cc; }
:root[data-theme="dark"] .sys.key-change button { background: #3a2222; color: #f2c1c1; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sys.e2e-note button { background: #1d2c26; color: #c4d3cc; }
  :root:not([data-theme="light"]) .sys.key-change button { background: #3a2222; color: #f2c1c1; }
}
.safety { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 14px; font: 600 20px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .04em; text-align: center; background: var(--panel-2); border-radius: 12px; padding: 18px 12px; margin: 6px 0 14px; color: var(--ink); }
@media (max-width: 420px) { .safety { grid-template-columns: repeat(3, 1fr); font-size: 18px; } }
.dialog p.warn { color: var(--danger); }
.dialog p.ok { color: var(--accent); font-weight: 600; }
.sig-warn { color: #d58512; font-weight: 700; }
.media img.broken { min-height: 120px; background: repeating-linear-gradient(45deg, rgba(0,0,0,.05) 0 10px, transparent 10px 20px); }
.media img { background: rgba(0, 0, 0, .06); }

/* ---------- Inloggning: andra steget och återställning ---------- */
#auth:not(.recover) .recover-only { display: none; }
#auth.recover .login-pw, #auth.recover .reg-only { display: none; }
#auth:not(.login) .login-only { display: none; }
#twofaForm { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; text-align: center; }
#twofaForm[hidden] { display: none; }
#twofaForm h2 { margin: 0; font-size: 18px; }
#twofaCode { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); font-size: 22px; letter-spacing: .2em; text-align: center; }
#twofaCode:focus { outline: 2px solid var(--accent); border-color: transparent; }
.recovery-key { font: 600 17px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .05em; background: var(--panel-2); border-radius: 12px; padding: 14px; text-align: center; word-spacing: .4em; color: var(--ink); user-select: all; margin: 8px 0 12px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 18px; font: 600 16px/1.6 ui-monospace, Menlo, Consolas, monospace; background: var(--panel-2); border-radius: 12px; padding: 14px 18px; margin: 8px 0 12px; user-select: all; color: var(--ink); }
.check-line { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--ink); cursor: pointer; margin: 6px 0; }
.check-line input { margin-top: 3px; accent-color: var(--accent); }
.qr { display: block; width: 200px; height: 200px; margin: 6px auto 10px; background: #fff; border-radius: 10px; padding: 8px; }
.secret { text-align: center; font: 600 15px ui-monospace, Menlo, monospace; color: var(--ink); margin-bottom: 8px; user-select: all; word-break: break-all; }

/* ---------- Länkförhandsvisning ---------- */
.preview-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px 0 16px; }
.preview-bar .link-card { flex: 1; margin: 0; max-width: none; }
.lc-loading { color: var(--muted); font-size: 13px; padding: 6px 0; }
.link-card { display: flex; flex-direction: column; text-decoration: none; color: inherit; background: rgba(0, 0, 0, .05); border-radius: 6px; overflow: hidden; margin: 0 -3px 6px; max-width: 360px; }
.preview-bar .link-card { flex-direction: row; }
.preview-bar .link-card img { width: 72px; height: 72px; object-fit: cover; flex: none; }
.link-card img { width: 100%; max-height: 180px; object-fit: cover; display: block; }
.lc-body { padding: 8px 10px; min-width: 0; }
.lc-title { font-weight: 600; font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lc-desc { font-size: 13px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lc-site { font-size: 12px; color: var(--muted); margin-top: 4px; }
.timer { font-size: 11px; }

/* ---------- Adminpanel ---------- */
.admin-view { position: fixed; inset: 0; z-index: 110; background: var(--panel-2); display: flex; flex-direction: column; animation: fade .15s; }
.a-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; padding-top: max(12px, env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); }
.a-head h2 { margin: 0; font-size: 19px; }
.a-tabs { display: flex; gap: 4px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.a-tabs button { padding: 12px 14px; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.a-tabs button.active { color: var(--accent); border-color: var(--accent); }
.a-content { flex: 1; overflow-y: auto; padding: 20px; max-width: 1100px; width: 100%; margin: 0 auto; }
.a-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.a-card { background: var(--panel); border-radius: 12px; padding: 14px 16px; border: 1px solid var(--line); }
.a-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.a-value { font-size: 19px; font-weight: 600; margin: 4px 0 2px; overflow-wrap: anywhere; }
.a-sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.a-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.a-note { font-size: 13.5px; color: var(--muted); margin: 8px 0; line-height: 1.5; }
.a-note.warn { color: var(--danger); background: var(--panel); padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); }
.a-section { background: var(--panel); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; border: 1px solid var(--line); }
.a-section h3 { margin: 0 0 12px; font-size: 15px; color: var(--accent); }
.a-section h4 { margin: 18px 0 8px; font-size: 14px; }
.a-section select, .a-section input[type=text], .a-section input[type=number] { padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); font: inherit; min-width: 0; }
.a-section > select { width: 100%; max-width: 480px; }
.a-inline { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.a-inline input[type=text] { flex: 1; min-width: 180px; }
.a-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 14px; margin: 10px 0; }
.a-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.a-list { display: flex; flex-direction: column; }
.a-row { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.a-row:last-child { border-bottom: 0; }
.a-main { flex: 1; min-width: 0; }
.a-name { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; overflow-wrap: anywhere; }
.a-name .muted { font-weight: 400; }
.a-badges { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0; }
.tag.danger { background: #fde2e1; color: #a02828; }
.tag.warn { background: #fff1cc; color: #7a5600; }
.a-out, .a-key { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; font: 12.5px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all; color: var(--danger); margin: 8px 0; }
.a-out.ok { color: var(--accent); }
.a-key { color: var(--ink); user-select: all; }
.row .tag { margin-left: 4px; }
@media (max-width: 600px) { .a-content { padding: 12px; } }

#twofaCode, .auth-card input { width: 100%; min-width: 0; }
.auth-card { overflow-wrap: anywhere; }
.admin-view .btn.secondary { background: var(--panel); border: 1px solid var(--line); }
.admin-view .btn.secondary:hover { border-color: var(--accent); }
