/* ─── Header (mobile: fixed top bar) ─────────────────────────── */
.header {
  height: calc(var(--touch-target) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg-header);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding-left: max(0.75rem, var(--safe-left));
  padding-right: max(0.75rem, var(--safe-right));
  gap: 0.5rem;
  flex-shrink: 0;
  z-index: 20;
}

.header-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  border: none;
  background: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  position: relative;
}
.header-btn:active { background: var(--bg-surface-hover); }

.header-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-width: 0;
}

.header-channel {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.connection-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.connection-dot.connected {
  background: var(--green);
  box-shadow: 0 0 8px rgba(40, 201, 64, 0.4);
}

.user-count {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.5625rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 1rem;
  text-align: center;
}

/* ─── Main layout ────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

/* ─── Chat area ──────────────────────────────────────────────── */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem;
  padding-left: max(0.5rem, var(--safe-left));
  padding-right: max(0.5rem, var(--safe-right));
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ─── Input bar (fixed bottom) ───────────────────────────────── */
.input-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  padding-bottom: max(0.5rem, var(--safe-bottom));
  padding-left: max(0.5rem, var(--safe-left));
  padding-right: max(0.5rem, var(--safe-right));
  background: var(--bg-header);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: 20;
}

.input-bar input {
  flex: 1;
  min-height: var(--touch-target);
  padding: 0 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 1rem;
  outline: none;
}
.input-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(122, 162, 247, 0.15);
}
.input-bar input::placeholder { color: var(--text-faint); }

.input-bar button {
  width: var(--touch-target);
  height: var(--touch-target);
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.input-bar button:active { opacity: 0.8; }

/* ─── Sidebar / Users: drawers on mobile ─────────────────────── */
.sidebar,
.users-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: var(--bg-app);
  z-index: 100;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar {
  left: 0;
  transform: translateX(-100%);
  border-right: 1px solid var(--border-subtle);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
}
.sidebar.open { transform: translateX(0); }

.users-panel {
  right: 0;
  transform: translateX(100%);
  border-left: 1px solid var(--border-subtle);
  padding-top: var(--safe-top);
  padding-right: var(--safe-right);
}
.users-panel.open { transform: translateX(0); }

.sidebar-overlay,
.users-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.sidebar-overlay.visible,
.users-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ─── Tablet: sidebar always visible ─────────────────────────── */
@media (min-width: 640px) {
  .sidebar {
    position: relative;
    transform: none;
    width: 240px;
    max-width: none;
    z-index: auto;
    flex-shrink: 0;
  }
  .sidebar-overlay { display: none; }

  .header #btn-sidebar { display: none; }
}

/* ─── Desktop: three-column layout ───────────────────────────── */
@media (min-width: 1024px) {
  .sidebar { width: 220px; }

  .users-panel {
    position: relative;
    transform: none;
    width: 200px;
    max-width: none;
    z-index: auto;
    flex-shrink: 0;
  }
  .users-overlay { display: none; }

  .header #btn-users { display: none; }
  .user-count { display: none; }

  #app {
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-lg);
    box-shadow:
      0 0 0 0.5px rgba(255, 255, 255, 0.05),
      0 24px 80px rgba(0, 0, 0, 0.5),
      0 8px 32px rgba(0, 0, 0, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.03);
  }
}
