@use '../variables' as v;
@use '../mixins' as m;

// ─────────────────────────────────────────────
// Contacts list - clickable rows
// ─────────────────────────────────────────────
.contact-row {
  cursor: pointer;
  transition: background v.$transition-base;

  &:hover {
    background: var(--bg-hover) !important;
  }

  td:first-child {
    cursor: default;
  }
}

// ─────────────────────────────────────────────
// Contact Detail - outer layout
// ─────────────────────────────────────────────
.contact-detail-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
  align-items: start;

  @include m.max-lg {
    grid-template-columns: 1fr;
  }
}

// ─────────────────────────────────────────────
// Breadcrumb + nav row
// ─────────────────────────────────────────────
.cd-topbar {
  @include m.flex-between;
  margin-bottom: 16px;
}

.cd-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: v.$font-size-sm;
  color: var(--text-secondary);

  a {
    color: var(--text-secondary);
    text-decoration: none;

    &:hover {
      color: var(--text-primary);
    }
  }

  &__sep {
    color: var(--border-color);
  }

  &__current {
    color: var(--text-primary);
    font-weight: 500;
  }
}

.cd-nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

// ─────────────────────────────────────────────
// Contact Header Card
// ─────────────────────────────────────────────
.cd-header {
  @include m.card-base;
  padding: 20px 24px;
  margin-bottom: 0;
}

.cd-header-meta {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.cd-avatar {
  width: 64px;
  height: 64px;
  border-radius: v.$radius-full;
  background: var(--bg-hover-strong);
  border: 2px solid var(--border-color);
  @include m.flex-center;
  flex-shrink: 0;
  color: var(--text-muted);

  svg {
    width: 34px;
    height: 34px;
  }
}

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

.cd-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.cd-name {
  font-size: v.$font-size-lg;
  font-weight: 700;
  color: var(--text-primary);
}

.cd-badge-type {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 10px;
  border-radius: v.$radius-full;
  font-size: v.$font-size-xs;
  font-weight: 500;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background v.$transition-base;

  svg {
    width: 11px;
    height: 11px;
  }

  &:hover {
    background: var(--bg-hover);
  }
}

.cd-badge-status {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 10px;
  border-radius: v.$radius-full;
  font-size: v.$font-size-xs;
  font-weight: 500;
  background: var(--success-light);
  border: 1px solid var(--success-border);
  color: var(--success);
  cursor: pointer;
  transition: background v.$transition-base;

  svg {
    width: 11px;
    height: 11px;
  }

  &:hover {
    background: var(--success-light);
  }
}

.cd-email-line {
  font-size: v.$font-size-sm;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.cd-added-line {
  font-size: v.$font-size-xs;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.cd-action-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cd-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border: 1px solid var(--border-color);
  border-radius: v.$radius;
  background: var(--bg-surface);
  font-size: v.$font-size-xs;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background v.$transition-base;

  svg {
    width: 14px;
    height: 14px;
  }

  &:hover {
    background: var(--bg-hover);
  }
}

// Lists & Tags chips area
.cd-lt-area {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border-color);
  margin-top: 16px;
  padding-top: 16px;
}

.cd-lt-section {
  flex: 1;
  min-width: 160px;
}

.cd-lt-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: v.$font-size-xs;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.cd-lt-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 1px solid var(--border-color);
  border-radius: v.$radius-sm;
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  transition: background v.$transition-base;

  &:hover {
    background: var(--bg-hover-strong);
  }
}

.cd-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.cd-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--bg-hover-strong);
  border-radius: v.$radius-sm;
  font-size: v.$font-size-xs;
  color: var(--text-secondary);
}

.cd-chip-remove {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  margin-left: 2px;

  &:hover {
    color: var(--text-primary);
  }
}

// ─────────────────────────────────────────────
// Tabs
// ─────────────────────────────────────────────
.cd-tabs {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-bottom: none;
  border-radius: v.$radius-md v.$radius-md 0 0;
  padding: 0 20px;
  overflow-x: auto;
  margin-top: 16px;
  @include m.scrollbar-thin;
}

.cd-tab {
  padding: 12px 16px;
  font-size: v.$font-size-sm;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  text-decoration: none;
  transition: color v.$transition-base, border-color v.$transition-base;

  &:hover {
    color: var(--text-primary);
  }

  &.is-active {
    color: var(--info);
    border-bottom-color: var(--info);
  }
}

// ─────────────────────────────────────────────
// Tab panels
// ─────────────────────────────────────────────
.cd-tab-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 v.$radius-md v.$radius-md;
  padding: 24px;
}

// ─────────────────────────────────────────────
// Overview tab - form layout
// ─────────────────────────────────────────────
.cd-overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;

  @include m.max-md {
    grid-template-columns: 1fr;
    gap: 24px;
  }
}

.cd-section-title {
  font-size: v.$font-size-base;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.cd-form-group {
  margin-bottom: 14px;

  &:last-of-type {
    margin-bottom: 0;
  }
}

.cd-dob-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.cd-prefix-row {
  display: grid;
  grid-template-columns: 110px 1fr 1fr;
  gap: 12px;

  @include m.max-sm {
    grid-template-columns: 1fr;
  }
}

.cd-addr-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;

  @include m.max-sm {
    grid-template-columns: 1fr;
  }
}

.cd-custom-fields-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  border-radius: v.$radius;
  font-size: v.$font-size-xs;
  color: var(--text-secondary);
  background: var(--bg-surface);
  cursor: pointer;
  margin-top: 16px;
  transition: background v.$transition-base;

  &:hover {
    background: var(--bg-hover);
  }
}

.cd-update-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

// ─────────────────────────────────────────────
// Emails tab
// ─────────────────────────────────────────────
.cd-email-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);

  &:last-child {
    border-bottom: none;
  }
}

// ─────────────────────────────────────────────
// Form Submissions tab
// ─────────────────────────────────────────────
.cd-form-sub-item {
  @include m.flex-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: v.$font-size-sm;

  &:last-child {
    border-bottom: none;
  }
}

// ─────────────────────────────────────────────
// Notes & Activities tab
// ─────────────────────────────────────────────
.cd-note-card {
  background: var(--warning-light);
  border: 1px solid var(--warning-border);
  border-radius: v.$radius;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: v.$font-size-sm;
  color: var(--text-primary);
}

.cd-note-meta {
  font-size: v.$font-size-xs;
  color: var(--text-muted);
  margin-top: 6px;
}

.cd-activity-list {
  margin-top: 20px;
}

.cd-activity-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);

  &:last-child {
    border-bottom: none;
  }
}

.cd-activity-dot {
  width: 8px;
  height: 8px;
  border-radius: v.$radius-full;
  background: var(--info);
  margin-top: 5px;
  flex-shrink: 0;

  &--green {
    background: var(--success);
  }
}

// ─────────────────────────────────────────────
// Empty state (used in multiple tabs)
// ─────────────────────────────────────────────
.cd-empty {
  text-align: center;
  padding: 40px 0;
  color: var(--text-muted);
  font-size: v.$font-size-sm;

  svg {
    width: 36px;
    height: 36px;
    margin: 0 auto 10px;
    color: var(--border-color);
    display: block;
  }
}

// ─────────────────────────────────────────────
// Aside panel
// ─────────────────────────────────────────────
.cd-aside {
  @include m.card-base;
  padding: 20px;
  position: sticky;
  top: calc(v.$topbar-height + 20px);
}

.cd-aside-title {
  font-size: v.$font-size-sm;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.cd-aside-empty {
  font-size: v.$font-size-xs;
  color: var(--text-muted);
  text-align: center;
  padding: 16px 0;
  line-height: 1.7;
}

// ─────────────────────────────────────────────
// Import wizard (unchanged)
// ─────────────────────────────────────────────
.import-wizard {
  max-width: 780px;
}

.column-mapping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: v.$font-size-sm;

  th {
    padding: 10px 14px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-color);
    font-size: v.$font-size-xs;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
  }

  tbody tr:last-child td {
    border-bottom: none;
  }
}

// ─────────────────────────────────────────────
// Responsive Table & Card View for Contacts List
// ─────────────────────────────────────────────
@media (max-width: 1024px) {
  .data-table thead {
    display: none;
  }
  .data-table tbody tr {
    display: block;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
    position: relative;
  }
  .data-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: none;
    padding: 8px 0;
    font-size: 13px;
    text-align: right;
  }
  .data-table tbody td.cell-checkbox {
    position: absolute;
    top: 16px;
    left: 16px;
    padding: 0;
    z-index: 2;
  }
  .data-table tbody td.cell-avatar {
    position: absolute;
    top: 16px;
    left: 48px;
    padding: 0;
    z-index: 2;
  }
  .data-table tbody td.cell-email {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    text-align: left;
    padding-left: 88px;
    padding-right: 75px;
    font-weight: 600;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
    min-height: 38px;
    word-break: break-all;
    overflow-wrap: anywhere;

    &[data-label]::before {
      font-size: 9px;
      padding: 2px 5px;
      border-radius: 4px;
      background: var(--bg-hover);
      color: var(--text-muted);
      letter-spacing: 0.06em;
      flex-shrink: 0;
    }
  }
  .data-table tbody td.cell-actions {
    position: absolute;
    top: 10px;
    right: 12px;
    padding: 0;
    z-index: 2;
  }
  .data-table tbody td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.05em;
    margin-right: 8px;
  }
}

@media (max-width: 640px) {
  .cd-header-meta {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .cd-name-row {
    justify-content: center;
  }
  .cd-email-line, .cd-added-line {
    text-align: center;
  }
}