:root,
[data-theme="dark"] {
  --bg: #000000;
  --surface: #121214;
  --surface-2: #1c1c1e;
  --surface-3: #2c2c2e;
  --border: #222224;
  --text: #ffffff;
  --text-2: #8e8e93;
  --accent: #6B189A;
  --accent-light: #9333ea;
  --bubble-out: #6B189A;
  --bubble-out-text: #ffffff;
  --bubble-in: #1c1c1e;
  --bubble-in-text: #ffffff;
  --danger: #ff453a;
  --blue: #0a84ff;
  --header-bg: rgba(12, 12, 14, 0.92);
  --wallpaper-opacity: 0.055;
  --msg-font-size: 15px;
}

[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f2f2f7;
  --surface-2: #ffffff;
  --surface-3: #e5e5ea;
  --border: #e5e5ea;
  --text: #000000;
  --text-2: #6c6c70;
  --accent: #6B189A;
  --accent-light: #7e22ce;
  --bubble-out: #6B189A;
  --bubble-out-text: #ffffff;
  --bubble-in: #f2f2f7;
  --bubble-in-text: #000000;
  --danger: #ff3b30;
  --blue: #007aff;
  --header-bg: rgba(255, 255, 255, 0.92);
  --wallpaper-opacity: 0.04;
  --msg-font-size: 15px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
  user-select: none;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-new(root) {
  z-index: 9999;
}

#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9998;
}

.hidden {
  display: none !important;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}

.screen.active {
  display: flex;
}

#auth-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.auth-box {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.app-logo {
  width: 82px;
  height: 82px;
  border-radius: 22px;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin-bottom: 16px;
  overflow: hidden;
}

.app-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.auth-box h1 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 6px;
}

.auth-sub {
  color: var(--text-2);
  font-size: 14px;
  margin-bottom: 22px;
}

.auth-tabs {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 18px;
}

.auth-tab {
  border: none;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 4px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.auth-tab.active {
  background: var(--surface-3);
  color: var(--text);
}

#auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field input,
.form-group input,
.form-group textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 13px 14px;
  outline: none;
  transition: border-color 0.2s;
}

.field input:focus,
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.segmented.small {
  width: 132px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--accent);
  color: #ffffff;
}

.primary-btn {
  width: 100%;
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 14px;
  border-radius: 12px;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity 0.15s, transform 0.1s;
}

.primary-btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  padding: 4px 0;
}

.main-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.tab-view {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.tab-view.active {
  display: flex;
}

.ios-header {
  background: var(--header-bg);
  border-bottom: 0.5px solid var(--border);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
}

.header-spacer {
  width: 34px;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  min-width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
}

.icon-btn:active {
  opacity: 0.6;
}

.text-btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  width: auto;
  padding: 0 6px;
}

.accent-text { color: var(--accent-light); }
.danger-text { color: var(--danger); }
.muted-text { color: var(--text-2); }

.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--text-2);
}

.search-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.scroll-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.empty-state {
  height: 100%;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  gap: 10px;
  padding: 32px;
  text-align: center;
}

.empty-state i {
  font-size: 42px;
  opacity: 0.5;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}

.chat-item:active {
  background: var(--surface);
}

.chat-item::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 78px;
  height: 0.5px;
  background: var(--border);
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 600;
  font-size: 20px;
  overflow: hidden;
  position: relative;
}

.avatar.sm {
  width: 38px;
  height: 38px;
  font-size: 15px;
}

.avatar.lg {
  width: 92px;
  height: 92px;
  font-size: 34px;
}

.avatar img,
.avatar video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-item-name {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-size: 12px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.chat-item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-item-preview {
  font-size: 14px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.verified-badge {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.ios-tabbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--header-bg);
  border-top: 0.5px solid var(--border);
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 6px);
  z-index: 10;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

.tab-btn i {
  font-size: 24px;
}

.tab-btn span {
  font-size: 10px;
  font-weight: 500;
}

.tab-btn.active {
  color: var(--accent-light);
}

.settings-body {
  padding: 16px 14px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.profile-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 8px 0;
}

.profile-hero-name {
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
}

.profile-hero-sub {
  font-size: 13px;
  color: var(--text-2);
}

.ios-group {
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
}

.ios-row {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  position: relative;
  text-align: right;
}

.ios-row:not(:last-child)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 14px;
  height: 0.5px;
  background: var(--border);
}

.static-row {
  cursor: default;
  justify-content: space-between;
}

.row-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.accent-bg { background: var(--accent); }
.blue-bg { background: var(--blue); }

.row-label {
  flex: 1;
}

.row-arrow {
  color: var(--text-2);
  font-size: 16px;
}

.font-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mini-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: var(--surface-3);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.ios-switch {
  position: relative;
  width: 48px;
  height: 28px;
}

.ios-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border-radius: 28px;
  transition: background 0.2s;
  cursor: pointer;
}

.slider::before {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  left: 2px;
  top: 2px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.ios-switch input:checked + .slider {
  background: var(--accent);
}

.ios-switch input:checked + .slider::before {
  transform: translateX(20px);
}

.form-group {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.slide-page {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  z-index: 30;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.slide-page.open {
  transform: translateX(0);
  pointer-events: auto;
}

.modal-page {
  z-index: 40;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  background: var(--header-bg);
  border-bottom: 0.5px solid var(--border);
  z-index: 5;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
  text-align: center;
  cursor: pointer;
}

.chat-header-title {
  font-size: 16px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
}

.chat-header-status {
  font-size: 12px;
  color: var(--text-2);
}

.chat-header-status.typing {
  color: var(--accent-light);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%23888888' stroke-opacity='0.14' stroke-width='1.2'%3E%3Ccircle cx='20' cy='20' r='8'/%3E%3Cpath d='M75 18l10 10-10 10-10-10z'/%3E%3Cpath d='M25 85c6-8 14-8 20 0'/%3E%3Crect x='80' y='78' width='16' height='16' rx='4'/%3E%3Ccircle cx='60' cy='58' r='4'/%3E%3C/g%3E%3C/svg%3E");
}

.date-divider {
  align-self: center;
  background: rgba(120, 120, 128, 0.28);
  color: var(--text);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 14px;
  margin: 10px 0 6px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  position: relative;
  transition: transform 0.12s ease-out;
  touch-action: pan-y;
}

.msg-row.out {
  align-self: flex-start;
}

.msg-row.in {
  align-self: flex-end;
}

.msg-bubble {
  padding: 8px 12px 6px;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  user-select: text;
}

.msg-row.out .msg-bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 5px;
}

.msg-row.in .msg-bubble {
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  border-bottom-left-radius: 5px;
}

.msg-reply-preview {
  border-right: 2px solid rgba(255, 255, 255, 0.65);
  background: rgba(0, 0, 0, 0.16);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 5px;
  font-size: 12px;
  cursor: pointer;
}

.msg-row.in .msg-reply-preview {
  border-right-color: var(--accent-light);
  background: rgba(107, 24, 154, 0.12);
}

.msg-reply-author {
  font-weight: 600;
  font-size: 11px;
  margin-bottom: 1px;
}

.msg-reply-snippet {
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.msg-text {
  font-size: var(--msg-font-size);
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg-text a {
  color: #d8b4fe;
  text-decoration: underline;
}

.msg-row.in .msg-text a {
  color: var(--accent-light);
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
  font-size: 11px;
  opacity: 0.72;
}

.msg-ticks {
  font-size: 14px;
  display: inline-flex;
  align-items: center;
}

.scroll-bottom-btn {
  position: absolute;
  left: 14px;
  bottom: 76px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  z-index: 6;
}

.unread-pill {
  position: absolute;
  top: -8px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #ffffff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.compose-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--surface);
  border-top: 0.5px solid var(--border);
}

.compose-context-line {
  width: 3px;
  height: 32px;
  border-radius: 2px;
  background: var(--accent-light);
}

.compose-context-body {
  flex: 1;
  min-width: 0;
}

.compose-context-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-light);
}

.compose-context-text {
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--header-bg);
  border-top: 0.5px solid var(--border);
}

#msg-input {
  flex: 1;
  max-height: 120px;
  min-height: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 8px 14px;
  resize: none;
  outline: none;
  line-height: 1.4;
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.send-btn:active {
  transform: scale(0.92);
}

.context-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}

.context-sheet {
  width: 100%;
  max-width: 360px;
  background: var(--surface-2);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.context-item {
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.context-item:not(:last-child) {
  border-bottom: 0.5px solid var(--border);
}

.context-item:active {
  background: var(--surface-3);
}

.ios-dialog {
  width: 100%;
  max-width: 300px;
  background: var(--surface-2);
  border-radius: 16px;
  overflow: hidden;
  text-align: center;
  align-self: center;
}

.ios-dialog h3 {
  font-size: 16px;
  padding: 16px 16px 4px;
}

.ios-dialog p {
  font-size: 13px;
  color: var(--text-2);
  padding: 0 16px 14px;
}

.dialog-btn {
  width: 100%;
  border: none;
  border-top: 0.5px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 13px;
  cursor: pointer;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 12px;
}

.media-thumb {
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  position: relative;
}

.media-thumb img,
.media-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-del-btn {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.7);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.profile-info-card {
  margin: 12px 14px;
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-info-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.profile-info-label {
  font-size: 12px;
  color: var(--text-2);
}

.profile-info-val {
  font-size: 15px;
}
