/* ============================================
   FireCalc CRM Module Styles
   Contacts, Clients, Sites common styling
   ============================================ */

/* ============================================
   CONTACT CARDS
   ============================================ */

.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.contact-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.contact-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.contact-card.inactive {
  opacity: 0.6;
}

.contact-card.inactive .contact-name::after {
  content: ' (Inactive)';
  font-size: 12px;
  color: var(--muted);
  font-weight: normal;
}

.contact-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, #ff6b35 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
}

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

.contact-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 2px;
}

.contact-company {
  font-size: 13px;
  color: var(--primary);
  margin-bottom: 4px;
}

.contact-detail {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-types {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.contact-type-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 11px;
  color: var(--muted);
}

.contact-type-badge.more {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.contact-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  align-items: center;
}

/* Quick Action Icons (inline call/email/sms buttons) */
.quick-actions-row {
  display: flex;
  gap: 4px;
  margin-right: 8px;
}

.quick-action-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg);
  text-decoration: none;
  font-size: 16px;
  transition: all 0.2s ease;
  border: 1px solid var(--border);
}

.quick-action-icon:hover {
  background: var(--primary);
  border-color: var(--primary);
  transform: scale(1.1);
}

/* ============================================
   FILTER BAR
   ============================================ */

.crm-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.crm-search-input {
  flex: 1;
  min-width: 200px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--panel);
}

.crm-search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.crm-filter-select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--panel);
  min-width: 150px;
}

.crm-filter-select:focus {
  outline: none;
  border-color: var(--primary);
}

/* ============================================
   CONTACT TYPES CHECKBOXES (Modal)
   ============================================ */

.contact-types-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.contact-type-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.contact-type-checkbox:hover {
  background: var(--panel);
}

.contact-type-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.contact-type-checkbox .type-icon {
  font-size: 14px;
}

.contact-type-checkbox .type-label {
  font-size: 13px;
  color: var(--text);
}

/* ============================================
   MODAL ENHANCEMENTS FOR CRM
   ============================================ */

.modal-section {
  margin-bottom: 24px;
}

.modal-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.form-row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.toast-notification {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast-notification.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-success {
  background: #10b981;
  color: #fff;
}

.toast-error {
  background: #ef4444;
  color: #fff;
}

.toast-info {
  background: #3b82f6;
  color: #fff;
}

/* ============================================
   EMPTY STATE VARIATIONS
   ============================================ */

.empty-state.loading {
  color: var(--primary);
}

.empty-state.error {
  color: var(--danger);
}

.empty-state a {
  color: var(--primary);
  text-decoration: underline;
}

/* ============================================
   BADGE (Count)
   ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
  .contact-card {
    flex-wrap: wrap;
    padding: 12px;
  }
  
  .contact-avatar {
    width: 40px;
    height: 40px;
    font-size: 14px;
  }
  
  .contact-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }
  
  .crm-filter-bar {
    flex-direction: column;
  }
  
  .crm-search-input,
  .crm-filter-select {
    width: 100%;
  }
  
  .contact-types-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .contact-types-grid {
    grid-template-columns: 1fr;
  }
  
  .contact-type-badge {
    font-size: 10px;
    padding: 2px 6px;
  }
}

/* ============================================
   ASSIGNED CONTACTS LIST
   ============================================ */

.assigned-contacts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.assigned-contact-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.assigned-contact-card:hover {
  border-color: var(--primary);
}

.assigned-contact-card.primary {
  border-left: 3px solid var(--primary);
  background: linear-gradient(90deg, rgba(255, 107, 53, 0.05) 0%, var(--bg) 50%);
}

.assigned-contact-card.error {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.05);
  justify-content: space-between;
  align-items: center;
}

.assigned-contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, #ff6b35 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

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

.assigned-contact-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-badge {
  display: inline-block;
  padding: 2px 6px;
  background: var(--primary);
  color: #fff;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.assigned-contact-role {
  font-size: 13px;
  color: var(--primary);
  margin-top: 2px;
}

.assigned-contact-detail {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.assigned-contact-detail a {
  color: var(--muted);
  text-decoration: none;
}

.assigned-contact-detail a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.assigned-contact-notes {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  font-style: italic;
}

.assigned-contact-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ============================================
   FORM ENHANCEMENTS
   ============================================ */

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.form-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  margin-left: 26px;
}

/* ============================================
   RESPONSIVE - ASSIGNED CONTACTS
   ============================================ */

@media (max-width: 768px) {
  .assigned-contact-card {
    flex-wrap: wrap;
  }
  
  .assigned-contact-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }
}

/* ============================================
   CONTACT DETAIL VIEW
   ============================================ */

.contact-detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
}

.contact-detail-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, #ff6b35 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  flex-shrink: 0;
}

.contact-detail-title h1 {
  margin: 0;
}

.contact-detail-title .view-subtitle {
  margin: 4px 0 0 0;
}

/* Quick Actions */
.contact-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.quick-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
  transition: all 0.2s ease;
}

.quick-action-btn:hover {
  border-color: var(--primary);
  background: var(--bg);
}

.quick-action-icon {
  font-size: 18px;
}

/* Contact Info Grid */
.contact-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
}

.contact-info-section {
  padding: 16px;
  background: var(--bg);
  border-radius: 8px;
}

.contact-info-section.full-width {
  grid-column: 1 / -1;
}

.contact-info-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.contact-info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.contact-info-row:last-child {
  border-bottom: none;
}

.contact-info-label {
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
  width: 120px;
}

.contact-info-value {
  font-size: 14px;
  color: var(--text);
  text-align: right;
  flex: 1;
}

.contact-info-value a {
  color: var(--primary);
  text-decoration: none;
}

.contact-info-value a:hover {
  text-decoration: underline;
}

.contact-info-value .empty {
  color: var(--muted);
  font-style: italic;
}

.contact-info-value .contact-type-badge {
  margin-left: 4px;
}

.contact-notes-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
}

.contact-address-block {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
}

/* Status Badge in contact info */
.status-badge.status-active {
  background: #dcfce7;
  color: #166534;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.status-badge.status-inactive {
  background: #fee2e2;
  color: #991b1b;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

/* Contact Assignments List */
.contact-assignments-list {
  display: flex;
  flex-direction: column;
}

.assignment-group-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 0 8px;
  margin-top: 8px;
}

.assignment-group-title:first-child {
  margin-top: 0;
  padding-top: 0;
}

.assignment-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.assignment-item:hover {
  border-color: var(--primary);
  background: var(--panel);
}

.assignment-icon {
  font-size: 24px;
  flex-shrink: 0;
}

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

.assignment-entity-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.assignment-role {
  font-size: 13px;
  color: var(--primary);
  margin-top: 2px;
}

.assignment-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.assignment-arrow {
  color: var(--muted);
  font-size: 18px;
  flex-shrink: 0;
}

/* ============================================
   RESPONSIVE - CONTACT DETAIL
   ============================================ */

@media (max-width: 768px) {
  .contact-detail-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .contact-detail-avatar {
    width: 56px;
    height: 56px;
    font-size: 20px;
  }
  
  .contact-quick-actions {
    flex-direction: column;
  }
  
  .quick-action-btn {
    justify-content: center;
  }
  
  .contact-detail-grid {
    grid-template-columns: 1fr;
  }
  
  .contact-info-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  
  .contact-info-label {
    width: auto;
  }
  
  .contact-info-value {
    text-align: left;
  }
}

/* ============================================
   CARD HEADER ACTIONS
   ============================================ */

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

@media (max-width: 768px) {
  .card-header-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* ============================================
   IMPORT MODAL
   ============================================ */

.import-instructions {
  background: var(--bg);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}

.import-instructions p {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: var(--text);
}

.import-instructions p:last-child {
  margin-bottom: 0;
}

.import-instructions code {
  background: var(--panel);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--primary);
}

.import-instructions .link {
  color: var(--primary);
  text-decoration: none;
}

.import-instructions .link:hover {
  text-decoration: underline;
}

.import-upload-area {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  transition: all 0.2s ease;
  cursor: pointer;
}

.import-upload-area:hover,
.import-upload-area.drag-over {
  border-color: var(--primary);
  background: rgba(255, 107, 53, 0.05);
}

.import-upload-area .upload-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.import-upload-area p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.import-upload-area a {
  color: var(--primary);
  text-decoration: none;
}

.import-upload-area a:hover {
  text-decoration: underline;
}

.import-summary {
  background: var(--bg);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.import-summary p {
  margin: 0 0 8px 0;
  font-size: 14px;
}

.import-summary p:last-child {
  margin-bottom: 0;
}

.import-warning {
  color: #b45309;
}

.import-options {
  margin-bottom: 16px;
}

.import-options .checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.import-preview-container {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 20px;
}

.import-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.import-preview-table th,
.import-preview-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.import-preview-table th {
  background: var(--bg);
  font-weight: 600;
  position: sticky;
  top: 0;
}

.import-preview-table tr:last-child td {
  border-bottom: none;
}

.import-results-summary {
  padding: 20px;
  text-align: center;
}

.import-results-summary p {
  margin: 0 0 12px 0;
  font-size: 16px;
}

.import-results-summary p:last-child {
  margin-bottom: 0;
}

.import-success {
  color: #166534;
}

.import-info {
  color: #1e40af;
}

.import-error {
  color: #991b1b;
}

.import-error-list {
  text-align: left;
  margin: 12px 0 0 0;
  padding-left: 20px;
  font-size: 13px;
  color: var(--muted);
}
