:root {
  --bg-primary: #17212b;
  --bg-secondary: #0e1621;
  --bg-hover: #202b36;
  --bg-active: #2b5278;
  --bubble-out: #2b5278;
  --bubble-in: #182533;
  --text-main: #f5f5f5;
  --text-muted: #7f91a4;
  --accent: #5288c1;
  --border-color: #101921;
  --danger: #e53935;
  --verified-blue: #3390ec;
  --online-green: #4dcd5e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  background-color: var(--bg-secondary);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  direction: rtl;
}

.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-secondary);
}

.auth-card {
  background: var(--bg-primary);
  width: 100%;
  max-width: 380px;
  padding: 36px 28px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  text-align: center;
}

.nox-logo {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, #3390ec, #1e5a99);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 16px;
  box-shadow: 0 4px 15px rgba(51, 144, 236, 0.4);
}

.auth-card h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.auth-card p {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}

.tg-input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: var(--bg-secondary);
  border: 1px solid #243447;
  border-radius: 8px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: border 0.2s;
}

.tg-input:focus {
  border-color: var(--verified-blue);
}

.tg-btn {
  width: 100%;
  padding: 12px;
  background: var(--verified-blue);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.tg-btn:hover {
  opacity: 0.9;
}

.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

.sidebar {
  width: 340px;
  background: var(--bg-primary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

.brand-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
}

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

.chat-item {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.02);
}

.chat-item:hover {
  background: var(--bg-hover);
}

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

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #42a5f5, #1976d2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
  position: relative;
}

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

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

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

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

.chat-preview {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-item.active .chat-preview {
  color: #d0e3f5;
}

.unread-badge {
  background: var(--verified-blue);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 12px;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-secondary);
  background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 0);
  background-size: 24px 24px;
}

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

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

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

.header-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  background: rgba(255,255,255,0.06);
  border: none;
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.action-btn:hover {
  background: rgba(255,255,255,0.12);
}

.action-btn.danger {
  color: #ff6b6b;
}

.messages-container {
  flex: 1;
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-row {
  display: flex;
  width: 100%;
}

.msg-row.outgoing {
  justify-content: flex-start;
}

.msg-row.incoming {
  justify-content: flex-end;
}

.msg-bubble {
  max-width: 68%;
  padding: 8px 12px;
  border-radius: 12px;
  position: relative;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.msg-row.outgoing .msg-bubble {
  background: var(--bubble-out);
  border-bottom-right-radius: 3px;
}

.msg-row.incoming .msg-bubble {
  background: var(--bubble-in);
  border-bottom-left-radius: 3px;
}

.msg-image {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  display: block;
  margin-bottom: 6px;
  cursor: pointer;
}

.msg-file-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,0.2);
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  color: #64b5f6;
  text-decoration: none;
  font-size: 13px;
}

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

.msg-controls {
  display: inline-flex;
  gap: 6px;
  margin-right: 8px;
  opacity: 0.7;
}

.msg-controls span {
  cursor: pointer;
  font-size: 11px;
}

.msg-controls span:hover {
  color: #fff;
  text-decoration: underline;
}

.composer-bar {
  background: var(--bg-primary);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--border-color);
}

.composer-input {
  flex: 1;
  background: var(--bg-secondary);
  border: none;
  padding: 12px 16px;
  border-radius: 20px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.icon-btn:hover {
  color: var(--verified-blue);
  background: rgba(255,255,255,0.04);
}

.send-btn {
  background: var(--verified-blue);
  color: #fff;
  width: 42px;
  height: 42px;
}

.send-btn:hover {
  color: #fff;
  opacity: 0.9;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: var(--bg-primary);
  width: 90%;
  max-width: 400px;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 13px;
}

.mobile-back-btn {
  display: none;
}

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
  }
  .app-container.chat-open .sidebar {
    display: none;
  }
  .app-container:not(.chat-open) .chat-area {
    display: none;
  }
  .mobile-back-btn {
    display: inline-flex;
  }
  .msg-bubble {
    max-width: 84%;
  }
}
