:root {
  --bg-main: #0e1117;
  --bg-panel: #161b22;
  --bg-hover: #1f2733;
  --bg-bubble-lead: #1f2733;
  --bg-bubble-agent: #00a884;
  --border: #2a313c;
  --text-primary: #e8eaed;
  --text-secondary: #8b949e;
  --accent: #00a884;
  --danger: #e5534b;
  --warning: #d4a017;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 18px;
  margin: 0;
}

.count-badge {
  background: var(--accent);
  color: #04221b;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

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

.empty-state {
  color: var(--text-secondary);
  font-size: 13px;
  padding: 20px 16px;
  text-align: center;
}

.convo-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}

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

.convo-item.active {
  background: var(--bg-hover);
  border-left: 3px solid var(--accent);
}

.convo-top-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.convo-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.convo-time {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.convo-preview {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.convo-tag-chip {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-main);
  color: var(--accent);
  border: 1px solid var(--accent);
}

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

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.hidden {
  display: none !important;
}

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

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.chat-header h2 {
  margin: 0;
  font-size: 16px;
}

.chat-phone {
  font-size: 12px;
  color: var(--text-secondary);
}

.tag-pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #04221b;
  font-weight: 600;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 60%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

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

.bubble-agent {
  align-self: flex-end;
  background: var(--bg-bubble-agent);
  color: #04221b;
  border-top-right-radius: 2px;
}

.bubble-time {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  opacity: 0.7;
}

.chat-input-row {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

#message-input {
  flex: 1;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

#message-input:focus {
  border-color: var(--accent);
}

.send-btn {
  background: var(--accent);
  color: #04221b;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}

.send-btn:hover {
  opacity: 0.9;
}

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

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

.tag-btn {
  background: var(--bg-main);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tag-btn:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

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

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1f2733;
  border: 1px solid var(--accent);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  border-color: var(--danger);
}

/* ---------- Scrollbars ---------- */
.convo-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.convo-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
