/* ============================================================
   LeadFlow — Main Stylesheet
   ============================================================ */

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

:root {
  --ink: #0f172a;
  --bg: #f1f5f9;
  --white: #ffffff;
  --border: #e2e8f0;
  --muted: #64748b;
  --accent: #3b82f6;
  --accent-dark: #1d4ed8;
  --sidebar-w: 220px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 16px rgba(15,23,42,.10);
}

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- App Shell ---- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  background: #0f172a;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.logo-text {
  font-family: 'Syne', sans-serif;
  font-size: 22px;
  font-weight: 800;
  color: #f8fafc;
  letter-spacing: -.5px;
}

.logo-accent { color: #3b82f6; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #94a3b8;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  margin-bottom: 2px;
}

.nav-item:hover { background: rgba(255,255,255,.06); color: #f8fafc; }
.nav-item.active { background: #3b82f6; color: #fff; }
.nav-icon { font-size: 15px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }

.user-avatar {
  width: 30px; height: 30px;
  background: #3b82f6;
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}

.user-name { font-size: 12px; color: #94a3b8; truncate: ellipsis; overflow: hidden; white-space: nowrap; }
.logout-btn { color: #475569; text-decoration: none; font-size: 16px; padding: 4px; border-radius: 6px; }
.logout-btn:hover { color: #f87171; background: rgba(248,113,113,.1); }

/* ---- Main Content ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  overflow-x: hidden;
}

.page-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 28px 60px;
}

.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title { font-family: 'Syne', sans-serif; font-size: 22px; font-weight: 700; color: var(--ink); }
.page-sub   { font-size: 13px; color: var(--muted); margin-top: 3px; }

/* ---- Cards ---- */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad { padding: 20px 22px; }

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat-value {
  font-family: 'Syne', sans-serif;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}

.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.stat-blue   .stat-value { color: #2563eb; }
.stat-amber  .stat-value { color: #d97706; }
.stat-green  .stat-value { color: #16a34a; }
.stat-violet .stat-value { color: #7c3aed; }
.stat-red    .stat-value { color: #dc2626; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600; font-family: 'DM Sans', sans-serif;
  cursor: pointer; border: 1px solid transparent;
  text-decoration: none; transition: all .15s;
  white-space: nowrap;
}

.btn-primary   { background: #1d4ed8; color: #fff; border-color: #1d4ed8; }
.btn-primary:hover { background: #1e40af; }
.btn-secondary { background: var(--white); color: #334155; border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger    { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.btn-danger:hover { background: #fecaca; }
.btn-ghost     { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); color: var(--ink); }
.btn-sm        { padding: 5px 11px; font-size: 12px; }
.btn:disabled  { opacity: .5; cursor: not-allowed; }

/* ---- Forms ---- */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 5px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px; font-family: 'DM Sans', sans-serif;
  color: var(--ink); background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}

.form-textarea { resize: vertical; min-height: 80px; line-height: 1.6; }

/* ---- Filters bar ---- */
.filters-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 12px 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.filter-search { flex: 1; min-width: 180px; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }

table { width: 100%; border-collapse: collapse; background: var(--white); }
thead { background: #f8fafc; border-bottom: 1px solid var(--border); }

th {
  padding: 10px 14px;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  text-align: left; white-space: nowrap;
}

td { padding: 12px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

.td-name { font-weight: 600; color: var(--ink); }
.td-sub  { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---- Badge ---- */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}

/* ---- Status select ---- */
.status-select {
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 12px; font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer; outline: none;
}

/* ---- Lead detail ---- */
.lead-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.detail-section { padding: 18px 20px; }
.detail-section h3 {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 14px;
}

.detail-row { display: flex; flex-direction: column; gap: 3px; margin-bottom: 12px; }
.detail-row:last-child { margin-bottom: 0; }
.detail-key { font-size: 11px; color: var(--muted); font-weight: 500; }
.detail-val { font-size: 13px; color: var(--ink); font-weight: 500; }
.detail-val a { color: var(--accent); text-decoration: none; }
.detail-val a:hover { text-decoration: underline; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }

.tab-btn {
  padding: 10px 16px;
  font-size: 13px; font-weight: 500;
  color: var(--muted);
  background: none; border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer; transition: all .15s;
  margin-bottom: -1px;
}

.tab-btn:hover  { color: var(--ink); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---- Activity timeline ---- */
.activity-list { display: flex; flex-direction: column; }

.activity-item {
  display: flex; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid #f1f5f9;
}

.activity-item:last-child { border-bottom: none; }
.activity-icon { font-size: 18px; flex-shrink: 0; padding-top: 2px; }
.activity-title { font-size: 13px; font-weight: 500; color: var(--ink); }
.activity-body  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.activity-date  { font-size: 11px; color: #94a3b8; margin-top: 3px; }

/* ---- Reminders ---- */
.reminder-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  background: #f8fafc; border: 1px solid var(--border);
  margin-bottom: 8px;
}

.reminder-check {
  width: 18px; height: 18px; flex-shrink: 0; margin-top: 2px;
  border: 2px solid #cbd5e1; border-radius: 4px;
  cursor: pointer; appearance: none; background: white;
}

.reminder-check:checked { background: #16a34a; border-color: #16a34a; }
.reminder-overdue { background: #fef2f2; border-color: #fecaca; }
.reminder-title   { font-size: 13px; font-weight: 500; color: var(--ink); }
.reminder-due     { font-size: 11px; color: var(--muted); margin-top: 2px; }
.reminder-due.overdue { color: #dc2626; font-weight: 600; }

/* ---- AI Email panel ---- */
.email-panel {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-top: 16px;
}

.email-variant { margin-bottom: 20px; }
.email-variant:last-child { margin-bottom: 0; }
.email-variant-label {
  font-size: 10px; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 6px;
}

.email-subject { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 8px; }
.email-body    {
  font-size: 12px; color: #374151; line-height: 1.75;
  white-space: pre-wrap; background: white;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; margin-bottom: 8px;
}

.generating-indicator {
  display: flex; align-items: center; gap: 10px;
  color: var(--accent); font-size: 13px; padding: 12px 0;
}

.spinner {
  width: 18px; height: 18px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

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

/* ---- Flash messages ---- */
.flash {
  padding: 10px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  margin-bottom: 16px;
}

.flash-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.flash-error   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.flash-info    { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }

/* ---- Modal ---- */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 100;
  align-items: center; justify-content: center; padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: white; border-radius: 14px;
  width: 100%; max-width: 580px; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow-md);
}

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

.modal-title { font-family: 'Syne', sans-serif; font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 18px; color: var(--muted); cursor: pointer; padding: 4px; }
.modal-close:hover { color: var(--ink); }
.modal-body  { padding: 20px 22px; }

/* ---- Login page ---- */
.login-page {
  min-height: 100vh; background: #0f172a;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}

.login-card {
  width: 100%; max-width: 400px;
  background: #1e293b; border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px; padding: 36px;
  box-shadow: 0 24px 60px rgba(0,0,0,.4);
}

.login-logo {
  font-family: 'Syne', sans-serif; font-size: 28px; font-weight: 800;
  color: #f8fafc; text-align: center; margin-bottom: 6px;
}

.login-tagline { text-align: center; color: #64748b; font-size: 13px; margin-bottom: 28px; }

.login-tabs {
  display: flex; gap: 4px; background: #0f172a;
  border-radius: 8px; padding: 4px; margin-bottom: 22px;
}

.login-tab {
  flex: 1; padding: 8px; border-radius: 6px;
  font-size: 13px; font-weight: 600; cursor: pointer; border: none;
  color: #64748b; background: transparent; transition: all .15s;
}

.login-tab.active { background: #3b82f6; color: white; }

.login-label { display: block; font-size: 11px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 5px; }

.login-input {
  width: 100%; padding: 10px 12px; margin-bottom: 14px;
  background: #0f172a; border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px; font-size: 13px; color: #f8fafc;
  outline: none; font-family: 'DM Sans', sans-serif;
}

.login-input:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.login-input::placeholder { color: #334155; }
.login-btn { width: 100%; padding: 11px; background: #3b82f6; color: white; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; margin-top: 4px; font-family: 'DM Sans', sans-serif; }
.login-btn:hover { background: #2563eb; }
.login-error { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.2); color: #f87171; font-size: 13px; border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }

/* ---- Today page ---- */
.today-section { margin-bottom: 20px; }
.today-section-header {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
  padding: 6px 0; margin-bottom: 10px;
  display: flex; align-items: center; gap: 10px;
}
.today-section-header::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .nav-label, .user-name, .logo-text { display: none; }
  .logo-accent { display: none; }
  .main-content { margin-left: 60px; }
  .lead-detail-grid { grid-template-columns: 1fr; }
  .page-wrap { padding: 16px 14px 40px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
