:root {
  color-scheme: dark;
  --bg: #07101f;
  --panel: rgba(11, 19, 34, .88);
  --panel-2: rgba(19, 30, 49, .84);
  --line: rgba(255,255,255,.12);
  --text: #eef5ff;
  --muted: #9fb0c6;
  --blue: #3193ff;
  --green: #2be7a2;
  --danger: #ff5870;
  --shadow: 0 22px 70px rgba(0,0,0,.36);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, textarea, select {
  font: inherit;
}

button {
  border: 0;
  color: var(--text);
  cursor: pointer;
}

.hidden { display: none !important; }
.mobile-only { display: none; }

.auth-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 18% 12%, rgba(49,147,255,.26), transparent 34%),
    radial-gradient(circle at 86% 76%, rgba(43,231,162,.18), transparent 32%),
    url("/web/assets/chat_bg.png") center / cover fixed,
    #07101f;
}

.auth-card {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(8, 15, 28, .82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.auth-logo {
  width: 82px;
  height: 82px;
  border-radius: 24px;
  display: block;
  margin: 0 auto 16px;
  box-shadow: 0 16px 44px rgba(100, 70, 255, .32);
}

.auth-card h1,
.auth-card p {
  text-align: center;
  margin: 0;
}

.auth-card h1 {
  font-size: 36px;
}

.auth-card p {
  color: var(--muted);
  margin-top: 8px;
  margin-bottom: 22px;
}

input, textarea {
  width: 100%;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  outline: 0;
  color: var(--text);
  background: rgba(255,255,255,.08);
}

input {
  height: 48px;
  padding: 0 15px;
}

select {
  width: 100%;
  height: 48px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  padding: 0 15px;
  outline: 0;
  color: var(--text);
  background: rgba(255,255,255,.08);
}

textarea {
  min-height: 96px;
  padding: 13px 15px;
  resize: vertical;
}

.auth-card input + input {
  margin-top: 10px;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.auth-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.auth-actions button,
.profile-card button,
.channel-form button {
  height: 46px;
  border-radius: 15px;
  background: rgba(255,255,255,.1);
}

.auth-actions .primary,
.send-btn,
.profile-card .primary,
.channel-form .primary {
  color: white;
  background: linear-gradient(135deg, #2d8cff, #36d9a0);
}

.error {
  min-height: 20px;
  margin-top: 14px;
  color: #ffb4bf;
  text-align: center;
}

.app-shell {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 380px 1fr;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 4%, rgba(49,147,255,.24), transparent 30%),
    radial-gradient(circle at 92% 94%, rgba(43,231,162,.16), transparent 32%),
    #07101f;
}

.sidebar {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: rgba(7, 13, 25, .86);
  backdrop-filter: blur(20px);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 12px;
}

.brand-row img {
  width: 48px;
  height: 48px;
  border-radius: 15px;
}

.brand-row strong,
.head-title strong {
  display: block;
  font-size: 18px;
}

.brand-row span,
.head-title span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.search-row {
  padding: 0 14px 12px;
}

.tab-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 0 12px 12px;
}

.tab-row button {
  position: relative;
  height: 42px;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.tab-row button.active {
  color: white;
  background: rgba(49,147,255,.22);
}

#unreadBadge:not(:empty) {
  display: inline-grid;
  min-width: 19px;
  height: 19px;
  place-items: center;
  margin-left: 4px;
  border-radius: 99px;
  background: var(--danger);
  color: white;
  font-size: 11px;
}

.list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 10px 16px;
}

.item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 10px;
  border-radius: 18px;
  background: transparent;
  text-align: left;
}

.item:hover,
.item.active {
  background: rgba(255,255,255,.08);
}

.avatar,
.avatar-fallback {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}

.avatar-fallback {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2d8cff, #c34dff);
  color: white;
  font-weight: 800;
}

.item-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
}

.item-copy {
  min-width: 0;
  overflow: hidden;
}

.check {
  color: var(--blue);
}

.item-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-pill {
  min-width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  padding: 0 8px;
  border-radius: 99px;
  background: var(--blue);
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.main {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: 76px 1fr auto;
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 13, 25, .74);
  backdrop-filter: blur(20px);
  z-index: 3;
}

.head-title {
  min-width: 0;
  flex: 1;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.messages {
  position: relative;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 18px 18px 22px;
  background:
    linear-gradient(rgba(7, 13, 25, .62), rgba(7, 13, 25, .62)),
    url("/web/assets/chat_bg.png") center / 420px auto repeat;
}

.messages.light {
  background:
    linear-gradient(rgba(246, 248, 252, .66), rgba(246, 248, 252, .66)),
    url("/web/assets/chat_bg_light.png") center / 420px auto repeat;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.day-note,
.system-note {
  width: fit-content;
  max-width: min(520px, 100%);
  margin: 10px auto;
  padding: 8px 12px;
  border-radius: 99px;
  color: var(--muted);
  background: rgba(0,0,0,.22);
  font-size: 13px;
}

.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 8px 0;
}

.message.mine {
  justify-content: flex-end;
}

.bubble {
  max-width: min(680px, 72%);
  padding: 10px 12px 8px;
  border-radius: 18px;
  background: rgba(15, 24, 40, .92);
  box-shadow: 0 10px 30px rgba(0,0,0,.14);
}

.message.mine .bubble {
  background: linear-gradient(135deg, rgba(45,140,255,.94), rgba(41,205,158,.92));
}

.bubble img,
.bubble video {
  display: block;
  max-width: min(420px, 100%);
  max-height: 420px;
  border-radius: 14px;
  object-fit: cover;
  background: rgba(0,0,0,.24);
}

.bubble audio {
  width: min(330px, 70vw);
}

.file-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
  padding: 10px;
  border-radius: 14px;
  color: var(--text);
  text-decoration: none;
  background: rgba(255,255,255,.08);
}

.meta {
  margin-top: 5px;
  color: rgba(238,245,255,.72);
  font-size: 11px;
  text-align: right;
}

.reactions {
  margin-top: 5px;
  color: white;
  font-size: 13px;
}

.message-menu {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
  opacity: 0;
}

.message:hover .message-menu {
  opacity: 1;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: end center;
  padding: 18px;
  background: rgba(0,0,0,.38);
}

.action-sheet {
  width: min(420px, 100%);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(8, 15, 28, .96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.sheet-title {
  padding: 8px 10px 12px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.action-sheet button {
  width: 100%;
  height: 46px;
  margin-top: 6px;
  border-radius: 16px;
  background: rgba(255,255,255,.09);
}

.action-sheet .danger {
  color: #ffb4bf;
}

.composer {
  display: grid;
  grid-template-columns: 44px 44px 1fr 48px;
  gap: 8px;
  align-items: center;
  padding: 12px 16px calc(28px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(7, 13, 25, .84);
  backdrop-filter: blur(22px);
}

.composer input {
  height: 46px;
  border-radius: 23px;
}

.send-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-weight: 900;
}

.profile-card,
.admin-card,
.channel-form,
.post-card,
.comment-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  margin: 0 auto 12px;
  width: min(720px, 100%);
  background: rgba(9, 16, 30, .86);
  backdrop-filter: blur(16px);
}

.profile-card label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin: 14px 0 6px;
}

.profile-card .primary,
.channel-form .primary {
  margin-top: 12px;
  width: 100%;
}

.profile-card > button {
  width: 100%;
  margin-top: 10px;
}

.settings-menu {
  width: min(720px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 10px;
}

.settings-button {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 68px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(9, 16, 30, .86);
  text-align: left;
  backdrop-filter: blur(16px);
}

.settings-button strong,
.settings-button small {
  display: block;
}

.settings-button small {
  margin-top: 3px;
  color: var(--muted);
}

.settings-button b {
  font-size: 28px;
  color: var(--muted);
}

.settings-back {
  width: min(720px, 100%);
  height: 42px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.09);
  color: var(--text);
}

.admin-card h2,
.admin-card h3 {
  margin: 0 0 12px;
}

.admin-card h3 {
  margin-top: 18px;
  color: var(--muted);
  font-size: 15px;
}

.admin-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid rgba(255,255,255,.08);
}

.admin-info {
  min-width: 0;
}

.admin-info strong,
.admin-info span {
  display: block;
}

.admin-info span,
.admin-muted {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-actions button {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.1);
}

.admin-actions .primary {
  background: linear-gradient(135deg, #2d8cff, #36d9a0);
}

.post-head {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  margin-bottom: 8px;
}

.post-text {
  white-space: pre-wrap;
  line-height: 1.45;
}

.post-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.post-actions button {
  height: 36px;
  padding: 0 12px;
  border-radius: 18px;
  background: rgba(255,255,255,.1);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  min-width: min(380px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(10, 18, 31, .96);
  color: var(--text);
  box-shadow: var(--shadow);
  text-align: center;
}

.call-panel {
  position: fixed;
  left: 50%;
  top: max(18px, env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 90;
  width: min(420px, calc(100vw - 28px));
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(8, 15, 28, .96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  text-align: center;
}

.call-panel span {
  color: var(--muted);
  font-size: 13px;
}

.call-actions {
  display: flex;
  gap: 8px;
}

.call-actions button {
  flex: 1;
  min-height: 42px;
  border-radius: 16px;
  background: rgba(255,255,255,.1);
}

.call-actions .primary {
  background: linear-gradient(135deg, #2d8cff, #36d9a0);
}

.call-actions .danger {
  background: rgba(255,88,112,.22);
  color: #ffd6dc;
}

body.light-style {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: rgba(255,255,255,.9);
  --panel-2: rgba(248,250,255,.9);
  --line: rgba(18, 32, 51, .12);
  --text: #142033;
  --muted: #65758d;
  --shadow: 0 22px 70px rgba(48, 64, 90, .18);
}

body.light-style .auth-shell,
body.light-style .app-shell {
  background:
    radial-gradient(circle at 18% 12%, rgba(49,147,255,.18), transparent 34%),
    radial-gradient(circle at 86% 76%, rgba(43,231,162,.18), transparent 32%),
    #f5f7fb;
}

body.light-style .sidebar,
body.light-style .chat-head,
body.light-style .composer,
body.light-style .profile-card,
body.light-style .admin-card,
body.light-style .settings-button,
body.light-style .post-card,
body.light-style .comment-card,
body.light-style .action-sheet,
body.light-style .call-panel {
  background-color: rgba(255,255,255,.88);
  color: var(--text);
}

body.light-style input,
body.light-style textarea,
body.light-style select {
  background: rgba(255,255,255,.92);
  color: var(--text);
  border-color: rgba(18, 32, 51, .14);
}

body.light-style .messages {
  background:
    linear-gradient(rgba(246, 248, 252, .72), rgba(246, 248, 252, .72)),
    url("/web/assets/chat_bg_light.png") center / 420px auto repeat;
}

body.light-style .bubble {
  background: rgba(255,255,255,.96);
  color: var(--text);
}

body.light-style .message.mine .bubble {
  color: white;
}

body.light-style .meta,
body.light-style .reactions {
  color: rgba(20, 32, 51, .72);
}

body.light-style .message.mine .meta,
body.light-style .message.mine .reactions {
  color: rgba(255,255,255,.82);
}

body.light-style .icon-btn,
body.light-style .message-menu,
body.light-style .post-actions button,
body.light-style .profile-card > button {
  background: rgba(18, 32, 51, .08);
  color: var(--text);
}

body.light-style .file-link {
  color: var(--text);
  background: rgba(18, 32, 51, .07);
}

body.light-style .tab-row {
  background: rgba(255,255,255,.72);
  border-color: rgba(18, 32, 51, .12);
}

body.light-style .tab-row button {
  color: #111827;
}

body.light-style .tab-row button.active {
  color: white;
}

body.aurora-style {
  --bg: #06111b;
}

body.aurora-style .auth-shell,
body.aurora-style .app-shell {
  background:
    linear-gradient(118deg, rgba(6,17,27,.94), rgba(15,70,105,.88), rgba(23,178,132,.76), rgba(8,21,40,.94)),
    url("/web/assets/chat_bg.png") center / 520px auto repeat,
    #06111b;
  background-size: 220% 220%, 520px auto, auto;
  animation: auroraShift 12s ease-in-out infinite;
}

body.aurora-style .sidebar,
body.aurora-style .chat-head,
body.aurora-style .composer,
body.aurora-style .profile-card,
body.aurora-style .admin-card,
body.aurora-style .settings-button,
body.aurora-style .post-card,
body.aurora-style .comment-card {
  background-color: rgba(5, 12, 23, .76);
  border-color: rgba(255,255,255,.16);
}

body.aurora-style .messages {
  background:
    linear-gradient(rgba(5, 12, 23, .64), rgba(5, 12, 23, .64)),
    url("/web/assets/chat_bg.png") center / 420px auto repeat;
}

@keyframes auroraShift {
  0%, 100% { background-position: 0% 50%, center, center; }
  50% { background-position: 100% 50%, center, center; }
}

@media (max-width: 1024px) {
  .mobile-only { display: grid; }

  .app-shell {
    grid-template-columns: 1fr;
    height: 100dvh;
  }

  .sidebar {
    position: absolute;
    inset: 0;
    z-index: 5;
    border-right: 0;
  }

  .app-shell:not(.chat-open) .main {
    display: none;
  }

  .app-shell.chat-open .sidebar {
    visibility: visible;
    pointer-events: none;
    transform: none;
    background: transparent;
    backdrop-filter: none;
  }

  .app-shell.chat-open .brand-row,
  .app-shell.chat-open .search-row,
  .app-shell.chat-open .list {
    display: none;
  }

  .app-shell.chat-open .tab-row {
    display: none;
  }

  .app-shell.chat-open.tabs-visible .tab-row {
    display: grid;
    visibility: visible;
    pointer-events: auto;
  }

  .app-shell.chat-open .main {
    display: grid;
    width: 100vw;
  }

  .main {
    height: 100dvh;
  }

  .chat-head {
    padding-top: calc(9px + env(safe-area-inset-top));
    min-height: calc(68px + env(safe-area-inset-top));
  }

  .messages {
    padding: 12px 10px calc(102px + env(safe-area-inset-bottom));
  }

  .bubble {
    max-width: 84%;
  }

  .message-menu {
    opacity: 1;
  }

  .composer {
    grid-template-columns: 42px 42px 1fr 46px;
    padding: 10px 10px calc(92px + env(safe-area-inset-bottom));
  }

  .tab-row {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 20;
    gap: 4px;
    padding: 8px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 30px;
    background: rgba(255,255,255,.13);
    box-shadow: 0 18px 46px rgba(0,0,0,.38);
    backdrop-filter: blur(22px);
    order: 4;
  }

  .tab-row button {
    height: 54px;
    border-radius: 24px;
    font-size: 12px;
    color: rgba(255,255,255,.7);
  }

  .tab-row button.active {
    color: white;
    background: rgba(49,147,255,.42);
  }

  .list {
    flex: 1;
    padding-bottom: calc(98px + env(safe-area-inset-bottom));
  }

  .brand-row {
    padding-top: calc(18px + env(safe-area-inset-top));
  }

  .admin-row {
    grid-template-columns: 1fr;
  }

  .admin-actions {
    justify-content: flex-start;
  }
}
