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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f0f0f;
  color: #e0e0e0;
  height: 100vh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* mobile viewport fix */
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: #1a1a1a;
  border-right: 1px solid #2a2a2a;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #2a2a2a;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 600;
  color: #ff6b9d;
}

.btn-primary {
  background: #ff6b9d;
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s;
  min-height: 36px;
}

.btn-primary:hover {
  background: #ff8fb3;
}

.leads-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.lead-item {
  padding: 14px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 48px;
}

.lead-item:hover {
  background: #252525;
}

.lead-item.active {
  background: #2a1a2a;
  border: 1px solid #ff6b9d33;
}

.lead-item .lead-id {
  font-size: 12px;
  color: #888;
  font-family: monospace;
}

.lead-item .lead-stage {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  background: #333;
  color: #aaa;
}

.lead-item .lead-stage.qualified {
  background: #1a3a1a;
  color: #4caf50;
}

.lead-item .lead-stage.qualifying {
  background: #3a3a1a;
  color: #ff9800;
}

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: #ff6b9d;
  font-size: 24px;
  padding: 8px;
  cursor: pointer;
}

/* Chat Container */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0f0f0f;
  min-width: 0;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid #2a2a2a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 56px;
}

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

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #666;
}

.status-dot.active {
  background: #4caf50;
}

.status-dot.human {
  background: #ff9800;
}

#lead-name {
  font-weight: 500;
  font-size: 15px;
}

.lead-meta {
  display: flex;
  gap: 8px;
}

.badge {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  background: #252525;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge.active {
  background: #1a3a1a;
  color: #4caf50;
}

.badge.human {
  background: #3a2a1a;
  color: #ff9800;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 80px; /* space for input */
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #666;
  font-size: 14px;
}

.message {
  max-width: 75%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  animation: fadeIn 0.3s ease;
}

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

.message.inbound {
  align-self: flex-start;
  background: #252525;
  color: #e0e0e0;
  border-bottom-left-radius: 4px;
}

.message.outbound {
  align-self: flex-end;
  background: #ff6b9d22;
  color: #ff6b9d;
  border: 1px solid #ff6b9d33;
  border-bottom-right-radius: 4px;
}

.message .timestamp {
  font-size: 11px;
  color: #666;
  margin-top: 4px;
  display: block;
}

/* Input Area - Fixed at bottom */
.input-area {
  position: fixed;
  bottom: 0;
  left: 280px;
  right: 0;
  padding: 12px 16px;
  border-top: 1px solid #2a2a2a;
  background: #141414;
  z-index: 10;
}

.facts-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  min-height: 0;
}

.facts-bar.has-facts {
  min-height: 28px;
}

.fact-tag {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  background: #1a2a3a;
  color: #64b5f6;
  border: 1px solid #64b5f633;
}

.fact-tag.missing {
  background: #2a2a2a;
  color: #666;
  border: 1px solid #333;
}

.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

#message-input {
  flex: 1;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  padding: 12px 14px;
  color: #e0e0e0;
  font-size: 16px; /* prevents iOS zoom */
  outline: none;
  transition: border-color 0.2s;
  min-height: 44px;
}

#message-input:focus {
  border-color: #ff6b9d;
}

#message-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#send-btn {
  background: #ff6b9d;
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.2s;
  min-height: 44px;
  min-width: 64px;
}

#send-btn:hover:not(:disabled) {
  background: #ff8fb3;
}

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

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

.btn-secondary {
  background: #252525;
  color: #aaa;
  border: 1px solid #333;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
  min-height: 36px;
}

.btn-secondary:hover:not(:disabled) {
  background: #333;
  color: #e0e0e0;
}

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

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

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

::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: #444;
}

/* ─── MOBILE RESPONSIVE ─── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    width: 260px;
    box-shadow: 2px 0 10px rgba(0,0,0,0.5);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 99;
  }

  .sidebar-overlay.show {
    display: block;
  }

  .sidebar-toggle {
    display: block;
  }

  .chat-header {
    padding: 10px 12px;
    min-height: 52px;
  }

  .messages {
    padding: 12px;
    padding-bottom: 140px;
  }

  .message {
    max-width: 85%;
    padding: 10px 12px;
    font-size: 15px;
  }

  .input-area {
    left: 0;
    padding: 10px 12px;
  }

  .input-row {
    gap: 6px;
  }

  #message-input {
    padding: 10px 12px;
    font-size: 16px;
  }

  #send-btn {
    padding: 10px 16px;
    font-size: 14px;
  }

  .facts-bar {
    margin-bottom: 8px;
  }

  .fact-tag {
    font-size: 10px;
    padding: 2px 8px;
  }

  .btn-secondary {
    padding: 6px 10px;
    font-size: 11px;
  }
}

/* Very small screens */
@media (max-width: 380px) {
  .sidebar {
    width: 240px;
  }

  .message {
    max-width: 90%;
    font-size: 14px;
  }

  #lead-name {
    font-size: 13px;
  }
}
