/* ============================================================
   Lead Automation CRM — Design System
   Palette: cool paper/navy base, functional pipeline-stage accents
   (violet -> amber -> emerald/coral) used consistently as the
   product's own visual vocabulary, not decoration.
   ============================================================ */

:root {
  --ink: #10152b;
  --paper: #f5f6fa;
  --violet: #6c5ce7;
  --violet-soft: #efecfd;
  --amber: #f5a524;
  --amber-soft: #fef3e0;
  --emerald: #12b76a;
  --emerald-soft: #e3f9ef;
  --coral: #f0524a;
  --coral-soft: #fde8e7;

  --bg: var(--paper);
  --bg-elevated: #ffffff;
  --bg-sidenav: #10152b;
  --text-primary: #10152b;
  --text-secondary: #5b6178;
  --text-inverse: #f5f6fa;
  --border: #e3e5ee;
  --border-strong: #c7cade;
  --shadow: 0 1px 2px rgba(16, 21, 43, 0.04), 0 4px 16px rgba(16, 21, 43, 0.06);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --sidenav-w: 232px;
  --sidenav-w-collapsed: 68px;
  --topbar-h: 60px;
}

[data-theme="dark"] {
  --bg: #0b0e1c;
  --bg-elevated: #141a30;
  --bg-sidenav: #0b0e1c;
  --text-primary: #eef0fa;
  --text-secondary: #9297b3;
  --text-inverse: #10152b;
  --border: #232a45;
  --border-strong: #333d63;
  --violet-soft: #221f45;
  --amber-soft: #3a2a10;
  --emerald-soft: #0f2e22;
  --coral-soft: #3a1815;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.15s ease, color 0.15s ease;
}

h1, h2, h3, h4, .brand-word {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

code, .mono, .entity-code, .amount {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

a { color: inherit; }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--violet);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Login ---------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 20%, rgba(108, 92, 231, 0.16), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(18, 183, 106, 0.12), transparent 40%),
    var(--bg);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 32px;
}

.login-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.pipeline-dot-trio { display: flex; gap: 4px; }
.pipeline-dot-trio span {
  width: 9px; height: 9px; border-radius: 50%; display: block;
}
.pipeline-dot-trio span:nth-child(1) { background: var(--violet); }
.pipeline-dot-trio span:nth-child(2) { background: var(--amber); }
.pipeline-dot-trio span:nth-child(3) { background: var(--emerald); }

.login-card h1 { font-size: 19px; }
.login-card p.sub { color: var(--text-secondary); margin: 4px 0 24px; font-size: 13px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 13.5px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px var(--violet-soft);
  outline: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.12s ease, background 0.12s ease;
}
.btn:active { filter: brightness(0.92); }
.btn-primary { background: var(--violet); color: #fff; }
.btn-primary:hover { background: #5d4bd6; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text-primary); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger-ghost { background: transparent; border-color: var(--coral); color: var(--coral); }
.btn-danger-ghost:hover { background: var(--coral-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 7px; }

.alert {
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-danger { background: var(--coral-soft); color: var(--coral); }
.alert-success { background: var(--emerald-soft); color: var(--emerald); }

/* ---------- App shell ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidenav {
  width: var(--sidenav-w);
  flex-shrink: 0;
  background: var(--bg-sidenav);
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: width 0.15s ease;
}
.sidenav::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--violet), var(--amber), var(--emerald));
}
.sidenav.collapsed { width: var(--sidenav-w-collapsed); }

.sidenav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  white-space: nowrap;
  overflow: hidden;
}
.sidenav-brand .brand-word { color: #fff; font-size: 15px; }
.sidenav.collapsed .brand-word, .sidenav.collapsed .nav-label, .sidenav.collapsed .nav-section-label { display: none; }

.nav-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7093;
  padding: 16px 18px 6px;
  font-weight: 600;
}

.nav-list { list-style: none; margin: 0; padding: 0 10px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: #c4c8dd;
  text-decoration: none;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  margin-bottom: 2px;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(108, 92, 231, 0.22); color: #fff; }
.nav-item .nav-icon { width: 17px; text-align: center; flex-shrink: 0; }

.sidenav-footer {
  margin-top: auto;
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.collapse-toggle {
  width: 100%;
  background: transparent;
  border: none;
  color: #9297b3;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
}
.collapse-toggle:hover { background: rgba(255,255,255,0.06); color: #fff; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
}
.topbar h2 { font-size: 16px; flex: 1; }
.theme-toggle {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  width: 40px;
  height: 24px;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.theme-toggle .knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--violet);
  transition: transform 0.15s ease;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
}
[data-theme="dark"] .theme-toggle .knob { transform: translateX(16px); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 14px;
  border-left: 1px solid var(--border);
}
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--violet);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}
.user-chip .who { line-height: 1.25; }
.user-chip .who .name { font-size: 12.5px; font-weight: 600; }
.user-chip .who .role { font-size: 11px; color: var(--text-secondary); }

.content { padding: 24px; flex: 1; overflow-y: auto; }
.toast-area { position: fixed; top: 16px; right: 16px; z-index: 1000; width: 320px; }
.toast-area .alert { box-shadow: var(--shadow); animation: slide-in 0.15s ease; }
@keyframes slide-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.toast-close { margin-left: auto; background: none; border: none; cursor: pointer; color: inherit; opacity: 0.6; font-size: 15px; line-height: 1; }
.toast-close:hover { opacity: 1; }

/* ---------- Dashboard ---------- */

.page-header { margin-bottom: 20px; }
.page-header .eyebrow { color: var(--text-secondary); font-size: 13px; margin-bottom: 2px; }
.page-header h1 { font-size: 22px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-card .stat-icon {
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px; font-size: 14px;
}
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; font-family: 'Space Grotesk', sans-serif; margin-top: 2px; }

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header h3 { font-size: 14.5px; }
.panel-body { padding: 18px; }

.pipeline-bar { display: flex; height: 28px; border-radius: 6px; overflow: hidden; margin-bottom: 12px; }
.pipeline-bar-seg { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 11px; font-weight: 700; min-width: 2px; transition: flex-basis 0.3s ease; }
.pipeline-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--text-secondary); }
.pipeline-legend .legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Tables & entity views ---------- */

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search-input { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.search-input input { padding-left: 32px; }
.search-input::before { content: '\26C1'; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); font-size: 14px; }

.table-responsive { overflow-x: auto; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:hover { background: var(--bg); }
.data-table tbody tr:last-child td { border-bottom: none; }
.col-actions { text-align: right; white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-violet { background: var(--violet-soft); color: var(--violet); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-emerald { background: var(--emerald-soft); color: var(--emerald); }
.badge-coral { background: var(--coral-soft); color: var(--coral); }
.badge-neutral { background: var(--border); color: var(--text-secondary); }

.create-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.create-form .field { margin-bottom: 0; min-width: 140px; flex: 1; }

/* Skeleton loading */
.skeleton-row td { padding: 12px 14px; }
.skeleton-bar { height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--border) 25%, var(--border-strong) 50%, var(--border) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Empty state */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-secondary); }
.empty-state .empty-icon { font-size: 30px; margin-bottom: 10px; opacity: 0.5; }
.empty-state h4 { color: var(--text-primary); font-size: 14.5px; margin-bottom: 4px; }
.empty-state p { font-size: 13px; margin: 0 0 14px; }

.error-state { text-align: center; padding: 32px 20px; color: var(--coral); font-size: 13px; }

/* Modal (confirm dialogs) */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16,21,43,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 1100;
}
.modal-box {
  background: var(--bg-elevated); border-radius: var(--radius-md); box-shadow: var(--shadow);
  padding: 22px; width: 340px; border: 1px solid var(--border);
}
.modal-box h4 { font-size: 15px; margin-bottom: 8px; }
.modal-box p { font-size: 13px; color: var(--text-secondary); margin: 0 0 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

@media (max-width: 860px) {
  .sidenav { position: fixed; z-index: 900; height: 100vh; width: var(--sidenav-w-collapsed); }
  .sidenav .brand-word, .sidenav .nav-label, .sidenav .nav-section-label { display: none; }
  .main-col { margin-left: var(--sidenav-w-collapsed); }
  .content { padding: 16px; }
}
