/* ============================================================
   ClientFlows Dashboard — Dark Theme
   Colors: bg #0A0F1E, card #0F172A, accent #3B82F6, green #22C55E
   ============================================================ */

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

:root {
  --bg: #0A0F1E;
  --surface: #0F172A;
  --surface2: #1E293B;
  --border: #1E293B;
  --text: #E2E8F0;
  --text-muted: #64748B;
  --text-sm: #94A3B8;
  --blue: #3B82F6;
  --blue-hover: #2563EB;
  --green: #22C55E;
  --purple: #A855F7;
  --red: #EF4444;
  --yellow: #F59E0B;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

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

/* ============================================================ Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ============================================================ Sidebar */
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 32px; height: 32px;
  background: var(--blue);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
}

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

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.nav-item:hover { color: var(--text); background: var(--surface2); }
.nav-item.active { color: var(--blue); background: rgba(59,130,246,0.1); }
.nav-item.logout { color: var(--red); margin-top: 4px; }
.nav-item.logout:hover { background: rgba(239,68,68,0.1); }

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
}

/* ============================================================ Main */
.main-content {
  margin-left: 220px;
  flex: 1;
  padding: 28px 32px;
  max-width: 100%;
  overflow-x: hidden;
}

/* ============================================================ Page Header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

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

/* ============================================================ Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.card h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 14px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.search-card { border-color: rgba(59,130,246,0.2); }

/* ============================================================ Forms */
.form-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 160px;
}

.form-group-sm { min-width: 90px; flex: 0 0 90px; }
.form-group-action { min-width: auto; flex: 0 0 auto; }

.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
  width: 100%;
}

.form-input:focus {
  outline: none;
  border-color: var(--blue);
}

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

select.form-input { cursor: pointer; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}

.hint a { color: var(--blue); text-decoration: none; }

/* ============================================================ Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-outline:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }

.btn-ghost { background: var(--surface2); color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }

.btn-full { width: 100%; justify-content: center; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-xs {
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 4px;
}

.btn-blue { background: rgba(59,130,246,0.15); color: var(--blue); }
.btn-blue:hover { background: rgba(59,130,246,0.25); }

.btn-purple { background: rgba(168,85,247,0.15); color: var(--purple); }
.btn-purple:hover { background: rgba(168,85,247,0.25); }

.btn-danger { background: rgba(239,68,68,0.15); color: var(--red); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }

/* ============================================================ Table */
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.table-header h3 { margin-bottom: 0; }

.table-wrapper { overflow-x: auto; }

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

.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 12px;
  border-bottom: 1px solid rgba(30,41,59,0.5);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: rgba(255,255,255,0.02); }

.td-company { min-width: 160px; }
.td-actions { white-space: nowrap; }
.td-actions .btn + .btn { margin-left: 4px; }
.td-empty { text-align: center; color: var(--text-muted); padding: 32px; }

.company-name { display: block; font-weight: 500; }
.company-niche { font-size: 12px; color: var(--text-muted); }

.link-external {
  color: var(--blue);
  text-decoration: none;
  font-size: 13px;
}
.link-external:hover { text-decoration: underline; }

/* ============================================================ Badges & Statuses */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface2);
  color: var(--text-muted);
}

.badge-blue { background: rgba(59,130,246,0.15); color: var(--blue); }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.status-pending { background: rgba(100,116,139,0.15); color: var(--text-muted); }
.status-running { background: rgba(245,158,11,0.15); color: var(--yellow); }
.status-done, .status-sent { background: rgba(34,197,94,0.15); color: var(--green); }
.status-error { background: rgba(239,68,68,0.15); color: var(--red); }
.status-draft { background: rgba(59,130,246,0.15); color: var(--blue); }
.status-sending { background: rgba(168,85,247,0.15); color: var(--purple); }

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-dot.pulse {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.rating { color: var(--yellow); font-weight: 500; }

.cro-score {
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

/* ============================================================ Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stats-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

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

.stat-card-sm { padding: 14px; }

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

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

.stat-card-sm .stat-value { font-size: 22px; }

/* ============================================================ Leads Checklist */
.leads-checklist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.checkbox-item:hover { background: rgba(255,255,255,0.03); }
.checkbox-item input { accent-color: var(--blue); }
.checkbox-item em { color: var(--text-muted); font-style: normal; }

/* ============================================================ Login */
.login-page {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 24px;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 32px;
}

.login-logo .logo-icon { width: 40px; height: 40px; font-size: 14px; }
.login-logo .logo-text { font-size: 20px; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.login-card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 24px;
  text-align: center;
}

/* ============================================================ Alert */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
}

.alert-error { background: rgba(239,68,68,0.1); color: var(--red); border: 1px solid rgba(239,68,68,0.2); }

/* ============================================================ Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}

.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.info { background: var(--blue); }
.toast.hidden { display: none; }

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

/* ============================================================ Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
}

.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

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

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

.prompt-textarea {
  width: 100%;
  min-height: 240px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  resize: vertical;
}

/* ============================================================ Spinner */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

.spinner.hidden { display: none; }

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

/* ============================================================ Utilities */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.hidden { display: none !important; }

/* ============================================================ Responsive */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar .logo-text, .sidebar .nav-item span { display: none; }
  .main-content { margin-left: 60px; padding: 16px; }
  .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; }
}
