:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #17223b;
  --muted: #6b7280;
  --line: #e6e8ef;
  --primary: #5f4bdb;
  --primary-soft: #ece9ff;
  --guest: #eef7ff;
  --bot: #effcf4;
  --agent: #f2efff;
  --system: #f8fafc;
  --shadow: 0 10px 30px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, #efeafe 0%, transparent 35%),
    radial-gradient(circle at left top, #e5f4ff 0%, transparent 40%),
    var(--bg);
}

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.25rem;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 700;
}

h1 {
  margin: 0.2rem 0;
  font-size: 1.8rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.header-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.9rem;
  background: #e9fff3;
  color: #0f8a4b;
  border: 1px solid #b7f2d1;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #0f8a4b;
}

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1rem;
  min-height: calc(100vh - 130px);
}

.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid #ffffff;
}

.chat-list-panel,
.chat-window-panel {
  padding: 1rem;
}

.panel-heading,
.chat-window-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

h2 {
  margin: 0;
  font-size: 1.08rem;
}

#chat-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.6rem;
}

#chat-list li {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff 0%, #fcfdff 100%);
  border-radius: 12px;
  padding: 0.8rem;
  cursor: pointer;
  transition: all 160ms ease;
}

#chat-list li:hover {
  transform: translateY(-1px);
  border-color: #cbc9ff;
}

#chat-list li.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(95, 75, 219, 0.14);
}

.chat-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.preview {
  margin-top: 0.35rem;
  color: #374151;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta {
  margin-top: 0.35rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.73rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-badge.bot-active {
  background: #ecfdf5;
  color: #047857;
  border-color: #bbf7d0;
}

.status-badge.awaiting-agent {
  background: #fff7ed;
  color: #c2410c;
  border-color: #fed7aa;
}

.status-badge.agent-active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #d6ceff;
}

.status-badge.muted {
  background: #f3f4f6;
  color: var(--muted);
  border-color: #e5e7eb;
}

.chat-history {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
  height: 58vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
}

.empty-state {
  margin: auto;
  min-height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  color: var(--muted);
}

.empty-state h3 {
  margin: 0 0 0.35rem;
  color: #374151;
}

.message {
  margin-bottom: 0.7rem;
  max-width: 84%;
  padding: 0.62rem 0.75rem;
  border-radius: 12px;
  border: 1px solid transparent;
}

.message.guest {
  background: var(--guest);
  border-color: #d7eaff;
}

.message.bot {
  background: var(--bot);
  border-color: #c6f6d5;
}

.message.agent {
  margin-left: auto;
  background: var(--agent);
  border-color: #ded7ff;
}

.message.system {
  background: var(--system);
  border-color: #e5e7eb;
  font-style: italic;
}

.message .meta {
  margin-top: 0.45rem;
}

.agent-form {
  margin-top: 0.85rem;
  display: grid;
  gap: 0.6rem;
}

.input-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.86rem;
  color: #374151;
  font-weight: 600;
}

input,
textarea,
button,
.ghost-btn {
  width: 100%;
  border-radius: 10px;
  padding: 0.65rem 0.7rem;
  font-family: inherit;
  font-size: 0.92rem;
}

input,
textarea {
  border: 1px solid #d6dae6;
  background: #fff;
  color: var(--text);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: #b5abff;
  box-shadow: 0 0 0 3px rgba(95, 75, 219, 0.14);
}

button {
  border: none;
  background: linear-gradient(90deg, #5f4bdb, #715df4);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.03);
}

.ghost-btn {
  width: auto;
  border: 1px solid #d7dbeb;
  background: #fff;
  color: #374151;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .app-header {
    flex-direction: column;
  }

  .chat-history {
    height: 42vh;
  }
}

/* Right side message format*/
.message-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}

.message-wrapper.guest {
  align-self: flex-end;
  text-align: right;
}

.message-wrapper.bot {
  align-self: flex-start;
}

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

/* Guest bubble */
.message-wrapper.guest .message-bubble {
  background-color: #e5e7eb;
}

/* Bot bubble */
.message-wrapper.bot .message-bubble {
  background-color: #d1fae5;
}

.message-meta {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.6;
}
