:root {
  --bg: #0f1020;
  --bg2: #17182b;
  --panel: rgba(25, 27, 46, 0.76);
  --panel-solid: #191b2e;
  --border: rgba(255,255,255,.1);
  --text: #f7f7fb;
  --muted: #a5abc8;
  --accent: #ff3868;
  --accent2: #7c3aed;
  --mine1: #ff3868;
  --mine2: #7c3aed;
  --other: rgba(255,255,255,.08);
  --shadow: 0 24px 80px rgba(0,0,0,.35);
  color-scheme: dark;
}

body[data-theme="light"] {
  --bg: #f4f5fb;
  --bg2: #ffffff;
  --panel: rgba(255,255,255,.78);
  --panel-solid: #ffffff;
  --border: rgba(20,22,40,.1);
  --text: #141629;
  --muted: #626981;
  --accent: #e11d48;
  --accent2: #2563eb;
  --mine1: #f43f5e;
  --mine2: #2563eb;
  --other: rgba(20,22,40,.06);
  color-scheme: light;
}

body[data-theme="aurora"] {
  --bg: #10091b;
  --bg2: #17132b;
  --accent: #22c55e;
  --accent2: #06b6d4;
  --mine1: #22c55e;
  --mine2: #06b6d4;
}

body[data-theme="ocean"] {
  --bg: #06131f;
  --bg2: #0b2035;
  --accent: #38bdf8;
  --accent2: #6366f1;
  --mine1: #38bdf8;
  --mine2: #6366f1;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--accent) 26%, transparent), transparent 32%),
    radial-gradient(circle at 90% 20%, color-mix(in srgb, var(--accent2) 22%, transparent), transparent 36%),
    linear-gradient(135deg, var(--bg), var(--bg2));
  color: var(--text);
  overflow: hidden;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.5; }

.app-shell { height: 100vh; }
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.orb {
  position: absolute;
  width: 420px;
  height: 420px;
  border-radius: 999px;
  filter: blur(40px);
  opacity: .25;
}
.orb-a { background: var(--accent); top: -120px; left: -80px; }
.orb-b { background: var(--accent2); bottom: -150px; right: -120px; }
.login-card {
  position: relative;
  width: min(380px, 100%);
  padding: 24px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  border-radius: 24px;
}
.login-logo-wrap { display: flex; justify-content: center; margin: 0 0 22px; }
.login-logo { width: 190px; max-width: 80%; height: auto; object-fit: contain; }
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}
.brand.mini { margin: 0; }
.side-logo { width: 150px; height: auto; object-fit: contain; }
.brand-mark {
  width: 50px;
  height: 50px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 25px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  box-shadow: 0 16px 36px color-mix(in srgb, var(--accent) 34%, transparent);
}
.brand h1, .brand h2 { margin: 0; line-height: 1; }
.brand p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
label { display: block; margin: 13px 0; }
label span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel-solid) 72%, transparent);
  color: var(--text);
  border-radius: 14px;
  outline: none;
  padding: 11px 13px;
}
input:focus, textarea:focus { border-color: color-mix(in srgb, var(--accent) 70%, white); }
.alert {
  background: rgba(244, 63, 94, .14);
  border: 1px solid rgba(244,63,94,.28);
  color: #ff8fa3;
  padding: 12px 14px;
  border-radius: 16px;
  margin: 12px 0;
}
.primary-btn, .send-btn, .soft-btn, .icon-btn {
  border: 0;
  color: var(--text);
}
.primary-btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: 15px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  box-shadow: 0 20px 45px color-mix(in srgb, var(--accent) 25%, transparent);
}

.chat-view {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  height: 100vh;
}
.sidebar, .settings-panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
}
.sidebar {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.side-top, .chat-header, .panel-head, .header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--other);
}
.soft-btn {
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--other);
}
.soft-btn.danger { color: #fb7185; }
.searchbox {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0 12px;
  background: var(--other);
}
.searchbox input { border: 0; background: transparent; padding-left: 0; }
.rooms { display: grid; gap: 8px; overflow: auto; }
.room {
  display: flex;
  gap: 12px;
  padding: 10px;
  border-radius: 15px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.room.active, .room:hover {
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 16%, transparent), color-mix(in srgb, var(--accent2) 12%, transparent));
  border-color: var(--border);
}
.room-ico {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.room-title { font-weight: 750; }
.room-desc { color: var(--muted); font-size: 12px; margin-top: 3px; }
.unread-badge {
  margin-left: auto;
  align-self: center;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0 7px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 800;
}
.profile-box {
  margin-top: auto;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 17px;
  background: var(--other);
}
.profile-line { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: white;
}
.conversation {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  min-height: 0;
  position: relative;
}
.chat-header {
  min-height: 54px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  backdrop-filter: blur(16px);
}
.chat-header h2 { margin: 0; }
.chat-header p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.chat-header h2 {
  max-width: 52vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20px;
  line-height: 1.1;
}
.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pinned-box {
  margin: 8px 14px 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-solid));
  color: var(--text);
  font-size: 13px;
}
.pinned-link {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.msg.highlight .bubble,
.msg.highlight .attachment,
.msg.highlight .reply-quote {
  outline: 2px solid color-mix(in srgb, var(--accent) 80%, white);
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 16%, transparent);
}
.jump-bottom {
  position: absolute;
  right: 18px;
  bottom: 76px;
  z-index: 10;
  border: 0;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  font-size: 20px;
  box-shadow: var(--shadow);
}
.msg {
  display: grid;
  grid-template-columns: 36px minmax(0, 680px);
  gap: 8px;
  align-items: end;
}
.msg.mine {
  grid-template-columns: minmax(0, 680px) 36px;
  align-self: flex-end;
}
.msg.mine .avatar { grid-column: 2; }
.msg.mine .bubble-wrap { grid-column: 1; grid-row: 1; align-items: flex-end; }
.bubble-wrap { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; }
.meta { display: flex; gap: 8px; align-items: baseline; color: var(--muted); font-size: 12px; padding: 0 6px; }
.meta strong { color: var(--text); }
.user-link {
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.user-link:hover { text-decoration: underline; }
.avatar-btn {
  border: 0;
  padding: 0;
  cursor: pointer;
}
.badge {
  border-radius: 999px;
  padding: 2px 7px;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: color-mix(in srgb, var(--accent) 70%, white);
  font-size: 11px;
}
.bubble {
  padding: 9px 12px;
  border-radius: 16px 16px 16px 7px;
  background: var(--other);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 12px 26px rgba(0,0,0,.08);
}
.edit-inline {
  display: grid;
  gap: 6px;
}
.edit-inline textarea {
  min-width: min(520px, 72vw);
  min-height: 70px;
}
.edit-actions { display: flex; justify-content: flex-end; gap: 6px; }
.mine .bubble {
  border-radius: 16px 16px 7px 16px;
  color: white;
  background: linear-gradient(135deg, var(--mine1), var(--mine2));
  border: 0;
}
body.no-gradient .mine .bubble {
  background: color-mix(in srgb, var(--accent) 80%, black);
}
.reactions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 6px;
}
.reaction, .react-add, .msg-action {
  border: 1px solid var(--border);
  background: var(--other);
  color: var(--text);
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 12px;
}
.reply-quote {
  width: 100%;
  max-width: min(520px, 72vw);
  padding: 7px 9px;
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--muted);
  font-size: 12px;
}
.reply-quote b { color: var(--text); }
.profile-info {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}
.profile-info div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--other) 76%, transparent);
}
.profile-info span { color: var(--muted); }
.profile-info b {
  color: var(--text);
  text-align: right;
}
.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 38px 38px minmax(0, 1fr) 46px;
  grid-auto-rows: min-content;
  align-items: end;
  gap: 8px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 84%, transparent);
}
.reply-preview {
  grid-column: 1 / -1;
  grid-row: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 13px;
  background: color-mix(in srgb, var(--accent) 10%, var(--other));
  color: var(--muted);
  font-size: 13px;
}
.composer textarea {
  resize: none;
  min-height: 38px;
  max-height: 140px;
  grid-column: 3;
  grid-row: auto;
}
.send-btn {
  width: 46px;
  height: 38px;
  align-self: end;
  grid-column: 4;
  grid-row: auto;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  font-size: 20px;
}
.composer { position: relative; }
.composer-popover, .reaction-popover {
  position: absolute;
  z-index: 50;
  display: flex;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}
.composer-popover { left: 18px; bottom: 64px; }
.reaction-popover { transform: translateY(-8px); }
.composer-popover button, .reaction-popover button {
  border: 0;
  background: var(--other);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 12px;
  font-size: 18px;
}
.msg-tools {
  display: flex;
  gap: 5px;
  opacity: .82;
  transition: opacity .15s ease;
}
.msg:hover .msg-tools { opacity: 1; }
.attachment {
  max-width: min(520px, 72vw);
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--border);
}
.attachment img, .attachment video {
  display: block;
  max-width: 100%;
  max-height: 360px;
}
.attachment-preview {
  grid-column: 1 / -1;
  grid-row: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--other);
  color: var(--muted);
  font-size: 13px;
}
.avatar-img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}
.avatar-setting {
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar-upload {
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 12px;
  border-radius: 13px;
  background: var(--other);
  cursor: pointer;
}
.avatar-upload input { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0,0,0,.48);
  backdrop-filter: blur(10px);
}
.modal-card {
  width: min(420px, 100%);
  max-height: 88vh;
  overflow: auto;
  padding: 16px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.profile-card { display: grid; gap: 12px; }
.profile-head { display: flex; align-items: center; gap: 12px; }
.react-user { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(360px, 92vw);
  height: 100vh;
  padding: 18px;
  border-left: 1px solid var(--border);
  border-right: 0;
  box-shadow: var(--shadow);
  z-index: 20;
}
.setting-block {
  border: 1px solid var(--border);
  background: var(--other);
  border-radius: 20px;
  padding: 14px;
  margin-top: 14px;
}
.setting-block h4 { margin: 0 0 12px; }
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-dot {
  padding: 12px;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 16px;
}
.theme-dot.midnight { background: linear-gradient(135deg, #0f1020, #7c3aed); }
.theme-dot.light { background: linear-gradient(135deg, #fff, #e2e8f0); color: #111827; }
.theme-dot.aurora { background: linear-gradient(135deg, #111827, #22c55e); }
.theme-dot.ocean { background: linear-gradient(135deg, #06131f, #38bdf8); }
.switch-row { display: flex; align-items: center; justify-content: space-between; margin: 10px 0; }
.switch-row input { width: auto; }
.emoji-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-picker button { border: 0; border-radius: 12px; background: var(--other); padding: 8px 10px; }

body.compact .messages { gap: 8px; padding-top: 16px; padding-bottom: 16px; }
body.compact .bubble { padding: 9px 12px; }

@media (max-width: 820px) {
  .chat-view { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 86vw;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .chat-header {
    min-height: 46px;
    padding: 6px 8px;
    gap: 6px;
  }
  .chat-header h2 {
    max-width: 46vw;
    font-size: 15px;
    line-height: 1.1;
  }
  .chat-header p { display: none; }
  .header-actions { gap: 5px; }
  .header-actions .soft-btn {
    padding: 6px 8px;
    border-radius: 10px;
    font-size: 0;
    min-width: 38px;
    height: 34px;
  }
  #notifyBtn::before {
    content: "🔔";
    font-size: 16px;
  }
  #logoutBtn::before {
    content: "↪";
    font-size: 17px;
  }
  .messages { padding-left: 10px; padding-right: 10px; padding-top: 12px; }
  .composer { padding-left: 10px; padding-right: 10px; }
}
