:root {
  --font-fa: "IRANSansX", "Vazirmatn", "Yekan Bakh", "Sahel", "Shabnam", "Segoe UI", Tahoma, sans-serif;

  --bg-main: #080e1c;
  --bg-sub: #101a31;
  --bg-glow-1: rgba(68, 141, 255, 0.28);
  --bg-glow-2: rgba(29, 227, 204, 0.2);

  --ink: #e8efff;
  --muted: #93a9ce;

  --card: rgba(15, 23, 41, 0.62);
  --card-border: rgba(151, 183, 236, 0.24);
  --card-shadow: 0 18px 44px rgba(3, 8, 22, 0.52);

  --accent: #4a9dff;
  --accent-soft: rgba(74, 157, 255, 0.2);
  --success: #34d39d;
  --danger: #ff5c73;

  --bubble: rgba(19, 31, 54, 0.92);
  --bubble-me: rgba(16, 45, 88, 0.95);
  --bubble-border: rgba(128, 164, 223, 0.25);

  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 11px;
}

body[data-theme="light"] {
  --bg-main: #f3f7ff;
  --bg-sub: #e8efff;
  --bg-glow-1: rgba(97, 163, 255, 0.36);
  --bg-glow-2: rgba(67, 219, 195, 0.24);

  --ink: #13233b;
  --muted: #60779a;

  --card: rgba(255, 255, 255, 0.74);
  --card-border: rgba(255, 255, 255, 0.96);
  --card-shadow: 0 15px 36px rgba(18, 32, 53, 0.15);

  --accent: #0a7dff;
  --accent-soft: rgba(10, 125, 255, 0.14);
  --success: #109f67;
  --danger: #d83947;

  --bubble: rgba(255, 255, 255, 0.91);
  --bubble-me: rgba(220, 237, 255, 0.95);
  --bubble-border: rgba(72, 118, 186, 0.19);
}

body[data-theme="ultra"] {
  --bg-main: #000000;
  --bg-sub: #030303;
  --bg-glow-1: rgba(26, 43, 66, 0.35);
  --bg-glow-2: rgba(20, 30, 24, 0.18);

  --ink: #f2f5fb;
  --muted: #8791a5;

  --card: rgba(8, 8, 8, 0.82);
  --card-border: rgba(126, 141, 168, 0.18);
  --card-shadow: 0 22px 50px rgba(0, 0, 0, 0.72);

  --accent: #4596ff;
  --accent-soft: rgba(69, 150, 255, 0.18);
  --success: #2fd092;
  --danger: #ff6178;

  --bubble: rgba(10, 10, 10, 0.95);
  --bubble-me: rgba(14, 26, 47, 0.98);
  --bubble-border: rgba(126, 141, 168, 0.21);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-fa);
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 11%, var(--bg-glow-1) 0%, transparent 42%),
    radial-gradient(circle at 88% 9%, var(--bg-glow-2) 0%, transparent 44%),
    linear-gradient(160deg, var(--bg-main), var(--bg-sub));
}

body {
  min-height: -webkit-fill-available;
  height: var(--app-height, 100dvh);
}

button,
input,
textarea {
  font-family: inherit;
}

.app-shell {
  width: min(1320px, 100%);
  height: var(--app-height, 100dvh);
  margin: 0 auto;
  padding: clamp(8px, 1.8vw, 16px);
  display: grid;
  gap: 10px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.glass {
  backdrop-filter: blur(18px) saturate(1.28);
  background: var(--card);
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow);
}

.topbar {
  border-radius: var(--radius-xl);
  padding: 10px;
  min-height: 0;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(16px, 2.2vw, 22px);
  letter-spacing: 0.01em;
}

.brand p {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.profile-chip {
  border: 1px solid rgba(164, 198, 255, 0.35);
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  padding: 5px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.profile-name {
  font-size: 12px;
  font-weight: 700;
}

.avatar {
  --av-bg1: #4a9dff;
  --av-bg2: #1f59ff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.02em;
  background: linear-gradient(142deg, var(--av-bg1), var(--av-bg2));
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.25), 0 5px 14px rgba(4, 10, 21, 0.35);
}

.avatar-lg {
  width: 58px;
  height: 58px;
  font-size: 16px;
}

.meta-row {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.mode-label {
  font-size: 12px;
  color: var(--muted);
}

.meta-right {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 66%;
}

.typing-indicator {
  min-height: 16px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.online-badge {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: #ddfff0;
  background: rgba(21, 168, 109, 0.3);
  border: 1px solid rgba(59, 204, 142, 0.4);
}

body[data-theme="light"] .online-badge {
  color: #085f3d;
  background: rgba(21, 168, 109, 0.15);
  border-color: rgba(21, 168, 109, 0.27);
}

.tabs-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: nowrap;
}

.tabs,
.dm-users {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
  touch-action: pan-x;
}

.tabs {
  flex: 1;
}

.tabs::-webkit-scrollbar,
.dm-users::-webkit-scrollbar {
  display: none;
}

.tab-btn,
.peer-btn,
.tab-link {
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.14s ease, box-shadow 0.22s ease, border-color 0.22s ease;
}

.peer-btn {
  flex: 0 0 auto;
  max-width: min(76vw, 240px);
  min-width: 0;
}

.tab-link {
  flex: 0 0 auto;
}

body[data-theme="light"] .tab-btn,
body[data-theme="light"] .peer-btn,
body[data-theme="light"] .tab-link {
  background: rgba(255, 255, 255, 0.74);
}

.aparat-link {
  border-color: rgba(255, 97, 97, 0.36);
  background: rgba(255, 74, 74, 0.12);
}

.tab-btn.active,
.peer-btn.active {
  border-color: rgba(108, 171, 255, 0.55);
  background: linear-gradient(130deg, rgba(74, 157, 255, 0.34), rgba(22, 226, 195, 0.26));
  box-shadow: 0 7px 17px rgba(13, 71, 154, 0.25);
}

.tab-btn:active,
.peer-btn:active,
.icon-btn:active,
.action-btn:active,
.ghost-btn:active,
.save-btn:active,
.theme-choice:active,
.menu-action-btn:active,
.menu-react-btn:active,
.tab-link:active {
  transform: scale(0.98);
}

.badge {
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(145deg, #ff6f69, #ff3d63);
}

.dm-users {
  margin-top: 8px;
  width: 100%;
  padding-bottom: 2px;
  align-items: center;
  min-height: 40px;
}

.peer-avatar {
  width: 24px;
  height: 24px;
  font-size: 10px;
}

.peer-text {
  max-width: 132px;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3add94;
  box-shadow: 0 0 0 2px rgba(58, 221, 148, 0.26);
}

.dim {
  margin: 2px 0;
  font-size: 12px;
  color: var(--muted);
}

.chat-feed {
  border-radius: var(--radius-xl);
  border: 1px solid rgba(160, 188, 235, 0.22);
  background: rgba(7, 14, 27, 0.28);
  padding: 10px;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

body[data-theme="light"] .chat-feed {
  background: rgba(255, 255, 255, 0.35);
}

.empty-feed {
  margin: auto;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.msg {
  width: min(100%, 700px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-self: flex-start;
  min-width: 0;
}

.msg.me {
  align-self: flex-end;
  grid-template-columns: minmax(0, 1fr) auto;
}

.msg.me .msg-avatar-wrap {
  order: 2;
}

.msg.me .msg-card {
  order: 1;
}

.msg-avatar-wrap {
  display: flex;
  align-items: flex-end;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  font-size: 11px;
}

.msg-avatar[data-open-dm] {
  cursor: pointer;
}

.msg-card {
  max-width: 100%;
  min-width: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--bubble-border);
  background: var(--bubble);
  box-shadow: 0 9px 20px rgba(2, 9, 20, 0.26);
  padding: 8px 10px;
  overflow: hidden;
}

.msg.me .msg-card {
  background: var(--bubble-me);
}

.msg-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.msg-user {
  font-size: 12px;
  color: var(--ink);
}

.msg-user.dm-openable {
  cursor: pointer;
}

.msg-user.dm-openable:hover {
  text-decoration: underline;
}

.msg-user.dm-openable:focus-visible {
  outline: 2px solid rgba(100, 167, 255, 0.7);
  outline-offset: 2px;
  border-radius: 6px;
}

.msg-time {
  font-size: 11px;
  color: var(--muted);
}

.msg-reply-ref {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  padding: 5px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(165, 188, 231, 0.18);
}

.msg-body {
  margin-top: 6px;
  display: grid;
  gap: 7px;
  min-width: 0;
}

.msg-body p {
  margin: 0;
  line-height: 1.47;
  font-size: 14px;
  color: var(--ink);
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg-body img,
.msg-body video,
.msg-body audio {
  max-width: 100%;
}

.deleted-text {
  color: var(--muted);
  font-style: italic;
}

.msg-image {
  display: block;
  width: auto;
  max-width: min(100%, 310px);
  max-height: min(52vh, 340px);
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
}

.msg-audio {
  width: min(100%, 320px);
}

.msg-file {
  display: inline-block;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  color: #b3dbff;
  padding: 8px 11px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(91, 170, 255, 0.3);
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

body[data-theme="light"] .msg-file {
  color: #0a4f98;
}

.msg-meta {
  margin-top: 5px;
  min-height: 14px;
  font-size: 11px;
  color: var(--muted);
}

.msg-react-summary {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.react-chip {
  border-radius: 999px;
  border: 1px solid rgba(142, 177, 232, 0.32);
  background: rgba(255, 255, 255, 0.07);
  padding: 3px 8px;
  font-size: 11px;
  color: var(--ink);
}

.react-chip.active {
  border-color: rgba(105, 173, 255, 0.56);
  background: rgba(74, 157, 255, 0.26);
}

.composer {
  border-radius: var(--radius-xl);
  padding: 7px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
}

.compose-state {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(145, 178, 234, 0.28);
  background: rgba(255, 255, 255, 0.05);
}

.compose-preview {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.composer-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid rgba(151, 185, 239, 0.25);
  background: rgba(255, 255, 255, 0.06);
}

#messageInput {
  width: 100%;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  min-width: 0;
}

#messageInput::placeholder {
  color: #92a8cb;
}

#messageInput:focus {
  border-color: rgba(95, 164, 255, 0.56);
  box-shadow: 0 0 0 3px rgba(74, 157, 255, 0.18);
}

.icon-btn,
.action-btn,
.ghost-btn,
.save-btn,
.theme-choice,
.menu-action-btn,
.menu-react-btn {
  border: none;
  border-radius: 999px;
  cursor: pointer;
}

.icon-btn {
  width: 34px;
  height: 34px;
  font-size: 15px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
}

.action-btn {
  width: 40px;
  height: 40px;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(140deg, #258dff, #13c3f5);
  box-shadow: 0 9px 18px rgba(28, 146, 255, 0.34);
}

.composer-hint {
  min-height: 15px;
  margin-top: 5px;
  font-size: 11px;
  color: var(--success);
}

.composer-hint:empty {
  display: none;
}

.composer-hint.error {
  color: var(--danger);
}

.emoji-picker {
  margin-top: 8px;
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(142, 177, 236, 0.23);
  background: rgba(0, 0, 0, 0.14);
  display: grid;
  grid-template-columns: repeat(10, minmax(26px, 1fr));
  gap: 6px;
}

body[data-theme="light"] .emoji-picker {
  background: rgba(255, 255, 255, 0.47);
}

.emoji-item {
  border: 1px solid rgba(142, 177, 236, 0.28);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 9px;
  padding: 5px;
  font-size: 16px;
  cursor: pointer;
}

.sheet,
.msg-menu {
  position: fixed;
  inset: 0;
  z-index: 30;
}

.sheet {
  background: rgba(4, 10, 22, 0.5);
  display: grid;
  place-items: end center;
  padding: 12px;
}

.sheet-card {
  width: min(500px, 100%);
  border-radius: var(--radius-xl);
  padding: 12px;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sheet-head h2 {
  margin: 0;
  font-size: 18px;
}

.sheet-body {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.profile-hero {
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-title {
  font-weight: 800;
}

.uid-code {
  color: var(--muted);
  font-size: 12px;
}

.field-label {
  font-size: 12px;
  color: var(--muted);
}

.field-input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(141, 176, 236, 0.3);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}

.field-input:focus {
  border-color: rgba(95, 164, 255, 0.62);
  box-shadow: 0 0 0 3px rgba(74, 157, 255, 0.2);
}

.theme-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.theme-segment {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.theme-choice {
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(145, 171, 219, 0.35);
}

.theme-choice.active {
  border-color: rgba(111, 174, 255, 0.6);
  background: rgba(74, 157, 255, 0.26);
}

.ghost-btn {
  padding: 6px 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(145, 171, 219, 0.36);
}

.save-btn {
  padding: 10px 12px;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(140deg, #2f8dff, #27d1d1);
}

.msg-menu {
  z-index: 45;
  pointer-events: none;
}

.msg-menu-card {
  position: fixed;
  min-width: 250px;
  max-width: min(360px, calc(100vw - 24px));
  border-radius: 18px;
  padding: 10px;
  pointer-events: auto;
}

.msg-menu-reactions,
.msg-menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.msg-menu-actions {
  margin-top: 8px;
}

.menu-react-btn {
  border: 1px solid rgba(143, 177, 232, 0.34);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 5px 9px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.menu-react-btn small {
  font-size: 10px;
  color: var(--muted);
}

.menu-react-btn.active {
  border-color: rgba(109, 176, 255, 0.6);
  background: rgba(74, 157, 255, 0.28);
}

.menu-action-btn {
  border: 1px solid rgba(143, 177, 232, 0.34);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}

.menu-action-btn.danger {
  color: #ffd2d8;
  border-color: rgba(255, 95, 113, 0.4);
  background: rgba(255, 95, 113, 0.15);
}

@media (min-width: 1080px) {
  .app-shell {
    grid-template-columns: 320px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: stretch;
  }

  .topbar {
    grid-column: 1;
    grid-row: 1 / span 2;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .tabs-row {
    flex-direction: column;
    align-items: stretch;
  }

  .tabs,
  .dm-users {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .tab-btn,
  .peer-btn,
  .tab-link {
    width: 100%;
    justify-content: flex-start;
  }

  .chat-feed {
    grid-column: 2;
    grid-row: 1;
    border-radius: 20px;
  }

  .composer {
    grid-column: 2;
    grid-row: 2;
    border-radius: 20px;
  }
}

@media (max-width: 900px) {
  .app-shell {
    padding: 8px;
    gap: 8px;
  }

  .topbar,
  .chat-feed,
  .composer,
  .sheet-card {
    border-radius: 18px;
  }

  .msg {
    width: min(100%, 96vw);
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 6px 6px 4px;
    gap: 6px;
  }

  .topbar {
    padding: 8px;
  }

  .brand p {
    margin-top: 1px;
    font-size: 10px;
  }

  .meta-row {
    margin-top: 6px;
  }

  .tabs-row {
    margin-top: 6px;
    gap: 6px;
  }

  .tab-btn,
  .peer-btn,
  .tab-link {
    padding: 6px 10px;
  }

  .dm-users {
    margin-top: 6px;
  }

  .chat-feed {
    padding: 8px;
  }

  .composer {
    padding: 6px;
    padding-bottom: calc(5px + env(safe-area-inset-bottom));
  }

  .composer-hint {
    min-height: 0;
  }

  .msg-menu {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 10px;
    background: rgba(3, 8, 18, 0.45);
  }

  .msg-menu-card {
    position: relative;
    left: auto !important;
    top: auto !important;
    width: min(580px, 100%);
    max-width: 100%;
  }
}

@media (max-width: 560px) {
  .topbar {
    max-height: min(42dvh, 320px);
    overflow: hidden;
  }

  .title-row {
    align-items: flex-start;
  }

  .profile-chip {
    padding: 4px 8px;
  }

  .profile-name {
    max-width: 82px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand p {
    display: none;
  }

  .msg {
    width: 100%;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px;
  }

  .msg.me {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .msg-avatar {
    width: 24px;
    height: 24px;
    font-size: 10px;
  }

  .tabs-row {
    align-items: center;
    gap: 5px;
  }

  .tab-btn,
  .tab-link {
    font-size: 12px;
    padding: 6px 9px;
  }

  .peer-btn {
    max-width: min(82vw, 190px);
  }

  .peer-text {
    max-width: 96px;
  }

  .typing-indicator {
    max-width: 120px;
  }

  .meta-right .typing-indicator {
    display: none;
  }
}

@media (hover: none) and (pointer: coarse) {
  #emojiBtn {
    display: none;
  }

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