/* ============================================
   SentinelBot — Telegram Web K Clone
   Pixel-perfect copy of Telegram Web K design
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-color: #0e1621;
  --bg-secondary: #17212b;
  --bg-tertiary: #1e2b37;
  --bg-hover: #202b36;
  --bg-selected: #2b5278;
  --bg-input: #242f3d;
  --text-color: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-muted: rgba(255, 255, 255, 0.35);
  --text-faint: rgba(255, 255, 255, 0.2);
  --accent: #2ea6ff;
  --accent-hover: #6ab4f0;
  --own-bubble: #2b5278;
  --other-bubble: #182533;
  --border-color: rgba(255, 255, 255, 0.08);
  --divider-color: rgba(255, 255, 255, 0.04);
  --green: #4fae4e;
  --red: #e53935;
  --orange: #fb8c00;
  --sidebar-width: 320px;
  --header-height: 54px;
  --input-height: 52px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-color);
  background: var(--bg-color);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   SCREENS
   ============================================ */
.screen {
  display: none;
  height: 100vh;
  height: 100dvh;
}

.screen.active {
  display: block;
}

/* ============================================
   AUTH SCREEN
   ============================================ */
.auth-container {
  max-width: 400px;
  margin: 0 auto;
  padding: 80px 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
}

.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  box-shadow: 0 4px 20px rgba(46, 166, 255, 0.3);
}

.auth-logo svg {
  width: 36px;
  height: 36px;
  stroke: white;
}

.auth-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-color);
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 36px;
}

.auth-card {
  width: 100%;
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 24px;
  border: 1px solid var(--border-color);
}

.auth-step-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
}

.auth-step-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.auth-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-color);
  font-size: 15px;
  font-family: inherit;
  margin-bottom: 14px;
  transition: border-color 0.15s;
  outline: none;
}

.auth-input:focus {
  border-color: var(--accent);
}

.auth-input::placeholder {
  color: var(--text-muted);
}

.auth-button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s;
}

.auth-button:hover {
  background: var(--accent-hover);
}

.auth-button:active {
  opacity: 0.85;
}

.auth-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-back-button {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  margin-top: 6px;
  transition: opacity 0.15s;
}

.auth-back-button:hover {
  opacity: 0.8;
}

.auth-footer {
  margin-top: 28px;
  text-align: center;
}

.auth-footer p {
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================
   APP LAYOUT
   ============================================ */
.app-layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ============================================
   SIDEBAR — Telegram Web K
   ============================================ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  background: var(--bg-secondary);
}

.sidebar-header h1 {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-color);
}

.sidebar-header .icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.sidebar-header .icon-btn:hover {
  background: var(--bg-hover);
}

/* Search */
.search-section {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  color: var(--text-muted);
  transition: background 0.15s;
}

.search-box:focus-within {
  background: var(--bg-input);
  border: 1px solid var(--accent);
}

.search-box svg {
  flex-shrink: 0;
  opacity: 0.5;
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-color);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.filter-buttons {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.filter-btn {
  flex: 1;
  padding: 5px 8px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn:hover {
  background: var(--bg-hover);
  color: var(--text-color);
}

.filter-btn.active {
  background: var(--accent);
  color: #fff;
}

/* Chat List */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.chat-list::-webkit-scrollbar {
  width: 4px;
}

.chat-list::-webkit-scrollbar-track {
  background: transparent;
}

.chat-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

/* Chat Item — Telegram Web K style */
.chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: none;
}

.chat-item:hover {
  background: var(--bg-hover);
}

.chat-item.active {
  background: var(--bg-selected);
}

.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  position: relative;
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chat-avatar .avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: #fff;
}

.chat-info {
  flex: 1;
  min-width: 0;
  padding: 2px 0;
}

.chat-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 2px;
}

.chat-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-color);
}

.chat-time {
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
  white-space: nowrap;
}

.chat-preview {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 0;
  line-height: 1.3;
}

.chat-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.chat-type-badge {
  font-size: 10px;
  color: var(--text-faint);
}

/* ============================================
   MAIN CHAT AREA
   ============================================ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-color);
  position: relative;
  min-width: 0;
}

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
  gap: 12px;
}

.empty-state svg {
  opacity: 0.1;
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 500;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 13px;
  max-width: 280px;
  color: var(--text-muted);
}

/* Chat View */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Chat Header */
.chat-header {
  height: var(--header-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.back-button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.chat-header-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-width: 0;
}

.chat-header-info .chat-avatar {
  width: 36px;
  height: 36px;
  font-size: 15px;
}

.chat-details {
  min-width: 0;
}

.chat-details h3 {
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-color);
}

.chat-details p {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-actions {
  display: flex;
  gap: 4px;
}

.chat-header-actions .icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.chat-header-actions .icon-btn:hover {
  background: var(--bg-hover);
}

/* Messages Container — Telegram pattern background */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-color);
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.012'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.messages-container::-webkit-scrollbar {
  width: 4px;
}

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

/* Date Separator — Telegram style */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0;
  position: relative;
}

.date-separator span {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-color);
  padding: 4px 12px;
  border-radius: 8px;
  z-index: 1;
}

/* Message Rows */
.message-row {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  margin: 1px 0;
  position: relative;
  animation: messageFadeIn 0.15s ease-out;
}

@keyframes messageFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-row.own {
  align-self: flex-end;
  align-items: flex-end;
}

.message-row.other {
  align-self: flex-start;
  align-items: flex-start;
}

/* Sender name in groups — Telegram style colored */
.message-sender {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 1px;
  padding-left: 12px;
  cursor: pointer;
  transition: opacity 0.1s;
}

.message-sender:hover {
  opacity: 0.8;
}

/* Message Bubble — Telegram Web K exact */
.message-bubble {
  padding: 6px 10px 6px 12px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
  max-width: 100%;
}

/* Own message — blue bubble */
.message-row.own .message-bubble {
  background: var(--own-bubble);
  color: #fff;
  border-radius: 12px 12px 4px 12px;
}

/* Other message — dark bubble */
.message-row.other .message-bubble {
  background: var(--other-bubble);
  color: #fff;
  border-radius: 12px 12px 12px 4px;
}

/* Deleted message */
.message-deleted .message-bubble {
  background: transparent;
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
  padding: 4px 10px;
  border: 1px dashed var(--border-color);
  border-radius: 8px;
}

/* Message time inside bubble — Telegram style */
.message-time {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 2px;
  white-space: nowrap;
  padding-left: 8px;
  display: inline;
  float: right;
  line-height: 1;
  vertical-align: baseline;
}

.message-row.other .message-time {
  color: rgba(255, 255, 255, 0.3);
}

/* Media messages */
.message-media .message-bubble {
  padding: 4px;
  overflow: hidden;
}

.message-media img,
.message-media video {
  max-width: 100%;
  border-radius: 8px;
  display: block;
}

.message-media .message-text {
  padding: 4px 8px 2px;
  font-size: 14px;
}

.message-media .message-time {
  padding: 0 8px 4px;
}

/* Sticker */
.message-sticker {
  width: 140px;
  height: 140px;
  display: block;
}

/* Voice message */
.message-voice {
  width: 220px;
  height: 40px;
  border-radius: 8px;
}

/* Document */
.message-document {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.message-document svg {
  flex-shrink: 0;
  opacity: 0.6;
}

/* ============================================
   MESSAGE INPUT — Telegram style
   ============================================ */
.message-input-area {
  padding: 8px 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  flex-shrink: 0;
  height: var(--input-height);
}

.message-input-area input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  color: var(--text-color);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.message-input-area input:focus {
  border-color: var(--accent);
}

.message-input-area input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:active {
  opacity: 0.85;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================
   PROFILE PANEL
   ============================================ */
.profile-panel {
  width: 340px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.profile-header {
  height: var(--header-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.profile-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  text-align: center;
}

.profile-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-name {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 2px;
}

.profile-username {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.profile-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.profile-info-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-size: 13px;
}

.profile-info-item svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.profile-info-item span {
  color: var(--text-secondary);
}

/* ============================================
   SKELETON LOADING
   ============================================ */
.skeleton-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  flex-shrink: 0;
  animation: pulse 1.5s ease-in-out infinite;
}

.skeleton-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.skeleton-line {
  height: 12px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  animation: pulse 1.5s ease-in-out infinite;
}

.skeleton-line.short {
  width: 60%;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.7; }
}

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-color);
  z-index: 1000;
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  border-color: var(--red);
  background: rgba(229, 57, 53, 0.15);
}

.toast.success {
  border-color: var(--green);
  background: rgba(79, 174, 78, 0.15);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: absolute;
    z-index: 10;
    height: 100%;
  }

  .sidebar.hidden {
    display: none;
  }

  .chat-area {
    width: 100%;
  }

  .back-button {
    display: flex;
  }

  .profile-panel {
    width: 100%;
    position: absolute;
    z-index: 10;
    height: 100%;
  }
}

@media (min-width: 769px) {
  .back-button {
    display: none;
  }
}