:root {
  --bg: #0b1220;
  --sidebar: #111827;
  --panel: #172033;
  --panel-2: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #253247;
  --accent: #3390ec;
  --accent-2: #2477c9;
  --success: #16a34a;
  --danger: #dc2626;
  --message-me: #2b5278;
  --message-peer: #1b2538;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: Inter, Arial, sans-serif;
  background: linear-gradient(180deg, #09101d, #0b1220);
  color: var(--text);
}

.hidden { display: none !important; }
.screen { min-height: 100vh; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.auth-card {
  width: 100%;
  max-width: 420px;
  margin: 70px auto;
  background: rgba(17, 24, 39, 0.98);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.35);
}

.auth-card h1 { margin: 0 0 8px; }
.auth-actions { margin-top: 12px; }

.input,
.bio-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0b1324;
  color: var(--text);
  margin-top: 10px;
  outline: none;
}

.bio-input {
  min-height: 92px;
  resize: vertical;
  font-family: inherit;
}

.input:focus,
.bio-input:focus {
  border-color: var(--accent);
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover { filter: brightness(1.08); }
.primary { background: var(--accent); }
.primary:hover { background: var(--accent-2); }
.small-btn { padding: 8px 12px; font-size: 12px; }
.success-btn { background: var(--success); }
.danger-btn { background: var(--danger); }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #121b2d;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
}

.icon-btn:hover {
  border-color: var(--accent);
  background: #18243a;
}

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

.error {
  margin-top: 12px;
  color: #fca5a5;
  min-height: 20px;
}

#appScreen {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
}

.sidebar {
  background: rgba(15, 23, 42, 0.98);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 12px;
  overflow: hidden;
}

.cardish,
.panel {
  background: rgba(17, 24, 39, 0.98);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-avatar,
.avatar-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  object-fit: cover;
}

.sidebar-avatar-wrap,
.avatar-wrap {
  position: relative;
}

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

.brand {
  font-size: 22px;
  font-weight: 700;
}

.panel {
  padding: 12px;
  overflow: hidden;
}

.grow {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.section-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tabs-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.tab-btn {
  border: 1px solid var(--border);
  background: #10192b;
  color: var(--muted);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.tab-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.2);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.tab-panel {
  min-height: 0;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
}

.compact-list { max-height: 180px; }

.item {
  background: #0d1629;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
}

.item:hover { border-color: #35527a; }

.item-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.item-subtitle {
  color: var(--muted);
  font-size: 13px;
}

.item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #20324f;
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex: 0 0 auto;
  object-fit: cover;
}

.user-meta {
  flex: 1;
  min-width: 0;
}

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #162236;
  color: var(--muted);
  margin-top: 6px;
}

.unread {
  background: var(--accent);
  color: white;
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 12px;
  margin-left: auto;
}

.chat-item {
  padding: 10px;
}

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

.chat-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex: 0 0 auto;
  object-fit: cover;
}

.chat-main {
  flex: 1;
  min-width: 0;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-time {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
}

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

.chat-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background:
    radial-gradient(circle at top left, rgba(51,144,236,0.08), transparent 30%),
    linear-gradient(180deg, #09101d, #0b1220);
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 420px;
}

.empty-icon {
  font-size: 56px;
  margin-bottom: 12px;
}

.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.98);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

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

.chat-title {
  font-size: 19px;
  font-weight: 700;
}

.header-btn {
  white-space: nowrap;
}

.typing {
  color: #7cc4ff;
  font-size: 13px;
  min-width: 90px;
  text-align: right;
}

.media-panel {
  background: rgba(10, 15, 30, 0.98);
  border-bottom: 1px solid var(--border);
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 220px;
  grid-template-rows: 220px auto;
  gap: 12px;
}

.remote-wrap,
.local-wrap {
  position: relative;
  background: #0b1324;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.remote-wrap { grid-column: 1 / 2; }
.local-wrap { grid-column: 2 / 3; }

.remote-video,
.local-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #020617;
}

.media-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(2, 6, 23, 0.7);
  color: white;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.media-actions {
  grid-column: 1 / 3;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  max-width: 72%;
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.4;
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}

.message.me {
  align-self: flex-end;
  background: var(--message-me);
}

.message.peer {
  align-self: flex-start;
  background: var(--message-peer);
}

.message-meta {
  margin-top: 6px;
  font-size: 11px;
  color: rgba(255,255,255,0.72);
}

.message-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.message-action-btn {
  border: 0;
  background: rgba(255,255,255,0.12);
  color: white;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}

.reply-preview {
  border-left: 3px solid rgba(255,255,255,0.35);
  padding-left: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.85);
}

.deleted-message {
  opacity: 0.75;
  font-style: italic;
}

.voice-bubble {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 230px;
}

.voice-title {
  font-size: 13px;
  opacity: 0.92;
}

.voice-audio {
  width: 100%;
  max-width: 320px;
}

.image-message {
  max-width: 320px;
  border-radius: 12px;
  display: block;
}

.video-message {
  width: 100%;
  max-width: 360px;
  border-radius: 12px;
  display: block;
  background: #000;
}

.file-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 240px;
}

.file-name {
  font-weight: 600;
  word-break: break-word;
}

.file-meta {
  color: rgba(255,255,255,0.72);
  font-size: 12px;
}

.file-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.composer-meta {
  border-top: 1px solid var(--border);
  background: rgba(14, 21, 34, 0.96);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.composer-meta-text {
  font-size: 13px;
  color: var(--muted);
}

.composer {
  border-top: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.98);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.composer-input {
  margin-top: 0;
  flex: 1;
}

.attach-btn,
.voice-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 20px;
  border-radius: 50%;
}

.recording-indicator {
  color: #fca5a5;
  font-size: 13px;
  min-width: 86px;
}

.send-btn {
  min-width: 110px;
}

.notice {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 2px;
}

.success { color: #86efac; }

.call-modal,
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.call-card,
.modal-card {
  width: 100%;
  max-width: 420px;
  background: rgba(17, 24, 39, 0.98);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.4);
}

.call-title,
.modal-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 10px;
}

.call-actions,
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
  flex-wrap: wrap;
}

.avatar-settings {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

@media (max-width: 980px) {
  #appScreen {
    grid-template-columns: 1fr;
    height: auto;
  }

  .sidebar { height: auto; }
  .chat-screen { height: calc(100vh - 20px); }

  .chat-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .chat-header-right {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .message { max-width: 88%; }

  .media-panel {
    grid-template-columns: 1fr;
    grid-template-rows: 220px 160px auto;
  }

  .remote-wrap,
  .local-wrap,
  .media-actions {
    grid-column: auto;
  }
}
