/* === Telegram Authentic Theme Styles === */

:root {
  --tg-blue: #2481cc;
  --tg-blue-hover: #1e71b2;
  --tg-green: #4fae4e;
  --tg-red: #e53935;
  --tg-red-hover: #c62828;
  
  /* Dark Theme Palette (Default) */
  --bg-primary: #0e1621;
  --bg-secondary: #17212b;
  --bg-active: #232e3c;
  --bg-hover: #1c2733;
  --bg-input: #242f3d;
  --border-color: #101921;

  --text-primary: #f5f5f5;
  --text-secondary: #7f91a4;
  --text-muted: #5e6e7f;

  --bubble-out: #2b5278;
  --bubble-in: #182533;
  --bubble-out-text: #ffffff;
  --bubble-in-text: #ffffff;
  --time-out: #7da5cc;
  --time-in: #728496;

  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.light-theme {
  --bg-primary: #ffffff;
  --bg-secondary: #ffffff;
  --bg-active: #f4f4f5;
  --bg-hover: #f0f2f5;
  --bg-input: #f4f4f5;
  --border-color: #dfe1e5;

  --text-primary: #111111;
  --text-secondary: #707579;
  --text-muted: #999999;

  --bubble-out: #eeffde;
  --bubble-in: #ffffff;
  --bubble-out-text: #000000;
  --bubble-in-text: #000000;
  --time-out: #4fae4e;
  --time-in: #a0a0a0;

  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}
body.light-theme ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
}

/* --- Avatars --- */
.avatar {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #ffffff;
  user-select: none;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}
.avatar.sm { width: 42px; height: 42px; font-size: 16px; }
.avatar.md { width: 50px; height: 50px; font-size: 18px; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.avatar.xl { width: 110px; height: 110px; font-size: 38px; }

/* --- Buttons & Inputs --- */
button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  outline: none;
}
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.btn-primary {
  background: var(--tg-blue);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.2s;
  width: 100%;
}
.btn-primary:hover {
  background: var(--tg-blue-hover);
}

/* --- Auth Overlay --- */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-logo { margin-bottom: 16px; }
.auth-card h2 { font-size: 22px; margin-bottom: 6px; }
.auth-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.auth-tabs {
  display: flex;
  background: var(--bg-input);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  padding: 8px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}
.auth-tab.active {
  background: var(--tg-blue);
  color: #fff;
}
.form-group { margin-bottom: 14px; }
.form-group input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus {
  border-color: var(--tg-blue);
}
.auth-error {
  color: var(--tg-red);
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

/* --- Main Layout --- */
.app-layout {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
}

/* --- Sidebar --- */
.sidebar {
  width: 380px;
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.sidebar-header {
  height: 56px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-color);
}
.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border-radius: 20px;
  padding: 0 12px;
  height: 38px;
}
.search-icon {
  color: var(--text-muted);
  margin-right: 8px;
}
.search-box input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
.search-box input::placeholder {
  color: var(--text-muted);
}

/* Side Drawer */
.side-drawer {
  position: absolute;
  top: 0;
  left: -300px;
  width: 280px;
  height: 100%;
  background: var(--bg-secondary);
  box-shadow: 2px 0 12px rgba(0,0,0,0.4);
  z-index: 100;
  transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}
.side-drawer.open { left: 0; }
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  display: none;
}
.drawer-backdrop.open { display: block; }
.drawer-header {
  padding: 24px 16px;
  background: var(--bg-active);
  display: flex;
  align-items: center;
  gap: 14px;
}
.my-name { font-size: 16px; font-weight: 600; }
.my-username { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.drawer-menu { padding: 10px 0; flex: 1; }
.drawer-item {
  width: 100%;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-primary);
  font-size: 15px;
  transition: background 0.15s;
}
.drawer-item:hover { background: var(--bg-hover); }
.drawer-item.danger { color: var(--tg-red); }
.drawer-divider {
  height: 1px;
  background: var(--border-color);
  margin: 8px 0;
}

/* Chat List */
.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;
  position: relative;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--tg-blue); }
.chat-item.active .chat-item-name,
.chat-item.active .chat-item-snippet,
.chat-item.active .chat-item-time {
  color: #fff !important;
}
.chat-avatar-wrap {
  position: relative;
}
.online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--tg-green);
  border: 2px solid var(--bg-secondary);
}
.chat-item-content {
  flex: 1;
  min-width: 0;
}
.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.chat-item-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-time {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-item-snippet {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.unread-badge {
  background: var(--tg-green);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 12px;
  padding: 2px 7px;
  margin-left: 6px;
}

/* --- Chat View --- */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-primary);
  position: relative;
}
.no-chat-selected {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-state {
  text-align: center;
  max-width: 320px;
  padding: 20px;
}
.empty-icon { margin-bottom: 18px; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; }
.empty-state p { color: var(--text-secondary); font-size: 14px; margin-bottom: 20px; }

.active-chat-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}
.chat-header {
  height: 56px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 5;
}
.mobile-only { display: none; }
.chat-header-info {
  flex: 1;
  min-width: 0;
}
.chat-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-status {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}
.chat-status.online { color: var(--tg-blue); }

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

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-primary);
  background-image: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.015) 0%, transparent 100%);
}

.msg-date-badge {
  align-self: center;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 12px;
  margin: 8px 0;
}

.msg-row {
  display: flex;
  width: 100%;
}
.msg-row.out { justify-content: flex-end; }
.msg-row.in { justify-content: flex-start; }

.msg-bubble {
  max-width: 65%;
  min-width: 80px;
  padding: 8px 12px 6px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.35;
  position: relative;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.msg-row.out .msg-bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 4px;
}
.msg-row.in .msg-bubble {
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  border-bottom-left-radius: 4px;
}

.msg-meta {
  float: right;
  margin-left: 8px;
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  user-select: none;
}
.msg-row.out .msg-meta { color: var(--time-out); }
.msg-row.in .msg-meta { color: var(--time-in); }

.check-icon {
  width: 14px;
  height: 14px;
}

/* Voice Message Bubble */
.voice-msg-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
  min-width: 220px;
}
.voice-play-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tg-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.voice-waveform-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.voice-waveform-slider {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  accent-color: var(--tg-blue);
  cursor: pointer;
}
.voice-duration {
  font-size: 12px;
  color: var(--time-in);
}
.msg-row.out .voice-duration { color: var(--time-out); }

/* Image Bubble */
.msg-image {
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
  display: block;
  margin-bottom: 4px;
}

/* Typing Indicator */
.typing-indicator {
  padding: 4px 20px 8px;
  font-size: 13px;
  color: var(--tg-blue);
  display: flex;
  align-items: center;
  gap: 4px;
}
.typing-dot {
  width: 5px;
  height: 5px;
  background: var(--tg-blue);
  border-radius: 50%;
  animation: typing 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* Chat Input Bar */
.chat-input-bar {
  min-height: 56px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  position: relative;
}
.input-wrapper {
  flex: 1;
  background: var(--bg-input);
  border-radius: 18px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
}
.input-wrapper textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.35;
  outline: none;
  resize: none;
  max-height: 120px;
  font-family: inherit;
}
.input-wrapper textarea::placeholder {
  color: var(--text-muted);
}
.voice-btn, .send-btn {
  color: var(--tg-blue);
}

/* Voice Recording Bar */
.voice-recording-bar {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  border-radius: 18px;
  padding: 6px 14px;
}
.recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--tg-red);
  font-weight: 600;
  font-size: 14px;
}
.recording-dot {
  width: 10px;
  height: 10px;
  background: var(--tg-red);
  border-radius: 50%;
  animation: pulse 1s infinite alternate;
}
@keyframes pulse {
  from { opacity: 0.3; }
  to { opacity: 1; }
}

/* Contacts Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  background: var(--bg-secondary);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.contacts-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}
.contact-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s;
}
.contact-item:hover { background: var(--bg-hover); }
.contact-name { font-weight: 600; font-size: 15px; }
.contact-username { color: var(--text-secondary); font-size: 13px; }

/* === WebRTC Audio Call Screen (Overlay) === */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.call-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(14, 22, 33, 0.94);
  backdrop-filter: blur(20px);
}
.call-content {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 100%;
  max-width: 360px;
  padding: 30px;
}

.call-avatar-wrapper {
  position: relative;
  margin-bottom: 24px;
}
.call-pulse-ring {
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 2px solid rgba(36, 129, 204, 0.5);
  animation: ripple 2s infinite ease-out;
}
.call-pulse-ring.delay {
  animation-delay: 1s;
}
@keyframes ripple {
  0% { transform: scale(0.9); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

.call-name {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
  color: #fff;
}
.call-status {
  font-size: 15px;
  color: var(--tg-blue);
  margin-bottom: 20px;
  font-weight: 500;
}

#call-visualizer {
  width: 240px;
  height: 40px;
  margin-bottom: 40px;
}

.call-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
}
.call-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
  color: #fff;
}
.call-btn:active { transform: scale(0.92); }
.call-btn.secondary {
  background: rgba(255, 255, 255, 0.15);
}
.call-btn.secondary.muted {
  background: var(--tg-red);
}
.call-btn.success {
  background: var(--tg-green);
}
.call-btn.danger {
  background: var(--tg-red);
}

/* === Responsive (Mobile view) === */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
  }
  .chat-view {
    position: absolute;
    inset: 0;
    z-index: 20;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .chat-view.active {
    transform: translateX(0);
  }
  .mobile-only {
    display: flex;
  }
  .msg-bubble {
    max-width: 82%;
  }
}

/* Admin & Notice Styles */
.auth-footer-notice {
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

.my-badge-role {
  font-size: 11px;
  font-weight: 600;
  color: var(--tg-green);
  margin-top: 2px;
}

.admin-item {
  color: #ffb74d !important;
}
.admin-item svg {
  color: #ffb74d;
}

.admin-modal-card {
  max-width: 520px;
}
.admin-modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  max-height: 70vh;
}
.admin-create-section h4, .admin-users-section h4 {
  font-size: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}
.admin-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.admin-form-grid input[type="text"],
.admin-form-grid input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
.admin-checkbox-label {
  grid-column: span 2;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-primary);
}
.admin-create-btn {
  padding: 10px;
  font-size: 14px;
}
.admin-form-msg {
  font-size: 13px;
  margin-top: 8px;
  min-height: 16px;
}
.admin-divider {
  height: 1px;
  background: var(--border-color);
  margin: 20px 0;
}
.admin-users-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.admin-user-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-input);
  border-radius: 10px;
}
.admin-user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.admin-user-name {
  font-weight: 600;
  font-size: 14px;
}
.admin-user-tag {
  font-size: 12px;
  color: var(--text-secondary);
}
.admin-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 183, 77, 0.2);
  color: #ffb74d;
  margin-left: 6px;
}
.admin-del-btn {
  color: var(--tg-red);
  padding: 6px;
  border-radius: 6px;
  transition: background 0.15s;
}
.admin-del-btn:hover {
  background: rgba(229, 57, 53, 0.15);
}
