/* ─── Base Reset + Variables ────────────────────────────────────────────── */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

:root {
  --bg: #0e0e10;
  --bg-card: #18181b;
  --bg-hover: #1f1f23;
  --bg-input: #27272a;
  --border: #2e2e33;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-dim: #71717a;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --orange: #f97316;
  --purple: #a855f7;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

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

.sidebar {
  width: 220px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-logo {
  padding: 0 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.sidebar-logo h1 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -.02em;
}

.sidebar-logo span {
  display: block;
  font-size: .75rem;
  color: var(--text-dim);
  margin-top: .15rem;
}

.sidebar nav { flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1.25rem;
  color: var(--text-muted);
  font-size: .875rem;
  cursor: pointer;
  transition: all .15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.nav-item:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.nav-item.active {
  color: var(--text);
  background: var(--bg-hover);
  border-right: 2px solid var(--accent);
}

.nav-item svg { width: 18px; height: 18px; opacity: .7; }

.main {
  flex: 1;
  margin-left: 220px;
  padding: 2rem 2.5rem;
  max-width: 1200px;
}

/* ─── Page Header ───────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.75rem;
}

.page-header h2 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -.02em;
}

/* ─── Stat Cards ────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-card .label {
  font-size: .75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .35rem;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -.03em;
}

.stat-card .sub {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

/* ─── Pipeline Board ────────────────────────────────────────────────────── */
.pipeline {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .75rem;
  margin-bottom: 2rem;
}

.pipeline-col {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 300px;
}

.pipeline-col-header {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pipeline-col-header h3 {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.pipeline-count {
  background: var(--bg-input);
  font-size: .7rem;
  padding: .15rem .5rem;
  border-radius: 99px;
  color: var(--text-muted);
}

.pipeline-cards {
  padding: .5rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.pipeline-card {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .6rem .75rem;
  cursor: pointer;
  transition: border-color .15s;
}

.pipeline-card:hover { border-color: var(--accent); }

.pipeline-card .pc-name {
  font-size: .8rem;
  font-weight: 500;
  margin-bottom: .2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pipeline-card .pc-meta {
  font-size: .7rem;
  color: var(--text-dim);
}

/* ─── Table ─────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

th {
  text-align: left;
  padding: .75rem 1rem;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }
tr { cursor: pointer; }

/* ─── Badges / Tags ─────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-new { background: #3b82f620; color: #60a5fa; }
.badge-contacted { background: #a855f720; color: #c084fc; }
.badge-follow_up { background: #eab30820; color: #facc15; }
.badge-proposal { background: #f9731620; color: #fb923c; }
.badge-won { background: #22c55e20; color: #4ade80; }
.badge-lost { background: #ef444420; color: #f87171; }
.badge-unqualified { background: #71717a20; color: #a1a1aa; }

.badge-draft { background: #71717a20; color: #a1a1aa; }
.badge-sent { background: #3b82f620; color: #60a5fa; }
.badge-paid { background: #22c55e20; color: #4ade80; }
.badge-overdue { background: #ef444420; color: #f87171; }
.badge-cancelled { background: #71717a20; color: #71717a; }
.badge-failed { background: #ef444420; color: #f87171; }
.badge-delivered { background: #22c55e20; color: #4ade80; }
.badge-queued { background: #eab30820; color: #facc15; }

.score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: .75rem;
  font-weight: 700;
}

.score-low { background: #ef444430; color: #f87171; }
.score-mid { background: #eab30830; color: #facc15; }
.score-high { background: #22c55e30; color: #4ade80; }

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}

.btn:hover { background: var(--bg-hover); border-color: var(--text-dim); }

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

.btn-danger { color: var(--red); }
.btn-danger:hover { background: #ef444420; border-color: var(--red); }

.btn-sm { padding: .3rem .6rem; font-size: .75rem; }

.btn-group { display: flex; gap: .5rem; }

/* ─── Forms ─────────────────────────────────────────────────────────────── */
input, select, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: .5rem .75rem;
  font-size: .85rem;
  font-family: inherit;
  width: 100%;
  transition: border-color .15s;
}

input[type="checkbox"] {
  width: auto;
  padding: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 80px; }

label {
  display: block;
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: .3rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group { margin-bottom: 1rem; }

.search-bar {
  max-width: 320px;
}

.search-bar input {
  padding-left: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2371717a' viewBox='0 0 24 24'%3E%3Cpath d='M21 21l-4.35-4.35M11 19a8 8 0 100-16 8 8 0 000 16z' stroke='%2371717a' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: .75rem center;
}

/* ─── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}

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

.modal-header h3 { font-size: 1rem; font-weight: 600; }

.modal-body { padding: 1.25rem; }

.modal-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: .25rem;
}
.close-btn:hover { color: var(--text); }

/* ─── Detail Panel ──────────────────────────────────────────────────────── */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.detail-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.detail-field .label {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-dim);
  margin-bottom: .15rem;
}

.detail-field .value {
  font-size: .9rem;
}

.detail-section {
  margin-bottom: 2rem;
}

.detail-section h3 {
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .75rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

.review-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: end;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 38px;
  margin-bottom: 0;
}

.checkbox-label input {
  flex-shrink: 0;
}

.review-pill-row {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  margin-top: .4rem;
}

.badge-primary {
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
  font-weight: 700;
}

.review-pill-row .badge:not(.badge-primary) {
  opacity: 0.88;
}

.badge-platform {
  background: #14b8a620;
  color: #67e8f9;
}

/* Timeline */
.timeline { list-style: none; }

.timeline-item {
  display: flex;
  gap: .75rem;
  padding: .5rem 0;
  font-size: .8rem;
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  margin-top: .4rem;
  flex-shrink: 0;
}

.timeline-dot.note { background: var(--accent); }
.timeline-dot.email { background: var(--green); }
.timeline-dot.sms { background: var(--purple); }
.timeline-dot.call { background: var(--yellow); }
.timeline-dot.stage_change { background: var(--orange); }
.timeline-dot.invoice { background: var(--green); }

.timeline-content { flex: 1; }
.timeline-date { color: var(--text-dim); font-size: .7rem; }

/* ─── Utilities ─────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-sm { font-size: .8rem; }
.text-xs { font-size: .7rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-dim);
  font-size: .85rem;
}

/* ─── Pagination ───────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 1rem;
  margin-top: .75rem;
}

.pagination-info {
  font-size: .8rem;
  color: var(--text-dim);
}

.pagination-buttons {
  display: flex;
  align-items: center;
  gap: .3rem;
}

.pagination-buttons .btn-sm { min-width: 2rem; justify-content: center; }
.pagination-buttons .btn[disabled] { opacity: .35; pointer-events: none; }

.pagination-dots {
  padding: 0 .35rem;
  color: var(--text-dim);
  font-size: .8rem;
}

/* ─── Outreach ──────────────────────────────────────────────────────────── */
.outreach-stats-bar {
  display: flex;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.outreach-stat {
  font-size: .8rem;
  color: var(--text-muted);
}

.outreach-stat strong {
  font-weight: 600;
  color: var(--text);
}

.outreach-filters {
  display: flex;
  gap: .4rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.badge-good { background: #22c55e20; color: #4ade80; }
.badge-template { background: #f9731620; color: #fb923c; }
.badge-bad { background: #ef444420; color: #f87171; }
.badge-none { background: #71717a20; color: #a1a1aa; }
.badge-skip { background: #71717a20; color: #71717a; }
.badge-pending { background: #3b82f610; color: #60a5fa; }
.badge-no-email { background: #14b8a620; color: #2dd4bf; }

.outreach-issues {
  font-size: .7rem;
  color: var(--text-dim);
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 1rem; }
  .pipeline { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .detail-info { grid-template-columns: 1fr; }
  .review-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
