/* ============================================
   NexHome Chat - Responsive Design System
   Modern Glassmorphism Chat Interface
   Based on UI Pro Max Design System
   ============================================ */

/* --- 1. CSS Variables for Chat --- */
:root {
  /* Chat-specific spacing (rem-based) */
  --chat-sidebar-width: 20rem;
  --chat-header-height: 4rem;
  --chat-input-height: auto;
  --chat-avatar-sm: 2.25rem;
  --chat-avatar-md: 3rem;
  --chat-avatar-lg: 5rem;

  /* Message bubble */
  --bubble-max-width: 70%;
  --bubble-radius: 1rem;
  --bubble-padding: 0.75rem 1rem;

  /* Glassmorphism effects - Enhanced */
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-bg-hover: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.2);
  --glass-blur: 16px;
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);

  /* Design System Colors */
  --chat-primary: #E11D48;
  --chat-secondary: #FB7185;
  --chat-cta: #2563EB;
  --chat-bg-light: #FFF1F2;
  --chat-text-dark: #881337;

  /* Transitions */
  --transition-smooth: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* --- 2. Container Layout --- */
.chat-container {
  display: flex;
  height: 100vh;
  background: var(--bg-primary);
  overflow: hidden;
}

/* --- 3. Sidebar --- */
.chat-sidebar {
  width: var(--chat-sidebar-width);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-right: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  display: flex;
  flex-direction: column;
  transition: var(--transition-smooth);
  flex-shrink: 0;
  position: relative;
}

/* Glassmorphism light reflection */
.chat-sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  pointer-events: none;
}

.chat-sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--chat-header-height);
  background: rgba(255, 255, 255, 0.02);
}

.chat-sidebar-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

/* --- 4. Search Bar --- */
.chat-search {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.chat-search input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--glass-bg);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: var(--transition-smooth);
}

.chat-search input:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

/* --- 5. Tabs --- */
.chat-tabs {
  display: flex;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.02);
}

.chat-tab {
  flex: 1;
  padding: 0.75rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition-smooth);
  position: relative;
  font-weight: 500;
}

.chat-tab::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.05), transparent);
  opacity: 0;
  transition: var(--transition-smooth);
}

.chat-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.chat-tab:hover::before {
  opacity: 1;
}

.chat-tab.active {
  color: var(--accent-cyan);
  border-bottom-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.08);
  font-weight: 600;
}

.chat-tab.active::before {
  opacity: 0;
}

/* --- 6. Chat List --- */
.chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.chat-item {
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
  transition: var(--transition-smooth);
  position: relative;
}

/* Glassmorphism hover effect */
.chat-item::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(56, 189, 248, 0.05), transparent);
  opacity: 0;
  transition: var(--transition-smooth);
}

.chat-item:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateX(4px);
}

.chat-item:hover::before {
  opacity: 1;
}

.chat-item.active {
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.15), rgba(56, 189, 248, 0.08));
  border-left: 3px solid var(--accent-cyan);
  box-shadow: inset 0 0 20px rgba(56, 189, 248, 0.1);
}

.chat-item.active::before {
  opacity: 0;
}

/* --- 7. Avatar (Clickable) --- */
.chat-avatar {
  width: var(--chat-avatar-md);
  height: var(--chat-avatar-md);
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.125rem;
  flex-shrink: 0;
  cursor: pointer;
  transition: var(--transition-bounce);
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.2);
}

/* Glassmorphism ring effect on hover */
.chat-avatar::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  padding: 2px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.6), rgba(129, 140, 248, 0.6));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: var(--transition-smooth);
}

.chat-avatar:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 8px 24px rgba(56, 189, 248, 0.4);
}

.chat-avatar:hover::before {
  opacity: 1;
}

.chat-avatar:active {
  transform: scale(0.95);
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* --- 8. Chat Item Content --- */
.chat-item-content {
  flex: 1;
  min-width: 0;
}

.chat-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.chat-item-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9375rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-item-preview {
  font-size: 0.875rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-unread-badge {
  background: var(--color-danger);
  color: #fff;
  border-radius: 0.625rem;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

/* --- 9. Main Chat Area --- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-width: 0;
  position: relative;
}

/* Subtle gradient overlay */
.chat-main::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 200px;
  background: radial-gradient(ellipse at top, rgba(56, 189, 248, 0.08), transparent);
  pointer-events: none;
  z-index: 0;
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  min-height: var(--chat-header-height);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 1;
}

/* Light reflection on header */
.chat-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  pointer-events: none;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.chat-header-name {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

/* --- 10. Messages Area --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: linear-gradient(180deg, rgba(15, 25, 35, 0.3) 0%, rgba(15, 25, 35, 0.1) 100%);
}

.chat-message {
  display: flex;
  gap: 0.75rem;
  max-width: var(--bubble-max-width);
  animation: slideUpBounce 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes slideUpBounce {
  0% {
    opacity: 0;
    transform: translateY(1rem) scale(0.9);
  }
  60% {
    transform: translateY(-0.1rem) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-message.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message-avatar {
  width: var(--chat-avatar-sm);
  height: var(--chat-avatar-sm);
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.875rem;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(56, 189, 248, 0.3);
}

.chat-message-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  max-width: 100%;
}

.chat-message-bubble {
  padding: var(--bubble-padding);
  border-radius: var(--bubble-radius);
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  word-wrap: break-word;
  word-break: break-word;
  transition: var(--transition-smooth);
  position: relative;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

/* Glassmorphism light reflection on bubble */
.chat-message-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent);
  border-radius: var(--bubble-radius) var(--bubble-radius) 0 0;
  pointer-events: none;
}

.chat-message.own .chat-message-bubble {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(129, 140, 248, 0.15));
  border-color: rgba(56, 189, 248, 0.4);
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.2);
}

.chat-message-bubble:hover {
  background: var(--glass-bg-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.chat-message.own .chat-message-bubble:hover {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.25), rgba(129, 140, 248, 0.2));
  box-shadow: 0 6px 20px rgba(56, 189, 248, 0.3);
}

.chat-message-time {
  font-size: 0.6875rem;
  color: var(--text-muted);
  padding: 0 0.25rem;
}

/* --- 11. Image Messages --- */
.chat-message-image {
  max-width: 100%;
  width: auto;
  height: auto;
  max-height: 20rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  object-fit: cover;
  transition: var(--transition-smooth);
  display: block;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.chat-message-image:hover {
  transform: scale(1.03) translateY(-2px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
  border-color: rgba(56, 189, 248, 0.4);
}

.chat-image-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  cursor: pointer;
  animation: fadeIn 0.3s ease-out;
}

.chat-image-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.1);
  animation: zoomIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes zoomIn {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* --- 12. Input Area --- */
.chat-input-area {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.1);
}

.chat-input-wrapper {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9375rem;
  resize: none;
  max-height: 8rem;
  font-family: inherit;
  line-height: 1.5;
  transition: var(--transition-smooth);
  min-height: 2.75rem;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15), inset 0 2px 4px rgba(0, 0, 0, 0.1);
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.chat-input::placeholder {
  color: var(--text-muted);
}

/* --- 13. Input Actions --- */
.chat-input-actions {
  display: flex;
  gap: 0.5rem;
  position: relative;
  margin-bottom: 0.5rem;
}

.chat-input-actions .btn-icon {
  color: var(--text-secondary);
  font-size: 1.125rem;
  padding: 0.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-bounce);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
}

.chat-input-actions .btn-icon:hover {
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.3);
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.2);
}

.chat-input-actions .btn-icon:active {
  transform: translateY(0) scale(0.95);
}

/* --- 14. Emoji Picker --- */
.emoji-picker {
  position: absolute;
  bottom: 100%;
  left: 0;
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 0.5rem;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
  max-height: 12.5rem;
  overflow-y: auto;
  z-index: var(--z-dropdown);
  margin-bottom: 0.5rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1);
  animation: slideUpBounce 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.emoji-picker button {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.375rem;
  border-radius: 0.375rem;
  transition: var(--transition-bounce);
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-picker button:hover {
  background: rgba(56, 189, 248, 0.15);
  transform: scale(1.2) rotate(5deg);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.2);
}

.emoji-picker button:active {
  transform: scale(0.9);
}

/* --- 15. Empty State --- */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 0.75rem;
  padding: 2rem;
  text-align: center;
}

.chat-empty i {
  font-size: 4rem;
  opacity: 0.3;
}

/* --- 16. Friend Request Item --- */
.friend-request-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.friend-request-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

/* --- 17. Responsive Breakpoints --- */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
  :root {
    --chat-sidebar-width: 18rem;
  }

  .chat-message {
    max-width: 80%;
  }

  .chat-sidebar-title {
    font-size: 1.125rem;
  }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  :root {
    --chat-sidebar-width: 100%;
    --chat-header-height: 3.5rem;
  }

  .chat-container {
    flex-direction: column;
  }

  .chat-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--glass-border);
    max-height: 50vh;
  }

  .chat-main {
    flex: 1;
  }

  .chat-sidebar-header {
    padding: 0.75rem 1rem;
  }

  .chat-header {
    padding: 0.75rem 1rem;
  }

  .chat-messages {
    padding: 1rem;
    gap: 0.75rem;
  }

  .chat-input-area {
    padding: 0.75rem 1rem;
  }

  .chat-message {
    max-width: 85%;
  }

  .chat-message-bubble {
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
  }

  .chat-avatar {
    width: 2.5rem;
    height: 2.5rem;
  }

  .chat-item {
    padding: 0.625rem 0.875rem;
  }

  .emoji-picker {
    grid-template-columns: repeat(6, 1fr);
  }

  /* Hide sidebar when chat is open on mobile */
  .chat-container.chat-active .chat-sidebar {
    display: none;
  }
}

/* Small Mobile (< 480px) */
@media (max-width: 480px) {
  .chat-message {
    max-width: 90%;
  }

  .chat-sidebar-title {
    font-size: 1rem;
  }

  .chat-header-name {
    font-size: 1rem;
  }

  .emoji-picker {
    grid-template-columns: repeat(5, 1fr);
    max-height: 10rem;
  }

  .chat-input {
    font-size: 1rem; /* Prevent zoom on iOS */
  }
}

/* --- 18. Touch Targets (Mobile) --- */
@media (max-width: 768px) {
  .btn-icon,
  .chat-tab,
  .chat-item {
    min-height: 2.75rem; /* 44px minimum touch target */
  }

  .chat-avatar {
    min-width: 2.75rem;
    min-height: 2.75rem;
  }
}

/* --- 19. Animations --- */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideUpBounce {
  0% {
    opacity: 0;
    transform: translateY(1rem) scale(0.9);
  }
  60% {
    transform: translateY(-0.1rem) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes zoomIn {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* --- 20. Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .chat-message,
  .emoji-picker,
  .chat-image-overlay img,
  .chat-avatar:hover,
  .chat-item:hover,
  .chat-input:focus {
    animation: none;
    transform: none;
  }
}
