:root {
  --bg-primary: #17212b;
  --bg-secondary: #0e1621;
  --bg-hover: #202b36;
  --bg-active: #2b5278;
  --bg-message-out: #2b5278;
  --bg-message-in: #182533;
  --bg-input: #242f3d;
  --text-primary: #f5f5f5;
  --text-secondary: #708499;
  --text-link: #6ab2f2;
  --accent: #5288c1;
  --accent-hover: #6ba0d6;
  --green: #4fae4e;
  --red: #e53935;
  --border: #0e1621;
  --shadow: rgba(0,0,0,0.3);
}

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

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

/* AUTH */
.auth-container {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg-secondary);
}
.auth-box {
  background: var(--bg-primary); border-radius: 12px;
  padding: 40px; width: 360px;
  box-shadow: 0 4px 20px var(--shadow);
}
.auth-box h1 { text-align: center; margin-bottom: 8px; font-size: 24px; }
.auth-box .subtitle {
  text-align: center; color: var(--text-secondary);
  margin-bottom: 24px; font-size: 14px;
}
.form-group { margin-bottom: 16px; }
.form-group input {
  width: 100%; padding: 12px 16px;
  background: var(--bg-input); border: 2px solid transparent;
  border-radius: 8px; color: var(--text-primary);
  font-size: 15px; outline: none; transition: border 0.2s;
}
.form-group input:focus { border-color: var(--accent); }
.form-group input::placeholder { color: var(--text-secondary); }

.btn {
  width: 100%; padding: 12px; background: var(--accent);
  border: none; border-radius: 8px; color: #fff;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background 0.2s;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #c62828; }
.btn-sm { width: auto; padding: 6px 16px; font-size: 13px; }

.auth-toggle {
  text-align: center; margin-top: 16px;
  color: var(--text-secondary); font-size: 14px;
}
.auth-toggle a { color: var(--text-link); cursor: pointer; text-decoration: none; }

.error-msg {
  background: rgba(229,57,53,0.15); color: var(--red);
  padding: 10px; border-radius: 8px; margin-bottom: 16px;
  font-size: 13px; text-align: center; display: none;
}

/* APP LAYOUT */
.app-container { display: none; height: 100vh; width: 100vw; }
.app-layout { display: flex; height: 100%; }

/* SIDEBAR */
.sidebar {
  width: 380px; min-width: 380px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; height: 100%;
}
.sidebar-header {
  padding: 8px 12px; display: flex;
  align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header .hamburger {
  width: 40px; height: 40px; border: none;
  background: transparent; color: var(--text-secondary);
  font-size: 20px; cursor: pointer; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.sidebar-header .hamburger:hover { background: var(--bg-hover); }

.search-box { flex: 1; position: relative; }
.search-box input {
  width: 100%; padding: 10px 16px 10px 36px;
  background: var(--bg-input); border: none;
  border-radius: 20px; color: var(--text-primary);
  font-size: 14px; outline: none;
}
.search-box input::placeholder { color: var(--text-secondary); }
.search-box i {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%); color: var(--text-secondary); font-size: 14px;
}

.chat-list {
  flex: 1; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--bg-hover) transparent;
}
.chat-item {
  display: flex; align-items: center; padding: 10px 12px;
  cursor: pointer; transition: background 0.15s; gap: 12px;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }

.chat-avatar-wrap { position: relative; flex-shrink: 0; }
.chat-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); display: flex;
  align-items: center; justify-content: center;
  font-size: 20px; font-weight: 600; color: #fff;
  text-transform: uppercase;
}
.online-dot {
  width: 14px; height: 14px; background: var(--green);
  border: 2px solid var(--bg-secondary); border-radius: 50%;
  position: absolute; bottom: 0; right: 0;
}
.chat-info { flex: 1; min-width: 0; }
.chat-info-top {
  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: 12px; color: var(--text-secondary); flex-shrink: 0; }
.chat-preview {
  font-size: 14px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-unread-wrap { flex-shrink: 0; }
.chat-unread {
  background: var(--accent); color: #fff; border-radius: 12px;
  min-width: 22px; height: 22px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}

.search-results { display: none; flex: 1; overflow-y: auto; }
.search-result-item {
  display: flex; align-items: center; padding: 10px 12px;
  cursor: pointer; gap: 12px; transition: background 0.15s;
}
.search-result-item:hover { background: var(--bg-hover); }
.search-section-title {
  padding: 8px 16px; font-size: 13px;
  color: var(--text-link); font-weight: 600;
}

/* MAIN CHAT */
.main-area {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg-primary); position: relative;
}
.no-chat {
  display: flex; align-items: center; justify-content: center;
  flex: 1; color: var(--text-secondary); font-size: 16px;
  flex-direction: column; gap: 8px;
}
.no-chat i { font-size: 48px; opacity: 0.3; }

#chatView { display: none; flex: 1; flex-direction: column; }
#chatView.active { display: flex; }

.chat-header {
  padding: 10px 16px; background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.chat-header-back {
  display: none; background: transparent; border: none;
  color: var(--text-secondary); font-size: 20px;
  cursor: pointer; padding: 4px;
}
.chat-header-info { flex: 1; cursor: pointer; }
.chat-header-name { font-size: 15px; font-weight: 600; }
.chat-header-status { font-size: 13px; color: var(--text-secondary); }
.chat-header-status.online { color: var(--green); }

.messages-area {
  flex: 1; overflow-y: auto; padding: 10px 20px;
  display: flex; flex-direction: column;
  scrollbar-width: thin; scrollbar-color: var(--bg-hover) transparent;
}

.message {
  max-width: 70%; margin-bottom: 4px; padding: 8px 12px;
  border-radius: 12px; position: relative;
  font-size: 14px; line-height: 1.4; word-wrap: break-word;
}
.message.out {
  background: var(--bg-message-out); align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.message.in {
  background: var(--bg-message-in); align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.message .msg-text { margin-bottom: 2px; white-space: pre-wrap; }
.message .msg-meta {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 4px; margin-top: 2px;
}
.message .msg-time { font-size: 11px; color: rgba(255,255,255,0.4); }
.message .msg-status { font-size: 12px; color: rgba(255,255,255,0.4); }
.message .msg-status.read { color: var(--text-link); }
.message .msg-edited { font-size: 11px; color: rgba(255,255,255,0.3); font-style: italic; }

.date-separator { text-align: center; margin: 12px 0; }
.date-separator span {
  background: var(--bg-secondary); padding: 4px 12px;
  border-radius: 12px; font-size: 13px; color: var(--text-secondary);
}

.typing-indicator {
  font-size: 13px; color: var(--text-link);
  padding: 4px 20px; display: none;
}

.message-input-area {
  padding: 8px 12px; background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex; align-items: flex-end; gap: 8px;
}
.message-input-area textarea {
  flex: 1; padding: 10px 14px; background: var(--bg-input);
  border: none; border-radius: 20px; color: var(--text-primary);
  font-size: 14px; resize: none; outline: none;
  max-height: 120px; min-height: 42px;
  font-family: inherit; line-height: 1.4;
}
.message-input-area textarea::placeholder { color: var(--text-secondary); }

.editing-bar {
  padding: 6px 12px; background: var(--bg-input);
  display: none; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-link);
  border-top: 1px solid var(--border);
}
.editing-bar .cancel-edit {
  background: transparent; border: none; color: var(--text-secondary);
  cursor: pointer; font-size: 16px; margin-left: auto;
}

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

/* SLIDE MENU */
.slide-menu-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); z-index: 100;
  display: none; opacity: 0; transition: opacity 0.25s;
}
.slide-menu-overlay.show { display: block; opacity: 1; }

.slide-menu {
  position: fixed; top: 0; left: -300px;
  width: 300px; height: 100%; background: var(--bg-secondary);
  z-index: 101; transition: left 0.25s ease;
  display: flex; flex-direction: column;
}
.slide-menu.open { left: 0; }

.slide-menu-header {
  padding: 20px 16px; border-bottom: 1px solid var(--border);
}
.slide-menu-avatar {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--accent); display: flex;
  align-items: center; justify-content: center;
  font-size: 24px; font-weight: 600; color: #fff;
  text-transform: uppercase; margin-bottom: 12px;
}
.slide-menu-name { font-size: 16px; font-weight: 600; }
.slide-menu-username { font-size: 14px; color: var(--text-secondary); }

.slide-menu-items { flex: 1; padding: 8px 0; }
.slide-menu-item {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; cursor: pointer; color: var(--text-primary);
  font-size: 15px; transition: background 0.15s;
}
.slide-menu-item:hover { background: var(--bg-hover); }
.slide-menu-item i { width: 24px; text-align: center; color: var(--text-secondary); font-size: 18px; }

.slide-menu-footer {
  padding: 12px 20px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-secondary);
}

/* PANELS */
.panel-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 200; display: none;
}
.panel-overlay.show { display: flex; }

.panel {
  width: 420px; height: 100%; background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  animation: slideIn 0.2s ease;
}
@keyframes slideIn {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}
.panel-backdrop { flex: 1; background: rgba(0,0,0,0.4); }

.panel-header {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.panel-header button {
  background: transparent; border: none; color: var(--text-secondary);
  font-size: 20px; cursor: pointer; width: 40px; height: 40px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.panel-header button:hover { background: var(--bg-hover); }
.panel-header h2 { font-size: 18px; font-weight: 600; }

.panel-body { flex: 1; overflow-y: auto; }

.profile-section {
  display: flex; flex-direction: column;
  align-items: center; padding: 30px 20px;
}
.profile-big-avatar {
  width: 100px; height: 100px; border-radius: 50%;
  background: var(--accent); display: flex;
  align-items: center; justify-content: center;
  font-size: 40px; font-weight: 600; color: #fff;
  text-transform: uppercase; margin-bottom: 16px;
}
.profile-edit-name {
  width: 80%; padding: 10px; background: var(--bg-input);
  border: none; border-radius: 8px; color: var(--text-primary);
  font-size: 18px; text-align: center; outline: none; margin-bottom: 8px;
}
.profile-edit-about {
  width: 80%; padding: 10px; background: var(--bg-input);
  border: none; border-radius: 8px; color: var(--text-primary);
  font-size: 14px; text-align: center; outline: none;
  resize: none; min-height: 60px; margin-bottom: 16px;
}
.profile-save-btn { margin: 0 auto; display: block; padding: 10px 40px; }

.profile-info-row {
  width: 100%; padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.profile-info-row label {
  font-size: 13px; color: var(--text-link); display: block; margin-bottom: 4px;
}
.profile-info-row span { font-size: 15px; }

/* KEYS PANEL */
.keys-controls {
  padding: 16px; border-bottom: 1px solid var(--border);
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.keys-controls input {
  width: 70px; padding: 8px; background: var(--bg-input);
  border: none; border-radius: 8px; color: var(--text-primary);
  font-size: 14px; outline: none; text-align: center;
}
.keys-controls label { font-size: 13px; color: var(--text-secondary); }

.key-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.key-item.exhausted { opacity: 0.5; }
.key-code {
  font-family: 'Courier New', monospace; font-size: 16px;
  font-weight: 600; color: var(--text-link);
  letter-spacing: 2px; flex: 1; cursor: pointer;
}
.key-item.exhausted .key-code {
  color: var(--text-secondary); text-decoration: line-through;
}
.key-info { font-size: 12px; color: var(--text-secondary); text-align: right; }
.key-actions { display: flex; gap: 4px; }
.key-actions button {
  background: transparent; border: none; color: var(--text-secondary);
  cursor: pointer; font-size: 16px; padding: 6px; border-radius: 4px;
}
.key-actions button:hover { color: var(--text-primary); background: var(--bg-hover); }

/* CONTEXT MENU */
.context-menu {
  position: fixed; background: var(--bg-secondary);
  border-radius: 8px; box-shadow: 0 4px 16px var(--shadow);
  z-index: 300; display: none; min-width: 160px; padding: 6px 0;
}
.context-menu-item {
  padding: 10px 16px; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  transition: background 0.15s;
}
.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item i { width: 20px; text-align: center; color: var(--text-secondary); }
.context-menu-item.danger { color: var(--red); }
.context-menu-item.danger i { color: var(--red); }

/* TOAST */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: var(--bg-secondary); color: var(--text-primary);
  padding: 10px 20px; border-radius: 8px; font-size: 14px;
  box-shadow: 0 4px 16px var(--shadow); z-index: 500;
  opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* MOBILE */
@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: 100%; }
  .main-area { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 50; }
  .main-area.mobile-show { display: flex; }
  .chat-header-back { display: block; }
  .message { max-width: 85%; }
  .panel { width: 100%; }
}
