:root {
  --bg: #0f0f1a;
  --bg2: #1a1a2e;
  --bg3: #252540;
  --surface: #2a2a45;
  --accent: #6c5ce7;
  --accent2: #a29bfe;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --text: #e8e8f0;
  --text2: #9898b8;
  --sent: #6c5ce7;
  --received: #2a2a45;
  --danger: #ff6b6b;
  --success: #51cf66;
  --radius: 14px;
  --radius-sm: 8px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  direction: rtl;
}

.screen {
  display: none;
  height: 100vh;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Auth Screen */
#auth-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg2) 100%);
  padding: 20px;
}

.auth-container {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.auth-logo {
  margin-bottom: 16px;
}

.auth-container h1 {
  font-size: 28px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-subtitle {
  color: var(--text2);
  margin: 4px 0 24px;
  font-size: 14px;
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group {
  text-align: right;
}

.input-group label {
  display: block;
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 6px;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--surface);
  background: var(--bg2);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: border 0.2s;
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-primary {
  padding: 12px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.2s;
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  display: none;
}

.gender-selector {
  display: flex;
  gap: 12px;
}

.gender-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border: 2px solid var(--surface);
  background: var(--bg2);
  color: var(--text2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 15px;
}

.gender-option input {
  display: none;
}

.gender-option .gender-icon {
  font-size: 22px;
}

.gender-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text);
}

.gender-option:has(input:checked) .gender-icon {
  color: var(--accent2);
}

/* Chat Screen */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--surface);
  flex-shrink: 0;
  z-index: 10;
}

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

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

.btn-icon {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--surface);
  color: var(--text);
}

/* Visibility Toggle */
.visibility-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}

.visibility-toggle .toggle-label {
  font-size: 11px;
  color: var(--text2);
  transition: color 0.2s;
}

.visibility-toggle .toggle-label-off {
  color: var(--text2);
}

.visibility-toggle .toggle-label-on {
  color: var(--text2);
}

.visibility-toggle input:checked ~ .toggle-label-on {
  color: var(--success);
}

.visibility-toggle input:not(:checked) ~ .toggle-label-off {
  color: var(--danger);
}

.visibility-toggle input {
  display: none;
}

.visibility-toggle .toggle-slider {
  width: 36px;
  height: 20px;
  background: var(--surface);
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
}

.visibility-toggle .toggle-slider::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text2);
  top: 2px;
  right: 2px;
  transition: all 0.2s;
}

.visibility-toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.visibility-toggle input:checked + .toggle-slider::after {
  background: #fff;
  right: 18px;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Panel base */
.panel {
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.panel.active {
  display: flex;
}

/* Users Panel */
.panel-users {
  flex: 1;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--surface);
  flex-shrink: 0;
}

.panel-header h3 {
  font-size: 15px;
  font-weight: 500;
}

.online-count {
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 600;
}

.users-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}

.user-item:hover {
  background: var(--surface);
}

.user-item .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.user-item .user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.user-item .user-info {
  flex: 1;
}

.user-item .user-name {
  font-weight: 500;
  font-size: 14px;
}

.user-item .user-status {
  font-size: 12px;
  color: var(--text2);
}

.empty-state {
  text-align: center;
  color: var(--text2);
  margin-top: 40px;
  font-size: 14px;
}

/* Chat Panel */
.panel-chat {
  flex: 1;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--surface);
  flex-shrink: 0;
}

.partner-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.partner-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.partner-name {
  font-weight: 600;
  font-size: 14px;
}

.partner-status {
  font-size: 11px;
  color: var(--text2);
}

.hidden {
  display: none !important;
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: msgIn 0.2s ease-out;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.sent {
  align-self: flex-end;
  background: var(--sent);
  color: #fff;
  border-bottom-left-radius: 4px;
}

.message.received {
  align-self: flex-start;
  background: var(--received);
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.message .msg-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: left;
}

.message.received .msg-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent2);
  margin-bottom: 2px;
}

.system-msg {
  text-align: center;
  color: var(--text2);
  font-size: 12px;
  padding: 8px;
}

/* Message Form */
.message-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg2);
  border-top: 1px solid var(--surface);
  flex-shrink: 0;
}

.message-form input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--surface);
  background: var(--bg3);
  color: var(--text);
  border-radius: 20px;
  font-size: 14px;
  transition: border 0.2s;
}

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

.message-form input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-send {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

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

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Desktop layout: side by side */
@media (min-width: 768px) {
  #chat-screen {
    max-width: 860px;
    margin: 0 auto;
    border-left: 1px solid var(--surface);
    border-right: 1px solid var(--surface);
  }

  .main-content {
    flex-direction: row;
  }

  .panel-users {
    width: 300px;
    flex: none;
    border-left: 1px solid var(--surface);
  }

  .panel-chat {
    flex: 1;
    display: flex !important;
    flex-direction: column;
  }

  .panel-chat:not(.active) {
    /* always visible on desktop */
  }

  #chat-back-btn {
    display: none;
  }
}

/* Mobile layout */
@media (max-width: 767px) {
  .panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }

  .panel-chat.active {
    z-index: 5;
    background: var(--bg);
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--surface);
  border-radius: 2px;
}