/* CRM — uses theme.css variables, extends for app layout */

/* ─── APP LAYOUT ─── */
.crm-app {
  padding-top: 72px;  /* below fixed nav */
  min-height: 100vh;
}

.crm-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  max-width: 1200px;
  margin: 0 auto;
  min-height: calc(100vh - 72px);
}

/* ─── SIDEBAR NAV ─── */
.crm-sidebar {
  border-right: 1px solid var(--border);
  padding: 32px 0;
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  overflow-y: auto;
}
.sidebar-section {
  margin-bottom: 32px;
}
.sidebar-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--fg-muted);
  padding: 0 20px;
  margin-bottom: 8px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 14px;
  color: var(--fg-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.15s;
  cursor: pointer;
}
.sidebar-link:hover {
  color: var(--fg);
  background: var(--bg-alt);
}
.sidebar-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(232,84,26,0.05);
}
.sidebar-link .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 20px;
}
.sidebar-link .count.accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ─── MAIN CONTENT ─── */
.crm-main {
  padding: 40px 48px;
  min-width: 0;
}

/* ─── PAGE HEADERS ─── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 40px;
  gap: 20px;
}
.page-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--fg);
  margin-bottom: 4px;
}
.page-subtitle {
  font-size: 14px;
  color: var(--fg-muted);
}

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.15s;
  font-family: var(--sans);
}
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: var(--accent-dark);
  color: white;
}
.btn-secondary {
  background: white;
  color: var(--fg);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg-alt);
  color: var(--fg);
}
.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}
.btn-danger {
  background: transparent;
  color: #dc2626;
  border: 1px solid #fca5a5;
}
.btn-danger:hover {
  background: #fef2f2;
}

/* ─── STAT CARDS ─── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 40px;
}
.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.stat-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 8px;
}
.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: -1px;
  line-height: 1;
  margin-bottom: 4px;
}
.stat-note {
  font-size: 12px;
  color: var(--fg-muted);
}

/* ─── SECTION HEADERS ─── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}

/* ─── TABLES ─── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 32px;
}
.data-table th {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--fg-muted);
  padding: 12px 16px;
  text-align: left;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 14px 16px;
  font-size: 14px;
  color: var(--fg);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td {
  border-bottom: none;
}
.data-table tr:hover td {
  background: var(--bg);
}
.client-name {
  font-weight: 600;
  color: var(--fg);
}
.client-email {
  font-size: 12px;
  color: var(--fg-muted);
  font-family: var(--mono);
}
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
}
.status-badge.active   { background: #dcfce7; color: #15803d; }
.status-badge.new      { background: #dbeafe; color: #1d4ed8; }
.status-badge.paused   { background: #fef3c7; color: #92400e; }
.status-badge.converted { background: #dcfce7; color: #15803d; }
.status-badge.lost     { background: #fee2e2; color: #991b1b; }
.status-badge.contacted { background: #f3e8ff; color: #6b21a8; }

.ref-source {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.ref-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.table-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ─── FORMS ─── */
.form-section {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  margin-bottom: 28px;
}
.form-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.form-grid .full {
  grid-column: 1 / -1;
}
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
  font-family: var(--mono);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.form-input,
.form-textarea,
.form-select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--sans);
  color: var(--fg);
  background: var(--bg);
  transition: border-color 0.15s;
  width: 100%;
}
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  background: white;
}
.form-textarea {
  resize: vertical;
  min-height: 100px;
}
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

/* ─── MODAL OVERLAY ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,22,40,0.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-box {
  background: white;
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--fg);
}
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--fg-muted);
  line-height: 1;
}

/* ─── DETAIL PAGE ─── */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 36px;
  gap: 20px;
}
.client-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.detail-name {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--fg);
  margin-bottom: 4px;
}
.detail-meta {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--fg-muted);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-bottom: 32px;
}
.detail-section {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.detail-section-header {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--fg-muted);
  padding: 12px 16px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}
.detail-section-body {
  padding: 16px;
}
.activity-entry {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.activity-entry:last-child {
  border-bottom: none;
}
.activity-type-icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  background: var(--bg-alt);
  color: var(--fg-muted);
}
.activity-type-icon.note { background: #dbeafe; color: #1d4ed8; }
.activity-type-icon.appointment { background: #dcfce7; color: #15803d; }
.activity-type-icon.reminder { background: #fef3c7; color: #92400e; }
.activity-type-icon.call { background: #f3e8ff; color: #6b21a8; }
.activity-content {
  flex: 1;
  min-width: 0;
}
.activity-time {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg-muted);
  margin-bottom: 4px;
}
.activity-text {
  font-size: 14px;
  color: var(--fg);
}
.reminder-label {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 4px;
}
.empty-state {
  text-align: center;
  padding: 40px 24px;
  color: var(--fg-muted);
}
.empty-state-icon {
  font-size: 32px;
  margin-bottom: 12px;
}
.empty-state p {
  font-size: 14px;
  margin-bottom: 16px;
}

/* ─── TABS ─── */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.tab {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  text-decoration: none;
  display: inline-block;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── REFERRAL SOURCE CARD ─── */
.ref-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ref-info { display: flex; flex-direction: column; gap: 4px; }
.ref-name-sm { font-size: 14px; font-weight: 600; color: var(--fg); }
.ref-type-sm { font-family: var(--mono); font-size: 11px; color: var(--fg-muted); }
.ref-clients {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--fg-muted);
}
.ref-clients strong { color: var(--fg); font-size: 16px; }

/* ─── DASHBOARD GRID ─── */
.dashboard-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-bottom: 32px;
}
.ref-sources-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── TOAST / ALERT ─── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}
.alert-success { background: #dcfce7; color: #15803d; }
.alert-error   { background: #fee2e2; color: #991b1b; }

/* ─── RESPONSIVE ─── */
@media (max-width: 900px) {
  .crm-layout { grid-template-columns: 1fr; }
  .crm-sidebar { display: none; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .dashboard-cols { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .crm-main { padding: 24px 20px; }
  .stat-row { grid-template-columns: 1fr; }
}