/* ── CRM Variables (extends existing theme) ── */
:root {
  --sidebar-w: 220px;
  --header-h: 56px;
  --purple: #b088f0;
  --yellow: #f0c850;
  --orange: #f09050;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: 66px;
  overflow: hidden;
}

/* ── App Layout ── */
.crm-app {
  display: flex;
  height: calc(100dvh - 66px);
}

/* ── Sidebar ── */
.crm-sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  z-index: 50;
}

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

.sidebar-logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}
.sidebar-logo span {
  color: var(--accent);
  font-weight: 400;
  margin-left: 2px;
}

.sidebar-menu {
  list-style: none;
  padding: 8px 8px;
  flex: 1;
}

.sidebar-menu li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}

.sidebar-menu li a:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text);
}

.sidebar-menu li a.active {
  background: var(--accent-surface);
  color: var(--accent);
}

.sidebar-menu li a svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar-menu li a.active svg {
  opacity: 1;
}

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

.sidebar-footer .sidebar-seed-btn {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.sidebar-footer .sidebar-seed-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Fund info in sidebar ── */
.sidebar-fund {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}
.sidebar-fund .fund-name {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.sidebar-fund .fund-bar {
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  margin: 6px 0 4px;
  overflow: hidden;
}
.sidebar-fund .fund-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}
.sidebar-fund .fund-stats {
  display: flex;
  justify-content: space-between;
}

/* ── Main content ── */
.crm-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 28px;
  min-width: 0;
}

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

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,0.08); }

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

.btn-danger {
  color: var(--danger);
  border-color: rgba(240,96,96,0.3);
}
.btn-danger:hover { background: rgba(240,96,96,0.1); }

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

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
}

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

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

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

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-card .stat-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.stat-accent { color: var(--accent); }
.stat-ok     { color: var(--ok); }
.stat-purple { color: var(--purple); }
.stat-orange { color: var(--orange); }

/* ── Pipeline overview (dashboard) ── */
.pipeline-overview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

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

.pipeline-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pipeline-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pipeline-bar-label {
  width: 120px;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  flex-shrink: 0;
}

.pipeline-bar-track {
  flex: 1;
  height: 24px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.pipeline-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.4s ease;
  min-width: 2px;
  display: flex;
  align-items: center;
  padding: 0 8px;
}

.pipeline-bar-count {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.pipeline-bar-value {
  width: 90px;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  flex-shrink: 0;
}

/* ── Kanban pipeline ── */
.kanban {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 16px;
  min-height: 400px;
}

.kanban-col {
  min-width: 240px;
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.kanban-col-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.kanban-col-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.kanban-col-title {
  font-size: 12px;
  font-weight: 600;
  flex: 1;
}

.kanban-col-count {
  font-size: 11px;
  color: var(--muted);
  background: rgba(255,255,255,0.06);
  padding: 2px 7px;
  border-radius: 10px;
}

.kanban-col-cards {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
  padding: 4px;
  border-radius: 8px;
  transition: background 0.15s;
}

.kanban-col-cards.drag-over {
  background: rgba(80,173,240,0.06);
}

.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: grab;
  transition: all 0.15s;
  border-left: 3px solid var(--accent);
}

.kanban-card:hover {
  border-color: rgba(255,255,255,0.15);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.kanban-card.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
}

.kanban-card-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  cursor: pointer;
}
.kanban-card-name:hover { color: var(--accent); }

.kanban-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.kanban-card-tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
  font-weight: 500;
}

.kanban-card-amount {
  font-size: 11px;
  color: var(--ok);
  font-weight: 600;
  margin-left: auto;
}

.kanban-card-partner {
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
}

/* ── Tables ── */
.crm-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.crm-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
  white-space: nowrap;
}

.crm-table td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}

.crm-table tbody tr {
  transition: background 0.1s;
}

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

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

.table-link {
  color: var(--accent);
  cursor: pointer;
  font-weight: 500;
}
.table-link:hover { text-decoration: underline; }

/* ── Tags ── */
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.tag-sector {
  background: rgba(80,173,240,0.12);
  color: var(--accent);
}

.tag-stage {
  background: rgba(176,136,240,0.12);
  color: var(--purple);
}

.tag-pipeline {
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.tag-invested {
  background: rgba(61,232,176,0.12);
  color: var(--ok);
}

.tag-passed {
  background: rgba(240,96,96,0.12);
  color: var(--danger);
}

/* ── Search / filter bar ── */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.filter-input:focus {
  border-color: var(--accent);
}

.filter-select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}

/* ── Modal ── */
.crm-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.crm-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 80dvh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 18px;
  transition: all 0.15s;
}
.modal-close:hover { background: rgba(255,255,255,0.06); color: var(--text); }

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

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

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

.form-group.full {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

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

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Activity timeline ── */
.activity-timeline {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.activity-item {
  display: flex;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 8px;
  transition: background 0.1s;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

.activity-item:hover {
  background: rgba(255,255,255,0.02);
}

.activity-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 14px;
}

.activity-icon.Meeting    { background: rgba(80,173,240,0.15); color: var(--accent); }
.activity-icon.Call       { background: rgba(61,232,176,0.15); color: var(--ok); }
.activity-icon.Email      { background: rgba(176,136,240,0.15); color: var(--purple); }
.activity-icon.Note       { background: rgba(240,200,80,0.15); color: var(--yellow); }
.activity-icon.Due\ Diligence,
.activity-icon[class*="Due"]  { background: rgba(240,144,80,0.15); color: var(--orange); }
.activity-icon.IC\ Memo,
.activity-icon[class*="IC"]   { background: rgba(240,96,96,0.15); color: var(--danger); }

.activity-body {
  flex: 1;
  min-width: 0;
}

.activity-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.activity-type {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.activity-company {
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
}

.activity-date {
  font-size: 11px;
  color: var(--muted);
  margin-left: auto;
}

.activity-summary {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 2px;
}

.activity-details {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.activity-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  align-self: flex-start;
}

/* ── Company detail ── */
.company-header {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.company-info {
  flex: 1;
  min-width: 200px;
}

.company-info h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.company-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.company-desc {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin-top: 8px;
}

.company-actions {
  display: flex;
  gap: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.detail-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.detail-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.detail-row:last-child { border-bottom: none; }
.detail-row .label { color: var(--muted); }
.detail-row .value { font-weight: 500; text-align: right; }

/* ── Portfolio cards ── */
.portfolio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.portfolio-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s;
  border-top: 3px solid var(--ok);
}

.portfolio-card:hover {
  border-color: rgba(255,255,255,0.12);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.portfolio-card-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.portfolio-card-sector {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}

.portfolio-card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.portfolio-stat-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.portfolio-stat-value {
  font-size: 16px;
  font-weight: 600;
}

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

.empty-state svg {
  width: 48px;
  height: 48px;
  opacity: 0.3;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 16px;
}

/* ── Section header (for dashboard sections) ── */
.section-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}

/* ── Back link ── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 16px;
  transition: color 0.15s;
}
.back-link:hover { color: var(--accent); }

/* ── Contact mini-cards (in company detail) ── */
.contact-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.contact-mini:last-child { border-bottom: none; }

.contact-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-surface);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.contact-mini-info {
  flex: 1;
  min-width: 0;
}

.contact-mini-name {
  font-size: 13px;
  font-weight: 500;
}

.contact-mini-role {
  font-size: 11px;
  color: var(--muted);
}

/* ── Mobile hamburger ── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 60;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.hamburger {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.mobile-header .sidebar-logo {
  font-size: 16px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }

  .crm-app {
    height: calc(100dvh - var(--header-h) - 66px);
    margin-top: var(--header-h);
  }

  .crm-sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 66px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 55;
  }

  .crm-sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .crm-main {
    padding: 16px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .kanban {
    min-height: 300px;
  }

  .kanban-col {
    min-width: 200px;
    width: 200px;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

/* ── Scrollbar ── */
.crm-main::-webkit-scrollbar,
.crm-modal::-webkit-scrollbar,
.kanban::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.crm-main::-webkit-scrollbar-track,
.crm-modal::-webkit-scrollbar-track,
.kanban::-webkit-scrollbar-track {
  background: transparent;
}

.crm-main::-webkit-scrollbar-thumb,
.crm-modal::-webkit-scrollbar-thumb,
.kanban::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}

/* ── Utilities ── */
.text-muted { color: var(--muted); }
.text-accent { color: var(--accent); }
.text-ok { color: var(--ok); }
.text-danger { color: var(--danger); }
.font-mono { font-family: "SF Mono", "Fira Code", monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
