/* ════════════════════════════════════════════════════════════════
   CRM DASHBOARD — Mobile-optimized styling
   ════════════════════════════════════════════════════════════════ */

.crm-container {
  padding: 12px;
  background: #f9fafb;
  min-height: 100vh;
}

/* ════════════════════════════════════════════════════════════════
   MOBILE-FIRST DEFAULTS (≤768px)
   ════════════════════════════════════════════════════════════════ */

/* STAT CARDS */
.crm-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.crm-stat-card {
  background: white;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.crm-stat-card:active {
  transform: scale(0.97);
  box-shadow: 0 4px 6px rgba(0,0,0,0.12);
}

.crm-stat-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

.crm-stat-label {
  font-size: 11px;
  color: #666;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.crm-stat-value {
  font-size: 28px;
  font-weight: bold;
  color: #1f2937;
}

.crm-stat-card.hot { border-top: 3px solid #ef4444; }
.crm-stat-card.warm { border-top: 3px solid #f59e0b; }
.crm-stat-card.cold { border-top: 3px solid #6b7280; }
.crm-stat-card.today { border-top: 3px solid #3b82f6; }

/* FILTERS */
.crm-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.crm-filter-btn {
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  background: white;
  color: #666;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 40px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.crm-filter-btn.active {
  background: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

/* LEAD CARDS */
.crm-leads-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.crm-lead-card {
  background: white;
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 4px solid #d1d5db;
  -webkit-tap-highlight-color: transparent;
  min-height: 50px;
}

.crm-lead-card:active {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.crm-lead-card.urgent {
  border-left-color: #ef4444;
  background: #fef2f2;
}

.crm-lead-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.crm-lead-name {
  font-size: 15px;
  font-weight: 700;
  color: #1f2937;
}

.crm-lead-badge {
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
}

.crm-lead-badge.new { background: #dbeafe; color: #1e40af; }
.crm-lead-badge.interested { background: #dcfce7; color: #15803d; }
.crm-lead-badge.campus { background: #fef3c7; color: #92400e; }
.crm-lead-badge.quote { background: #f3e8ff; color: #6b21a8; }
.crm-lead-badge.lost { background: #fee2e2; color: #7f1d1d; }

.crm-lead-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 12px;
  color: #666;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e5e7eb;
}

.crm-lead-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.crm-lead-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.crm-action-btn {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: white;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 44px; /* Touch target size */
  min-width: 44px;  /* Touch target size */
  -webkit-tap-highlight-color: transparent; /* Mobile tap feedback */
}

.crm-action-btn:active {
  background: #f3f4f6;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.crm-action-btn.primary {
  background: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

/* MODALS */
.crm-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  padding: 12px;
}

.crm-modal.active {
  display: flex;
  align-items: flex-end;
}

.crm-modal-content {
  background: white;
  border-radius: 12px 12px 0 0;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.crm-modal-header {
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: white;
}

.crm-modal-title {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
}

.crm-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #9ca3af;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s;
}

.crm-modal-close:active {
  color: #6b7280;
}

.crm-modal-body {
  padding: 16px;
}

/* ACTIVITY TIMELINE */
.crm-timeline {
  position: relative;
  padding-left: 20px;
}

.crm-timeline-item {
  margin-bottom: 16px;
  position: relative;
}

.crm-timeline-item::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid white;
  box-shadow: 0 0 0 2px #3b82f6;
}

.crm-timeline-time {
  font-size: 11px;
  color: #9ca3af;
  margin-bottom: 2px;
}

.crm-timeline-text {
  font-size: 13px;
  color: #374151;
  padding: 8px;
  background: #f9fafb;
  border-radius: 6px;
}

/* STAGE SELECTOR */
.crm-stage-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.crm-stage-option {
  padding: 14px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: white;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.crm-stage-option:active {
  background: #f0f9ff;
  border-color: #3b82f6;
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
}

/* FORM INPUTS */
.crm-form-group {
  margin-bottom: 12px;
}

.crm-form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #4b5563;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.crm-form-input,
.crm-form-textarea,
.crm-form-select {
  width: 100%;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 16px; /* Prevents auto-zoom on mobile */
  font-family: inherit;
  -webkit-appearance: none; /* Removes iOS default styling */
  appearance: none;
  transition: border-color 0.2s;
}

.crm-form-input:focus,
.crm-form-textarea:focus,
.crm-form-select:focus {
  border-color: #3b82f6;
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.crm-form-textarea {
  resize: vertical;
  min-height: 80px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* UTILITY */
.crm-badge-priority {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.crm-badge-hot { background: #fee2e2; color: #7f1d1d; }
.crm-badge-warm { background: #fef3c7; color: #92400e; }
.crm-badge-cold { background: #f3f4f6; color: #374151; }

.crm-status-icon {
  font-size: 20px;
  display: inline-block;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE: MOBILE (≤768px) — Already optimized above
   RESPONSIVE: DESKTOP (≥769px) — Table-format, centered modals
   ═══════════════════════════════════════════════════════════════ */

@media (min-width: 769px) {
  /* CONTAINER */
  .crm-container {
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
  }

  /* STATS: 4-column grid for desktop */
  .crm-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
  }

  .crm-stat-card {
    padding: 16px;
    font-size: 14px;
  }

  .crm-stat-icon {
    font-size: 28px;
  }

  .crm-stat-label {
    font-size: 12px;
  }

  .crm-stat-value {
    font-size: 32px;
  }

  /* FILTERS: Horizontal inline layout */
  .crm-filters {
    gap: 10px;
    margin-bottom: 20px;
    overflow-x: visible;
    padding-bottom: 0;
    flex-wrap: wrap;
  }

  .crm-filter-btn {
    padding: 8px 16px;
    font-size: 13px;
  }

  /* LEADS LIST: Table-like grid format */
  .crm-leads-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
  }

  /* LEAD CARD: Horizontal table row */
  .crm-lead-card {
    border-left: 0;
    border-bottom: 1px solid #e5e7eb;
    padding: 16px;
    display: grid;
    grid-template-columns: 150px 120px 100px 100px 80px 80px;
    gap: 12px;
    align-items: center;
    background: white;
    box-shadow: none;
    border-radius: 0;
  }

  .crm-lead-card:last-child {
    border-bottom: none;
  }

  .crm-lead-card:hover {
    background: #f9fafb;
  }

  .crm-lead-card:active {
    transform: none;
    box-shadow: none;
  }

  .crm-lead-card.urgent {
    background: #fffbeb;
    border-left: none;
  }

  /* LEAD HEADER: First column (Name + Badge) */
  .crm-lead-header {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    margin-bottom: 0;
    gap: 4px;
  }

  .crm-lead-name {
    font-size: 14px;
    font-weight: 600;
  }

  .crm-lead-badge {
    font-size: 10px;
    padding: 2px 6px;
  }

  /* LEAD META: Display as separate columns (not a grid) */
  .crm-lead-meta {
    display: contents; /* Flatten the grid */
  }

  .crm-lead-meta-item {
    font-size: 12px;
    color: #666;
    border-bottom: none;
    padding-bottom: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .crm-lead-meta-item:nth-of-type(1)::before { content: "📞 "; }
  .crm-lead-meta-item:nth-of-type(2)::before { content: "📅 "; }
  .crm-lead-meta-item:nth-of-type(3)::before { content: "🎯 "; }
  .crm-lead-meta-item:nth-of-type(4)::before { content: "👤 "; }

  /* LEAD ACTIONS: Right-aligned action buttons */
  .crm-lead-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-bottom: 0;
  }

  .crm-action-btn {
    padding: 6px;
    font-size: 11px;
    gap: 2px;
  }

  /* MODALS: Centered dialog box layout */
  .crm-modal {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .crm-modal.active {
    align-items: center;
  }

  .crm-modal-content {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideDown 0.3s ease-out;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
  }

  @keyframes slideDown {
    from {
      opacity: 0;
      transform: scale(0.95);
    }
    to {
      opacity: 1;
      transform: scale(1);
    }
  }

  .crm-modal-header {
    padding: 20px;
  }

  .crm-modal-title {
    font-size: 18px;
  }

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

  /* TIMELINE: Side-by-side layout for desktop */
  .crm-timeline {
    padding-left: 24px;
  }

  .crm-timeline-item {
    margin-bottom: 20px;
  }

  .crm-timeline-item::before {
    width: 10px;
    height: 10px;
    left: -30px;
    top: 4px;
  }

  .crm-timeline-time {
    font-size: 12px;
  }

  .crm-timeline-text {
    font-size: 14px;
    padding: 10px;
  }

  /* STAGE OPTIONS: 3-column grid for desktop */
  .crm-stage-options {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }

  .crm-stage-option {
    padding: 14px;
    font-size: 13px;
  }

  /* FORM: 2-column layout for desktop */
  .crm-form-group {
    margin-bottom: 16px;
  }

  .crm-form-label {
    font-size: 13px;
  }

  .crm-form-input,
  .crm-form-textarea,
  .crm-form-select {
    font-size: 14px;
    padding: 12px;
  }

  .crm-form-textarea {
    min-height: 100px;
  }

  /* UTILITY: Slightly larger badges for desktop */
  .crm-badge-priority {
    font-size: 12px;
    padding: 4px 10px;
  }

  .crm-status-icon {
    font-size: 24px;
  }
}
