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

:root {
  --bg-base: hsl(220, 20%, 8%);
  --bg-surface: hsl(220, 18%, 11%);
  --bg-elevated: hsl(220, 16%, 15%);
  --bg-hover: hsl(220, 14%, 19%);
  --border: hsl(220, 14%, 20%);

  --green: hsl(142, 70%, 45%);
  --green-dim: hsl(142, 70%, 38%);
  --green-glow: hsla(142, 70%, 45%, 0.15);
  --green-text: hsl(142, 60%, 75%);

  --accent: hsl(220, 80%, 60%);
  --accent-dim: hsl(220, 80%, 50%);

  --text-primary: hsl(220, 15%, 92%);
  --text-secondary: hsl(220, 10%, 60%);
  --text-muted: hsl(220, 8%, 40%);

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --shadow-sm: 0 2px 8px hsla(0, 0%, 0%, .3);
  --shadow-md: 0 4px 20px hsla(0, 0%, 0%, .4);

  --topbar-h: 58px;
  --sidebar-w: 300px;
  --activity-w: 260px;

  font-size: 14px;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-base);
  color: var(--text-primary);
}

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ─── Top Bar ─────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.topbar-left {
  display: flex;
  align-items: center;
  width: var(--sidebar-w);
}

.topbar-center {
  flex: 1;
  max-width: 480px;
  margin: 0 auto;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

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

.logo-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

/* Search */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 40px;
  padding: 0 14px;
  gap: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-bar:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
}

.search-icon {
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-bar input {
  background: none;
  border: none;
  outline: none;
  width: 100%;
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  padding: 8px 0;
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

/* Stats */
.stat-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  line-height: 1.2;
}

.stat-num {
  font-size: 15px;
  font-weight: 700;
  color: var(--green);
}

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}

/* WS Status */
.ws-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 40px;
  padding: 5px 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.4s;
}

.status-dot.connected {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s infinite;
}

.status-dot.disconnected {
  background: hsl(0, 60%, 55%);
}

.status-dot.connecting {
  background: hsl(45, 80%, 55%);
  animation: pulse 1s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1
  }

  50% {
    opacity: .45
  }
}

/* ─── Layout ──────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  margin-top: var(--topbar-h);
  overflow: hidden;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

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

.sidebar-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.convo-count {
  background: var(--green);
  color: hsl(145, 80%, 10%);
  font-size: 11px;
  font-weight: 700;
  border-radius: 40px;
  padding: 1px 8px;
}

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

/* Conversation Card */
.convo-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  position: relative;
  border: 1px solid transparent;
  animation: slideIn 0.25s ease;
}

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

.convo-card.active {
  background: var(--green-glow);
  border-color: hsla(142, 70%, 45%, 0.3);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-10px)
  }

  to {
    opacity: 1;
    transform: none
  }
}

.convo-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: white;
}

.avatar-0 {
  background: linear-gradient(135deg, hsl(142, 70%, 45%), hsl(142, 70%, 30%));
}

.avatar-1 {
  background: linear-gradient(135deg, hsl(220, 80%, 60%), hsl(220, 80%, 40%));
}

.avatar-2 {
  background: linear-gradient(135deg, hsl(280, 70%, 60%), hsl(280, 70%, 40%));
}

.avatar-3 {
  background: linear-gradient(135deg, hsl(30, 90%, 60%), hsl(30, 90%, 40%));
}

.avatar-4 {
  background: linear-gradient(135deg, hsl(0, 70%, 60%), hsl(0, 70%, 40%));
}

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

.convo-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.convo-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.convo-time {
  font-size: 10.5px;
  color: var(--text-muted);
}

.convo-badge {
  background: var(--green);
  color: hsl(145, 80%, 8%);
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

/* ─── Message Panel ──────────────────────────────────────────────────────────*/
.message-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  overflow: hidden;
  position: relative;
}

/* Welcome */
.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.welcome-glow {
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--green-glow) 0%, transparent 65%);
  pointer-events: none;
}

.welcome-content {
  text-align: center;
  max-width: 420px;
  padding: 32px;
  position: relative;
  z-index: 1;
}

.welcome-icon svg {
  width: 80px;
  height: 80px;
}

.welcome-icon {
  margin-bottom: 24px;
}

.welcome-content h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 12px;
}

.welcome-content p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 24px;
}

.webhook-info {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  text-align: left;
}

.webhook-info-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.webhook-info code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  color: var(--green);
  background: var(--green-glow);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  display: block;
  word-break: break-all;
}

/* Chat View */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-view.hidden {
  display: none;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--green), var(--green-dim));
  flex-shrink: 0;
}

.chat-meta {
  flex: 1;
}

.chat-name {
  font-size: 15px;
  font-weight: 600;
}

.chat-phone {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.btn-icon {
  width: 34px;
  height: 34px;
  border: none;
  background: var(--bg-elevated);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}

.btn-icon svg {
  width: 16px;
  height: 16px;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.msg-row.inbound {
  justify-content: flex-start;
}

.msg-row.outbound {
  justify-content: flex-end;
}

.msg-bubble {
  max-width: 68%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  line-height: 1.55;
  font-size: 13.5px;
  position: relative;
  animation: bubbleIn 0.2s ease;
}

@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: scale(.94) translateY(6px)
  }

  to {
    opacity: 1;
    transform: none
  }
}

.msg-row.inbound .msg-bubble {
  background: var(--bg-elevated);
  border-bottom-left-radius: var(--radius-sm);
  color: var(--text-primary);
}

.msg-row.outbound .msg-bubble {
  background: linear-gradient(135deg, hsl(142, 65%, 35%), hsl(142, 70%, 28%));
  border-bottom-right-radius: var(--radius-sm);
  color: hsl(130, 60%, 92%);
}

.msg-text {
  word-break: break-word;
}

.msg-time {
  font-size: 10.5px;
  margin-top: 4px;
  text-align: right;
  opacity: 0.55;
}

.msg-type-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  background: var(--green-glow);
  color: var(--green-text);
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 5px;
  text-transform: uppercase;
}

.day-divider {
  text-align: center;
  margin: 12px 0;
  font-size: 11px;
  color: var(--text-muted);
  position: relative;
}

.day-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}

.day-divider span {
  background: var(--bg-base);
  padding: 0 10px;
  position: relative;
}

/* ─── Activity Panel ─────────────────────────────────────────────────────────*/
.activity-panel {
  width: var(--activity-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

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

.activity-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: hsla(0, 70%, 55%, 0.12);
  color: hsl(0, 70%, 65%);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .6px;
  border-radius: 40px;
  padding: 3px 9px;
  border: 1px solid hsla(0, 70%, 55%, .25);
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: hsl(0, 70%, 65%);
  animation: pulse 1s infinite;
}

.activity-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.activity-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border-bottom: 1px solid var(--border);
  animation: slideIn 0.2s ease;
  cursor: default;
  transition: background 0.15s;
}

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

.activity-item:last-child {
  border-bottom: none;
}

.act-user {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.act-msg {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.act-time {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── Empty State ────────────────────────────────────────────────────────────*/
.empty-state {
  text-align: center;
  padding: 40px 20px;
}

.empty-icon {
  font-size: 36px;
  margin-bottom: 12px;
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 13px;
}

.empty-state small {
  color: var(--text-muted);
  font-size: 11.5px;
  margin-top: 6px;
  display: block;
}

/* ─── Toast ──────────────────────────────────────────────────────────────────*/
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-primary);
  animation: toastIn 0.25s ease;
  max-width: 300px;
}

.toast.toast-success {
  border-left: 3px solid var(--green);
}

.toast.toast-sent {
  border-left: 3px solid var(--accent);
}

.toast.toast-info {
  border-left: 3px solid var(--accent);
}

.toast.toast-error {
  border-left: 3px solid hsl(0, 70%, 55%);
}

.toast-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.toast-body {
  flex: 1;
}

.toast-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.toast-sub {
  font-size: 11.5px;
  color: var(--text-secondary);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(20px)
  }

  to {
    opacity: 1;
    transform: none
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: none
  }

  to {
    opacity: 0;
    transform: translateX(20px)
  }
}

/* ─── Composer ───────────────────────────────────────────────────────────────*/
.composer {
  flex-shrink: 0;
  padding: 10px 16px 14px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 8px 8px 8px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer-inner:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
}

.compose-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  padding: 4px 0;
  overflow-y: auto;
}

.compose-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}

.send-btn:hover:not(:disabled) {
  background: var(--green-dim);
  transform: scale(1.07);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.96);
}

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

.send-btn svg {
  width: 16px;
  height: 16px;
}

/* Sending spinner state */
.send-btn.sending {
  animation: spin 0.7s linear infinite;
  background: var(--green-dim);
}

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

  to {
    transform: rotate(360deg)
  }
}

.composer-hint {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: center;
}

.composer-hint kbd {
  font-family: inherit;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 10px;
}

/* ─── Utility ────────────────────────────────────────────────────────────────*/
.hidden {
  display: none !important;
}