/**
 * ContactsTable Styles
 * 
 * Modern, clean design with compact spacing
 * Requirements: 1.3, 16.1, 16.2, 16.3, 16.4, 5.1
 * 
 * Design Principles:
 * - Ample whitespace for readability
 * - Subtle borders for visual separation
 * - Clear typography hierarchy
 * - Consistent spacing and alignment
 */

/* Table Header - Requirements 5.1, 6.1 */
.contacts-table-header {
  margin-bottom: 20px;
}

.contacts-table-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 16px;
  min-height: 44px;
}

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

.btn-manage-circles {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--color-primary, #3b82f6);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-add-contact {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--chat-bubble-bg);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(139, 111, 92, 0.3);
}

.btn-add-contact:hover {
  background: var(--chat-bubble-hover);
  box-shadow: 0 2px 6px rgba(139, 111, 92, 0.4);
  transform: translateY(-1px);
}

.btn-add-contact:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(139, 111, 92, 0.3);
}

/* Sort Controls - Requirement 6.1 */
.sort-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.sort-controls label {
  font-size: 14px;
  font-weight: 500;
  color: #6b7280;
  white-space: nowrap;
  line-height: 1;
}

.sort-order-select {
  padding: 10px 32px 10px 12px;
  border: 1px solid var(--border-primary, #d1d5db);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary, #1f2937);
  background-color: var(--bg-primary, white);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat !important;
  background-position: right 10px center;
  background-size: 12px 12px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
  height: 44px;
  line-height: 1;
}

/* Light theme explicit styling */
:root .sort-order-select,
[data-theme="light"] .sort-order-select {
  background-color: white;
  border-color: #d1d5db;
  color: #1f2937;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
}

.sort-order-select:hover {
  border-color: #9ca3af;
}

.sort-order-select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Sort Indicators - Requirement 6.4 */
.sort-indicator {
  display: inline-block;
  margin-left: 4px;
  font-size: 10px;
  color: #9ca3af;
  transition: color 0.2s ease;
}

.sort-indicator.sort-asc,
.sort-indicator.sort-desc {
  color: #3b82f6;
  font-weight: bold;
}

.contacts-table-layout {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.contacts-table-wrapper {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 600px;
  background: var(--bg-surface);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  border: 1px solid var(--border-subtle);
  /* Allow dropdowns to overflow the table wrapper */
  position: relative;
}

.contacts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.4;
  letter-spacing: 0.01em;
  table-layout: fixed;
}

/* Table Header */
.contacts-table thead {
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 10;
}

.contacts-table th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.contacts-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s ease;
}

.contacts-table th.sortable:hover {
  background: var(--bg-hover);
  color: var(--accent-primary);
}

/* Table Body - Compact Spacing */
.contacts-table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color 0.15s ease;
}

/* Row Hover Effect - Requirement 16.3 */
.contacts-table tbody tr:hover {
  background-color: rgba(139, 111, 92, 0.05);
  box-shadow: inset 0 0 0 1px rgba(139, 111, 92, 0.1);
}

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

.contacts-table td {
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 14px;
  vertical-align: middle;
}

/* Compact spacing for better data density */
.contacts-table td {
  max-width: 200px;
}

.contacts-table td.contact-name,
.contacts-table td.contact-email,
.contacts-table td.contact-phone,
.contacts-table td.contact-location,
.contacts-table td.contact-timezone,
.contacts-table td.contact-frequency {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contacts-table td.contact-tags,
.contacts-table td.contact-groups {
  overflow: hidden;
  display: block;
  max-width: 150px;
}

.contacts-table td.contact-tags .badge,
.contacts-table td.contact-groups .badge {
  display: inline-block;
  margin: 2px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contacts-table td.contact-name {
  font-weight: 500;
  color: var(--text-primary);
  font-size: 14px;
  max-width: 180px;
}

.contacts-table td.contact-email,
.contacts-table td.contact-phone {
  color: var(--text-secondary);
  font-size: 13px;
}

/* Avatar Component - Requirement 6.5 */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

/* Warm pastel variants - Requirement 6.5 */
.avatar--sage {
  background: #d1fae5;
  color: #065f46;
}

.avatar--sand {
  background: #fef3c7;
  color: #92400e;
}

.avatar--rose {
  background: #fce7f3;
  color: #9d174d;
}

.avatar--stone {
  background: #e7e5e4;
  color: #44403c;
}

/* Badge Styling - Requirements 1.4, 1.5, 16.4 */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  margin-right: 4px;
  margin-bottom: 2px;
  transition: all 0.2s ease;
}

/* Circle Badge - Requirement 8.1, 8.2 */
.badge-circle {
  color: white;
  font-weight: 600;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.badge-uncategorized {
  background-color: #f3f4f6;
  color: #6b7280;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
}

/* Google Source Badge - Light grey background */
.badge-google {
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.badge-google svg {
  margin-right: 4px;
}

/* Tag Badge - Unified amber/accent color */
.badge-tag {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  border: 1px solid var(--accent-hover);
  border-radius: 14px;
}

/* Group Badge - Unified amber/accent color */
.badge-group {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  border: 1px solid var(--accent-hover);
  border-radius: 14px;
}

/* Tags and Groups columns - allow wrapping for multiple badges */
.contacts-table td.contact-tags,
.contacts-table td.contact-groups {
  white-space: normal;
  max-width: 250px;
  line-height: 1.8;
}

/* Actions Column */
.contacts-table td.contact-actions {
  text-align: center;
  width: 80px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.2s ease;
  opacity: 0.7;
  margin: 0 2px;
}

.action-btn:hover {
  opacity: 1;
  transform: scale(1.1);
}

.action-btn.btn-confirm {
  color: var(--status-success);
}

.action-btn.btn-confirm:hover {
  background-color: var(--status-success-bg);
}

.action-btn.btn-cancel {
  color: var(--status-error);
}

.action-btn.btn-cancel:hover {
  background-color: var(--status-error-bg);
}

/* Legacy delete button support */
.btn-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 18px;
  color: var(--status-error);
  transition: all 0.2s ease;
  opacity: 0.7;
}

.btn-delete:hover {
  background-color: var(--status-error-bg);
  opacity: 1;
  transform: scale(1.1);
}

/* Empty State */
.contacts-table .empty-state td {
  padding: 60px 20px;
  text-align: center;
  color: #9ca3af;
  font-size: 15px;
}

/* Dark Mode Support - Requirement 16.5 */
/* Colors automatically handled by CSS variables in stone-clay-theme.css */

[data-theme="dark"] .badge-uncategorized {
  background-color: #374151;
  color: #9ca3af;
  border-color: #4b5563;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .badge-tag {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  border-color: var(--accent-hover);
  box-shadow: 0 1px 2px rgba(245, 158, 11, 0.2);
}

[data-theme="dark"] .badge-group {
  background-color: var(--accent-subtle);
  color: var(--accent-primary);
  border-color: var(--accent-hover);
  box-shadow: 0 1px 2px rgba(245, 158, 11, 0.2);
}

[data-theme="dark"] .badge-circle {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .badge-google {
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  border-color: var(--border-subtle);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .action-btn.btn-confirm {
  color: var(--status-success);
}

[data-theme="dark"] .action-btn.btn-confirm:hover {
  background-color: var(--status-success-bg);
}

[data-theme="dark"] .action-btn.btn-cancel {
  color: var(--status-error);
}

[data-theme="dark"] .action-btn.btn-cancel:hover {
  background-color: var(--status-error-bg);
}

[data-theme="dark"] .btn-delete {
  color: var(--status-error);
}

[data-theme="dark"] .btn-delete:hover {
  background-color: var(--status-error-bg);
}

[data-theme="dark"] .contacts-table .empty-state td {
  color: #6b7280;
}

/* Mobile Responsive - Requirement 17.1, 17.2 */
@media (max-width: 768px) {
  .contacts-table-wrapper {
    border-radius: 0;
    box-shadow: none;
    border: none;
  }

  /* Transform table to card-based layout */
  .contacts-table thead {
    display: none;
  }

  .contacts-table,
  .contacts-table tbody,
  .contacts-table tr,
  .contacts-table td {
    display: block;
    width: 100%;
  }

  .contacts-table tbody tr {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    margin-bottom: 16px;
    padding: 16px;
    box-shadow: 0 2px 4px var(--card-shadow);
  }

  .contacts-table tbody tr:hover {
    box-shadow: 0 4px 8px var(--card-shadow);
  }

  .contacts-table td {
    padding: 8px 0;
    border: none;
    max-width: none;
    white-space: normal;
    text-overflow: clip;
    overflow: visible;
  }

  /* Add labels before each field */
  .contacts-table td::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 4px;
  }

  /* Name field - larger and prominent */
  .contacts-table td.contact-name {
    font-size: 18px;
    font-weight: 600;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: 12px;
  }

  .contacts-table td.contact-name::before {
    display: none;
  }

  /* Actions at the bottom */
  .contacts-table td.contact-actions {
    text-align: right;
    padding-top: 12px;
    border-top: 1px solid var(--border-primary);
    margin-top: 12px;
  }

  .contacts-table td.contact-actions::before {
    display: none;
  }

  /* Badges wrap nicely */
  .badge {
    font-size: 11px;
    padding: 3px 8px;
    margin-right: 4px;
    margin-bottom: 4px;
  }

  /* New contact row in mobile */
  .new-contact-row {
    display: block;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 16px;
  }

  .new-contact-row td {
    display: block;
    padding: 8px 0;
  }

  .new-contact-row td::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 4px;
  }

  .new-contact-row td.contact-actions::before {
    display: none;
  }
}

/* Inline Editing Styles - Requirements 2.1, 2.2, 2.3, 2.4, 2.5 */

/* Editable cells */
.contacts-table td.editable {
  cursor: pointer;
  position: relative; /* Required for autocomplete positioning */
}

.contacts-table td.editable:hover:not(.editing) {
  background-color: #f3f4f6;
  outline: 1px solid #e5e7eb;
}

.contacts-table td.editing {
  padding: 4px;
  background-color: white;
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

/* Text input */
.inline-edit-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  color: #1f2937;
  background: white;
  outline: none;
}

.inline-edit-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Dropdown select */
.inline-edit-select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  color: #1f2937;
  background: white;
  cursor: pointer;
  outline: none;
}

.inline-edit-select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Multi-select container */
.inline-edit-multiselect {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 32px;
}

.multiselect-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 24px;
}

.multiselect-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background-color: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.chip-remove {
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: #1e40af;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.chip-remove:hover {
  opacity: 1;
}

.multiselect-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  color: #1f2937;
  background: white;
  outline: none;
}

.multiselect-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Autocomplete dropdown - Requirement 2.4 */
.autocomplete-list {
  position: fixed !important;
  max-height: 200px;
  overflow-y: auto;
  background: white !important;
  border: 2px solid #3b82f6 !important;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
  z-index: 99999 !important;
  min-width: 200px !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  color: #1f2937 !important;
  transition: background-color 0.15s ease;
  border-bottom: 1px solid #f3f4f6;
  background: white !important;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  color: #1f2937;
  transition: background-color 0.15s ease;
  border-bottom: 1px solid #f3f4f6;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover {
  background-color: #eff6ff;
  color: #1e40af;
}

.autocomplete-item:active {
  background-color: #dbeafe;
}

/* Validation error */
.inline-edit-error {
  position: absolute;
  bottom: -24px;
  left: 0;
  padding: 4px 8px;
  background-color: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Dark mode for inline editing */
[data-theme="dark"] .contacts-table td.editable:hover:not(.editing) {
  background-color: #374151;
  outline-color: #4b5563;
}

[data-theme="dark"] .contacts-table td.editing {
  background-color: #1f2937;
  outline-color: #60a5fa;
}

[data-theme="dark"] .inline-edit-input,
[data-theme="dark"] .inline-edit-select,
[data-theme="dark"] .multiselect-input {
  background: #111827;
  border-color: #4b5563;
  color: #f3f4f6;
}

[data-theme="dark"] .inline-edit-input:focus,
[data-theme="dark"] .inline-edit-select:focus,
[data-theme="dark"] .multiselect-input:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
}

[data-theme="dark"] .multiselect-chip {
  background-color: #1e3a8a;
  color: #93c5fd;
  border-color: #1e40af;
}

[data-theme="dark"] .chip-remove {
  color: #93c5fd;
}

[data-theme="dark"] .autocomplete-list {
  background: #1f2937;
  border-color: #60a5fa;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .autocomplete-item {
  color: #d1d5db;
  border-bottom-color: #374151;
}

[data-theme="dark"] .autocomplete-item:hover {
  background-color: #1e3a8a;
  color: #93c5fd;
}

[data-theme="dark"] .autocomplete-item:active {
  background-color: #1e40af;
}

[data-theme="dark"] .inline-edit-error {
  background-color: #7f1d1d;
  color: #fecaca;
  border-color: #991b1b;
}

/* Mobile adjustments for inline editing */
@media (max-width: 768px) {
  .inline-edit-input,
  .inline-edit-select,
  .multiselect-input {
    font-size: 16px; /* Prevent zoom on iOS */
  }

  .autocomplete-list {
    max-height: 150px;
  }
}

/* New Contact Row Styles - Requirements 5.1, 5.2, 5.4, 5.5 */

.new-contact-row {
  background-color: rgba(139, 111, 92, 0.1);
  border: 2px solid var(--chat-bubble-bg);
  animation: slideInFromTop 0.3s ease;
}

@keyframes slideInFromTop {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.new-contact-row td {
  padding: 8px;
  vertical-align: middle;
}

.new-contact-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  color: #1f2937;
  background: white;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.new-contact-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.new-contact-input.error {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.new-contact-input::placeholder {
  color: #9ca3af;
}

.new-contact-input[required]::placeholder::after {
  content: ' *';
  color: #ef4444;
}

/* Save and Cancel buttons for new contact */
.btn-save-new,
.btn-cancel-new {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: #f3f4f6;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.2s ease;
  opacity: 0.8;
}

.btn-save-new {
  color: #10b981;
}

.btn-cancel-new {
  color: #ef4444;
}

.btn-save-new:hover {
  background-color: #d1fae5;
  opacity: 1;
  transform: scale(1.05);
}

.btn-cancel-new:hover {
  background-color: #fee2e2;
  opacity: 1;
  transform: scale(1.05);
}

.btn-save-new:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Dark mode for controls and new contact row */
[data-theme="dark"] .btn-add-contact {
  background: var(--chat-bubble-bg);
  box-shadow: 0 1px 3px rgba(155, 127, 108, 0.4);
}

[data-theme="dark"] .btn-add-contact:hover {
  background: var(--chat-bubble-hover);
  box-shadow: 0 2px 6px rgba(155, 127, 108, 0.5);
}

[data-theme="dark"] .sort-controls label {
  color: #9ca3af;
}

[data-theme="dark"] .sort-order-select {
  background-color: #1f2937;
  border-color: #4b5563;
  color: #f3f4f6;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca3af' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat !important;
  background-position: right 10px center;
  background-size: 12px 12px;
}

[data-theme="dark"] .sort-order-select:hover {
  border-color: #6b7280;
}

[data-theme="dark"] .sort-order-select:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
}

[data-theme="dark"] .sort-indicator {
  color: #6b7280;
}

[data-theme="dark"] .sort-indicator.sort-asc,
[data-theme="dark"] .sort-indicator.sort-desc {
  color: #60a5fa;
}

[data-theme="dark"] .new-contact-row {
  background-color: rgba(155, 127, 108, 0.15);
  border-color: var(--chat-bubble-bg);
}

[data-theme="dark"] .new-contact-input {
  background: #111827;
  border-color: #4b5563;
  color: #f3f4f6;
}

[data-theme="dark"] .new-contact-input:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
}

[data-theme="dark"] .new-contact-input.error {
  border-color: #f87171;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.1);
}

[data-theme="dark"] .new-contact-input::placeholder {
  color: #6b7280;
}

[data-theme="dark"] .btn-save-new {
  background: #374151;
  color: #34d399;
}

[data-theme="dark"] .btn-cancel-new {
  background: #374151;
  color: #f87171;
}

[data-theme="dark"] .btn-save-new:hover {
  background-color: #064e3b;
}

[data-theme="dark"] .btn-cancel-new:hover {
  background-color: #7f1d1d;
}

/* Mobile adjustments for controls and new contact row */
@media (max-width: 768px) {
  .contacts-table-controls {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .header-actions {
    flex-shrink: 0;
  }

  .btn-add-contact {
    padding: 10px 16px;
    font-size: 13px;
  }

  .sort-controls {
    flex-shrink: 0;
  }

  .sort-controls label {
    font-size: 13px;
  }

  .sort-order-select {
    font-size: 13px;
    padding: 8px 28px 8px 10px;
  }

  .new-contact-input {
    font-size: 16px; /* Prevent zoom on iOS */
  }
}

/* A-Z Scrollbar Styles - Requirements 3.1, 3.2, 3.3, 3.4, 3.5 */

.az-scrollbar {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-surface);
  padding: 8px 6px;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--border-subtle);
  user-select: none;
  position: sticky;
  top: 20px;
  align-self: flex-start;
}

.az-letter {
  width: 24px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  transition: all 0.2s ease;
  cursor: pointer;
  color: var(--text-secondary);
}

/* Active letters (have contacts) - Requirement 3.1 */
.az-letter.active {
  color: var(--chat-bubble-bg);
}

.az-letter.active:hover {
  background-color: rgba(139, 111, 92, 0.1);
  color: var(--chat-bubble-hover);
  transform: scale(1.15);
}

/* Inactive letters (no contacts) */
.az-letter.inactive {
  color: var(--text-tertiary);
  cursor: default;
  pointer-events: none;
}

/* Current letter highlighting - Requirement 3.4 */
.az-letter.current {
  background-color: var(--chat-bubble-bg);
  color: white;
  transform: scale(1.2);
  box-shadow: 0 2px 4px rgba(139, 111, 92, 0.3);
}

/* Theme support via data-theme attribute */
[data-theme="dark"] .az-scrollbar {
  background: var(--bg-elevated);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  border-color: var(--border-primary);
}

[data-theme="dark"] .az-letter.active {
  color: var(--chat-bubble-bg);
}

[data-theme="dark"] .az-letter.active:hover {
  background-color: rgba(155, 127, 108, 0.2);
  color: var(--chat-bubble-hover);
}

[data-theme="dark"] .az-letter.inactive {
  color: var(--text-tertiary);
}

[data-theme="dark"] .az-letter.current {
  background-color: var(--chat-bubble-bg);
  color: white;
}

/* Hide A-Z scrollbar on mobile - Requirement 17.3 */
@media (max-width: 768px) {
  .az-scrollbar {
    display: none;
  }
}

/* SearchFilterBar Styles - Requirements 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 8.4 */

.search-filter-bar {
  margin-bottom: 20px;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-primary, white);
  border: 2px solid var(--border-primary, #e5e7eb);
  border-radius: 8px;
  padding: 0 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  height: 44px;
}

/* Light theme explicit styling */
:root .search-input-wrapper,
[data-theme="light"] .search-input-wrapper {
  background: white;
  border-color: #e5e7eb;
}

.search-input-wrapper:focus-within {
  border-color: var(--accent-primary, #d97706);
  box-shadow: 0 0 0 3px var(--accent-glow, rgba(217, 119, 6, 0.1));
  outline: none;
}

/* Remove any browser default focus indicators */
.search-input-wrapper *:focus {
  outline: none !important;
}

.search-icon {
  font-size: 18px;
  color: var(--text-secondary, #9ca3af);
  margin-right: 8px;
  user-select: none;
}

.search-input {
  flex: 1;
  border: none !important;
  outline: none !important;
  padding: 0 8px;
  margin: 0;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary, #1f2937);
  background: transparent;
  line-height: 40px;
  height: 40px;
  box-shadow: none !important;
  caret-color: var(--text-primary, #1f2937);
  vertical-align: middle;
}

.search-input:focus {
  outline: none !important;
  box-shadow: none !important;
  border: none !important;
}

/* Dark mode caret color */
[data-theme="dark"] .search-input {
  caret-color: var(--text-primary, #f3f4f6);
}

/* Light theme explicit styling */
:root .search-input,
[data-theme="light"] .search-input {
  color: #1f2937;
}

.search-input::placeholder {
  color: var(--text-secondary, #9ca3af);
}

/* Light theme placeholder */
:root .search-input::placeholder,
[data-theme="light"] .search-input::placeholder {
  color: #9ca3af;
}

.filter-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: #f3f4f6;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  color: #6b7280;
  transition: all 0.2s ease;
  margin-left: 8px;
  flex-shrink: 0;
}

.filter-toggle-btn:hover {
  background: #e5e7eb;
  color: #374151;
  transform: scale(1.1);
}

.clear-filters-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: #f3f4f6;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  color: #6b7280;
  transition: all 0.2s ease;
  margin-left: 8px;
}

.clear-filters-btn:hover {
  background: #e5e7eb;
  color: #374151;
  transform: scale(1.1);
}

/* Filter Chips Panel */
.filter-chips-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-secondary, #f9fafb);
  border-radius: 8px;
  border: 1px solid var(--border-secondary, #e5e7eb);
}

.filter-chip-selector {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 13px;
  color: #374151;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.filter-chip-selector:hover {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #1e40af;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.1);
}

.filter-chip-icon {
  font-size: 14px;
}

.filter-chip-text {
  font-weight: 500;
}

.filter-chip-arrow {
  font-size: 10px;
  opacity: 0.6;
}

/* Filter Dropdown */
.filter-dropdown {
  position: absolute;
  max-height: 300px;
  overflow-y: auto;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  animation: fadeInDown 0.2s ease;
}

.filter-dropdown-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  color: #1f2937;
  transition: background-color 0.15s ease;
  border-bottom: 1px solid #f3f4f6;
}

.filter-dropdown-item:last-child {
  border-bottom: none;
}

.filter-dropdown-item:hover {
  background-color: #f9fafb;
  color: #1e40af;
}

.filter-dropdown-item:active {
  background-color: #f3f4f6;
}

/* Active Filters Display */
.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  display: none; /* Hidden by default, shown when filters active */
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--accent-subtle);
  border: 1px solid var(--accent-hover);
  border-radius: 16px;
  font-size: 13px;
  color: var(--accent-primary);
  font-weight: 500;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.filter-chip-label {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

.filter-chip-value {
  font-weight: 500;
}

.filter-chip-remove {
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  margin-left: 2px;
}

.filter-chip-remove:hover {
  opacity: 1;
}

/* Autocomplete Dropdown - Requirements 4.2, 4.3, 4.4 */
.search-autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 300px;
  overflow-y: auto;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  animation: fadeInDown 0.2s ease;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.search-autocomplete-item {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  border-bottom: 1px solid #f3f4f6;
}

.search-autocomplete-item:last-child {
  border-bottom: none;
}

.search-autocomplete-item:hover {
  background-color: #f9fafb;
}

.search-autocomplete-item:active {
  background-color: #f3f4f6;
}

.autocomplete-display {
  font-size: 14px;
  font-weight: 500;
  color: #1f2937;
  font-family: 'Monaco', 'Courier New', monospace;
}

.autocomplete-description {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
}

/* Dark Mode for SearchFilterBar */
[data-theme="dark"] .search-input-wrapper {
  background: #1f2937;
  border-color: #4b5563;
}

[data-theme="dark"] .search-input-wrapper:focus-within {
  border-color: var(--accent-primary, #f59e0b);
  box-shadow: 0 0 0 3px var(--accent-glow, rgba(245, 158, 11, 0.15));
}

[data-theme="dark"] .search-icon {
  color: #6b7280;
}

[data-theme="dark"] .search-input {
  color: #f3f4f6;
}

[data-theme="dark"] .search-input::placeholder {
  color: #6b7280;
}

[data-theme="dark"] .clear-filters-btn {
  background: #374151;
  color: #9ca3af;
}

[data-theme="dark"] .clear-filters-btn:hover {
  background: #4b5563;
  color: #d1d5db;
}

[data-theme="dark"] .filter-chip {
  background: var(--accent-subtle);
  border-color: var(--accent-hover);
  color: var(--accent-primary);
}

[data-theme="dark"] .search-autocomplete-list {
  background: #1f2937;
  border-color: #4b5563;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .search-autocomplete-item {
  border-bottom-color: #374151;
}

[data-theme="dark"] .search-autocomplete-item:hover {
  background-color: #374151;
}

[data-theme="dark"] .search-autocomplete-item:active {
  background-color: #4b5563;
}

[data-theme="dark"] .filter-toggle-btn {
  background: #374151;
  color: #9ca3af;
}

[data-theme="dark"] .filter-toggle-btn:hover {
  background: #4b5563;
  color: #d1d5db;
}

[data-theme="dark"] .filter-chips-panel {
  background: #111827;
  border-color: #374151;
}

[data-theme="dark"] .filter-chip-selector {
  background: #1f2937;
  border-color: #4b5563;
  color: #d1d5db;
}

[data-theme="dark"] .filter-chip-selector:hover {
  background: #1e3a8a;
  border-color: #60a5fa;
  color: #93c5fd;
}

[data-theme="dark"] .filter-dropdown {
  background: #1f2937;
  border-color: #4b5563;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .filter-dropdown-item {
  color: #d1d5db;
  border-bottom-color: #374151;
}

[data-theme="dark"] .filter-dropdown-item:hover {
  background-color: #374151;
  color: #93c5fd;
}

[data-theme="dark"] .filter-dropdown-item:active {
  background-color: #4b5563;
}

[data-theme="dark"] .autocomplete-display {
  color: #f3f4f6;
}

[data-theme="dark"] .autocomplete-description {
  color: #9ca3af;
}

/* Mobile Responsive for SearchFilterBar */
@media (max-width: 768px) {
  .search-input {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 10px 8px;
  }

  .search-input::placeholder {
    font-size: 13px;
  }

  .filter-chip {
    font-size: 12px;
    padding: 5px 8px;
  }

  .search-autocomplete-list {
    max-height: 200px;
  }

  .search-autocomplete-item {
    padding: 8px 12px;
  }

  .autocomplete-display {
    font-size: 13px;
  }

  .autocomplete-description {
    font-size: 11px;
  }
}


/* Explicit column widths for proper alignment */
.contacts-table th:nth-child(1),
.contacts-table td:nth-child(1) { width: 150px; min-width: 150px; } /* Name */
.contacts-table th:nth-child(2),
.contacts-table td:nth-child(2) { width: 130px; min-width: 130px; } /* Phone */
.contacts-table th:nth-child(3),
.contacts-table td:nth-child(3) { width: 180px; min-width: 180px; } /* Email */
.contacts-table th:nth-child(4),
.contacts-table td:nth-child(4) { width: 120px; min-width: 120px; } /* Location */
.contacts-table th:nth-child(5),
.contacts-table td:nth-child(5) { width: 140px; min-width: 140px; } /* Timezone */
.contacts-table th:nth-child(6),
.contacts-table td:nth-child(6) { width: 100px; min-width: 100px; } /* Frequency */
.contacts-table th:nth-child(7),
.contacts-table td:nth-child(7) { width: 130px; min-width: 130px; } /* Circle */
.contacts-table th:nth-child(8),
.contacts-table td:nth-child(8) { width: 150px; min-width: 150px; } /* Tags */
.contacts-table th:nth-child(9),
.contacts-table td:nth-child(9) { width: 150px; min-width: 150px; } /* Groups */
.contacts-table th:nth-child(10),
.contacts-table td:nth-child(10) { width: 100px; min-width: 100px; } /* Source */
.contacts-table th:nth-child(11),
.contacts-table td:nth-child(11) { width: 80px; min-width: 80px; } /* Actions */

/* Ensure Tags, Groups, Source, and Actions columns display properly */
.contacts-table td.contact-tags,
.contacts-table td.contact-groups {
  display: table-cell;
  vertical-align: middle;
  padding: 8px 12px;
}

.contacts-table td.contact-source {
  display: table-cell;
  vertical-align: middle;
  padding: 8px 12px;
  text-align: left;
}

.contacts-table td.contact-actions {
  display: table-cell;
  vertical-align: middle;
  padding: 8px 12px;
  text-align: center;
}

/* Empty cell placeholder styling */
.empty-cell {
  color: var(--text-disabled, #d1d5db);
  font-style: italic;
  font-size: 13px;
}

[data-theme="dark"] .empty-cell {
  color: #4b5563;
}

/* Manual source badge */
.badge-manual {
  background-color: #f3f4f6;
  color: #6b7280;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
}

[data-theme="dark"] .badge-manual {
  background-color: #374151;
  color: #9ca3af;
  border-color: #4b5563;
}
