/* ================= CHAT UI ================= */

#chat > .card {
  position: relative;
  overflow: hidden;
}

#chat > .card::before {
  content: "";
  display: block;
  height: 4px;
  width: 72px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  margin-bottom: 20px;
  box-shadow: 0 0 18px rgba(158, 182, 92, 0.34);
}

.chat-hero-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 22px 22px 20px;
  border-radius: 24px;
  border: 1px solid var(--card-border);
  background:
    radial-gradient(circle at top left, rgba(149, 170, 90, 0.18), transparent 42%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
    var(--surface);
  box-shadow: 0 24px 42px rgba(0, 0, 0, 0.18);
}

.chat-hero-copy h2 {
  margin-bottom: 8px;
}

.chat-hero-copy .muted {
  max-width: 560px;
  margin: 0;
}

.chat-search-shell {
  margin-bottom: 18px;
}

.chat-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.users-header {
  position: relative;
}

.users-header::before {
  content: "\2305";
  position: absolute;
  inset-inline-start: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-soft);
  font-size: 16px;
  pointer-events: none;
  opacity: 0.72;
}

#chatUserSearchInput {
  width: 100%;
  padding: 15px 18px 15px 44px;
  border: 1px solid var(--card-border);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.025)),
    var(--surface-strong);
  color: var(--text-main);
  outline: none;
  font-size: 15px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 14px 26px rgba(0, 0, 0, 0.12);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

#chatUserSearchInput::placeholder {
  color: var(--text-soft);
}

#chatUserSearchInput:focus {
  border-color: rgba(177, 193, 114, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 0 0 4px rgba(149, 170, 90, 0.12),
    0 18px 30px rgba(0, 0, 0, 0.16);
}

.chat-list-shell {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#chatAddContactSearchInput {
  width: 100%;
  padding: 15px 18px 15px 44px;
  border: 1px solid var(--card-border);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.025)),
    var(--surface-strong);
  color: var(--text-main);
  outline: none;
  font-size: 15px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 14px 26px rgba(0, 0, 0, 0.12);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

#chatAddContactSearchInput::placeholder {
  color: var(--text-soft);
}

#chatAddContactSearchInput:focus {
  border-color: rgba(177, 193, 114, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 0 0 4px rgba(149, 170, 90, 0.12),
    0 18px 30px rgba(0, 0, 0, 0.16);
}

.chat-add-contact-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 18px;
  border-radius: 18px;
  border: 1px solid rgba(183, 198, 121, 0.28);
  background:
    linear-gradient(180deg, rgba(149, 170, 90, 0.22), rgba(149, 170, 90, 0.12)),
    var(--surface);
  color: var(--text-main);
  font-weight: 900;
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.14);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-add-contact-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(183, 198, 121, 0.42);
  box-shadow: 0 20px 30px rgba(0, 0, 0, 0.18);
}

.chat-add-contact-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  font-size: 17px;
  line-height: 1;
}

.chat-add-contact-label {
  white-space: nowrap;
}

.chat-contact-panel[hidden] {
  display: none !important;
}

.chat-contact-panel-shell {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}

.chat-contact-panel-back {
  align-self: stretch;
  min-width: 48px;
  height: 48px;
  max-width: 64px;
  padding: 0 16px;
  border-radius: 16px;
  border: 1px solid var(--card-border);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02)),
    var(--surface-strong);
  color: var(--text-main);
  font-weight: 900;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-contact-panel-back:hover {
  transform: translateY(-1px);
  border-color: rgba(183, 198, 121, 0.32);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.14);
}

.chat-contact-panel-card {
  width: min(100%, 440px);
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 18px;
  border-radius: 34px;
  border: 1px solid var(--card-border);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.018)),
    radial-gradient(circle at top, rgba(183, 198, 121, 0.16), transparent 42%),
    var(--surface);
  box-shadow:
    0 30px 60px rgba(0, 0, 0, 0.26),
    inset 0 1px 0 rgba(255,255,255,0.06);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

#chatAddContactResults {
  min-height: 120px;
}

.users-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0 4px;
}

.chat-section-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  font-size: 12px;
  font-weight: 900;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.chat-section-toggle:hover {
  transform: translateY(-1px);
  border-color: rgba(183, 198, 121, 0.3);
}

.chat-section-toggle-icon {
  font-size: 13px;
  transition: transform 0.2s ease;
}

.chat-section-toggle.is-collapsed .chat-section-toggle-icon {
  transform: rotate(-90deg);
}

.chat-section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(183, 198, 121, 0.16);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 900;
}

.chat-section-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-section-body[hidden] {
  display: none !important;
}

.chat-empty-state {
  padding: 24px 20px;
  border-radius: 22px;
  border: 1px dashed var(--card-border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.015)),
    var(--surface);
  color: var(--text-soft);
  text-align: center;
}

.user-item {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--card-border);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02)),
    var(--panel-soft);
  cursor: pointer;
  transition:
    transform 0.22s ease,
    background 0.22s ease,
    border-color 0.22s ease,
    box-shadow 0.22s ease;
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.14);
}

.user-item::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  pointer-events: none;
}

.user-item:hover {
  transform: translateY(-1px);
  border-color: rgba(183, 198, 121, 0.3);
  box-shadow: 0 24px 34px rgba(0, 0, 0, 0.18);
}

.user-item:active {
  transform: translateY(0);
}

.user-item.active {
  border-color: rgba(183, 198, 121, 0.52);
  background:
    linear-gradient(180deg, rgba(168, 189, 96, 0.16), rgba(168, 189, 96, 0.08)),
    var(--panel-soft);
  box-shadow:
    0 22px 36px rgba(0, 0, 0, 0.18),
    0 0 0 1px rgba(183, 198, 121, 0.12);
}

.user-item-skeleton {
  min-height: 92px;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,255,255,0.1), rgba(255,255,255,0.04));
  background-size: 220% 100%;
  animation: chat-skeleton 1.1s ease-in-out infinite;
}

@keyframes chat-skeleton {
  100% {
    background-position: -220% 0;
  }
}

.user-avatar-wrap {
  position: relative;
  align-self: center;
}

.user-avatar {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
}

.user-presence-dot {
  position: absolute;
  inset-inline-end: 2px;
  bottom: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.03);
}

.user-presence-dot.is-online {
  background: #7fc971;
}

.user-presence-dot.is-away {
  background: rgba(255, 255, 255, 0.35);
}

.user-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-top-row,
.user-bottom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-name {
  min-width: 0;
  font-size: 16px;
  font-weight: 900;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-row-time {
  margin-inline-start: auto;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-soft);
  white-space: nowrap;
  flex-shrink: 0;
}

.user-subtitle {
  min-width: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-status-inline {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  white-space: nowrap;
}

.chat-badge {
  min-width: 28px;
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--primary), var(--primary-deep, var(--primary)));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.18);
}

.chat-header {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid var(--card-border);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.02)),
    var(--surface);
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.14);
}

#backToUsersBtn {
  border: 1px solid var(--card-border);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02)),
    var(--surface-strong);
  color: var(--text-main);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

#backToUsersBtn {
  min-width: 46px;
  height: 46px;
  padding: 0 14px;
  border-radius: 16px;
  font-weight: 800;
}

#backToUsersBtn:hover {
  border-color: rgba(183, 198, 121, 0.3);
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.12);
}

.chat-header .app-avatar {
  width: 52px;
  height: 52px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
}

.chat-header-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#chatWithName {
  margin: 0;
  color: var(--text-main);
  font-size: 19px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-status {
  min-height: 18px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
}

.messages-container {
  min-height: 420px;
  max-height: min(68vh, 760px);
  overflow-y: auto;
  padding: 18px 18px 22px;
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.09), rgba(0, 0, 0, 0.05)),
    var(--surface);
  border: 1px solid var(--card-border);
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 20px 32px rgba(0, 0, 0, 0.12);
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar {
  width: 10px;
}

.messages-container::-webkit-scrollbar-thumb {
  background: rgba(171, 190, 112, 0.28);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.chat-date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 18px 0 14px;
}

.chat-date-separator span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.045);
  border: 1px solid var(--card-border);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.08);
}

.message-row {
  width: 100%;
}

.user-item-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.user-row-action {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.03));
  color: var(--text-soft);
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.user-row-action:hover {
  transform: translateY(-1px);
  border-color: rgba(183, 198, 121, 0.32);
  color: var(--text-main);
}

.user-row-action.add {
  color: #f2f7ea;
  background: linear-gradient(180deg, rgba(114, 140, 61, 0.95), rgba(84, 105, 46, 0.95));
}

.user-row-action.remove {
  color: #f7ede7;
  background: linear-gradient(180deg, rgba(97, 69, 44, 0.9), rgba(70, 48, 31, 0.94));
}

.user-row-action.is-added {
  cursor: default;
  opacity: 0.7;
}

.message-group-break {
  margin-top: 14px;
}

.message-row-grouped {
  margin-top: 4px;
}

.received-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  column-gap: 12px;
  justify-content: flex-start;
  align-items: start;
}

.sent-row {
  display: flex;
  justify-content: flex-end;
}

.message-meta-row.received {
  display: contents;
}

.message-meta-row.sent {
  display: none;
}

.received-row .message-avatar {
  width: 42px;
  height: 42px;
  font-size: 12px;
  grid-column: 1;
  grid-row: 1 / span 2;
  align-self: flex-start;
  margin-top: 18px;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.16);
}

.message-meta-row.received .message-author {
  grid-column: 2;
  grid-row: 1;
  align-self: end;
  min-height: 18px;
  padding-inline: 4px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--text-soft);
}

.message {
  position: relative;
  padding: 12px 14px 10px;
  border-radius: 22px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.12);
  border: 1px solid transparent;
}

.received-row .message.received {
  grid-column: 2;
  grid-row: 2;
  max-width: min(74%, 640px);
}

.received-row.message-row-grouped .message.received {
  margin-inline-start: 54px;
}

.sent-row .message.sent {
  max-width: min(72%, 640px);
}

.message.sent {
  background: linear-gradient(180deg, rgba(110, 128, 73, 0.96), rgba(77, 95, 50, 0.94));
  color: #fff;
  border-color: rgba(208, 216, 152, 0.16);
  border-bottom-right-radius: 8px;
}

.message.received {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03));
  color: var(--text-main);
  border-color: var(--card-border);
  border-bottom-left-radius: 8px;
}

.message-group-chain.sent {
  border-bottom-right-radius: 17px;
}

.message-group-chain.received {
  border-bottom-left-radius: 17px;
}

.message-text {
  font-size: 14px;
  line-height: 1.58;
  white-space: pre-wrap;
}

.message-time {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  font-size: 11px;
  font-weight: 800;
  color: var(--text-soft);
  opacity: 0.92;
}

.message.sent .message-time {
  justify-content: flex-end;
  color: rgba(255, 255, 255, 0.84);
}

.seen-icon {
  font-size: 11px;
  letter-spacing: -0.16em;
  opacity: 0.92;
}

.chat-message-image {
  max-width: min(300px, 100%);
  max-height: 320px;
  border-radius: 16px;
  display: block;
  margin-bottom: 8px;
  cursor: pointer;
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.2);
}

.chat-file-link {
  display: inline-block;
  text-decoration: none;
  font-weight: 800;
  word-break: break-word;
  color: inherit;
}

.file-caption {
  font-size: 12px;
  opacity: 0.84;
  word-break: break-word;
}

.message-file-wrap,
.message-image-wrap {
  margin-bottom: 2px;
}

.chat-composer-shell {
  position: sticky;
  bottom: 0;
  z-index: 4;
  padding: 12px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(11, 17, 10, 0.06), rgba(11, 17, 10, 0.14)),
    rgba(18, 26, 18, 0.72);
  backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  box-shadow: 0 20px 28px rgba(0, 0, 0, 0.12);
}

.chat-input {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.attach-file-btn,
#sendMessageBtn {
  min-width: 50px;
  height: 50px;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  font-size: 18px;
  transition: transform 0.18s ease, filter 0.18s ease, box-shadow 0.18s ease;
}

#messageInput {
  min-width: 0;
  min-height: 50px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--card-border);
  background: linear-gradient(180deg, var(--surface-strong), var(--surface));
  color: var(--text-main);
  outline: none;
  font-size: 15px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#messageInput::placeholder {
  color: var(--text-soft);
}

#messageInput:focus {
  border-color: rgba(177, 193, 114, 0.55);
  box-shadow: 0 0 0 4px rgba(149, 170, 90, 0.1);
}

#sendMessageBtn {
  padding: 0 20px;
  font-weight: 900;
  white-space: nowrap;
}

#backToUsersBtn:hover,
#sendMessageBtn:hover,
.attach-file-btn:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
}

#backToUsersBtn:active,
#sendMessageBtn:active,
.attach-file-btn:active {
  transform: translateY(0);
}

html[data-theme="light"] .chat-hero-card,
html[data-theme="light"] .user-item,
html[data-theme="light"] .chat-header,
html[data-theme="light"] .messages-container,
html[data-theme="light"] .chat-composer-shell {
  box-shadow: 0 16px 28px rgba(77, 82, 68, 0.08);
}

html[data-theme="light"] .chat-hero-card {
  background:
    radial-gradient(circle at top left, rgba(149, 170, 90, 0.12), transparent 42%),
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(247,244,239,0.96)),
    var(--surface);
}

html[data-theme="light"] #chatUserSearchInput,
html[data-theme="light"] #messageInput,
html[data-theme="light"] #backToUsersBtn {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(247,244,239,0.96)),
    var(--surface);
}

html[data-theme="light"] .user-item.active {
  background:
    linear-gradient(180deg, rgba(194, 210, 145, 0.34), rgba(194, 210, 145, 0.16)),
    rgba(255,255,255,0.96);
}

html[data-theme="light"] .chat-section-toggle,
html[data-theme="light"] .user-row-action {
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(247,244,239,0.96));
}

html[data-theme="light"] .message.received {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 244, 239, 0.96));
  color: #243025;
  border-color: rgba(72, 89, 62, 0.1);
}

html[data-theme="light"] .chat-composer-shell {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.82), rgba(255,255,255,0.9)),
    rgba(255,255,255,0.7);
}

html[data-theme="light"] .message-time,
html[data-theme="light"] .message-author,
html[data-theme="light"] .chat-header-status,
html[data-theme="light"] .user-subtitle,
html[data-theme="light"] .chat-empty-state,
html[data-theme="light"] .chat-section-title,
html[data-theme="light"] .user-row-time,
html[data-theme="light"] .user-status-inline {
  color: var(--text-soft);
}

html[dir="rtl"] .users-header::before {
  inset-inline-start: auto;
  inset-inline-end: 16px;
}

html[dir="rtl"] .chat-section-header {
  flex-direction: row-reverse;
}

html[dir="rtl"] #chatUserSearchInput {
  padding: 15px 44px 15px 18px;
}

html[dir="rtl"] .chat-header {
  grid-template-columns: auto minmax(0, 1fr) auto auto;
}

html[dir="rtl"] .chat-header-main,
html[dir="rtl"] .message-text,
html[dir="rtl"] .message-author,
html[dir="rtl"] .user-main {
  text-align: right;
}

html[dir="rtl"] .user-row-time {
  margin-inline-start: 0;
  margin-inline-end: auto;
}

html[dir="rtl"] .received-row {
  grid-template-columns: minmax(0, 1fr) 42px;
}

html[dir="rtl"] .received-row .message-avatar {
  grid-column: 2;
}

html[dir="rtl"] .message-meta-row.received .message-author {
  grid-column: 1;
  text-align: right;
}

html[dir="rtl"] .received-row .message.received {
  grid-column: 1;
}

html[dir="rtl"] .received-row.message-row-grouped .message.received {
  margin-inline-start: 0;
  margin-inline-end: 54px;
}

html[dir="rtl"] .message.received {
  border-bottom-left-radius: 22px;
  border-bottom-right-radius: 8px;
}

html[dir="rtl"] .message-group-chain.received {
  border-bottom-right-radius: 17px;
}

@media (max-width: 900px) {
  .messages-container {
    min-height: 360px;
    max-height: calc(100dvh - 360px);
  }

  .received-row .message.received,
  .sent-row .message.sent {
    max-width: 84%;
  }
}

@media (max-width: 768px) {
  .chat-hero-card {
    padding: 18px 18px 16px;
    border-radius: 22px;
  }

  .user-item {
    padding: 13px 14px;
    border-radius: 20px;
  }

  .user-avatar {
    width: 52px;
    height: 52px;
  }

  .chat-header {
    grid-template-columns: auto auto minmax(0, 1fr);
    gap: 12px;
    padding: 12px 14px;
  }

  #chatWithName {
    font-size: 18px;
  }

  .chat-header .app-avatar {
    width: 44px;
    height: 44px;
  }

  .messages-container {
    min-height: 320px;
    max-height: calc(100dvh - 392px);
    padding: 14px 12px 18px;
    border-radius: 22px;
  }

  .received-row {
    grid-template-columns: 36px minmax(0, 1fr);
    column-gap: 8px;
  }

  .received-row .message-avatar {
    width: 36px;
    height: 36px;
  }

  .received-row .message.received,
  .sent-row .message.sent {
    max-width: 90%;
  }

  .received-row.message-row-grouped .message.received {
    margin-inline-start: 44px;
  }

  html[dir="rtl"] .received-row {
    grid-template-columns: minmax(0, 1fr) 36px;
  }

  html[dir="rtl"] .received-row.message-row-grouped .message.received {
    margin-inline-start: 0;
    margin-inline-end: 44px;
  }

  .chat-composer-shell {
    padding: 10px;
    border-radius: 22px;
    margin-bottom: 72px;
  }

  .chat-input {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
  }

  .attach-file-btn,
  #sendMessageBtn {
    min-width: 46px;
    height: 46px;
    border-radius: 16px;
  }

  #sendMessageBtn {
    padding: 0 16px;
  }
}

@media (max-width: 540px) {
  .user-item {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: start;
  }

  .user-item .chat-badge {
    grid-column: auto;
    justify-self: end;
    margin-top: 0;
  }

  .user-top-row,
  .user-bottom-row {
    gap: 8px;
  }

  .user-status-inline {
    display: none;
  }

  .chat-hero-card {
    margin-bottom: 16px;
  }

  .messages-container {
    max-height: calc(100dvh - 408px);
  }
}

.chat-contact-hero {
  position: relative;
  min-height: 560px;
  border-radius: 28px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
  background:
    radial-gradient(circle at top, rgba(205, 216, 169, 0.18), transparent 34%),
    linear-gradient(180deg, rgba(28, 34, 28, 0.32), rgba(12, 15, 12, 0.08)),
    rgba(15, 20, 15, 0.78);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.08),
    0 26px 50px rgba(0, 0, 0, 0.26);
}

.chat-contact-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(8, 10, 8, 0.02) 0%, rgba(8, 10, 8, 0.12) 35%, rgba(8, 10, 8, 0.74) 100%),
    radial-gradient(circle at bottom, rgba(0, 0, 0, 0.28), transparent 45%);
  pointer-events: none;
}

.chat-contact-avatar {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
  background:
    radial-gradient(circle at 50% 28%, rgba(199, 212, 160, 0.34), transparent 28%),
    linear-gradient(180deg, rgba(39, 47, 39, 0.95), rgba(16, 20, 16, 0.96));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(72px, 14vw, 120px);
  font-weight: 900;
  letter-spacing: -0.04em;
  color: rgba(244, 247, 232, 0.94);
  overflow: hidden;
}

.chat-contact-avatar .app-avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.chat-contact-overlay {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px 24px 24px;
}

.chat-contact-eyebrow-row {
  display: flex;
  justify-content: flex-start;
}

.chat-contact-meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(226, 235, 197, 0.2);
  background: rgba(8, 12, 8, 0.28);
  color: rgba(250, 252, 244, 0.92);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chat-contact-copy {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(100%, 300px);
}

.chat-contact-copy h3 {
  margin: 0;
  font-size: clamp(30px, 3vw, 38px);
  line-height: 1.04;
  color: #f8fbf1;
  text-wrap: balance;
}

.chat-contact-status {
  margin: 0;
  color: rgba(239, 244, 227, 0.82);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
  max-width: min(100%, 320px);
}

.chat-contact-meta-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chat-contact-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  max-width: 100%;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(8, 12, 8, 0.32);
  border: 1px solid rgba(226, 235, 197, 0.12);
  color: rgba(248, 250, 241, 0.9);
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chat-contact-meta-icon {
  opacity: 0.9;
  font-size: 13px;
}

.chat-contact-meta-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-contact-chip-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.chat-contact-chip-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(226, 235, 197, 0.18);
  background: rgba(8, 12, 8, 0.36);
  color: rgba(248, 250, 241, 0.96);
  font-size: 12px;
  font-weight: 900;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chat-contact-chip-action:hover {
  transform: translateY(-1px);
  border-color: rgba(226, 235, 197, 0.28);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
}

.chat-contact-chip-action-primary {
  background:
    linear-gradient(180deg, rgba(214, 223, 184, 0.96), rgba(182, 198, 121, 0.88)),
    rgba(183, 198, 121, 0.9);
  color: #1d2518;
  margin-inline-start: auto;
}

.chat-contact-chip-action-secondary {
  background: rgba(8, 12, 8, 0.36);
}

.chat-contact-chip-action-secondary.reset-btn {
  background:
    linear-gradient(180deg, rgba(142, 74, 63, 0.86), rgba(117, 47, 40, 0.82)),
    rgba(124, 52, 43, 0.84);
  border-color: rgba(255, 179, 164, 0.18);
  color: #fff3ef;
}

.chat-contact-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-contact-primary-btn,
.chat-contact-secondary-btn {
  width: 100%;
  min-height: 58px;
  border-radius: 999px;
  font-weight: 900;
}

.chat-contact-primary-btn {
  justify-content: center;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.92), rgba(238,241,226,0.88)),
    linear-gradient(180deg, rgba(255,255,255,0.2), rgba(255,255,255,0));
  color: #182016;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.18);
}

.chat-contact-primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 20px 36px rgba(0, 0, 0, 0.22);
}

.chat-contact-secondary-btn {
  min-height: 48px;
  border-radius: 18px;
}

.chat-contact-secondary-btn:not(.reset-btn) {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03)),
    rgba(10, 14, 10, 0.74);
  color: rgba(243, 247, 232, 0.92);
}

html[data-theme="light"] .chat-contact-panel-card,
html[data-theme="light"] .chat-contact-panel-back {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(247,244,239,0.96)),
    var(--surface);
}

html[data-theme="light"] .chat-contact-hero {
  background:
    radial-gradient(circle at top, rgba(189, 201, 160, 0.28), transparent 34%),
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(224, 229, 214, 0.88)),
    rgba(241, 239, 232, 0.96);
  border-color: rgba(90, 104, 76, 0.12);
}

html[data-theme="light"] .chat-contact-hero::after {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(39, 47, 33, 0.1) 40%, rgba(23, 31, 22, 0.62) 100%),
    radial-gradient(circle at bottom, rgba(29, 36, 24, 0.12), transparent 45%);
}

html[data-theme="light"] .chat-contact-avatar {
  background:
    radial-gradient(circle at 50% 28%, rgba(187, 199, 155, 0.36), transparent 28%),
    linear-gradient(180deg, rgba(225, 230, 214, 0.94), rgba(205, 214, 191, 0.96));
  color: #47553e;
}

html[data-theme="light"] .chat-contact-primary-btn {
  background:
    linear-gradient(180deg, rgba(74, 103, 57, 0.96), rgba(95, 122, 73, 0.92)),
    var(--brand);
  color: #f8fbf1;
}

html[data-theme="light"] .chat-contact-secondary-btn:not(.reset-btn) {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.9), rgba(240, 235, 225, 0.95)),
    var(--surface);
  color: #2b3427;
}

html[data-theme="light"] .chat-contact-meta-badge,
html[data-theme="light"] .chat-contact-meta-item {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.24);
  color: rgba(249, 251, 243, 0.96);
}

html[data-theme="light"] .chat-contact-chip-action {
  background: rgba(255,255,255,0.24);
  border-color: rgba(255,255,255,0.32);
  color: rgba(249, 251, 243, 0.98);
}

html[data-theme="light"] .chat-contact-chip-action-primary {
  background:
    linear-gradient(180deg, rgba(235, 240, 224, 0.98), rgba(205, 218, 168, 0.96)),
    rgba(205, 218, 168, 0.94);
  color: #253021;
}

html[data-theme="light"] .chat-contact-chip-action-secondary.reset-btn {
  background:
    linear-gradient(180deg, rgba(176, 96, 83, 0.9), rgba(145, 68, 57, 0.88)),
    rgba(145, 68, 57, 0.9);
  border-color: rgba(255,255,255,0.18);
  color: #fff7f4;
}

html[dir="rtl"] .chat-contact-eyebrow-row {
  justify-content: flex-end;
}

html[dir="rtl"] .chat-contact-copy,
html[dir="rtl"] .chat-contact-status {
  text-align: right;
}

html[dir="rtl"] .chat-contact-meta-list {
  justify-content: flex-end;
}

html[dir="rtl"] .chat-contact-chip-actions {
  justify-content: flex-end;
}

html[dir="rtl"] .chat-contact-chip-action-primary {
  margin-inline-start: 0;
  margin-inline-end: auto;
}

@media (max-width: 640px) {
  .chat-search-row {
    grid-template-columns: 1fr;
  }

  .chat-add-contact-btn {
    width: 100%;
  }

  .chat-contact-panel-card {
    width: 100%;
    padding: 14px 14px calc(18px + env(safe-area-inset-bottom, 0px));
    border-radius: 24px;
  }

  .chat-contact-hero {
    min-height: 470px;
    border-radius: 24px;
  }

  .chat-contact-overlay {
    padding: 22px 18px 18px;
  }

  .chat-contact-copy {
    max-width: 100%;
  }

  .chat-contact-copy h3 {
    font-size: 30px;
  }

  .chat-contact-status {
    font-size: 14px;
  }

  .chat-contact-chip-actions {
    gap: 8px;
  }

  .chat-contact-chip-action {
    min-height: 36px;
    padding: 0 12px;
  }
}

@media (max-width: 480px) {
  .chat-section-title {
    min-height: 32px;
    padding: 0 12px;
    font-size: 11px;
    letter-spacing: 0.12em;
  }

  .chat-header {
    gap: 10px;
  }

  .chat-header-main {
    gap: 2px;
  }

  .message {
    padding: 11px 12px 9px;
    border-radius: 19px;
  }

  .received-row .message.received,
  .sent-row .message.sent {
    max-width: 94%;
  }

  .chat-composer-shell {
    margin-bottom: 78px;
  }
}
