/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #3b82f6;
  --primary-light: #eff6ff;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius: 12px;
  --radius-lg: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
}

/* Page Layout */
.page {
  display: none;
  min-height: 100vh;
}

.page.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.page.hidden {
  display: none !important;
}

/* Login Page */
.login-page {
  background: linear-gradient(135deg, var(--gray-50) 0%, var(--primary-light) 100%);
}

.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-header {
  margin-bottom: 32px;
}

.login-header .logo {
  width: 64px;
  height: 64px;
  background: var(--primary-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: var(--primary-color);
}

.login-header h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.login-header p {
  font-size: 14px;
  color: var(--gray-500);
}

.login-form {
  text-align: left;
}

.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 15px;
  color: var(--gray-800);
  transition: all 0.2s;
  outline: none;
}

.input-group input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.btn-primary {
  width: 100%;
  padding: 14px 24px;
  background: var(--primary-color);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover:not(:disabled) {
  background: #2563eb;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-note {
  margin-top: 16px;
  font-size: 12px;
  color: var(--gray-400);
}

.login-error {
  margin-top: 12px;
  font-size: 13px;
  color: #ef4444;
  text-align: center;
}

/* Chat Page */
.chat-container {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  background: var(--white);
  display: flex;
  flex-direction: column;
}

.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--gray-50);
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-100);
  flex-shrink: 0;
}

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

.header-avatar {
  width: 40px;
  height: 40px;
  background: var(--primary-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-color);
}

.header-info h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-900);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--gray-500);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gray-300);
}

.status-dot.online {
  background: var(--success-color);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.status-dot.offline {
  background: var(--gray-300);
}

.status-text {
  color: var(--gray-500);
}

.btn-icon {
  padding: 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-500);
  border-radius: 8px;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--gray-50);
}

.messages-wrapper {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Message Bubbles */
.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: fadeIn 0.3s ease;
}

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

.message.user {
  align-self: flex-end;
}

.message.agent {
  align-self: flex-start;
}

.message-content {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.user .message-content {
  background: var(--primary-color);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.message.agent .message-content {
  background: var(--white);
  color: var(--gray-800);
  border: 1px solid var(--gray-100);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message-time {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 4px;
  padding: 0 4px;
}

.message.user .message-time {
  text-align: right;
}

.welcome-message {
  text-align: center;
  padding: 20px;
  color: var(--gray-500);
  font-size: 13px;
}

.welcome-message p {
  background: var(--white);
  display: inline-block;
  padding: 10px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  font-size: 12px;
  color: var(--gray-500);
  background: var(--white);
  border-top: 1px solid var(--gray-100);
}

.typing-dots {
  display: flex;
  gap: 3px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--gray-400);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Chat Footer */
.chat-footer {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 16px 20px;
  background: var(--white);
  border-top: 1px solid var(--gray-100);
  flex-shrink: 0;
}

#messageInput {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid var(--gray-200);
  border-radius: 24px;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 44px;
  font-family: inherit;
  transition: border-color 0.2s;
}

#messageInput:focus {
  border-color: var(--primary-color);
}

#messageInput:disabled {
  background: var(--gray-50);
  cursor: not-allowed;
}

.btn-send {
  width: 44px;
  height: 44px;
  background: var(--primary-color);
  color: var(--white);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
  background: #2563eb;
  transform: scale(1.05);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Admin Page */
.admin-page {
  flex-direction: column;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
}

.header-left h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-900);
}

.stats {
  display: flex;
  gap: 20px;
  margin-top: 8px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--gray-600);
}

.stat-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--primary-color);
}

.header-right {
  display: flex;
  gap: 8px;
}

.btn-secondary {
  padding: 8px 16px;
  background: var(--gray-100);
  color: var(--gray-700);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-secondary:hover {
  background: var(--gray-200);
}

/* Admin Body */
.admin-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Conversation Sidebar */
.conversation-sidebar {
  width: 320px;
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--gray-100);
}

.sidebar-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 12px;
}

.filter-tabs {
  display: flex;
  gap: 8px;
}

.filter-btn {
  padding: 6px 12px;
  background: var(--gray-100);
  color: var(--gray-600);
  border: none;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

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

.conversation-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  transition: all 0.2s;
}

.conversation-item:hover {
  background: var(--gray-50);
}

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

.conversation-avatar {
  width: 44px;
  height: 44px;
  background: var(--gray-100);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  flex-shrink: 0;
}

.conversation-item.active .conversation-avatar {
  background: var(--primary-color);
  color: var(--white);
}

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

.conversation-phone {
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.conversation-last-msg {
  font-size: 12px;
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.conversation-time {
  font-size: 11px;
  color: var(--gray-400);
}

.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--primary-color);
  color: var(--white);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.status-tag {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.status-tag.open {
  background: #d1fae5;
  color: #065f46;
}

.status-tag.pending {
  background: #fef3c7;
  color: #92400e;
}

.status-tag.closed {
  background: var(--gray-100);
  color: var(--gray-500);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--gray-400);
  text-align: center;
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
}

/* Chat Main */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--gray-50);
}

.empty-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
}

.empty-chat svg {
  margin-bottom: 16px;
  opacity: 0.3;
}

.active-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Admin Chat Header */
.admin-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-100);
}

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

.btn-status {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-status[data-status="pending"] {
  background: #fef3c7;
  color: #92400e;
}

.btn-status[data-status="pending"]:hover {
  background: #fde68a;
}

.btn-status[data-status="closed"] {
  background: var(--gray-100);
  color: var(--gray-600);
}

.btn-status[data-status="closed"]:hover {
  background: var(--gray-200);
}

/* Responsive */
@media (max-width: 768px) {
  .admin-body {
    flex-direction: column;
  }
  
  .conversation-sidebar {
    width: 100%;
    height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
  }
  
  .login-card {
    margin: 20px;
    padding: 32px 24px;
  }
}
