/* ---- CRM Follow-up — Polished Minimalist Redesign ---- */

/* CRM Back Button — ensure it's visible and well-positioned */
/* crmBackBtn is a sibling of toolDetailCard inside toolDetailView */
.crm-mode ~ #crmBackBtn {
  display: inline-flex;
  width: 36px;
  height: 36px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  color: #64748b;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.crm-mode ~ #crmBackBtn svg {
  width: 18px;
  height: 18px;
  color: #6366f1;
}

.crm-mode ~ #crmBackBtn:hover {
  background: #f1f5f9;
  color: #334155;
}

/* CRM crmFollowupIntro — ensure proper display */
.crm-mode ~ #crmFollowupIntro {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
}

/* Hide shared tool-detail header */
.crm-mode .tool-hero {
  display: none;
}

.crm-mode .tool-detail-head {
  display: none;
}

.crm-mode {
  padding: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
  backdrop-filter: none;
}

/* ---- Form Card ---- */
.crm-form-card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---- Textarea / Input Wrapper ---- */
.crm-textarea-wrap {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  transition: all 0.2s;
}

.crm-textarea-wrap:focus-within {
  border-color: #6366f1;
  background: white;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.crm-textarea-wrap textarea,
.crm-textarea-wrap input[type="text"] {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: #1e293b;
  font-size: 0.85rem;
  font-family: inherit;
  resize: none;
  box-sizing: border-box;
  line-height: 1.6;
}

.crm-textarea-wrap textarea::placeholder,
.crm-textarea-wrap input::placeholder {
  color: #94a3b8;
}

/* ---- Primary Button ---- */
.crm-btn-primary {
  width: 100%;
  padding: 14px;
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
  font-family: inherit;
}

.crm-btn-primary:active {
  opacity: 0.85;
}

.crm-add-customer-btn {
  background: linear-gradient(135deg, #f1e8ff, #ddcbff);
  color: #6d28d9;
  box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.28);
}

.crm-add-customer-btn:active {
  opacity: 0.92;
}

.crm-subpage-head {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.crm-subpage-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  border: none;
  background: none;
  color: var(--crm-primary);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.crm-subpage-back:active {
  opacity: 0.8;
}

/* ---- Status Row (customer detail) ---- */
.crm-status-row {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

/* ---- Ghost Button ---- */
.crm-btn-ghost {
  width: 100%;
  padding: 14px;
  background: white;
  color: #64748b;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.crm-btn-ghost:active {
  background: #f1f5f9;
  color: #334155;
}

/* CRM Follow-up & SOP Reminder Styles */

.crm-root {
  --crm-primary: #6366f1;
  --crm-success: #059669;
  --crm-warning: #d97706;
  --crm-danger: #dc2626;
  --crm-bg: #f8fafc;
  --crm-card: #ffffff;
  --crm-text: #1e293b;
  --crm-text-secondary: #64748b;
  --crm-border: #e2e8f0;
  --crm-radius: 14px;
}

/* -- Stats bar --------------------------------------------------------- */

.crm-stats-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.crm-stat-item {
  flex: 1;
  background: var(--crm-card);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  padding: 12px 8px;
  text-align: center;
}

.crm-stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--crm-primary);
}

.crm-stat-label {
  font-size: 0.7rem;
  color: var(--crm-text-secondary);
  margin-top: 2px;
}

/* -- Filter tabs ------------------------------------------------------- */

.crm-filter-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.crm-filter-tab {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--crm-border);
  background: var(--crm-card);
  font-size: 0.8rem;
  color: var(--crm-text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.crm-filter-tab.is-active {
  background: var(--crm-primary);
  color: #fff;
  border-color: var(--crm-primary);
}

/* -- Customer cards ---------------------------------------------------- */

.crm-customer-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.crm-customer-card {
  background: var(--crm-card);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  padding: 14px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.crm-customer-card:active {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.crm-customer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.crm-customer-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--crm-text);
}

.crm-customer-status {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.crm-customer-status.is-new { background: #dbeafe; color: #1d4ed8; }
.crm-customer-status.is-following { background: #fef3c7; color: #92400e; }
.crm-customer-status.is-won { background: #d1fae5; color: #065f46; }
.crm-customer-status.is-lost { background: #fee2e2; color: #991b1b; }

.crm-source-tag {
  display: inline-block;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 4px;
  font-weight: 500;
}

.crm-source-tag.is-wechat { background: #dcfce7; color: #166534; }
.crm-source-tag.is-douyin { background: #fce7f3; color: #9d174d; }
.crm-source-tag.is-xiaohongshu { background: #fee2e2; color: #991b1b; }
.crm-source-tag.is-kuaishou { background: #e0e7ff; color: #3730a3; }
.crm-source-tag.is-other { background: #f1f5f9; color: #475569; }

.crm-customer-meta {
  font-size: 0.75rem;
  color: var(--crm-text-secondary);
  margin-top: 4px;
}

.crm-pending-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--crm-danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
}

/* -- Empty state ------------------------------------------------------- */

.crm-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--crm-text-secondary);
  font-size: 0.85rem;
}

/* -- Task cards -------------------------------------------------------- */

.crm-task-card {
  background: var(--crm-card);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  padding: 12px;
  margin-bottom: 8px;
}

.crm-task-card.is-completed,
.crm-task-card.is-skipped {
  opacity: 0.55;
}

.crm-task-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--crm-text);
  margin-bottom: 4px;
}

.crm-task-due {
  font-size: 0.7rem;
  color: var(--crm-text-secondary);
}

.crm-task-due.is-overdue {
  color: var(--crm-danger);
  font-weight: 600;
}

.crm-task-script {
  font-size: 0.8rem;
  color: var(--crm-text-secondary);
  background: var(--crm-bg);
  border-radius: 6px;
  padding: 8px;
  margin: 8px 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 80px;
  overflow: hidden;
}

.crm-task-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.crm-task-btn {
  flex: 1;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--crm-border);
  background: var(--crm-card);
  font-size: 0.75rem;
  cursor: pointer;
  text-align: center;
}

.crm-task-btn.is-copy {
  background: var(--crm-primary);
  color: #fff;
  border-color: var(--crm-primary);
}

.crm-task-btn.is-done {
  background: var(--crm-primary);
  color: #fff;
  border-color: var(--crm-primary);
}

.crm-task-btn.is-skip {
  color: var(--crm-text-secondary);
}

/* -- Log timeline ------------------------------------------------------ */

.crm-log-timeline {
  border-left: 2px solid var(--crm-border);
  margin-left: 10px;
  padding-left: 16px;
}

.crm-log-entry {
  position: relative;
  padding-bottom: 14px;
}

.crm-log-entry::before {
  content: "";
  position: absolute;
  left: -21px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--crm-primary);
}

.crm-log-action {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--crm-primary);
  margin-bottom: 2px;
}

.crm-log-content {
  font-size: 0.8rem;
  color: var(--crm-text);
  white-space: pre-wrap;
}

.crm-log-time {
  font-size: 0.65rem;
  color: var(--crm-text-secondary);
  margin-top: 2px;
}

/* -- SOP template cards ------------------------------------------------ */

.crm-sop-card {
  background: var(--crm-card);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  padding: 12px;
  margin-bottom: 8px;
}

.crm-sop-card.is-system {
  border-left: 3px solid var(--crm-primary);
}

.crm-sop-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--crm-text);
}

.crm-sop-desc {
  font-size: 0.75rem;
  color: var(--crm-text-secondary);
  margin-top: 2px;
}

.crm-sop-steps {
  font-size: 0.7rem;
  color: var(--crm-text-secondary);
  margin-top: 4px;
}

.crm-sop-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* -- Step editor ------------------------------------------------------- */

.crm-step-editor {
  background: var(--crm-bg);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  padding: 12px;
  margin-bottom: 8px;
}

.crm-step-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.crm-step-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--crm-text);
}

.crm-step-field {
  margin-bottom: 6px;
}

.crm-step-field label {
  display: block;
  font-size: 0.7rem;
  color: var(--crm-text-secondary);
  margin-bottom: 2px;
}

.crm-step-field input,
.crm-step-field textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--crm-border);
  border-radius: 6px;
  font-size: 0.8rem;
  box-sizing: border-box;
}

/* -- Push banner ------------------------------------------------------- */

.crm-push-banner {
  background: linear-gradient(135deg, #dbeafe, #ede9fe);
  border: 1px solid #93c5fd;
  border-radius: var(--crm-radius);
  padding: 12px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.crm-push-banner-text {
  font-size: 0.8rem;
  color: #1e40af;
}

.crm-push-banner-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* -- Customer detail header -------------------------------------------- */

.crm-detail-header {
  margin-bottom: 16px;
}

.crm-detail-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--crm-text);
}

.crm-detail-status-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.crm-status-btn {
  padding: 4px 14px;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  background: white;
  font-size: 0.75rem;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.crm-status-btn.is-active {
  background: #6366f1;
  color: white;
  border-color: #6366f1;
}

/* -- Delete button ----------------------------------------------------- */

.crm-delete-btn {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--crm-danger);
  border-radius: 8px;
  background: transparent;
  color: var(--crm-danger);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
}

/* -- Add customer form ------------------------------------------------- */

.crm-form-group {
  margin-bottom: 12px;
}

.crm-form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--crm-text);
  margin-bottom: 4px;
}

.crm-form-group input,
.crm-form-group textarea,
.crm-form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--crm-border);
  border-radius: 8px;
  font-size: 0.85rem;
  box-sizing: border-box;
}

.crm-source-radios {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.crm-source-radio {
  flex-shrink: 0;
}

.crm-source-radio input {
  display: none;
}

.crm-source-radio span {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--crm-border);
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.crm-source-radio input:checked + span {
  background: var(--crm-primary);
  color: #fff;
  border-color: var(--crm-primary);
}

/* -- View navigation --------------------------------------------------- */

.crm-view {
  display: none;
}

.crm-view.is-active {
  display: block;
}

.crm-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--crm-border);
  border-radius: 8px;
  background: var(--crm-card);
  font-size: 0.8rem;
  cursor: pointer;
  margin-bottom: 12px;
}

.crm-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--crm-text);
  margin: 16px 0 8px;
}

/* -- SOP selection cards (add customer view) --------------------------- */

.crm-sop-select-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.crm-sop-select-card {
  background: var(--crm-card);
  border: 2px solid var(--crm-border);
  border-radius: var(--crm-radius);
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.crm-sop-select-card.is-selected {
  border-color: var(--crm-primary);
}

.crm-sop-select-card input {
  display: none;
}

/* -- Add log form ------------------------------------------------------ */

.crm-add-log-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.crm-add-log-form textarea {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--crm-border);
  border-radius: 8px;
  font-size: 0.8rem;
  resize: none;
  min-height: 36px;
}

.crm-add-log-form button {
  align-self: flex-end;
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  background: var(--crm-primary);
  color: #fff;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

/* -- CRM industry setup / AI preset additions -------------------------- */

.crm-setup-card,
.crm-profile-card,
.crm-ai-script-card {
  background: var(--crm-card);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
}

.crm-setup-card {
  padding: 18px 16px;
}

.crm-detail-card {
  background: var(--crm-card);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.crm-setup-badge {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.72rem;
  font-weight: 600;
}

.crm-setup-title {
  margin: 12px 0 8px;
  font-size: 1.05rem;
  color: var(--crm-text);
}

.crm-setup-desc {
  margin: 0 0 14px;
  color: var(--crm-text-secondary);
  font-size: 0.82rem;
  line-height: 1.55;
}

.crm-profile-card {
  padding: 14px;
  margin-bottom: 14px;
}

.crm-profile-top,
.crm-ai-script-top,
.crm-sop-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.crm-sop-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.crm-profile-label,
.crm-ai-script-label {
  font-size: 0.72rem;
  color: var(--crm-text-secondary);
}

.crm-profile-industry {
  margin-top: 4px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--crm-text);
}

.crm-profile-summary,
.crm-inline-note,
.crm-detail-note,
.crm-sop-desc,
.crm-ai-script-time {
  color: var(--crm-text-secondary);
  font-size: 0.78rem;
  line-height: 1.55;
}

.crm-profile-summary,
.crm-inline-note,
.crm-detail-note,
.crm-ai-script-card {
  margin-bottom: 12px;
}

.crm-inline-note {
  padding: 10px 12px;
  border-radius: 10px;
  background: #eef4ff;
}

.crm-template-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  font-size: 0.68rem;
  font-weight: 600;
  flex-shrink: 0;
}

.crm-template-badge.is-generated {
  background: #dbeafe;
  color: #1d4ed8;
}

.crm-ai-script-card {
  padding: 12px;
}

.crm-ai-script-body {
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--crm-text);
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

/* -- Loading overlay ------------------------------------------------- */

.crm-loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.crm-loading-content {
  text-align: center;
  color: var(--crm-text);
  font-size: 0.9rem;
  line-height: 1.6;
}

.crm-loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--crm-border);
  border-top-color: var(--crm-primary);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: crm-spin 0.8s linear infinite;
}

@keyframes crm-spin {
  to { transform: rotate(360deg); }
}

/* -- Trend chart ------------------------------------------------------ */

.crm-chart-section {
  margin-top: 20px;
  padding: 14px;
  background: var(--crm-card);
  border: 1px solid var(--crm-border);
  border-radius: var(--crm-radius);
}

.crm-chart-section canvas {
  width: 100%;
  height: 200px;
  display: block;
}

.crm-chart-legend {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 10px;
  font-size: 0.7rem;
  color: var(--crm-text-secondary);
}

.crm-chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.crm-chart-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
