/* App shell — two-column messaging layout */

.app {
  display: flex;
  height: 100%;
  height: 100dvh;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
  overflow-x: hidden;
  position: relative;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

@media (min-width: 901px) {
  .app { box-shadow: var(--shadow-lg); }
}

/* ── Sidebar / conversation list ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  max-width: 100%;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(229, 114, 142, 0.06), transparent 140px),
    var(--surface);
  border-right: 1px solid var(--border);
  transition: transform var(--smooth), opacity var(--smooth);
  z-index: 10;
  overflow: hidden;
  overflow-x: hidden;
  touch-action: pan-y;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  min-height: var(--header-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  display: block;
}

.brand-text {
  font: 700 18px var(--font);
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text) 60%, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--fast);
  position: relative;
}

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

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

.badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font: 700 10px var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
}

/* Search */
.search-wrap {
  padding: 12px 16px;
  flex-shrink: 0;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0 14px;
  transition: border-color var(--fast), box-shadow var(--fast);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-box svg {
  width: 16px;
  height: 16px;
  stroke: var(--text-tertiary);
  fill: none;
  stroke-width: 2;
  flex-shrink: 0;
}

.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 11px 0;
  font: 400 14px var(--font);
  color: var(--text);
  outline: none;
}

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

.search-box input:focus,
.search-box input:focus-visible {
  outline: none;
  box-shadow: none;
}

/* Conversation list */
.conv-list {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: none;
  overscroll-behavior-x: none;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  padding: 4px 8px 16px;
  max-width: 100%;
}

.conv-section-label {
  font: 600 11px var(--font);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 12px 12px 6px;
}

.conv-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 16px;
  cursor: pointer;
  transition: background var(--fast), transform var(--fast), box-shadow var(--fast);
  position: relative;
  max-width: 100%;
  min-width: 0;
}

.conv-row:hover { background: var(--surface2); }
.conv-row:active { opacity: 0.9; transform: scale(0.995); }
.conv-row.active {
  background: var(--unread-bg);
  box-shadow: inset 0 0 0 1px rgba(229, 114, 142, 0.18);
}

.conv-row.unread .conv-name { font-weight: 700; }
.conv-row.unread .conv-preview { color: var(--text); font-weight: 500; }

.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 700 18px/1 var(--font);
  color: #fff;
  background-size: cover;
  background-position: center;
  line-height: 1;
}

.avatar.sm { width: 40px; height: 40px; font-size: 14px; }
.avatar.lg { width: 88px; height: 88px; font-size: 32px; }

.avatar.avatar-photo {
  background: none;
  padding: 0;
  overflow: hidden;
}

.avatar.avatar-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}

.status-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2.5px solid var(--surface);
  background: var(--text-tertiary);
}

.status-dot.online { background: var(--green); }
.status-dot.typing { background: var(--accent); animation: pulse 1.5s ease infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 114, 142, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(229, 114, 142, 0); }
}

.conv-body { flex: 1; min-width: 0; }

.conv-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.conv-name {
  font: 600 15px var(--font);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font: 400 12px var(--font);
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.conv-preview {
  font: 400 13px var(--font);
  color: var(--text-secondary);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-preview .you-prefix { color: var(--text-tertiary); }

.unread-pill {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font: 700 11px var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.conv-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-tertiary);
  font: 400 14px var(--font);
}

.conv-empty svg {
  width: 48px;
  height: 48px;
  stroke: var(--text-tertiary);
  margin: 0 auto 16px;
  opacity: 0.5;
}

/* ── Main chat area ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--chat-wash), var(--bg);
  position: relative;
}

.main-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  color: var(--text-secondary);
}

.main-empty-icon {
  width: 80px;
  height: 80px;
  border-radius: 24px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.main-empty-icon svg {
  width: 36px;
  height: 36px;
  stroke: var(--accent);
  opacity: 0.7;
}

.main-empty h2 {
  font: 700 22px var(--font);
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.main-empty p {
  font: 400 14px var(--font);
  max-width: 320px;
  line-height: 1.5;
}

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  flex-shrink: 0;
}

.back-btn {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--fast);
}

.back-btn:hover { background: var(--surface2); color: var(--text); }
.back-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }

.chat-header-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-text { min-width: 0; }

.chat-header-name {
  font: 700 16px var(--font);
  letter-spacing: -0.01em;
}

.chat-header-status {
  font: 400 12px var(--font);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}

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

.chat-header-actions {
  display: flex;
  gap: 4px;
}

/* Mobile layout — stack panels; no horizontal translate (prevents sideways swipe) */
@media (max-width: 900px) {
  .app {
    border: none;
    max-width: 100%;
    width: 100%;
    overflow: hidden;
    overflow-x: clip;
    touch-action: pan-y;
  }

  .sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    transform: none;
    overflow: hidden;
    overflow-x: hidden;
    touch-action: pan-y;
    visibility: visible;
    pointer-events: auto;
    z-index: 1;
  }

  .sidebar.hidden-mobile {
    transform: none;
    visibility: hidden;
    pointer-events: none;
    z-index: 0;
  }

  .main {
    position: absolute;
    inset: 0;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    overflow-x: hidden;
    touch-action: pan-y;
    transform: none;
    transition: opacity 0.18s ease;
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
    z-index: 5;
  }

  .main.chat-open {
    transform: none;
    visibility: visible;
    pointer-events: auto;
    opacity: 1;
  }

  .back-btn { display: flex; }
}
