/* ============================================================
   Sabea Broker Portal — Contacts Module
   Scoped under .ct-* to avoid clashing with existing styles.
   Reuses CSS vars from index.html + patterns from crm.css.
   ============================================================ */

.ct-header {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 24px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.ct-title {
  font-family: 'Playfair Display', serif;
  font-size: 26px; font-weight: 700;
  color: var(--navy); line-height: 1;
}
.ct-sub { font-size: 13px; color: var(--mu); margin-top: 4px; }
.ct-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.ct-filterbar {
  background: #fff; border: 1.5px solid var(--br);
  border-radius: 12px; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.ct-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); padding: 6px 12px; border-radius: 8px;
  border: 1.5px solid var(--br); min-width: 280px;
}
.ct-search svg { color: var(--mu); flex: none; }
.ct-search input {
  border: 0; outline: 0; background: transparent;
  font-family: inherit; font-size: 13px; width: 100%;
  color: var(--navy);
}

.ct-bulkbar {
  background: var(--gold-l); border: 1.5px solid var(--gold-b);
  border-radius: 10px; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
  font-size: 13px; color: var(--navy);
}

.ct-tableview {
  background: #fff; border: 1.5px solid var(--br); border-radius: 12px;
  overflow: hidden;
}
.ct-table-scroll { overflow-x: auto; }
.ct-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.ct-table thead th {
  text-align: left; font-weight: 600; color: var(--mu);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  padding: 12px 14px; border-bottom: 1.5px solid var(--br);
  background: var(--bg);
  position: sticky; top: 0;
}
.ct-table tbody tr { border-bottom: 1px solid var(--br); transition: background .12s; }
.ct-table tbody tr:hover { background: var(--bg); }
.ct-table tbody tr.is-optout { opacity: .55; background: #f5f3ec; }
.ct-table tbody td { padding: 11px 14px; vertical-align: middle; }
.ct-table .ct-name { font-weight: 600; color: var(--navy); }
.ct-empty td { text-align: center; padding: 56px; color: var(--mu); }

.ct-tag {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .02em;
  background: var(--gold-l); color: #6b5820; border: 1px solid var(--gold-b);
  margin: 1px 2px;
}
.ct-tag--source-lead   { background: #d9e3f7; color: #1F4AA8; border-color: #b3c4e8; }
.ct-tag--source-member { background: var(--navy); color: #fff; border-color: var(--navy); }
.ct-tag--source-manual { background: #eaeaea; color: #555; border-color: #d0d0d0; }
.ct-tag--source-csv    { background: #d6ead9; color: #1E7D53; border-color: #b0d4b6; }

.ct-row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.ct-row-btn {
  background: transparent; border: 0; cursor: pointer;
  color: var(--mu); padding: 4px 6px; border-radius: 4px;
  font-size: 14px;
}
.ct-row-btn:hover { background: var(--bg); color: var(--navy); }

.ct-pagination {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-top: 16px; font-size: 13px; color: var(--mu);
}

/* --- Drawer (contact detail) --- */
.ct-drawer { position: fixed; inset: 0; z-index: 80; pointer-events: none; }
.ct-drawer[aria-hidden="false"] { pointer-events: auto; }
.ct-drawer-backdrop {
  position: absolute; inset: 0; background: rgba(18,21,61,.45);
  opacity: 0; transition: opacity .2s;
}
.ct-drawer[aria-hidden="false"] .ct-drawer-backdrop { opacity: 1; }
.ct-drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 100%; max-width: 480px;
  background: var(--bg);
  box-shadow: -24px 0 60px rgba(18,21,61,.2);
  transform: translateX(100%); transition: transform .25s ease;
  display: flex; flex-direction: column;
}
.ct-drawer[aria-hidden="false"] .ct-drawer-panel { transform: translateX(0); }
.ct-drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 20px 24px 16px; background: var(--navy); color: #fff;
}
.ct-drawer-head h2 {
  font-family: 'Playfair Display', serif; font-weight: 700;
  margin: 0; font-size: 20px; line-height: 1.2;
}
.ct-drawer-head p { margin: 4px 0 0; font-size: 12px; color: rgba(255,255,255,.7); }
.ct-drawer-close {
  border: 0; background: rgba(255,255,255,.1); color: #fff;
  width: 32px; height: 32px; border-radius: 8px;
  cursor: pointer; font-size: 16px; flex: none;
}
.ct-drawer-close:hover { background: rgba(255,255,255,.2); }
.ct-drawer-body { flex: 1; overflow-y: auto; padding: 20px 24px 16px; }

.ct-field { margin-bottom: 12px; }
.ct-field label {
  display: block; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--mu); margin-bottom: 4px;
}
.ct-field input,
.ct-field textarea {
  width: 100%; font-family: inherit; font-size: 13px;
  border: 1.5px solid var(--br); border-radius: 8px;
  padding: 8px 10px; background: #fff; color: var(--navy);
}
.ct-field input:focus,
.ct-field textarea:focus {
  outline: 2px solid var(--gold-l); outline-offset: 1px; border-color: var(--gold);
}

.ct-drawer-foot {
  display: flex; gap: 8px; align-items: center;
  padding: 12px 24px; background: #fff; border-top: 1.5px solid var(--br);
}

/* --- CSV Import Modal --- */
.ct-modal { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; }
.ct-modal-backdrop { position: absolute; inset: 0; background: rgba(18,21,61,.5); }
.ct-modal-panel {
  position: relative; background: var(--bg);
  border-radius: 16px; box-shadow: 0 40px 80px rgba(18,21,61,.35);
  width: 640px; max-width: calc(100vw - 32px); max-height: calc(100vh - 32px);
  display: flex; flex-direction: column; overflow: hidden;
}
.ct-modal-head {
  padding: 18px 24px; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
}
.ct-modal-head h2 {
  font-family: 'Playfair Display', serif; font-weight: 700;
  margin: 0; font-size: 20px;
}
.ct-modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.ct-modal-foot {
  padding: 12px 24px; background: #fff; border-top: 1.5px solid var(--br);
  display: flex; gap: 8px;
}

.ct-upload {
  border: 2px dashed var(--gold-b); border-radius: 10px;
  padding: 30px; text-align: center; background: #fff;
}

.ct-mapping-row {
  display: grid; grid-template-columns: 1fr auto 1fr;
  gap: 10px; align-items: center; margin-bottom: 8px;
  padding: 8px 12px; background: #fff;
  border: 1px solid var(--br); border-radius: 8px;
}
.ct-mapping-row .col {
  font-family: monospace; font-size: 12px; color: var(--navy); font-weight: 600;
}
.ct-mapping-row .arrow { color: var(--mu); }
.ct-mapping-row select {
  font-family: inherit; font-size: 12px;
  border: 1.5px solid var(--br); border-radius: 6px;
  padding: 4px 8px; background: #fff; color: var(--navy);
}

.ct-import-summary {
  background: #fff; border: 1.5px solid var(--br);
  border-radius: 10px; padding: 16px;
}
.ct-import-summary .row {
  display: flex; justify-content: space-between;
  padding: 6px 0; font-size: 13px;
}
.ct-import-summary .row + .row { border-top: 1px solid var(--br); }
.ct-import-summary strong { color: var(--navy); }

@media (max-width: 900px) {
  .ct-search { min-width: 0; flex: 1; }
  .ct-drawer-panel { max-width: 100%; }
  .ct-modal-panel { width: calc(100vw - 16px); }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE — contacts table → card list
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  /* Convert table rows into stacked cards */
  .ct-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  .ct-search-input {
    font-size: 16px; /* prevents iOS zoom */
    flex: 1 1 100%;
  }
  .ct-filter-pills {
    flex-wrap: wrap;
  }

  /* Hide the heavy table on small screens; show a cleaner card list */
  .ct-table thead { display: none; }
  .ct-table,
  .ct-table tbody,
  .ct-table tr,
  .ct-table td {
    display: block;
    width: 100%;
  }
  .ct-table tr {
    background: #fff;
    border-radius: 10px;
    margin-bottom: 8px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    border: 1px solid #EAEAEA;
  }
  .ct-table td {
    padding: 4px 0;
    border: none;
    text-align: left !important;
  }
  /* Add labels via data-attrs (apply via JS if needed; fallback shows raw) */
  .ct-name {
    font-size: 15px; font-weight: 700; color: var(--navy);
    margin-bottom: 4px;
  }
  .ct-email, .ct-phone {
    font-size: 12.5px;
    color: var(--mu);
  }
  .ct-tags {
    margin-top: 6px;
  }
  .ct-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #F0EEE7;
  }
  .ct-actions button {
    padding: 6px 10px;
    font-size: 12px;
    flex: 1;
  }

  /* Drawer — fullscreen */
  .ct-drawer {
    width: 100vw !important;
    max-width: 100vw !important;
  }
  .ct-drawer input,
  .ct-drawer select,
  .ct-drawer textarea {
    font-size: 16px;
  }

  /* Pagination — center, single line */
  .ct-pagination {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    padding: 10px;
  }
}

/* ════════════════════════════════════════════════════════════════
   CONTACT HOUSEHOLDS — joint contacts UI
   ════════════════════════════════════════════════════════════════ */

/* Joint chip in contacts list */
.ct-joint-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.18), rgba(20, 184, 166, 0.18));
  border: 1px solid rgba(201, 168, 76, 0.5);
  color: var(--navy, #12153D);
  font-size: 10.5px;
  font-weight: 600;
  margin-left: 6px;
  vertical-align: middle;
  white-space: nowrap;
}

/* Household card content in drawer */
.ct-household-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ct-household-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--navy, #12153D);
}
.ct-household-partner {
  background: #FFFEFB;
  border: 1px solid var(--br, #E8E5DA);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}
.btn-link {
  background: transparent;
  border: none;
  color: var(--gold, #C9A84C);
  text-decoration: underline;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 0;
  font-family: inherit;
  text-align: left;
}
.btn-link:hover { color: var(--navy, #12153D); }

/* Link-partner search results */
.ct-link-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
  max-height: 240px;
  overflow-y: auto;
}
.ct-link-result {
  text-align: left;
  background: #fff;
  border: 1px solid var(--br, #E8E5DA);
  border-radius: 4px;
  padding: 8px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  transition: background .12s, border-color .12s;
}
.ct-link-result:hover {
  border-color: var(--gold, #C9A84C);
  background: rgba(201, 168, 76, 0.05);
}
.ct-link-result.is-selected {
  border-color: var(--gold, #C9A84C);
  background: rgba(201, 168, 76, 0.12);
  box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.18);
}

/* Modal foot for the household modals (consistent with existing) */
.ct-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--br, #E8E5DA);
}

/* ── Partner MyFinancials sync status (Household card) ── */
.ct-myfi-sync {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.ct-myfi-sync-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .03em;
}
.ct-myfi-sync-pill--green {
  background: #DCFCE7;
  color: #166534;
  border: 1px solid #86EFAC;
}
.ct-myfi-sync-pill--amber {
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #FCD34D;
}
.ct-myfi-sync-pill--grey {
  background: #E5E7EB;
  color: #4B5563;
  border: 1px solid #D1D5DB;
}
.ct-myfi-invite-btn {
  font-size: 11.5px !important;
  padding: 4px 10px !important;
  border-color: var(--gold, #C9A84C) !important;
  color: var(--navy, #12153D) !important;
  background: rgba(201, 168, 76, 0.08) !important;
}
.ct-myfi-invite-btn:hover:not(:disabled) {
  background: rgba(201, 168, 76, 0.18) !important;
}
.ct-myfi-invite-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* ── Private contact indicator ── */
.ct-private-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(18, 21, 61, 0.06);
  color: var(--navy, #12153D);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .03em;
  margin-left: 8px;
  vertical-align: middle;
  border: 1px solid rgba(18, 21, 61, 0.18);
}
.ct-private-badge--inline {
  margin-left: 0;
  padding: 0;
  background: transparent;
  border: none;
  font-size: 11px;
  margin-right: 2px;
}
tr.is-private .ct-name {
  font-style: italic;
}

/* ── "Save to phone" vCard button (drawer header) ── */
.ct-drawer-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.ct-drawer-vcard {
  background: rgba(201, 168, 76, 0.18);
  color: #fff;
  border: 1.5px solid var(--gold, #C9A84C);
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 11.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background .12s, transform .08s;
  white-space: nowrap;
}
.ct-drawer-vcard:hover {
  background: rgba(201, 168, 76, 0.32);
  transform: translateY(-1px);
}
.ct-drawer-vcard:active {
  transform: translateY(0);
}
@media (max-width: 560px) {
  .ct-drawer-vcard span { display: none; }   /* show emoji only on small mobile */
  .ct-drawer-vcard { padding: 5px 9px; }
}

/* ── Quick-filter chips above the contacts list ── */
.ct-quickchips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 0 12px;
}
.ct-chip {
  background: #fff;
  border: 1.5px solid var(--br, #E8E5DA);
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  color: var(--navy, #12153D);
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .08s;
  white-space: nowrap;
}
.ct-chip:hover {
  background: rgba(201, 168, 76, 0.10);
  border-color: var(--gold, #C9A84C);
}
.ct-chip.is-active {
  background: var(--navy, #12153D);
  color: #fff;
  border-color: var(--navy, #12153D);
}
