:root {
  --primary: #e8a87c;
  --primary-dark: #c0764a;
  --bg: #faf7f4;
  --surface: #ffffff;
  --text: #2d2d2d;
  --text-light: #7a7a7a;
  --border: #eee6de;
  --success: #6ab04c;
  --warning: #e8a87c;
  --danger: #e74c3c;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 2rem;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

header span {
  color: var(--primary-dark);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.stat-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-card .number {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary-dark);
  line-height: 1;
}

.stat-card .label {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 0.5rem;
}

.conversations-list {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.conversations-list table {
  width: 100%;
  border-collapse: collapse;
}

.conversations-list th {
  text-align: left;
  padding: 1rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
  background: #faf7f4;
}

.conversations-list td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.conversations-list tr:last-child td { border-bottom: none; }

.conversations-list tr:hover td { background: #fdf9f6; }

.conversations-list .customer-name { font-weight: 600; }
.conversations-list .customer-email { color: var(--text-light); font-size: 0.8rem; }

.msg-count {
  background: var(--primary);
  color: white;
  border-radius: 10px;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.time-ago { color: var(--text-light); font-size: 0.8rem; }

.btn-resolve {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-resolve:hover { background: var(--primary-dark); }

.intent-badge {
  background: #f0e8df;
  color: var(--primary-dark);
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.status-escalated { color: var(--danger); }
.status-active { color: var(--success); }

/* Chat widget styles */
#chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 370px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.15);
  display: none;
  flex-direction: column;
  max-height: 500px;
  overflow: hidden;
  z-index: 9999;
}

#chat-widget.open { display: flex; }

#chat-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 1rem;
  font-weight: 600;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  justify-content: space-between;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 200px;
  max-height: 300px;
}

.msg {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.msg-agent {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.msg-customer {
  background: #f0e8df;
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg-system {
  background: #fff3cd;
  color: #856404;
  font-size: 0.8rem;
  align-self: center;
  text-align: center;
}

#chat-input-area {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
}

#chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

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

#chat-send {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}

#chat-send:hover { background: var(--primary-dark); }

#chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: none;
  cursor: pointer;
  font-size: 1.4rem;
  box-shadow: 0 4px 20px rgba(200,118,74,0.4);
  z-index: 9998;
  transition: transform 0.2s;
}

#chat-toggle:hover { transform: scale(1.08); }

.glowsync-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  line-height: 1;
}

/* Chat form */
#chat-email-form {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#chat-email-form input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  width: 100%;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.75rem 1rem;
  background: var(--primary);
  border-radius: 16px;
  width: fit-content;
  align-self: flex-end;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: rgba(255,255,255,0.6);
  border-radius: 50%;
  animation: typing 1s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 100% { opacity: 0.4; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-4px); }
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-light);
}

.empty-state h3 { margin-bottom: 0.5rem; color: var(--text); }