:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: rgba(30, 41, 59, 0.7);
  --bg-input: #334155;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: rgba(99, 102, 241, 0.15);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border-color: rgba(255, 255, 255, 0.08);
  --bubble-outgoing: #4338ca;
  --bubble-incoming: #334155;
  --online-color: #10b981;
  --offline-color: #64748b;
  --status-pending: #f59e0b;
  --status-sent: #94a3b8;
  --status-delivered: #38bdf8;
  --status-read: #34d399;
  --status-failed: #ef4444;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font-Tezkor: 'Inter', system-ui, -apple-system, sans-serif;
  --header-height: 60px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-Tezkor: var(--font-Tezkor);
  -webkit-tap-highlight-color: transparent;
}

body,
html {
  height: 100%;
  height: 100dvh;
  width: 100%;
  width: 100dvw;
  background-color: var(--bg-primary);
  color: var(--text-main);
  overflow: hidden;
}

/* Hidden Utility */
.hidden {
  display: none !important;
}

/* AUTH VIEWS */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  background: radial-gradient(circle at top left, #1e1b4b, #0f172a);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.3s ease-out;
}

.auth-header {
  text-align: center;
  margin-bottom: 28px;
}

.auth-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.auth-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 6px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--accent);
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-muted);
}

.auth-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

/* APP MAIN LAYOUT */
.app-container {
  display: flex;
  height: 100%;
  height: 100dvh;
  width: 100%;
  width: 100dvw;
  overflow: hidden;
  position: relative;
}

/* Connection status banner */
.connection-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: #f59e0b;
  color: #0f172a;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 4px;
  z-index: 1000;
  transition: all 0.3s;
}

.connection-banner.online {
  background: #10b981;
  color: #ffffff;
}

/* PWA INSTALL BANNER */
.pwa-install-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 420px;
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 999;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.3s ease-out;
}

.pwa-install-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pwa-install-icon {
  font-size: 28px;
}

.pwa-install-text h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.pwa-install-text p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.pwa-install-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-install {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-install:hover {
  background: var(--accent-hover);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translate(-50%, 20px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* SIDEBAR / CHAT LIST */
.sidebar {
  width: 100%;
  max-width: 360px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 10;
  transition: transform 0.3s ease;
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 12px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  gap: 8px;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  overflow: hidden;
  flex-shrink: 0;
  object-fit: cover;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.user-info .name {
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, transform 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  transform: scale(1.05);
}

.icon-btn.btn-logout:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.search-box {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: 20px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
}

.search-input-wrapper input:focus {
  border-color: var(--accent);
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  transition: background 0.2s;
  position: relative;
}

.chat-item:hover,
.chat-item.active {
  background: rgba(255, 255, 255, 0.05);
}

.avatar-wrapper {
  position: relative;
}

.online-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--online-color);
  border: 2px solid var(--bg-secondary);
  position: absolute;
  bottom: 0;
  right: 0;
}

.chat-details {
  flex: 1;
  min-width: 0;
}

.chat-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.chat-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-time {
  font-size: 11px;
  color: var(--text-dim);
}

.chat-bottom-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.last-msg {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.badge {
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 6px;
}

/* CHAT MAIN VIEW */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.empty-chat-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: var(--text-dim);
  gap: 12px;
}

.empty-chat-state icon {
  font-size: 48px;
}

.chat-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.peer-status {
  font-size: 12px;
  color: var(--text-muted);
}

.peer-status.online {
  color: var(--online-color);
}

.messages-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* MESSAGE BUBBLES */
.message-bubble-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.message-bubble-wrapper.outgoing {
  align-self: flex-end;
}

.message-bubble-wrapper.incoming {
  align-self: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  position: relative;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.4;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.message-bubble.outgoing {
  background: var(--bubble-outgoing);
  color: white;
  border-bottom-right-radius: 2px;
}

.message-bubble.incoming {
  background: var(--bubble-incoming);
  color: var(--text-main);
  border-bottom-left-radius: 2px;
}

.message-reply-preview {
  background: rgba(0, 0, 0, 0.2);
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin-bottom: 6px;
  color: #e2e8f0;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.6);
}

.msg-status-icon {
  font-size: 13px;
  line-height: 1;
  font-weight: 600;
}

.msg-status-icon.pending {
  color: var(--status-pending);
}

.msg-status-icon.sent {
  color: var(--status-sent);
}

.msg-status-icon.delivered {
  color: var(--status-delivered);
}

.msg-status-icon.read {
  color: #38bdf8;
  font-weight: 800;
  text-shadow: 0 0 4px rgba(56, 189, 248, 0.4);
}

.msg-status-icon.failed {
  color: var(--status-failed);
  cursor: pointer;
}

.attachment-media-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-top: 6px;
  max-width: 320px;
}

.attachment-file-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
}

.attachment-file-size {
  font-size: 11px;
  color: var(--text-muted);
}

.media-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
  width: 100%;
  margin-top: 4px;
}

.media-action-btn:hover {
  background: var(--accent-hover);
}

.inline-video-player {
  width: 100%;
  max-height: 280px;
  border-radius: var(--radius-sm);
  outline: none;
  background: black;
  margin-top: 6px;
}

.attachment-preview-img {
  max-width: 100%;
  max-height: 250px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
  cursor: pointer;
  object-fit: cover;
}

/* TYPING INDICATOR */
.typing-indicator {
  padding: 4px 16px;
  font-size: 12px;
  color: var(--accent);
  font-style: italic;
}

/* INPUT BAR */
.chat-input-bar {
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  z-index: 20;
}

.chat-input-wrapper {
  flex: 1;
  position: relative;
}

.chat-input-wrapper textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: 20px;
  color: var(--text-main);
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 100px;
  height: 40px;
}

.chat-input-wrapper textarea:focus {
  border-color: var(--accent);
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: transform 0.1s;
}

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

/* SEARCH MODAL */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 60px;
}

.modal-content {
  width: 90%;
  max-width: 450px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 20px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.search-results-list {
  max-height: 300px;
  overflow-y: auto;
  margin-top: 12px;
}

/* UPLOAD PROGRESS */
.upload-progress-card {
  background: var(--bg-input);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 12px;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s;
}

/* MOBILE FIRST RESPONSIVE */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    max-width: 100%;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100%;
    height: 100dvh;
    z-index: 10;
  }

  .sidebar.hidden-mobile {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .chat-main {
    width: 100%;
    height: 100%;
    height: 100dvh;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    z-index: 5;
  }

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

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}