/* LotPulse Dashboard — Functional, clean, operator-grade UI */
:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2d3148;
  --text: #e8eaf0;
  --muted: #8b92a8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --queued: #6366f1;
  --posted: #10b981;
  --failed: #ef4444;
  --delisted: #6b7280;
}

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

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Sidebar nav */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

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

.sidebar-logo p {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: color 0.15s, background 0.15s;
}

.nav-item:hover, .nav-item.active {
  color: var(--text);
  background: var(--surface2);
}

.nav-item.active { color: var(--accent); }

.nav-icon { font-size: 16px; }

/* Main content */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}

.topbar-title { font-size: 16px; font-weight: 600; }

.content {
  padding: 24px 28px;
  overflow-y: auto;
  flex: 1;
}

/* Alerts banner */
.alerts-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 24px;
}

.alerts-banner h3 {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.alert-item {
  font-size: 12px;
  color: #fca5a5;
  padding: 4px 0;
  border-top: 1px solid rgba(239, 68, 68, 0.15);
}

.alert-item:first-of-type { border-top: none; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-card.queued .stat-value { color: var(--queued); }
.stat-card.posted .stat-value { color: var(--posted); }
.stat-card.failed .stat-value { color: var(--danger); }
.stat-card.active .stat-value { color: var(--accent); }

/* Scrape control */
.scrape-control {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.scrape-info { flex: 1; }
.scrape-info h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.scrape-info p { font-size: 12px; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

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

.btn-spinning::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Table */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.table-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.table-title { font-size: 14px; font-weight: 600; }

.filter-tabs {
  display: flex;
  gap: 4px;
}

.filter-tab {
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  transition: all 0.15s;
}

.filter-tab:hover { color: var(--text); }
.filter-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-queued { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; }
.badge-posted { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; }
.badge-failed { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
.badge-delisted { background: rgba(107, 114, 128, 0.15); color: #9ca3af; }
.badge-pending { background: rgba(245, 158, 11, 0.15); color: #fcd34d; }

/* Vehicle photo thumbnail */
.photo-thumb {
  width: 60px;
  height: 42px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface2);
}

.no-photo {
  width: 60px;
  height: 42px;
  border-radius: 4px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* Settings form */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 20px;
}

.settings-section h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.form-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--muted); }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Toast notifications */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  min-width: 280px;
  animation: slideIn 0.2s ease;
}

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

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h3 { font-size: 15px; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 13px; }

/* Loading spinner */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Posting status banner */
.posting-banner {
  background: linear-gradient(135deg, rgba(59,130,246,0.12), rgba(99,102,241,0.08));
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 0 0 16px;
  color: #93c5fd;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Template page */
.template-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.template-editor, .template-preview { min-width: 0; }

.form-hint {
  font-size: 11px;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.preview-listing {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-top: 8px;
}

.preview-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.4;
}

.preview-body {
  font-size: 12px;
  color: #c8ccd8;
  white-space: pre-wrap;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  margin: 0;
}

/* ── Conversations: modal ──────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 860px;
  max-width: 95vw;
  height: 78vh;
  max-height: 640px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }

/* ── Conversations: chat thread ─────────────────────────────────────── */

#conv-modal-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  padding: 0;
}

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

.chat-bubble-row {
  display: flex;
}

.chat-left  { justify-content: flex-start; }
.chat-right { justify-content: flex-end;   }

.chat-bubble {
  max-width: 68%;
  border-radius: 16px;
  padding: 10px 14px;
  line-height: 1.45;
}

.chat-bubble-in {
  background: var(--surface2);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.chat-bubble-out {
  background: var(--accent);
  border-bottom-right-radius: 4px;
  color: #fff;
}

.chat-body { font-size: 13px; }

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

/* ── Conversations: sidebar ──────────────────────────────────────────── */

.conv-sidebar {
  width: 200px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  font-size: 13px;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .template-layout { grid-template-columns: 1fr; }
  .conv-sidebar { display: none; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Hot lead pulsing animation */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
