/* ================= BASE ================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
}

body {
  font-family: var(--font-body, 'Inter', system-ui, sans-serif);
  background: var(--bg, #0e0e12);
  color: var(--fg, #eaeaea);
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }

/* Variant switcher — top fixed */
.variant-switcher {
  position: fixed;
  top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 100;
  display: flex; gap: 6px;
  padding: 6px;
  background: rgba(20,20,24,0.85);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.variant-switcher button {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,0.6);
  border-radius: 9px;
  transition: all 0.2s;
  white-space: nowrap;
  font-family: 'Inter', system-ui, sans-serif;
}
.variant-switcher button:hover { color: #fff; background: rgba(255,255,255,0.05); }
.variant-switcher button.active {
  color: #fff;
  background: rgba(255,255,255,0.12);
}

.variant-container {
  padding-top: 72px;
  min-height: 100vh;
}

/* Variant wrapper */
.variant {
  display: none;
  width: 100%;
}
.variant.active { display: block; }

/* Device frame — desktop window */
.app-window {
  width: min(1320px, 96vw);
  margin: 0 auto 60px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05);
  height: 820px;
  display: flex;
  flex-direction: column;
}

.window-bar {
  height: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 8px;
}
.window-bar .dots { display: flex; gap: 7px; }
.window-bar .dot { width: 12px; height: 12px; border-radius: 50%; }
.window-bar .title {
  flex: 1; text-align: center; font-size: 12px;
  letter-spacing: 0.02em;
}

.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-nav {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 20px;
  flex-shrink: 0;
}

.nav-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  margin-left: 20px;
}
.nav-tab {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 8px;
  display: flex; align-items: center; gap: 8px;
  transition: all 0.15s;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
}

.main-area {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  overflow: hidden;
  min-height: 0;
}

/* Chat list */
.chat-list {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-list-header {
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chat-list-title { font-weight: 600; font-size: 14px; letter-spacing: 0.01em; }
.chat-search {
  margin: 0 14px 10px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  outline: none;
  border: none;
}
.chat-items { flex: 1; overflow-y: auto; padding: 4px 10px; }
.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.15s;
}
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-name { font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.chat-item-preview {
  font-size: 12px;
  opacity: 0.6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.chat-item-time { font-size: 10px; opacity: 0.5; font-weight: 400; }
.unread-dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-left: 6px;
  flex-shrink: 0;
}

/* Avatar */
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  position: relative;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 44px; height: 44px; font-size: 16px; }

.presence {
  position: absolute;
  bottom: -1px; right: -1px;
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg, #0e0e12);
}
.presence.online { background: #22c55e; }
.presence.idle { background: #f59e0b; }
.presence.dnd { background: #ef4444; }
.presence.offline { background: #71717a; }

/* Chat area */
.chat-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.chat-header {
  height: 64px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-weight: 600; font-size: 15px; }
.chat-header-status { font-size: 11px; opacity: 0.6; margin-top: 2px; }
.chat-header-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 26px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 14px;
  width: 100%;
}
.message-row.me { justify-content: flex-end; }
.message-row.them { justify-content: flex-start; }
.message-avatar-slot {
  width: 28px;
  flex-shrink: 0;
}
.message-row .message-group {
  margin-bottom: 0;
  min-width: 0;
  max-width: calc(100% - 40px);
  flex: 1 1 auto;
  align-items: flex-start;
}
.message-row.me .message-group { align-items: flex-end; }

.message-row .bubble { max-width: 100%; width: fit-content; }
.message-row.me .bubble { margin-left: auto; }

.message-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.message-group.me { align-items: flex-end; }
.message-group.them { align-items: flex-start; }
.message-sender {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  opacity: 0.7;
  padding: 0 4px;
}

.bubble {
  max-width: 70%;
  min-width: 60px;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.45;
  position: relative;
  word-wrap: break-word;
  white-space: normal;
}
.bubble .ts {
  font-size: 10px;
  opacity: 0.5;
  margin-top: 2px;
  display: block;
  white-space: nowrap;
}

.reactions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.reaction {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  display: flex; align-items: center; gap: 4px;
  cursor: pointer;
  transition: all 0.15s;
}
.reaction .count { font-weight: 600; opacity: 0.8; }

/* System events (calls etc) */
.event-row { display: flex; justify-content: center; margin: 10px 0; }
.event-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.event-pill svg { width: 12px; height: 12px; }

/* Media preview */
.media-preview {
  width: 240px;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}
.media-preview .media-image {
  width: 100%;
  aspect-ratio: 4/3;
  background: repeating-linear-gradient(
    45deg,
    rgba(255,255,255,0.04),
    rgba(255,255,255,0.04) 10px,
    rgba(255,255,255,0.07) 10px,
    rgba(255,255,255,0.07) 20px
  );
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-family: 'JetBrains Mono', monospace; opacity: 0.5;
  letter-spacing: 0.1em;
}
.media-preview .media-meta {
  padding: 10px 12px;
  font-size: 11px;
  display: flex; justify-content: space-between;
  font-family: 'JetBrains Mono', monospace;
  opacity: 0.7;
}

/* Composer */
.composer {
  padding: 14px 20px 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.composer-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 12px;
  border-radius: 12px;
  min-height: 44px;
}
.composer-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: inherit;
  font-size: 14px;
  padding: 8px 0;
}
.composer-btn {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Incoming call overlay */
.call-overlay {
  position: absolute;
  right: 24px;
  bottom: 100px;
  width: 300px;
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  animation: slideInCall 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slideInCall {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.call-info { flex: 1; min-width: 0; }
.call-name { font-weight: 600; font-size: 14px; }
.call-sub { font-size: 11px; opacity: 0.7; margin-top: 2px; }
.call-actions { display: flex; gap: 6px; }
.call-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white;
}
.call-btn.accept { background: #22c55e; }
.call-btn.decline { background: #ef4444; }

/* Profile hover card */
.profile-card {
  position: absolute;
  z-index: 10;
  width: 280px;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}
.profile-card-banner { height: 64px; }
.profile-card-body { padding: 14px; margin-top: -20px; position: relative; }
.profile-card-avatar {
  width: 60px; height: 60px;
  border-radius: 50%;
  border: 4px solid var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 22px;
}
.profile-card-name { font-weight: 700; font-size: 16px; margin-top: 10px; }
.profile-card-handle { font-size: 12px; opacity: 0.6; }
.profile-card-meta {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 11px;
  display: flex; flex-direction: column; gap: 6px;
  opacity: 0.8;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
