/* =============================== tokens =============================== */
:root {
  --accent: #0b8a76;
  --accent-strong: #08705f;
  --accent-soft: #d8f3ec;
  --danger: #e5484d;
  --read: #34b7f1;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(11, 20, 26, 0.16), 0 1px 3px rgba(11, 20, 26, 0.08);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, 'Helvetica Neue', sans-serif;
  --emoji-font: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
[data-theme='light'] {
  color-scheme: light;
  --app-bg: #dfe5e7;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --hover: #f5f6f6;
  --active: #e9edef;
  --border: #e3e7ea;
  --text: #111b21;
  --text-2: #54656f;
  --muted: #667781;
  --chat-bg: #efeae2;
  --doodle: rgba(84, 101, 111, 0.07);
  --bubble-in: #ffffff;
  --bubble-out: #d6f7ee;
  --bubble-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --quote-bg: rgba(11, 20, 26, 0.05);
  --sys-bg: #ffffffd9;
  --input-bg: #ffffff;
  --badge: #13a888;
}
[data-theme='dark'] {
  color-scheme: dark;
  --app-bg: #0c1317;
  --panel: #111b21;
  --panel-2: #1f2c33;
  --hover: #202c33;
  --active: #2a3942;
  --border: #222d34;
  --text: #e9edef;
  --text-2: #aebac1;
  --muted: #8696a0;
  --chat-bg: #0b141a;
  --doodle: rgba(233, 237, 239, 0.035);
  --bubble-in: #202c33;
  --bubble-out: #0b5c4f;
  --bubble-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.25);
  --quote-bg: rgba(0, 0, 0, 0.18);
  --sys-bg: #182229;
  --input-bg: #2a3942;
  --badge: #13a888;
  --accent-soft: #11332d;
}

/* ================================ base ================================ */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14.5px/1.4 var(--font);
  color: var(--text);
  background: var(--app-bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
kbd {
  font: 11.5px/1 var(--font);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 5px;
}

.ico { display: inline-flex; width: 1.4em; height: 1.4em; flex: none; }
.ico svg {
  width: 100%; height: 100%;
  fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  color: var(--text-2);
  transition: background 0.15s;
  font-size: 17px;
}
.icon-btn:hover, .icon-btn.active { background: var(--active); }
.icon-btn.small { width: 30px; height: 30px; font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 24px;
  background: var(--panel-2); color: var(--text);
  font-weight: 600; transition: filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(0.96); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); filter: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline { background: transparent; color: var(--danger); border: 1px solid currentColor; }
.btn-danger-outline .ico { font-size: 16px; }
.btn-block { width: 100%; }
.link-btn { color: var(--accent); font-weight: 600; margin-top: 8px; }

.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--badge); color: #fff;
  font-size: 11.5px; font-weight: 700; display: inline-grid; place-items: center;
}
.muted-badge { background: var(--muted); }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* shared form primitives (used by login + app settings) */
.field { display: grid; gap: 6px; }
.field > span:not(.pw-wrap) { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.field input, .text-input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--input-bg);
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus, .text-input:focus { border-color: var(--accent); }
.text-input:disabled { opacity: 0.7; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; color: var(--muted); font-size: 17px;
}
.pw-toggle:hover { background: var(--hover); color: var(--text); }
.pw-toggle:focus-visible { outline: 2px solid var(--accent); }
.form-error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }

/* ===================== Somaiya login (login page only) ===================== */
.som-view {
  --som-red: #e4022b;
  --som-maroon: #9b1c2e;
  --som-ink: #2b2b2b;
  --som-gray: #6b6f73;
  --som-blue: #1f54a0;
  --som-btn: #5a5f63;
  --som-serif: 'PT Serif', 'Playfair Display', Georgia, 'Times New Roman', serif;
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: #ffffff; color: var(--som-ink);
  font-family: var(--som-serif);
}
/* top red bar + stepped corner block */
.som-redbar { position: relative; height: 62px; flex: none; background: var(--som-red); }
.som-redbar::after {
  content: ''; position: absolute; top: 0; right: 0;
  width: clamp(120px, 12vw, 220px); height: 150px;
  background: #c10024; clip-path: polygon(22% 0, 100% 0, 100% 100%, 0 100%);
}
.som-split { flex: 1; display: flex; min-height: 0; }

/* left campus image — drop a photo at /img/campus.jpg to use the real one */
.som-media {
  flex: 1 1 50%; min-width: 0;
  background-color: #2e5d39;
  background-image:
    url('/img/campus.jpg'),
    radial-gradient(120% 80% at 20% 15%, #7fb08a 0%, transparent 55%),
    linear-gradient(160deg, #3c7a4a 0%, #2d5c39 45%, #244a2f 100%);
  background-size: cover, cover, cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* right login panel */
.som-panel {
  flex: 1 1 50%; min-width: 0;
  position: relative;
  background: #fff;
  overflow-y: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 28px 24px;
}
.som-panel-inner { width: min(480px, 100%); }

/* logos row */
.som-logos { display: flex; justify-content: center; margin-bottom: 26px; }
.som-logos img { width: 100%; max-width: 420px; height: auto; display: block; }

/* headings */
.som-title { margin: 0 0 6px; text-align: center; font-size: 26px; font-weight: 700; color: #222; }
.som-subtitle { margin: 0 0 26px; text-align: center; font-size: 15px; color: var(--som-gray); }

/* form */
.som-view #login-form { display: grid; gap: 16px; }
.som-view .field {
  gap: 2px; background: #fff;
  border: 1px solid #c9ccce; border-radius: 4px; padding: 8px 14px;
}
.som-view .field:focus-within { border-color: var(--som-gray); }
.som-view .field > span:not(.pw-wrap) { font-size: 13px; font-weight: 400; color: #76797c; }
.som-view .field > span em { color: var(--som-red); font-style: normal; }
.som-view .field input {
  border: 0; border-radius: 0; padding: 4px 0; background: transparent; font-size: 15px; color: #222;
}
.som-view .field input:focus { border: 0; }
.som-view .pw-wrap input { padding-right: 34px; }
.som-view .pw-toggle { right: -4px; width: 30px; height: 30px; font-size: 15px; }
.som-view .pw-toggle:focus-visible { outline-color: var(--som-gray); }

/* remember / forgot row */
.som-row { display: flex; align-items: center; justify-content: space-between; margin-top: -4px; }
.som-remember { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: #444; }
.som-remember input { width: 15px; height: 15px; accent-color: var(--som-red); }
.som-link {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-family: var(--som-serif); font-size: 14px; color: var(--som-blue); text-decoration: none;
}
.som-link:hover { text-decoration: underline; }

/* submit */
.som-submit {
  width: 100%; margin-top: 4px; padding: 13px; border-radius: 4px;
  background: var(--som-btn); color: #fff; font-family: var(--som-serif);
  font-size: 16px; font-weight: 700; transition: background 0.15s;
}
.som-submit:hover { background: #4a4e52; }

/* OR divider + alt button */
.som-or {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  margin: 18px 0; color: #9aa0a4; font-weight: 700; font-size: 14px;
}
.som-or::before, .som-or::after { content: ''; height: 1px; background: #e2e4e6; }
.som-alt {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  position: relative; padding: 12px; border-radius: 4px;
  border: 1px solid #c9ccce; background: #fff; color: #333;
  font-family: var(--som-serif); font-size: 15px; font-weight: 700; transition: background 0.15s;
}
.som-alt:hover { background: #f4f5f6; }
.som-alt-ico {
  position: absolute; right: 0; top: 0; bottom: 0; width: 46px;
  display: grid; place-items: center; color: #666; border-left: 1px solid #e2e4e6;
}

/* help + trust */
.som-help { margin: 18px 0 0; text-align: center; font-size: 13.5px; color: #555; line-height: 1.5; }
.som-help .som-link { font-weight: 700; }
.som-trust { position: absolute; right: 18px; bottom: 16px; width: 58px; height: auto; display: block; }

/* responsive: stack on narrow screens */
@media (max-width: 820px) {
  .som-split { flex-direction: column; }
  .som-media { flex: none; height: 150px; }
  .som-panel { flex: 1; }
  .som-redbar { height: 48px; }
}
@media (max-width: 480px) {
  .som-media { display: none; }
  .som-title { font-size: 22px; }
}

/* ============================== app layout ============================== */
.app {
  height: calc(100dvh - var(--keyboard, 0px));
  display: grid;
  grid-template-columns: minmax(320px, 30%) 1fr;
  grid-template-rows: minmax(0, 1fr);
  max-width: 1700px;
  margin: 0 auto;
  background: var(--panel);
  position: relative;
  overflow: hidden;
}
@media (min-width: 1440px) {
  body { padding: 19px 0; }
  .app { height: calc(100dvh - 38px); box-shadow: var(--shadow); width: calc(100% - 38px); }
}
.app:has(.info-panel:not([hidden])) { grid-template-columns: minmax(320px, 30%) 1fr 360px; }

/* =============================== sidebar =============================== */
.sidebar {
  display: flex; flex-direction: column; min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  position: relative;
}
.side-header, .chat-header, .drawer-header {
  height: 60px; flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  background: var(--panel-2);
}
.side-header { justify-content: space-between; }
.side-actions { display: flex; gap: 4px; }
.avatar-btn, .avatar-slot { display: grid; border-radius: 50%; }

.side-search { padding: 8px 12px 6px; display: grid; gap: 8px; }
.search-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2);
  border-radius: 9px;
  padding: 0 12px;
  height: 36px;
  color: var(--muted);
}
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; height: 100%; }
.search-box .ico { font-size: 14px; }
.chips { display: flex; gap: 8px; }
.chip {
  padding: 5px 13px; border-radius: 16px;
  background: var(--panel-2); color: var(--muted); font-size: 13.5px;
}
.chip.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.notif-banner {
  margin: 4px 12px 6px; padding: 12px;
  display: flex; gap: 12px; align-items: center;
  background: var(--accent-soft); border-radius: 10px; font-size: 13px;
}
.notif-banner > .ico { font-size: 22px; color: var(--accent); }
.notif-banner > div { flex: 1; }

.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-item {
  display: flex; align-items: center; gap: 13px;
  padding: 0 14px;
  height: 72px;
  cursor: pointer;
  position: relative;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.chat-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ci-main {
  flex: 1; min-width: 0; height: 100%;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  border-bottom: 1px solid var(--border);
}
.chat-item:last-child .ci-main { border-bottom: 0; }
.ci-top, .ci-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ci-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: 12px; color: var(--muted); flex: none; }
.has-unread .ci-time { color: var(--badge); font-weight: 600; }
.ci-preview {
  color: var(--muted); font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 3px; min-width: 0;
}
.ci-preview .typing { color: var(--badge); font-style: normal; font-weight: 500; }
.ci-badges { display: flex; align-items: center; gap: 5px; flex: none; color: var(--muted); }
.ci-flag { font-size: 13px; }
.ci-menu {
  width: 0; overflow: hidden; color: var(--muted); font-size: 16px;
  transition: width 0.12s;
}
.chat-item:hover .ci-menu { width: 20px; }
.list-heading {
  padding: 14px 16px 8px; color: var(--accent);
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
}
.list-empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.chat-item.action .ci-name { font-size: 15.5px; }
.action-icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 20px; flex: none;
}
.tag { font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 2px 7px; border-radius: 8px; }

/* avatars */
.avatar {
  position: relative; flex: none;
  border-radius: 50%;
  display: inline-grid; place-items: center; vertical-align: middle;
  color: #fff; font-weight: 600; letter-spacing: 0.02em;
  user-select: none;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar .ico { font-size: 1.4em; }
.online-dot {
  position: absolute; right: 0; bottom: 0;
  width: 26%; height: 26%; min-width: 10px; min-height: 10px;
  background: #25d366; border: 2px solid var(--panel); border-radius: 50%;
}

/* drawers (slide over the sidebar) */
.drawer {
  position: absolute; inset: 0; z-index: 5;
  background: var(--panel);
  display: flex; flex-direction: column;
  animation: slide-in 0.18s ease-out;
}
@keyframes slide-in { from { transform: translateX(-30px); opacity: 0; } }
.drawer-header { gap: 14px; height: 60px; }
.drawer-header h2 { font-size: 17px; font-weight: 600; margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; }
.form-pad { padding: 12px 16px; display: grid; gap: 14px; }
.sticky-bottom { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--border); }
.member-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px; }
.member-chips:empty { display: none; }
.member-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--panel-2); border-radius: 14px; padding: 3px 4px 3px 11px; font-size: 13px;
}
.member-chip button { display: grid; color: var(--muted); font-size: 12px; }
.check-box {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  border: 2px solid var(--muted); color: transparent; display: grid; place-items: center; font-size: 13px;
}
.check-box.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.profile-head { display: grid; justify-items: center; gap: 4px; padding: 26px 16px 18px; text-align: center; }
.profile-head h3 { margin: 10px 0 0; font-size: 21px; font-weight: 500; }
.profile-head p { margin: 0; }
.profile-avatar { position: relative; border-radius: 50%; overflow: hidden; }
.view-photo { border-radius: 50%; cursor: zoom-in; }
.view-photo:disabled { cursor: default; }
.crop { display: grid; justify-items: center; gap: 16px; }
.crop p { margin: 0; }
.crop-area { position: relative; width: 280px; height: 280px; overflow: hidden; border-radius: 50%; cursor: grab; touch-action: none; background: var(--panel-2); }
.crop-area img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; pointer-events: none; }
.crop input { width: 280px; accent-color: var(--accent); }
.crop .confirm-actions { justify-self: end; }
.avatar-overlay {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 4px;
  background: rgba(0, 0, 0, 0.45); color: #fff; font-size: 12px; text-transform: uppercase;
  opacity: 0; transition: opacity 0.15s;
}
.avatar-overlay .ico { font-size: 24px; }
.profile-avatar:hover .avatar-overlay { opacity: 1; }

.settings-me { display: flex; gap: 14px; align-items: center; padding: 16px; cursor: pointer; border-bottom: 1px solid var(--border); }
.settings-me div { display: grid; }
.settings-me strong { font-size: 17px; font-weight: 500; }
.settings-me small { color: var(--muted); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel-2); border-radius: 10px; padding: 3px; }
.segmented button { padding: 7px; border-radius: 8px; color: var(--text-2); }
.segmented button.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; cursor: pointer; }
.toggle-row:hover { background: var(--hover); }
.toggle-row > div { display: grid; }
.toggle-row strong { font-weight: 500; }
.toggle-row small { color: var(--muted); font-size: 12.5px; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.slider { position: absolute; inset: 0; background: var(--active); border-radius: 22px; transition: background 0.15s; }
.slider::before {
  content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; padding: 4px 16px 12px; margin: 0; font-size: 13px; }
.shortcuts dt { white-space: nowrap; color: var(--text-2); }
.shortcuts dd { margin: 0; color: var(--muted); }

/* ============================ chat (right) ============================ */
.chat { position: relative; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); }
.empty-state {
  flex: 1; display: grid; place-content: center; justify-items: center; text-align: center;
  padding: 30px; gap: 4px; color: var(--muted);
  background: var(--panel-2);
  border-bottom: 6px solid var(--accent);
}
.empty-state img { opacity: 0.9; margin-bottom: 14px; }
.empty-state h2 { color: var(--text); font-weight: 300; font-size: 30px; margin: 0 0 8px; }
.empty-state p { margin: 4px 0; max-width: 460px; }
.empty-state .ico { font-size: 13px; vertical-align: -2px; }

.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.chat-header { border-left: 1px solid var(--border); z-index: 2; }
.back-btn { display: none; }
.chat-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 13px; text-align: left; height: 100%; }
.chat-title-text { display: grid; min-width: 0; }
.chat-title-text strong { font-weight: 500; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title-text small { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title-text small.typing { color: var(--badge); }
.chat-actions { display: flex; gap: 2px; }

.msg-search {
  position: absolute; top: 60px; right: 0; z-index: 4;
  width: min(380px, 100%); max-height: 60%;
  background: var(--panel); box-shadow: var(--shadow);
  display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px; border-radius: 0 0 0 12px;
}
.msg-search-results { grid-column: 1 / -1; list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.msg-search-results li { padding: 9px 8px; border-bottom: 1px solid var(--border); cursor: pointer; display: grid; gap: 2px; }
.msg-search-results li:hover { background: var(--hover); }
.msg-search-results small { color: var(--muted); font-size: 12px; }
.msg-search-results span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* messages area + doodle wallpaper */
.messages {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column;
  padding: 10px 0 8px;
  outline: none;
  background-color: var(--chat-bg);
  background-image: radial-gradient(var(--doodle) 1.6px, transparent 1.8px),
    radial-gradient(var(--doodle) 1.2px, transparent 1.4px);
  background-size: 26px 26px, 26px 26px;
  background-position: 0 0, 13px 13px;
}
.no-wallpaper .messages { background-image: none; }
.messages-inner { display: flex; flex-direction: column; padding: 0 6%; flex: 1 0 auto; justify-content: flex-end; }
@media (max-width: 1100px) { .messages-inner { padding: 0 3%; } }

.loading { display: grid; place-items: center; padding: 40px; color: var(--muted); flex: 1; }
.load-older { display: grid; place-items: center; padding: 10px; }
.chat-start {
  align-self: center; margin: 8px 0 12px; padding: 6px 12px; border-radius: 8px;
  background: #fdf4c5; color: #54656f; font-size: 12.5px; text-align: center; max-width: 90%;
}
[data-theme='dark'] .chat-start { background: #182229; color: #ffd279; }
.chat-start .ico { font-size: 12px; vertical-align: -2px; }

.day-sep, .unread-sep { display: flex; justify-content: center; margin: 12px 0 8px; position: sticky; top: 4px; z-index: 1; }
.day-sep span, .sys-msg span {
  background: var(--sys-bg); color: var(--text-2);
  padding: 5px 12px; border-radius: 8px; font-size: 12.5px;
  box-shadow: var(--bubble-shadow);
}
.unread-sep { position: static; background: rgba(255, 255, 255, 0.25); padding: 4px 0; margin: 8px -10%; }
[data-theme='dark'] .unread-sep { background: rgba(0, 0, 0, 0.2); }
.unread-sep span { background: var(--sys-bg); color: var(--text-2); padding: 4px 18px; border-radius: 14px; font-size: 12.5px; }
.sys-msg { display: flex; justify-content: center; margin: 6px 0; text-align: center; }

/* message rows */
.msg-row { display: flex; position: relative; margin-top: 2px; padding: 0 0 0 8px; }
.msg-row.first { margin-top: 10px; }
.msg-row.out { justify-content: flex-end; padding: 0 8px 0 0; }
.msg-row.has-reactions { margin-bottom: 18px; }
.msg-row.flash .bubble { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px var(--accent); } }

.bubble {
  position: relative;
  max-width: min(65%, 560px);
  min-width: 70px;
  padding: 6px 8px 8px 9px;
  border-radius: 8px;
  background: var(--bubble-in);
  box-shadow: var(--bubble-shadow);
  overflow-wrap: anywhere;
}
.out .bubble { background: var(--bubble-out); }
@media (max-width: 760px) { .bubble { max-width: 85%; } }
/* the little tail on the first bubble of a group */
.first.in .bubble { border-top-left-radius: 0; }
.first.out .bubble { border-top-right-radius: 0; }
.first.in .bubble::before, .first.out .bubble::before {
  content: ''; position: absolute; top: 0; width: 8px; height: 13px;
  background: inherit;
}
.first.in .bubble::before { left: -8px; clip-path: polygon(100% 0, 0 0, 100% 100%); }
.first.out .bubble::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.jumbo-bubble { background: transparent !important; box-shadow: none !important; }
.jumbo-bubble::before { display: none; }

.sender { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.text { white-space: pre-wrap; font-size: 14.5px; line-height: 1.38; }
.text.jumbo { font-size: 44px; line-height: 1.15; font-family: var(--emoji-font); }
.text code { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; background: var(--quote-bg); padding: 1px 4px; border-radius: 4px; }
.text a { word-break: break-all; }
.mention { color: var(--accent); font-weight: 500; }
.meta {
  position: absolute; right: 7px; bottom: 3px;
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--muted); white-space: nowrap;
}
.meta.ghost { position: static; visibility: hidden; margin-left: 10px; height: 1px; vertical-align: baseline; }
.meta > .ico { font-size: 9px; }
.edited { font-style: italic; margin-right: 2px; }
.ticks { display: inline-flex; font-size: 15px; color: var(--muted); }
.ticks.read { color: var(--read); }
.ticks.failed { color: var(--danger); font-weight: 800; font-size: 13px; padding: 0 3px; }
.bubble.failed { cursor: pointer; outline: 1px dashed var(--danger); }
.pending .bubble { opacity: 0.85; }
.deleted .text { color: var(--muted); font-style: italic; }
.deleted .text .ico { font-size: 14px; vertical-align: -3px; }

/* media */
.has-media { padding: 3px 3px 4px; }
.has-media .text { padding: 4px 5px 0; }
.has-media .sender { padding: 2px 5px 0; }
.has-media .quote { margin: 0 0 3px; }
.media {
  position: relative; max-width: 100%; max-height: 420px;
  border-radius: 6px; overflow: hidden; cursor: zoom-in;
  background: var(--quote-bg);
}
.media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media.broken::after { content: 'Image unavailable'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.gif-badge {
  position: absolute; left: 6px; top: 6px; font-size: 10px; font-weight: 800;
  background: rgba(0, 0, 0, 0.55); color: #fff; padding: 1px 5px; border-radius: 4px;
}
.meta-over .meta {
  right: 9px; bottom: 9px; color: #fff;
  background: rgba(0, 0, 0, 0.35); padding: 1px 6px; border-radius: 8px;
}
.meta-over .meta .ticks { color: #fff; }
.meta-over .meta .ticks.read { color: #7fd8ff; }
.progress { height: 4px; border-radius: 2px; background: var(--quote-bg); margin: 4px 4px 2px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); transition: width 0.15s; }

.file-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 6px; background: var(--quote-bg);
  color: inherit; text-decoration: none; min-width: 230px; margin-bottom: 2px;
}
.has-file .text { padding-top: 4px; }
.file-icon {
  position: relative; display: grid; place-items: center; width: 36px; height: 44px; font-size: 32px; color: var(--accent); flex: none;
}
.file-icon small { position: absolute; bottom: 6px; font-size: 8px; font-weight: 800; }
.file-info { display: grid; min-width: 0; flex: 1; }
.file-info strong { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-info small { color: var(--muted); }
.file-dl { font-size: 20px; color: var(--muted); }

/* replies */
.quote {
  display: flex; gap: 8px; align-items: stretch;
  background: var(--quote-bg); border-left: 4px solid var(--accent);
  border-radius: 6px; padding: 5px 8px; margin: 1px 0 5px;
  cursor: pointer; font-size: 13px; min-width: 0;
}
.quote-body { display: grid; min-width: 0; flex: 1; }
.quote-body span { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; white-space: pre-wrap; }
.quote-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; margin: -2px -4px -2px 0; }

/* reactions */
.reactions {
  position: absolute; bottom: -16px; display: flex; gap: 2px; z-index: 1;
  background: var(--panel); border-radius: 12px; padding: 1px 4px;
  box-shadow: 0 1px 3px rgba(11, 20, 26, 0.2);
}
.in .reactions { left: 20px; }
.out .reactions { right: 20px; }
.reaction { font-size: 14px; padding: 1px 2px; border-radius: 8px; display: inline-flex; align-items: center; gap: 2px; font-family: var(--emoji-font); }
.reaction small { font-family: var(--font); font-size: 11px; color: var(--muted); }
.reaction.mine { background: var(--accent-soft); }

/* hover actions */
.msg-actions {
  align-self: center; display: flex; gap: 2px; opacity: 0;
  transition: opacity 0.12s; padding: 0 6px;
}
.in .msg-actions { order: 2; }
.out .msg-actions { order: -1; }
.msg-row:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.msg-actions button {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--panel); color: var(--muted); font-size: 15px;
  box-shadow: 0 1px 2px rgba(11, 20, 26, 0.15);
}
@media (hover: none) {
  .msg-actions { display: none; }
  .msg-row { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: pan-y pinch-zoom; transition: transform 0.12s; }
  .reaction { font-size: 16px; padding: 2px 5px; }
  /* iPhones zoom the page when a smaller input gets focus */
  input, textarea, #msg-input { font-size: 16px !important; }
}

.scroll-down {
  position: absolute; right: 18px; bottom: 80px; z-index: 3;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--panel); color: var(--text-2); box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: 20px;
}
.scroll-down .badge { position: absolute; top: -6px; right: -4px; }

/* pinned messages */
.pin-bar {
  display: flex; align-items: center; gap: 6px; flex: none; padding: 0 10px 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--border); z-index: 1;
}
.pin-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 9px 0; text-align: left; color: var(--text-2); font-size: 13.5px; }
.pin-main span:not(.ico) { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-main .ico { color: var(--accent); }
.pin-main small { color: var(--muted); flex: none; }

/* stickers */
.sticker { display: block; width: 150px; height: 150px; object-fit: contain; }
.sticker-bubble { background: transparent !important; box-shadow: none; padding-bottom: 20px; }
.sticker-bubble::before { display: none; }

/* "…" while someone types */
.typing-bubble { flex: none; padding: 8px 6% 4px; }
.typing-bubble .bubble { width: fit-content; margin-left: 8px; padding: 10px 14px; }
.typing-bubble .sender { display: block; color: var(--accent); }
.typing-bubble .sender:empty { display: none; }
.dots { display: flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: typing 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.35; } 30% { opacity: 1; transform: translateY(-3px); } }

/* =============================== composer =============================== */
.composer { position: relative; background: var(--panel-2); z-index: 3; }
.composer-row { display: flex; align-items: flex-end; gap: 4px; padding: 8px 12px; }
.composer-row .icon-btn { font-size: 21px; flex: none; margin-bottom: 1px; }
.input-wrap { flex: 1; min-width: 0; background: var(--input-bg); border-radius: 10px; padding: 9px 12px; margin: 0 4px; }
#msg-input {
  width: 100%; border: 0; outline: 0; background: transparent; resize: none;
  max-height: 160px; line-height: 1.4; display: block; font-size: 15px;
}
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 19px;
  transition: background 0.15s, transform 0.1s;
}
.send-btn:hover { background: var(--accent-strong); }
.send-btn:active { transform: scale(0.94); }
.composer-context {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px 0 60px;
}
.ctx-body {
  flex: 1; min-width: 0; display: grid;
  background: var(--quote-bg); border-left: 4px solid var(--accent); border-radius: 6px; padding: 6px 10px; font-size: 13px;
}
.composer-context.edit .ctx-body { border-left-color: #f5a524; }
.ctx-body span { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.emoji-suggest {
  position: absolute; left: 12px; bottom: 100%; margin-bottom: 6px; width: min(300px, calc(100% - 24px));
  background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: grid; grid-template-columns: minmax(0, 1fr);
}
.emoji-suggest button { display: flex; align-items: center; gap: 12px; padding: 5px 10px; border-radius: 8px; color: var(--text-2); text-align: left; white-space: nowrap; overflow: hidden; }
.emoji-suggest button.active, .emoji-suggest button:hover { background: var(--active); color: var(--text); }
.emoji-suggest span { font-size: 22px; font-family: var(--emoji-font); }

/* emoji / gif panel */
.picker-panel {
  height: 360px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--panel);
}
.picker-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.recent-emojis { display: flex; align-items: center; gap: 2px; padding: 6px 10px; overflow-x: auto; border-bottom: 1px solid var(--border); flex: none; }
.recent-label { font-size: 12px; color: var(--muted); margin-right: 6px; font-weight: 600; }
.emoji-btn { font-size: 24px; width: 38px; height: 38px; border-radius: 8px; flex: none; font-family: var(--emoji-font); }
.emoji-btn:hover { background: var(--hover); }
emoji-picker {
  width: 100%; flex: 1; min-height: 0; height: auto;
  --border-size: 0; --background: var(--panel); --input-border-color: var(--border);
  --indicator-color: var(--accent); --outline-color: var(--accent);
  --button-active-background: var(--active); --button-hover-background: var(--hover);
  --num-columns: 10; --emoji-size: 1.5rem;
  --input-border-radius: 9px; --input-padding: 0.45rem 0.8rem; --input-font-size: 14px;
  --input-font-color: var(--text); --input-placeholder-color: var(--muted);
}
@media (max-width: 760px) { emoji-picker { --num-columns: 8; } }
.picker-tabs { display: flex; justify-content: center; gap: 8px; padding: 4px; border-top: 1px solid var(--border); flex: none; }
.picker-tab { padding: 6px 18px; border-radius: 16px; color: var(--muted); font-size: 20px; }
.picker-tab.active { background: var(--accent-soft); color: var(--accent); }
.gif-pane .search-box { margin: 8px 10px; flex: none; }
.gif-scroll { flex: 1; overflow-y: auto; padding: 0 10px 10px; }
.gif-grid { columns: 4 140px; column-gap: 6px; }
.gif-tile { display: block; width: 100%; margin-bottom: 6px; border-radius: 6px; overflow: hidden; background: var(--panel-2); position: relative; break-inside: avoid; }
.gif-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gif-tile:hover { outline: 3px solid var(--accent); }
.gif-recent-tag { position: absolute; top: 4px; left: 4px; font-size: 9.5px; text-transform: uppercase; background: rgba(0,0,0,.55); color: #fff; padding: 1px 5px; border-radius: 4px; }
.sticker-grid, .my-sticker-grid { columns: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.sticker-grid .gif-tile, .my-sticker .gif-tile { aspect-ratio: 1; margin: 0; background: none; padding: 6px; }
.sticker-grid .gif-tile img, .my-sticker .gif-tile img { object-fit: contain; }
.my-stickers { padding: 8px 0 12px; }
.my-sticker-grid { margin-top: 6px; }
.my-sticker { position: relative; }
.add-sticker { aspect-ratio: 1; border: 2px dashed var(--border); border-radius: 10px; color: var(--muted); display: grid; place-content: center; justify-items: center; font-size: 13px; }
.add-sticker:hover { border-color: var(--accent); color: var(--accent); }
.remove-sticker { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; background: var(--panel-2); color: var(--muted); display: grid; place-items: center; font-size: 10px; }
.gif-status { text-align: center; color: var(--muted); padding: 14px; font-size: 13px; }
.gif-status p { margin: 4px 0; }
.floating-backdrop { position: fixed; inset: 0; z-index: 60; }
.floating-picker { position: fixed; z-index: 61; width: 340px; height: 400px; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); display: flex; }
.floating-picker emoji-picker { --num-columns: 8; height: 100%; }

.drop-overlay {
  position: absolute; inset: 60px 0 0; z-index: 10;
  display: grid; place-items: center; text-align: center;
  background: color-mix(in srgb, var(--panel-2) 88%, transparent);
  border: 3px dashed var(--accent); margin: 10px; border-radius: 16px;
  color: var(--accent); font-size: 18px; font-weight: 600; pointer-events: none;
}
.drop-overlay .ico { font-size: 52px; }

/* ============================== info panel ============================== */
.info-panel {
  background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0;
  animation: slide-left 0.18s ease-out;
}
@keyframes slide-left { from { transform: translateX(30px); opacity: 0; } }
.info-section { border-top: 8px solid var(--panel-2); padding-bottom: 4px; }
.about { margin: 0; padding: 0 16px 14px; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 0 16px 14px; }
.media-grid button { aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--panel-2); }
.media-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
@media (max-width: 1200px) {
  .app:has(.info-panel:not([hidden])) { grid-template-columns: minmax(320px, 30%) 1fr; }
  .info-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(380px, 100%); z-index: 20; box-shadow: var(--shadow); }
}

/* ============================== overlays ============================== */
.menu {
  position: fixed; z-index: 50; min-width: 200px;
  background: var(--panel); border-radius: 10px; padding: 6px 0;
  box-shadow: var(--shadow); animation: pop 0.12s ease-out;
}
@keyframes pop { from { transform: scale(0.96); opacity: 0; } }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 18px; text-align: left; color: var(--text-2); }
.menu-item:hover { background: var(--hover); }
.menu-item .ico { font-size: 17px; }
.menu-item.danger { color: var(--danger); }
.menu-reactions { display: flex; gap: 2px; padding: 2px 8px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-reactions button { font-size: 23px; width: 36px; height: 36px; border-radius: 50%; font-family: var(--emoji-font); transition: transform 0.1s; }
.menu-reactions button.mine { background: var(--accent-soft); }
.menu-emoji { font-size: 20px; font-family: var(--emoji-font); }
.menu-reactions button:hover { background: var(--hover); transform: scale(1.15); }
.menu-reactions .more { font-size: 16px; color: var(--muted); display: grid; place-items: center; background: var(--panel-2); }

.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(11, 20, 26, 0.55); display: grid; place-items: center; padding: 16px; }
.modal {
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  width: min(520px, 100%); max-height: 90dvh; overflow: auto; animation: pop 0.15s ease-out;
}
.confirm { padding: 22px 22px 16px; }
.confirm p { margin: 0 0 20px; font-size: 15px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-list h3, .upload-preview h3 { margin: 0; padding: 18px 18px 10px; font-size: 17px; font-weight: 600; }
.modal-list .chat-list { max-height: 50dvh; }
.upload-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; padding: 6px 18px; max-height: 55dvh; overflow: auto; }
.upload-grid.single { grid-template-columns: 1fr; }
.up-thumb { border-radius: 8px; overflow: hidden; background: var(--panel-2); aspect-ratio: 1; display: grid; place-items: center; }
.upload-grid.single .up-thumb { aspect-ratio: auto; max-height: 50dvh; }
.up-thumb img { width: 100%; height: 100%; object-fit: cover; }
.upload-grid.single .up-thumb img { object-fit: contain; max-height: 50dvh; }
.up-thumb.file { display: grid; place-content: center; justify-items: center; gap: 4px; padding: 10px; text-align: center; font-size: 12.5px; word-break: break-all; }
.up-thumb.file .ico { font-size: 36px; color: var(--accent); }
.up-thumb.file small { color: var(--muted); }
.upload-actions { display: flex; gap: 10px; padding: 12px 18px 18px; align-items: center; }
.caption { flex: 1; padding: 11px 14px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--input-bg); outline: none; }
.caption:focus { border-color: var(--accent); }

.lightbox { position: fixed; inset: 0; z-index: 45; background: rgba(8, 12, 14, 0.94); display: grid; grid-template-rows: auto 1fr; }
.lightbox-bar { display: flex; align-items: center; gap: 6px; padding: 10px 14px; color: #fff; }
.lightbox-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox-bar .icon-btn { color: #fff; }
.lightbox-bar .icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.lightbox img { max-width: 94vw; max-height: calc(100dvh - 90px); margin: auto; object-fit: contain; border-radius: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 70;
  background: #1f2c33; color: #fff; padding: 10px 18px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 14px; max-width: 90vw; animation: pop 0.15s ease-out;
}
.conn-banner {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%); z-index: 70;
  background: #f5a524; color: #111; padding: 4px 14px; border-radius: 0 0 10px 10px; font-size: 13px; font-weight: 600;
}

@keyframes sheet { from { transform: translateY(100%); } }

/* ================================ mobile ================================ */
@media (max-width: 760px) {
  .app, .app:has(.info-panel:not([hidden])) { grid-template-columns: 1fr; }
  .chat { display: none; }
  .app.show-chat .sidebar { display: none; }
  .app.show-chat .chat { display: flex; }
  .back-btn { display: inline-grid; }
  .chat-header { padding: 0 6px; border-left: 0; }
  .ci-menu { display: none; }
  .composer-row { padding: 6px; }
  .composer-row .icon-btn { width: 36px; }
  .composer-context { padding-left: 12px; }
  .picker-panel { height: 300px; }
  .composer { padding-bottom: env(safe-area-inset-bottom); }
  /* menus become a sheet at the bottom, within thumb reach */
  .menu-backdrop { position: fixed; inset: 0; z-index: 49; background: rgba(11, 20, 26, 0.45); }
  .menu {
    left: 0 !important; right: 0; top: auto !important; bottom: var(--keyboard, 0px); max-height: 80dvh; overflow-y: auto;
    border-radius: 18px 18px 0 0; padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); animation: sheet 0.18s ease-out;
  }
  .menu-item { padding: 13px 22px; font-size: 16px; }
  .menu-reactions { justify-content: space-around; padding: 4px 10px 12px; }
  .menu-reactions button { width: 44px; height: 44px; font-size: 28px; }
  .menu-reactions .more { font-size: 18px; }
  .gif-grid { columns: 3 100px; }
  .info-panel { width: 100%; }
  .msg-search { top: 60px; width: 100%; border-radius: 0; }
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 40%, transparent); border-radius: 3px; }
