@font-face {
  font-family: "Peyda";
  src: url("../fonts/Peyda-Regular.woff2") format("woff2"),
    url("../fonts/Peyda-Regular.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Peyda";
  src: url("../fonts/Peyda-Medium.woff2") format("woff2"),
    url("../fonts/Peyda-Medium.woff") format("woff");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Peyda";
  src: url("../fonts/Peyda-Bold.woff2") format("woff2"),
    url("../fonts/Peyda-Bold.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --primary: #3390ec;
  --primary-600: #2873bd;
  --bg: #f0f2f5;
  --panel: #ffffff;
  --muted: #7d8b99;
  --text: #1f2a37;
  --border: #e2e8f0;
  --chat-bg: #8caba1;
  --chat-bubble-me: #eeffde;
  --chat-bubble-other: #ffffff;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

body.dark {
  --bg: #0f0f0f;
  --panel: #17212b;
  --muted: #7a8794;
  --text: #f5f7fb;
  --border: #1c2732;
  --chat-bg: #0f0f0f;
  --chat-bubble-me: #2b5278;
  --chat-bubble-other: #182533;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Peyda", Tahoma, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
}

button,
input,
textarea {
  font-family: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.app {
  height: 100vh;
  width: 100%;
}

.icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

.icon.lg {
  width: 24px;
  height: 24px;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  background: var(--avatar-bg, #90a4ae);
  flex-shrink: 0;
}

.avatar.lg {
  width: 56px;
  height: 56px;
  font-size: 20px;
}

.avatar.has-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;
}

.dir-ltr {
  direction: ltr;
  text-align: left;
}

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top right, rgba(51, 144, 236, 0.15), transparent 55%),
    radial-gradient(circle at top left, rgba(0, 0, 0, 0.06), transparent 50%),
    var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 32px;
  border: 1px solid var(--border);
}

.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 12px 24px rgba(51, 144, 236, 0.35);
}

.auth-title {
  text-align: center;
  font-size: 20px;
  margin: 0 0 6px;
}

.auth-subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 24px;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  display: block;
}

.field {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

body.dark .field {
  background: #1c2935;
}

.field input {
  border: none;
  background: transparent;
  width: 100%;
  outline: none;
  color: inherit;
}

.btn {
  border: none;
  cursor: pointer;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 700;
  transition: transform 0.2s ease, background 0.2s ease;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 12px 24px rgba(51, 144, 236, 0.3);
}

.btn.primary:hover {
  background: var(--primary-600);
}

.btn.primary:active {
  transform: scale(0.98);
}

.btn.ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn.ghost:hover {
  background: rgba(51, 144, 236, 0.08);
}

.auth-toggle {
  margin-top: 18px;
  width: 100%;
  text-align: center;
  color: var(--primary);
  font-size: 13px;
  background: transparent;
  border: none;
  cursor: pointer;
}

.chat-screen {
  height: 100vh;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.sidebar {
  width: 340px;
  max-width: 100%;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 2;
  min-height: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
}

.sidebar-header .search {
  flex: 1;
  position: relative;
}

.search input {
  width: 100%;
  border: none;
  background: #f1f5f9;
  border-radius: 999px;
  padding: 10px 38px 10px 14px;
  font-size: 13px;
  outline: none;
}

body.dark .search input {
  background: #1c2935;
}

.search .icon {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 0 12px 6px;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
  position: relative;
}

.tab.active {
  color: var(--primary);
  font-weight: 700;
}

.tab.active::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 0;
  height: 3px;
  border-radius: 4px 4px 0 0;
  background: var(--primary);
}

.contacts-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.contact-item {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: background 0.2s ease;
}

.contact-item:hover {
  background: rgba(51, 144, 236, 0.08);
}

.contact-item.active {
  background: var(--primary);
  color: #fff;
}

.contact-meta {
  flex: 1;
  min-width: 0;
}

.contact-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.contact-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-time {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.contact-item.active .contact-time {
  color: rgba(255, 255, 255, 0.8);
}

.contact-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.contact-preview {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-item.active .contact-preview {
  color: rgba(255, 255, 255, 0.85);
}

.badge {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 700;
}

.contact-item.active .badge {
  background: #fff;
  color: var(--primary);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  position: absolute;
  bottom: 0;
  left: 0;
  border: 2px solid var(--panel);
}

.fab {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 14px 30px rgba(51, 144, 236, 0.4);
  cursor: pointer;
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  z-index: 20;
}

.drawer-overlay.active {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(320px, 85vw);
  background: var(--panel);
  box-shadow: -10px 0 24px rgba(15, 23, 42, 0.2);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 30;
  display: flex;
  flex-direction: column;
}

.drawer.active {
  transform: translateX(0);
}

.drawer-view {
  display: none;
  height: 100%;
}

.drawer-view.active {
  display: flex;
  flex-direction: column;
}

.drawer-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.drawer-list {
  padding: 8px 0;
  flex: 1;
  overflow-y: auto;
}

.drawer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  cursor: pointer;
  color: var(--text);
}

.drawer-item:hover {
  background: rgba(51, 144, 236, 0.08);
}

.drawer-item .label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.switch {
  width: 40px;
  height: 20px;
  border-radius: 999px;
  background: #cbd5f5;
  position: relative;
}

.switch::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 2px;
  right: 2px;
  transition: transform 0.2s ease;
}

.switch.active {
  background: var(--primary);
}

.switch.active::after {
  transform: translateX(-20px);
}

.profile-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.profile-info {
  display: flex;
  gap: 12px;
  align-items: center;
}

.profile-avatar-edit {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-avatar-edit .hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-contact {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.chat-contact .name {
  font-weight: 700;
  font-size: 15px;
}

.chat-contact .status {
  font-size: 12px;
  color: var(--muted);
}

.chat-actions {
  display: flex;
  gap: 4px;
  color: var(--muted);
}

.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  color: inherit;
}

.icon-btn:hover {
  background: rgba(51, 144, 236, 0.1);
}

.icon-btn.recording {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 16px;
  min-height: 0;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.25), transparent 40%),
    radial-gradient(circle at 80% 0%, rgba(255, 255, 255, 0.1), transparent 45%);
}

body.dark .chat-body {
  background-image:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.05), transparent 40%),
    radial-gradient(circle at 80% 0%, rgba(255, 255, 255, 0.03), transparent 45%);
}

.message {
  display: flex;
  margin-bottom: 10px;
}

.message.me {
  justify-content: flex-start;
}

.message.other {
  justify-content: flex-end;
}

.message-bubble {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 16px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  font-size: 13px;
  line-height: 1.5;
  position: relative;
}

.message-text {
  white-space: pre-wrap;
}

.message.me .message-bubble {
  background: var(--chat-bubble-me);
  border-bottom-right-radius: 6px;
  color: #0f172a;
}

body.dark .message.me .message-bubble {
  color: #fff;
}

.message.other .message-bubble {
  background: var(--chat-bubble-other);
  border-bottom-left-radius: 6px;
}

body.dark .message.other .message-bubble {
  color: #fff;
}

.message-time {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  justify-content: flex-end;
}

.message-status {
  color: #94a3b8;
}

.message-status.read {
  color: var(--primary);
}

.message-media {
  margin-top: 6px;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.05);
}

.message-media img {
  width: 100%;
  display: block;
}

.file-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(51, 144, 236, 0.1);
  color: var(--primary);
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 12px;
  margin-top: 6px;
}

.voice-player audio {
  width: 220px;
  max-width: 100%;
  display: block;
  margin-top: 6px;
}

.chat-input {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.input-box {
  flex: 1;
  background: #f1f5f9;
  border-radius: 16px;
  padding: 10px 14px;
}

body.dark .input-box {
  background: #1c2935;
}

.input-box textarea {
  width: 100%;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  color: inherit;
}

.profile-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(320px, 100%);
  background: var(--panel);
  box-shadow: -12px 0 26px rgba(15, 23, 42, 0.2);
  transform: translateX(100%);
  transition: transform 0.3s ease, opacity 0.2s ease;
  z-index: 10;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
}

.profile-panel.active {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.profile-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.profile-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
}

.profile-section {
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}

.profile-section:last-child {
  border-bottom: none;
}

.profile-section h4 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
}

.profile-section p {
  margin: 0;
  font-size: 14px;
}

.mobile-only {
  display: none;
}

@media (max-width: 900px) {
  .sidebar {
    width: 100%;
  }

  .chat-screen.mobile-chat-active .sidebar {
    display: none;
  }

  .chat-screen.mobile-chat-active .chat {
    display: flex;
  }

  .chat {
    display: none;
  }

  .mobile-only {
    display: inline-flex;
  }
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.4);
  border-radius: 999px;
}

body.dark ::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.7);
}
