/* CSS Design System & Theme Customization */
:root {
  --bg-app: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-hover: #334155;
  --border-color: #334155;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.15);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --success: #10b981;
  --warning: #f59e0b;
  
  --sidebar-width: 360px;
  --header-height: 70px;
  
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --border-radius: 12px;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.app-header {
  height: var(--header-height);
  background-color: rgba(30, 41, 59, 0.7);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  z-index: 10;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--primary);
}

.logo-area h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, #fff 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

.demo-badge {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 30px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  background-color: var(--bg-app);
  padding: 6px 12px;
  border-radius: 30px;
  border: 1px solid var(--border-color);
}

.status-dot {
  width: 8px;
  height: 8px;
  background-color: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--success);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--border-radius);
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition-smooth);
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.icon {
  width: 16px;
  height: 16px;
}

.spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Workspace layout */
.app-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Demo Banner */
.demo-banner {
  background: linear-gradient(90deg, #f59e0b 0%, #d97706 100%);
  color: #0f172a;
  padding: 8px 16px;
  font-size: 0.875rem;
  text-align: center;
  font-weight: 500;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}

.demo-banner code {
  background-color: rgba(255,255,255,0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
}

.split-view {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background-color: rgba(15, 23, 42, 0.95);
}

.search-container {
  padding: 16px;
  position: relative;
  border-bottom: 1px solid var(--border-color);
}

.search-container input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.875rem;
  outline: none;
  transition: var(--transition-smooth);
}

.search-container input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.search-icon {
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
  pointer-events: none;
}

/* Conversations List */
.conversations-list {
  flex: 1;
  overflow-y: auto;
}

.convo-item {
  display: flex;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.4);
  cursor: pointer;
  transition: var(--transition-smooth);
  position: relative;
}

.convo-item:hover {
  background-color: var(--bg-surface-hover);
}

.convo-item.active {
  background-color: var(--primary-light);
  border-left: 4px solid var(--primary);
}

.convo-item .avatar {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary) 0%, #818cf8 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: white;
  margin-right: 14px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.convo-info {
  flex: 1;
  min-width: 0;
}

.convo-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.convo-number {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.convo-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.convo-preview {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.convo-item.active .convo-preview {
  color: var(--text-secondary);
}

/* Chat Panel */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #0b0f19;
  position: relative;
}

.no-chat-selected {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  padding: 40px;
  text-align: center;
}

.no-chat-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  color: var(--border-color);
}

.no-chat-selected h2 {
  font-size: 1.5rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.active-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  height: var(--header-height);
  padding: 0 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  background-color: var(--bg-surface);
}

.chat-partner-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-partner-info .avatar {
  width: 40px;
  height: 40px;
  background-color: var(--border-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text-secondary);
}

.chat-partner-info h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.chat-partner-status {
  font-size: 0.75rem;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-partner-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background-color: var(--success);
  border-radius: 50%;
}

/* Messages container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background-color: #0b0f19;
}

.message-bubble {
  max-width: 65%;
  padding: 12px 16px;
  border-radius: var(--border-radius);
  position: relative;
  line-height: 1.45;
  font-size: 0.95rem;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-bubble.inbound {
  align-self: flex-start;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}

.message-bubble.outbound {
  align-self: flex-end;
  background-color: var(--primary);
  color: white;
  border-bottom-right-radius: 2px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 6px;
  font-size: 0.75rem;
}

.inbound .message-meta {
  color: var(--text-secondary);
}

.outbound .message-meta {
  color: rgba(255, 255, 255, 0.7);
}

.status-icon {
  width: 12px;
  height: 12px;
}

/* Chat Footer Banner */
.chat-footer-info {
  padding: 12px 24px;
  background-color: rgba(30, 41, 59, 0.4);
  border-top: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-footer-info svg {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Loading & Empty states */
.loading-state, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  text-align: center;
  gap: 12px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(99, 102, 241, 0.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px;
}

.back-btn svg {
  width: 24px;
  height: 24px;
}

.hidden {
  display: none !important;
}

/* Responsive Rules */
@media (max-width: 768px) {
  .back-btn {
    display: block;
  }
  
  .sidebar {
    width: 100%;
    flex: 1;
  }
  
  .chat-panel {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
  }
  
  /* When chat is active on mobile, hide sidebar and show chat panel */
  .app-workspace.chat-active .sidebar {
    display: none;
  }
  
  .app-workspace.chat-active .chat-panel {
    display: flex;
  }
}
