/* Contacts page — the full page stylesheet for contacts.html and sales-pipeline-contacts.html
 * (ISH-831).
 *
 * Moved verbatim out of contacts.html's inline <style> when ISH-831 gave the Sales Pipeline its
 * own Contacts page. The two pages are the same page with a different default scope, so the
 * alternative was a second copy of ~690 lines that would drift — the reason css/portal-rail.css,
 * css/stage-colors.css and css/more-dropdown.css all exist.
 *
 * ⚠️ Unlike those, this is a *page* stylesheet, not a component: it carries this page's chrome
 * (.top-nav, .page, .toolbar) alongside the contact-card rules. That is deliberate — the two hosts
 * are the same page — but it means this file must not be linked by anything else. A third page
 * linking it would inherit a whole page's layout, not a component.
 *
 * Neither host may re-declare these rules inline. A page linking this file *and* declaring
 * `.contact-card` locally is exactly how the pre-ISH-353 stage palette drifted.
 *
 * Depends on css/tokens.css for --red, --page-bg, --card-bg, --text-secondary, and on each host's
 * own :root for --text, --border, --border-light, --text-label, --radius.
 */

:root {
  --info-bg: #f4f4f4;
  --border: #e0e0e0;
  --border-light: #ebebeb;
  --text: #1a1a1a;
  --text-label: #999999;
  --green: #28a745;
  --radius: 6px;
  --radius-lg: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: Inter, system-ui, sans-serif;
  background: var(--page-bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Top navigation */
.top-nav {
  background: var(--nav-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 1.75rem;
}

.logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  height: 36px;
}

.logo img {
  height: 36px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  display: block;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-links a {
  color: #ffffff;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.nav-links a:hover:not(.active) {
  background: rgba(255, 255, 255, 0.08);
}

.nav-links a.active {
  background: var(--red);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.scroll-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  grid-column: 1 / -1;
  width: 100%;
}

.scroll-loader .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.scroll-end-message {
  text-align: center;
  padding: 2rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  grid-column: 1 / -1;
  width: 100%;
}

/* Page shell */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
  animation: fadeIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

/* Search & toolbar */
.toolbar {
  margin-bottom: 1.5rem;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.search-wrap {
  flex: 1;
  position: relative;
}

.search-wrap svg.search-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-label);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  padding: 0.65rem 2.5rem 0.65rem 2.5rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
}

.search-wrap input::placeholder {
  color: var(--text-label);
}

.search-wrap input:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(166, 38, 38, 0.12);
}

/* Possible-duplicates toggle (ISH-578) */
.dupe-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  /* 44px, matching the search input beside it — that input has no explicit height, it
     is 0.65rem of padding each side plus a 0.9rem line, and measures 44. A 40px
     button next to it sits 2px short top and bottom on the .search-row's
     align-items: center. Measured on the mock, not guessed. */
  height: 44px;
  padding: 0 0.85rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.dupe-toggle:hover {
  border-color: var(--red);
  color: var(--text);
}

/* The pressed state has to be unmistakable: this toggle changes what the whole
   page is showing, and a user who cannot tell it is on reads the grouped view as
   the contact list having lost most of its rows. */
.dupe-toggle[aria-pressed="true"] {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.dupe-toggle-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: rgba(166, 38, 38, 0.12);
  color: var(--red);
  font-size: 0.7rem;
  font-weight: 700;
}

.dupe-toggle[aria-pressed="true"] .dupe-toggle-count {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

/* Duplicate groups (ISH-578) */

/* In grouped mode the container stops being the card grid and becomes a column of
   group blocks, each holding its own grid. */
.contacts-grid.is-grouped {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.dupe-group {
  border: 1px solid var(--border);
  border-left: 3px solid var(--red);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem 1.25rem;
  background: rgba(166, 38, 38, 0.02);
}

.dupe-group-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.875rem;
}

.dupe-group-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.dupe-group-signal {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--red);
}

.dupe-group-value {
  font-size: 0.75rem;
  color: var(--text-secondary);
  word-break: break-all;
}

.dupe-note {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin: 0 0 1.25rem;
  line-height: 1.5;
}

/* Contacts Grid */
.contacts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

@media (max-width: 640px) {
  .contacts-grid {
    grid-template-columns: 1fr;
  }
}

.contact-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.contact-card:hover {
  border-color: #ccc;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.contact-header {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.contact-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

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

.contact-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-role {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 0.1rem;
}

.contact-details {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.875rem;
  flex: 1;
}

.contact-detail-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
}

.contact-detail-item svg {
  color: var(--text-label);
  flex-shrink: 0;
}

.contact-detail-item a {
  color: var(--red);
  text-decoration: none;
  font-weight: 500;
  word-break: break-all;
}

.contact-detail-item a:hover {
  text-decoration: underline;
}

.contact-detail-item span {
  font-weight: 500;
}

.contact-relations {
  border-top: 1px solid var(--border-light);
  padding-top: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

.relation-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.relation-label {
  color: var(--text-label);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.relation-value {
  font-weight: 500;
  color: var(--text);
  text-align: right;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.broker-badge {
  display: inline-flex;
  align-items: center;
  background: rgba(166, 38, 38, 0.08);
  color: var(--red);
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  text-decoration: none;
  transition: background 0.15s;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.broker-badge:hover {
  background: rgba(166, 38, 38, 0.15);
}

/* Statuses */
.status-banner {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.status-banner.error {
  color: var(--red);
}

.empty-state {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-secondary);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  grid-column: 1 / -1;
}

/* Premium Button Styles */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: #fff;
  background: var(--red);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn-primary:hover {
  background: var(--red-hover);
  border-color: var(--red-hover);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-secondary:hover {
  border-color: #ccc;
  background: var(--page-bg);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Modal Overlay & Transitions */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #ffffff;
  border-radius: 12px;
  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: 440px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.75rem;
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.is-visible .modal-card {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.modal-body {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 1.75rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.modal-footer button {
  min-width: 95px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Actions 3-Dots Dropdown menu */
.contacts-actions-dropdown-container {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 10;
}

.contacts-actions-btn {
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  width: 28px;
  height: 28px;
}

.contacts-actions-btn:hover {
  background: var(--border-light);
}

/* Input focus styles */
.edit-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  font-family: inherit;
}

.edit-input:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(166, 38, 38, 0.12);
}

/* Card avatar badge override */
.contact-card {
  position: relative;
}

/* Autocomplete item style */
.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background-color 0.15s ease;
}

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