/* ===== GLASSMORPHISM THEME ===== */
:root {
  /* Core Colors (Transparent) */
  --telegram-blue: #0088cc;
  --telegram-blue-dark: #006ba1;
  --telegram-blue-light: #40a7e3;

  /* Glass Backgrounds */
  --bg-dark: rgba(14, 22, 33, 0.4);
  /* Main Translucency */
  --bg-darker: rgba(10, 14, 21, 0.6);
  /* Darker Elements (Sidebar) */
  --bg-chat: rgba(23, 33, 43, 0.4);
  /* Message Area */

  /* Message Bubbles (Glassy) */
  --bg-message-out: rgba(43, 82, 120, 0.85);
  --bg-message-in: rgba(24, 37, 51, 0.7);

  --bg-secondary: var(--bg-chat);
  /* Compatibility alias */

  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);

  /* Borders & Highlights */
  --border-color: rgba(255, 255, 255, 0.1);
  --glass-border: 1px solid rgba(255, 255, 255, 0.1);
  --accent-green: #00a884;
}

/* ===== BASE STYLES ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Premium Mesh Gradient Background */
  background:
    radial-gradient(circle at 0% 0%, rgba(55, 0, 60, 0.8) 0%, transparent 50%),
    radial-gradient(circle at 100% 0%, rgba(0, 40, 80, 0.8) 0%, transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(40, 0, 60, 0.8) 0%, transparent 50%),
    radial-gradient(circle at 0% 100%, rgba(0, 20, 40, 0.8) 0%, transparent 50%),
    linear-gradient(135deg, #0f0c29, #302b63, #24243e);

  background-size: 200% 200%;
  animation: gradientBG 15s ease infinite;

  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  color: var(--text-primary);
}

@keyframes gradientBG {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

button,
.btn {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

button:active,
.btn:active {
  transform: scale(0.96);
}

/* ===== LAYOUT ===== */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  width: 30%;
  background: var(--bg-darker);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  border-right: var(--glass-border);
  box-shadow: 5px 0 15px rgba(0, 0, 0, 0.2);
}

.sidebar-header {
  padding: 15px 20px;
  background: var(--bg-chat);
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.tab-buttons {
  display: flex;
  gap: 0;
  padding: 0;
  background: var(--bg-darker);
  border-bottom: 2px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 8px 8px 0 0;
  /* Modern look */
}

.tab-btn:hover {
  color: var(--telegram-blue-light);
  background: rgba(0, 136, 204, 0.1);
}

.tab-btn.active {
  color: var(--telegram-blue);
  border-bottom-color: var(--telegram-blue);
  background: rgba(0, 136, 204, 0.05);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 20px;
  /* Prevent bottom congestion */
}

/* ... existing scrollbar styles ... */

.chat-header-info {
  cursor: pointer;
  transition: opacity 0.2s;
  padding: 4px 8px;
  border-radius: 8px;
}

.chat-header-info:hover {
  background: rgba(255, 255, 255, 0.05);
}

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

.chat-list::-webkit-scrollbar {
  width: 4px;
  /* Slimmer */
}

.chat-list::-webkit-scrollbar-track {
  background: transparent;
  /* Invisible track */
}

.chat-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  transition: background 0.2s;
}

.chat-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

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

.chat-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
  transform: translateX(2px);
}

.chat-item.active {
  background-color: rgba(0, 136, 204, 0.15);
  border-left: 3px solid var(--telegram-blue);
}

.chat-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--telegram-blue), var(--telegram-blue-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: white;
  position: relative;
  flex-shrink: 0;
}

.online-dot {
  width: 14px;
  height: 14px;
  background: var(--accent-green);
  border-radius: 50%;
  position: absolute;
  bottom: 0;
  right: 0;
  border: 3px solid var(--bg-darker);
}

.chat-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.list-subscribe-btn {
  background: var(--telegram-blue);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  margin-left: 8px;
  transition: all 0.2s;
}

.list-subscribe-btn:hover {
  background: var(--telegram-blue-light);
  transform: scale(1.05);
}

.locked-channel-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  text-align: center;
  padding: 20px;
}

.chat-name {
  font-weight: 500;
  font-size: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.chat-last {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  background: var(--telegram-blue);
  color: white;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  padding: 0 6px;
}

/* Feature Icon Buttons (Settings, Saved) */
.feature-icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 16px;
}

.feature-icon-btn:hover {
  background: var(--telegram-blue-light);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 0 10px rgba(0, 136, 204, 0.4);
  border-color: rgba(255, 255, 255, 0.3);
}

.new-chat-btn {
  background: var(--telegram-blue);
  border: none;
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.new-chat-btn:hover {
  background: var(--telegram-blue-light);
  transform: translateY(-1px);
  box-shadow: 0 0 15px rgba(0, 136, 204, 0.5);
  /* Stronger glow */
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ===== CHAT AREA ===== */
.chat-area {
  width: 70%;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  background: rgba(23, 33, 43, 0.6);
  /* Slightly more opaque for header */
  backdrop-filter: blur(20px);
  border-bottom: var(--glass-border);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

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

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-btn {
  padding: 8px 16px;
  background: var(--telegram-blue);
  color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.header-btn:hover {
  background: var(--telegram-blue-light);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 136, 204, 0.3);
}

.header-btn:active {
  transform: translateY(0);
}

.status {
  font-size: 13px;
  color: var(--telegram-blue-light);
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: var(--bg-dark);
}

.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #2a3942;
}

/* ===== TELEGRAM-STYLE MESSAGES ===== */
.message {
  max-width: 65%;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 12px;
  font-size: 14.5px;
  word-wrap: break-word;
  position: relative;
  animation: messageSlideIn 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }

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

/* Telegram-style bubble tails (Modified for Glass) */
.sent {
  background: var(--bg-message-out);
  backdrop-filter: blur(4px);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.sent::after {
  content: '';
  position: absolute;
  bottom: -1px;
  /* Adjust for border */
  right: -8px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 13px 8px;
  border-color: transparent transparent var(--bg-message-out) transparent;
}

.received {
  background: var(--bg-message-in);
  backdrop-filter: blur(4px);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.received::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: -8px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 8px 13px 0;
  border-color: transparent var(--bg-message-in) transparent transparent;
}

.message-time {
  font-size: 11px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

/* ===== MODALS ===== */
.modal {
  display: none;
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: opacity 0.3s ease;
}

.modal.show {
  display: flex;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal-content {
  background: rgba(30, 40, 50, 0.85);
  backdrop-filter: blur(30px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 24px;
  border-radius: 16px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  color: var(--text-primary);
  animation: modalSlideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }

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

/* ===== LOGIN ===== */
.login {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: rgba(23, 33, 43, 0.6);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 40px;
  border-radius: 16px;
  width: 360px;
  text-align: center;
  color: white;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.login-box h2 {
  margin-bottom: 24px;
  color: var(--telegram-blue);
  font-size: 28px;
}

.login-box input {
  width: 100%;
  padding: 14px;
  margin: 15px 0;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-darker);
  color: white;
  font-size: 15px;
  transition: all 0.2s;
}

.login-box input:focus {
  outline: none;
  border-color: var(--telegram-blue);
  background: var(--bg-dark);
}

.login-box button {
  width: 100%;
  padding: 14px;
  background: var(--telegram-blue);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 15px;
  font-weight: 600;
}


.login-box button:hover {
  background: var(--telegram-blue-light);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 136, 204, 0.4);
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 20px 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-color);
}

.divider::before {
  margin-right: 10px;
}

.divider::after {
  margin-left: 10px;
}

.google-btn {
  display: block;
  width: 100%;
  padding: 14px;
  background: white;
  color: #333;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 15px;
  transition: all 0.2s;
  text-align: center;
}

.google-btn:hover {
  background: #f1f1f1;
}

/* ===== SETTINGS & PROFILE MODALS ===== */
.settings-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.avatar-upload-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.settings-avatar-preview {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: bold;
  overflow: hidden;
  border: 2px solid var(--border-color);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transition: all 0.3s;
}

.settings-avatar-preview:hover {
  border-color: var(--telegram-blue);
  box-shadow: 0 0 15px rgba(0, 136, 204, 0.3);
}

.settings-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-input,
.settings-textarea {
  width: 100%;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  /* Darker glass for inputs */
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  transition: all 0.2s;
}

.settings-input:focus,
.settings-textarea:focus {
  background: rgba(0, 0, 0, 0.4);
  border-color: var(--telegram-blue);
  outline: none;
  box-shadow: 0 0 0 2px rgba(0, 136, 204, 0.2);
}

.settings-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.btn-cancel {
  flex: 1;
  padding: 12px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-cancel:hover {
  background: rgba(255, 255, 255, 0.05);
  color: white;
}

.btn-save {
  flex: 1;
  padding: 12px;
  background: var(--telegram-blue);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-save:hover {
  background: var(--telegram-blue-light);
  box-shadow: 0 4px 15px rgba(0, 136, 204, 0.4);
  transform: translateY(-1px);
}

/* Profile Read-Only */
.profile-modal-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  padding-bottom: 10px;
}

.profile-avatar-large {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 45px;
  font-weight: bold;
  overflow: hidden;
  border: 4px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.profile-name {
  margin: 0;
  font-size: 24px;
  color: var(--text-primary);
  font-weight: 700;
  text-align: center;
}

.profile-status {
  color: var(--telegram-blue-light);
  font-size: 14px;
  margin-top: 4px;
  text-align: center;
}

.profile-section {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  padding: 16px;
  border-radius: 12px;
  margin-top: 8px;
  border: 1px solid var(--border-color);
}

.sidebar {
  transition: width 0.3s ease, transform 0.3s ease;
}

.sidebar.closed {
  width: 0;
  opacity: 0;
  overflow: hidden;
  border: none;
}

.chat-area {
  transition: width 0.3s ease;
  width: 70%;
  /* Default */
}

.chat-area.expanded {
  width: 100%;
}

/* Show sidebar toggle button when sidebar is closed (chat area expanded) */
.chat-area.expanded #desktopSidebarToggle {
  display: block !important;
}

/* ===== RESPONSIVE ===== */
/* Tablet & Mobile (< 900px) */
@media (max-width: 900px) {
  .app {
    position: relative;
    overflow: hidden;
  }

  .sidebar {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 10;
    transform: translateX(0);
  }

  /* When sidebar is "closed" on mobile, it slides out or hides */
  .sidebar.mobile-hidden {
    transform: translateX(-100%);
    opacity: 0;
    display: none;
    /* Hide to prevent interactions */
  }

  .chat-area {
    width: 100%;
    height: 100%;
    display: flex;
    /* Always flex, but might be covered by sidebar */
  }

  /* Show/Hide Buttons Logic */
  #desktopSidebarToggle {
    display: none !important;
    /* Hide desktop hamburger on mobile */
  }

  #mobileBackBtn {
    display: block !important;
    /* Show back button on mobile */
  }

  .message {
    max-width: 85%;
  }

  .chat-input {
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    /* Slightly compact on mobile */
  }
}