/* ============================================================
   ISKRA MAIN APP STYLES
   ============================================================ */

/* ── App Shell ───────────────────────────────────────────── */
#app {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ── Auth Screen ─────────────────────────────────────────── */
#auth-screen {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  position: relative;
  overflow: hidden;
}

#auth-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% -10%, rgba(245,158,11,0.07) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 110%, rgba(59,130,246,0.05) 0%, transparent 60%);
  pointer-events: none;
}

/* ── Main Layout ─────────────────────────────────────────── */
#main-screen {
  width: 100%;
  height: 100%;
  display: flex;
  overflow: hidden;
  background: var(--bg-base);
}

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  position: relative;
  z-index: var(--z-sidebar);
  transition: transform var(--duration-slow) var(--ease-out);
  flex-shrink: 0;
}

/* ── Chat Area ───────────────────────────────────────────── */
#chat-area {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  position: relative;
}

/* ── Welcome Pane ────────────────────────────────────────── */
#welcome-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  color: var(--text-muted);
  padding: var(--space-8);
  text-align: center;
}

#welcome-pane .welcome-icon {
  font-size: 64px;
  margin-bottom: var(--space-2);
  filter: grayscale(0.3);
}

#welcome-pane h2 {
  font-size: var(--text-xl);
  color: var(--text-secondary);
  font-weight: var(--weight-semibold);
}

#welcome-pane p {
  font-size: var(--text-sm);
  max-width: 280px;
  line-height: var(--leading-relaxed);
}

/* ── Sidebar Header ──────────────────────────────────────── */
.sidebar-header {
  height: var(--header-h);
  min-height: var(--header-h);
  padding: 0 var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  gap: var(--space-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--text-primary);
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.35);
}

.brand-logo svg {
  width: 18px;
  height: 18px;
  fill: #0a0b0f;
}

.brand-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-black);
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* ── Icon Button ─────────────────────────────────────────── */
.icon-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition:
    background var(--duration-fast),
    color var(--duration-fast),
    transform var(--duration-fast);
  position: relative;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ── Chat Header ─────────────────────────────────────────── */
.chat-header {
  height: var(--header-h);
  min-height: var(--header-h);
  padding: 0 var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: var(--z-header);
}

.chat-header-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.chat-header-info:hover .chat-header-name {
  color: var(--accent);
}

.chat-header-name {
  font-weight: var(--weight-semibold);
  font-size: var(--text-base);
  transition: color var(--duration-fast);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-status {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-status.online {
  color: var(--status-online);
}

/* ── Chat Body ────────────────────────────────────────────── */
#chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding: var(--space-4) var(--space-4) var(--space-2);
  gap: var(--space-1);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.messages-container::-webkit-scrollbar { width: 4px; }

/* ── Date Divider ────────────────────────────────────────── */
.date-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) 0 var(--space-2);
  color: var(--text-muted);
}

.date-divider::before,
.date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.date-divider span {
  font-size: var(--text-xs);
  white-space: nowrap;
  padding: 0 var(--space-2);
  background: var(--bg-surface);
  border-radius: var(--radius-full);
}

/* ── Typing Indicator ────────────────────────────────────── */
.typing-bar {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-muted);
  height: 28px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  overflow: hidden;
}

.typing-dots {
  display: flex;
  gap: 3px;
  align-items: center;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Scroll To Bottom ────────────────────────────────────── */
.scroll-to-bottom {
  position: absolute;
  bottom: 80px;
  right: var(--space-4);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--duration-fast);
  opacity: 0;
  transform: translateY(8px) scale(0.85);
  pointer-events: none;
  z-index: 5;
}

.scroll-to-bottom.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

.scroll-to-bottom:hover {
  background: var(--accent-muted);
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.3);
}

.scroll-to-bottom .badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--text-inverse);
  font-size: 10px;
  font-weight: var(--weight-bold);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── Message Input Area ──────────────────────────────────── */
.input-area {
  padding: var(--space-3) var(--space-4);
  padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.reply-preview {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-hover);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: var(--text-sm);
}

.reply-preview-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

.reply-preview-author {
  color: var(--accent);
  font-weight: var(--weight-medium);
  font-size: var(--text-xs);
  display: block;
  margin-bottom: 2px;
}

.reply-close {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--duration-fast);
}

.reply-close:hover {
  background: var(--bg-active);
  color: var(--text-primary);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

.message-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  padding: var(--space-3) var(--space-4);
  color: var(--text-primary);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  resize: none;
  max-height: 200px;
  overflow-y: auto;
  transition:
    border-color var(--duration-fast),
    box-shadow var(--duration-fast);
  word-break: break-word;
}

.message-input:focus {
  border-color: rgba(var(--accent-rgb), 0.4);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.1);
  outline: none;
}

.message-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration-fast) var(--ease-spring);
  box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.3);
  flex-shrink: 0;
}

.send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(var(--accent-rgb), 0.45);
}

.send-btn:active {
  transform: scale(0.94);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.send-btn svg {
  width: 20px;
  height: 20px;
  fill: #0a0b0f;
  stroke: none;
  transition: transform var(--duration-fast);
}

/* ── Chat Search Bar ─────────────────────────────────────── */
.chat-search-bar {
  padding: var(--space-2) var(--space-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrap svg {
  position: absolute;
  left: var(--space-3);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-full);
  padding: 0 var(--space-10) 0 var(--space-8);
  font-size: var(--text-sm);
  color: var(--text-primary);
  transition: border-color var(--duration-fast);
}

.search-input:focus {
  border-color: rgba(var(--accent-rgb), 0.4);
  outline: none;
}

.search-input::placeholder { color: var(--text-muted); }

.search-nav {
  position: absolute;
  right: var(--space-2);
  display: flex;
  gap: 2px;
}

/* ── Pinned Message Banner ───────────────────────────────── */
.pinned-banner {
  padding: var(--space-2) var(--space-4);
  background: var(--accent-muted);
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.2);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}

.pinned-banner:hover {
  background: rgba(var(--accent-rgb), 0.12);
}

.pinned-banner-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.pinned-banner-content {
  flex: 1;
  min-width: 0;
}

.pinned-banner-label {
  font-size: var(--text-xs);
  color: var(--accent);
  font-weight: var(--weight-semibold);
}

.pinned-banner-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Sidebar Search ──────────────────────────────────────── */
.sidebar-search {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

/* ── Chat List ───────────────────────────────────────────── */
.chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.chat-list-section-label {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 1;
}

/* ── Empty States ────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-6);
  text-align: center;
  color: var(--text-muted);
  min-height: 200px;
}

.empty-state-icon {
  font-size: 40px;
  margin-bottom: var(--space-2);
}

.empty-state-title {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

.empty-state-desc {
  font-size: var(--text-sm);
  max-width: 240px;
  line-height: var(--leading-relaxed);
}

/* ── Connection Status Banner ────────────────────────────── */
.connection-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: calc(var(--z-toast) + 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transform: translateY(-100%);
  transition: transform var(--duration-slow) var(--ease-out);
}

.connection-banner.visible { transform: translateY(0); }
.connection-banner.offline { background: var(--danger); color: #fff; }
.connection-banner.reconnecting { background: var(--warning); color: #0a0b0f; }
.connection-banner.online { background: var(--success); color: #fff; }

/* ── Mobile Responsive ───────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    min-width: 100%;
    z-index: var(--z-drawer);
    transform: translateX(0);
  }

  #sidebar.slide-out {
    transform: translateX(-100%);
  }

  #chat-area {
    position: absolute;
    inset: 0;
    z-index: var(--z-drawer);
    transform: translateX(100%);
    transition: transform var(--duration-slow) var(--ease-out);
    background: var(--bg-base);
  }

  #chat-area.slide-in {
    transform: translateX(0);
  }

  #welcome-pane {
    display: none;
  }

  .msg-max-w { max-width: 85%; }
  --msg-max-w: 85%;
}

@media (min-width: 769px) {
  .back-btn { display: none; }
}
