/**
 * GroupsTable Styles - Stone & Clay Theme
 * 
 * Warm, cozy design with earth tones
 * Requirements: 8.1, 8.2, 8.3
 * 
 * Design Principles:
 * - Warm stone and clay color palette
 * - Ample whitespace for readability
 * - Subtle borders for visual separation
 * - Clear typography hierarchy
 * - Consistent spacing and alignment
 */

/* Add Group Button */
.groups-table-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 16px;
}

.btn-add-group {
  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-group:hover {
  background: var(--chat-bubble-hover);
  box-shadow: 0 2px 6px rgba(139, 111, 92, 0.4);
  transform: translateY(-1px);
}

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

/* Table Wrapper */
.groups-table-wrapper {
  width: 100%;
  overflow-x: auto;
  background: var(--bg-surface);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-subtle);
}

.groups-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.6;
  letter-spacing: 0.01em;
}

/* Table Header */
.groups-table thead {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
}

.groups-table th {
  padding: 14px 20px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

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

/* Sort Indicators */
.sort-indicator {
  display: inline-block;
  margin-left: 4px;
  font-size: 10px;
  color: var(--text-tertiary);
  transition: color 0.2s ease;
}

.sort-indicator.sort-asc,
.sort-indicator.sort-desc {
  color: var(--accent-primary);
  font-weight: bold;
}

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

/* Row Hover Effect */
.groups-table tbody tr.group-row:hover {
  background-color: var(--bg-hover);
  box-shadow: inset 0 0 0 1px var(--border-subtle);
}

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

.groups-table td {
  padding: 12px 20px;
  color: var(--text-primary);
  vertical-align: middle;
}

/* Group Name Column */
.groups-table td.group-name {
  font-weight: 500;
  color: var(--text-primary);
  max-width: 250px;
}

/* Group Description Column */
.groups-table td.group-description {
  color: var(--text-secondary);
  font-size: 13px;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Contact Count Column */
.groups-table td.group-contact-count {
  text-align: center;
  width: 150px;
}

.expand-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 13px;
  border-radius: 18px;
  background: #fef3c7;
  color: #92400e;
  font-weight: 500;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(146, 64, 14, 0.1);
}

.expand-toggle:hover {
  background: #fde68a;
  transform: scale(1.05);
}

.expand-icon {
  font-size: 10px;
  transition: transform 0.2s ease;
}

.count-badge {
  display: inline-block;
  padding: 3px 9px;
  background: var(--accent-primary);
  color: var(--text-inverse);
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(217, 119, 6, 0.2);
  transition: all 0.2s ease;
}

/* Member Rows */
.groups-table tbody tr.member-row {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
}

.groups-table tbody tr.member-row:hover {
  background-color: var(--bg-hover);
}

.groups-table tbody tr.member-row td {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.member-icon {
  margin-right: 6px;
  opacity: 0.6;
}

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

.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: 20px;
  transition: all 0.2s ease;
  opacity: 0.7;
  color: var(--status-error);
  font-weight: 300;
  line-height: 1;
}

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

/* Empty State */
.groups-table .empty-state td {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 15px;
}

/* Editable Cells */
.groups-table td.editable {
  cursor: pointer;
  position: relative;
}

.groups-table td.editable:hover:not(.editing) {
  background-color: var(--bg-hover);
  outline: 1px solid var(--border-subtle);
}

.groups-table td.editing {
  padding: 4px;
  background-color: var(--bg-surface);
  outline: 2px solid var(--accent-primary);
  outline-offset: -2px;
}

/* New Group Row */
.new-group-row {
  background-color: var(--accent-subtle);
  border: 2px solid var(--accent-primary);
  animation: slideInFromTop 0.3s ease;
}

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

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

.new-group-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-surface);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.new-group-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.new-group-input.error {
  border-color: var(--status-error);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.new-group-input::placeholder {
  color: var(--text-tertiary);
}

/* Save and Cancel buttons for new group */
.btn-save-new,
.btn-cancel-new {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 20px;
  padding: 6px 10px;
  border-radius: 4px;
  transition: all 0.2s ease;
  opacity: 0.8;
}

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

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

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

/* Dark Mode Support (Espresso) */
[data-theme="dark"] {
  .expand-toggle {
    background: rgba(245, 158, 11, 0.15);
    color: #DFA895;
  }

  .expand-toggle:hover {
    background: rgba(245, 158, 11, 0.25);
  }

  .btn-delete:hover {
    background-color: #7f1d1d;
  }
}

/* Add Contact Button in Member Rows */
.member-row.add-contact-row {
  background-color: transparent !important;
  border-bottom: none !important;
}

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

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

.member-row .btn-add-contact:active {
  transform: translateY(0);
}

/* Remove Contact Button */
.btn-remove-contact {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
  opacity: 0.5;
  color: var(--status-error);
}

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

/* Contact Search Modal */
.contact-search-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(28, 25, 23, 0.4);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-surface);
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 24px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
  opacity: 0.6;
  color: var(--text-secondary);
}

.modal-close:hover {
  background-color: var(--bg-hover);
  opacity: 1;
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.contact-search-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-app);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  margin-bottom: 16px;
}

.contact-search-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.contact-search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.contact-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.contact-result-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-default);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

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

.contact-result-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 4px;
}

.contact-result-details {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-select-contact {
  padding: 6px 16px;
  background: var(--text-primary);
  color: var(--bg-surface);
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-select-contact:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.no-results {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
  font-size: 14px;
}

/* Dark Mode Support for Modal - Espresso theme uses CSS variables */
[data-theme="dark"] {
  .btn-remove-contact:hover {
    background-color: #7f1d1d;
  }
}

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

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

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

  .groups-table tbody tr.group-row {
    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);
  }

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

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

  /* Add labels before each field */
  .groups-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;
  }

  /* Group name - larger and prominent */
  .groups-table td.group-name {
    font-size: 18px;
    font-weight: 600;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: 12px;
    max-width: none;
  }

  .groups-table td.group-name::before {
    display: none;
  }

  /* Description shows in mobile */
  .groups-table td.group-description {
    display: block;
    max-width: none;
    white-space: normal;
  }

  /* Contact count */
  .groups-table td.group-contact-count {
    text-align: left;
  }

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

  .groups-table td.group-actions::before {
    display: none;
  }

  /* Member rows in mobile */
  .groups-table tbody tr.member-row {
    background: var(--bg-tertiary);
    border: none;
    border-radius: 8px;
    margin-bottom: 8px;
    padding: 12px;
    margin-left: 16px;
    margin-right: 0;
  }

  .groups-table tbody tr.member-row td {
    padding: 4px 0;
  }

  .groups-table tbody tr.member-row td::before {
    display: none;
  }

  .btn-add-group {
    width: 100%;
    justify-content: center;
  }

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

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

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

  .new-group-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-group-row td.group-actions::before {
    display: none;
  }

  /* Modal adjustments for mobile */
  .modal-content {
    width: 95%;
    max-height: 90vh;
    margin: 0 10px;
  }

  .modal-header {
    padding: 16px;
  }

  .modal-header h3 {
    font-size: 16px;
  }

  .modal-body {
    padding: 16px;
  }

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

  .contact-result-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .btn-select-contact {
    width: 100%;
  }

  /* Add/Remove buttons in mobile */
  .member-row .btn-add-contact {
    width: 100%;
    justify-content: center;
  }

  .btn-remove-contact {
    font-size: 18px;
    padding: 6px 10px;
  }
}
