/* ========================================================
   Phase K.D — Properties surface
   List view (/properties), detail view (/properties/:id),
   add-by-MLS modal.
   Uses existing design tokens from styles.css.
   ======================================================== */

/* ── Toolbar ─────────────────────────────────────────────── */

.properties-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}
.properties-toolbar .messages-search-wrap {
  flex: 1 1 280px;
  min-width: 220px;
}
.properties-toolbar .messages-filter-chips {
  flex: 1 1 auto;
  flex-wrap: wrap;
}

/* UI/UX overhaul — colored dot on the admin 4-color status filter chips.
   Mirrors the row color-bar palette (colorFor → property-color-*). */
.chip-dot {
  display: inline-block;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  margin-right: 0.375rem;
  vertical-align: -1px;
  border: 1px solid rgba(0, 0, 0, 0.2);
}
.chip-dot-green  { background: var(--st-green2); }
.chip-dot-yellow { background: var(--st-amber); }
.chip-dot-red    { background: var(--st-coral); }
.chip-dot-white  { background: #e5e7eb; }
.properties-sort-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.properties-sort-wrap select {
  background: var(--bg-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  font-size: 0.875rem;
}

/* ── RAP-141 — search typeahead dropdown ─────────────────── */

/* .card sets overflow:hidden, which would clip the dropdown to the
   toolbar's own bottom edge — it would look like the menu renders one row
   tall. A dedicated class rather than loosening .filter-bar-card, which
   the Leads list also uses and which has no reason to change. The toolbar
   holds nothing else that needs clipping. */
.properties-filter-card { overflow: visible; }

/* Anchored to .messages-search-wrap, which is already position:relative
   (styles.css). Used by BOTH property search boxes — the list toolbar and
   the RAP-130 nav row — so it must not assume either one's surroundings. */
.typeahead-menu {
  position: absolute;
  z-index: 40;                 /* above the list card, below any modal */
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  overflow-y: auto;
  /* Bounded so the menu can never grow past the fold and strand its own
     last row. `contain` stops a flick inside the menu from scrolling the
     page behind it once the list hits its end. */
  max-height: min(50vh, 22rem);
  overscroll-behavior: contain;
}
.typeahead-menu[hidden] { display: none; }

.typeahead-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.typeahead-row:last-child { border-bottom: 0; }
.typeahead-row:hover,
.typeahead-row.is-active {
  background: var(--bg-3, rgba(255, 255, 255, 0.06));
}

/* Same colour vocabulary as a list row's bar, so a suggestion reads as
   the same object seen in a smaller frame. */
.typeahead-color {
  flex: 0 0 auto;
  width: 4px;
  align-self: stretch;
  min-height: 1.75rem;
  border-radius: 2px;
  background: var(--text-muted);
}
.typeahead-color-green  { background: var(--st-green2); }
.typeahead-color-yellow { background: var(--st-amber); }
.typeahead-color-red    { background: var(--st-coral); }
.typeahead-color-gray   { background: #e5e7eb; }

.typeahead-main {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;                /* lets the ellipsis below actually apply */
  flex: 1 1 auto;
}
.typeahead-address {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.typeahead-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.typeahead-row .badge { flex: 0 0 auto; }

.typeahead-empty { padding: 0.75rem; }

@media (max-width: 720px) {
  /* Thumb-sized rows, and a shorter menu so it clears the on-screen
     keyboard instead of hiding behind it. Both search boxes sit near the
     top of their page, so the visible band above the keyboard is where
     this lands. */
  .typeahead-row {
    min-height: 2.75rem;
    padding: 0.75rem;
  }
  .typeahead-menu { max-height: min(42vh, 18rem); }
}

/* ── List card ───────────────────────────────────────────── */

.properties-list-card { padding: 0; overflow: hidden; }
.properties-list-card .properties-result-count {
  padding: 0.75rem 1.25rem 0;
}
.properties-list-card .empty-state,
.properties-list-card .loading,
.properties-list-card .alert {
  margin: 1rem 1.25rem;
}
.properties-list-card #properties-list-body { padding-bottom: 0.5rem; }

.properties-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* RAP-135 — paging footer: infinite-scroll status + the explicit
   Load-more backstop. Centred and generously padded so it reads as the
   end of the list rather than another row, and so the button clears the
   44px thumb target on a phone. */
.properties-list-more {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem;
  text-align: center;
}
.properties-list-more:empty { padding: 0; }
.properties-list-more p { margin: 0; }
.properties-list-more button {
  min-height: 2.5rem;
  padding-inline: 1rem;
}

.properties-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1.25rem 0.875rem 1.5rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 120ms ease;
}
.properties-row:last-child { border-bottom: none; }
.properties-row:hover { background: var(--bg-2); }

.property-color-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--st-gray);
}
.property-color-red    .property-color-bar { background: var(--st-coral); }
.property-color-yellow .property-color-bar { background: var(--st-amber); }
.property-color-green  .property-color-bar { background: var(--st-green2); }
.property-color-gray   .property-color-bar { background: var(--st-gray); }

.property-row-main {
  flex: 1 1 auto;
  min-width: 0;
}
.property-row-headline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.property-address {
  color: var(--text-primary);
  font-weight: 500;
  font-size: 0.95rem;
}
.property-row-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.property-row-secondary .property-sep { opacity: 0.5; }
.property-mls {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}
.property-no-mls { font-style: italic; opacity: 0.7; }

.property-lock {
  font-size: 0.95rem;
  line-height: 1;
}
.property-lock.no-info { opacity: 0.85; }

.property-row-action { flex: 0 0 auto; }

.properties-row.is-highlight {
  animation: prop-highlight 2.5s ease-out;
}
@keyframes prop-highlight {
  0%   { background: var(--accent-soft); }
  100% { background: transparent; }
}

/* ── Status pill colors (mapped onto existing badge palette) ── */

.badge.property-status-available { background: rgba(245,158,11,.12); color: #fcd34d; border-color: rgba(245,158,11,.25); }
.badge.property-status-pending   { background: rgba(251,146,60,.14); color: #fdba74; border-color: rgba(251,146,60,.28); }
.badge.property-status-taken     { background: rgba(248,113,113,.14); color: #fca5a5; border-color: rgba(248,113,113,.28); }
.badge.property-status-withdrawn { background: rgba(248,113,113,.14); color: #fca5a5; border-color: rgba(248,113,113,.28); }
.badge.property-status-unknown   { background: rgba(107,114,128,.14); color: #d1d5db; border-color: rgba(107,114,128,.3); }

[data-theme="light"] .badge.property-status-available { color: #b45309; background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.3); }
[data-theme="light"] .badge.property-status-pending   { color: #b45309; background: rgba(251, 146, 60, 0.12); border-color: rgba(251, 146, 60, 0.32); }
[data-theme="light"] .badge.property-status-taken,
[data-theme="light"] .badge.property-status-withdrawn { color: #b91c1c; background: rgba(220, 38, 38, 0.08); border-color: rgba(220, 38, 38, 0.28); }

/* Dot indicator for the row's color-bar status (used in detail headlines too) */

.badge {
  display: inline-flex;
  align-items: center;
}

/* ── Detail page ─────────────────────────────────────────── */

.property-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: start;
}
.property-header h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.25;
  color: var(--text-primary);
}
.property-header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.property-header-meta code {
  font-size: 0.8rem;
}
.property-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}
.property-header-status {
  grid-column: 1 / -1;
  margin-top: 0.5rem;
}
.property-header-status.success {
  background: rgba(16,185,129,.12);
  border: 1px solid rgba(16,185,129,.32);
  color: var(--success);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.875rem;
}

.property-listing-agent .kv-grid + .property-reached-out {
  margin-top: 1rem;
}
.property-reached-out {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
  display: grid;
  gap: 0.4rem;
}
.property-reached-out-headline { color: var(--text-primary); }
.property-reached-out a { display: inline-block; margin-top: 0.25rem; }

.property-agent-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
}
.property-agent-actions .primary { width: auto; padding: 0.6rem 1rem; }

.property-block { margin-top: 1rem; }
.property-block h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}
.property-block-text {
  color: var(--text-secondary);
  white-space: pre-wrap;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.875rem;
  font-size: 0.875rem;
}
.property-lockbox-line code {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.property-access-input {
  width: 100%;
  background: var(--bg-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.65rem;
  font: inherit;
  font-size: 0.875rem;
}
.property-access-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-1);
}
.property-access-input::placeholder {
  color: var(--text-muted);
  font-style: italic;
}
textarea.property-access-input {
  resize: vertical;
  min-height: 2.4rem;
}

/* ── Interests table ─────────────────────────────────────── */

.property-interests .card-header { padding-bottom: 0.5rem; }
.property-interests-table th,
.property-interests-table td { padding: 0.55rem 0.75rem; }

.property-link-picker {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: grid;
  gap: 0.5rem;
}
.property-link-results { min-height: 1.5rem; }
.property-link-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.25rem;
}
.property-link-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  text-align: left;
  color: var(--text-primary);
}
.property-link-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.property-link-picker-actions {
  display: flex;
  justify-content: flex-end;
}

.property-notes textarea {
  width: 100%;
  min-height: 80px;
  background: var(--bg-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}
.property-notes textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.property-notes .field-hint { margin-top: 0.25rem; }

/* ── Add Property modal — pending state spinner ─────────── */

.add-prop-pending {
  display: grid;
  gap: 0.75rem;
  justify-items: center;
  text-align: center;
  padding: 0.5rem 0;
}
.add-prop-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: prop-spin 0.9s linear infinite;
}
@keyframes prop-spin {
  to { transform: rotate(360deg); }
}

.field-hint.is-error { color: var(--danger); }

/* ── Toast ───────────────────────────────────────────────── */

.properties-toast-host {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  display: grid;
  gap: 0.5rem;
  z-index: 200;
  pointer-events: none;
}
.properties-toast {
  pointer-events: auto;
  background: var(--bg-3);
  color: var(--text-primary);
  border: 1px solid var(--success);
  box-shadow: var(--shadow-md);
  padding: 0.65rem 0.875rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  animation: prop-toast-in 200ms ease-out;
}
.properties-toast.is-leaving {
  animation: prop-toast-out 350ms ease-in forwards;
}
@keyframes prop-toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}
@keyframes prop-toast-out {
  to { transform: translateY(8px); opacity: 0; }
}

/* ── RAP-130 — property detail section nav ───────────────── */

/* "← Back to properties · ‹ Prev | Next › ⋯ [search]".
   Links left, search right; on a phone the search drops to its own
   full-width line (see the media query below). */
.property-nav-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}
.property-nav-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8125rem;
}
.property-nav-links .nav-back { font-weight: 500; }
.property-nav-links .nav-pn { color: var(--text-secondary); }
.property-nav-links .nav-pn:hover { color: var(--text-primary); }
.property-nav-links .nav-sep { color: var(--text-muted); user-select: none; }

/* Ends of the list: still shown, visibly inert. Not hidden — the row
   would reflow mid-walk and the user would lose track of where the
   controls are. */
.property-nav-links .nav-pn.is-disabled {
  color: var(--text-muted);
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}
.property-nav-links .nav-position { margin-left: 0.25rem; }

.property-nav-search {
  flex: 0 1 300px;
  min-width: 200px;
}

@media (max-width: 720px) {
  .property-nav-row {
    /* Links on one line, search full-width beneath — the same stacking
       the list's own toolbar uses at this width. */
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .property-nav-search {
    flex: 1 1 auto;
    width: 100%;
  }
  /* Comfortable thumb targets for the control he taps most. */
  .property-nav-links .nav-pn,
  .property-nav-links .nav-back {
    padding: 0.25rem 0;
    display: inline-block;
  }
}

/* ── Mobile ─────────────────────────────────────────────── */

@media (max-width: 720px) {
  .property-header {
    grid-template-columns: 1fr;
  }
  .property-header-actions {
    justify-content: flex-start;
  }
  .properties-toolbar {
    gap: 0.5rem;
  }
  .properties-row {
    padding: 0.75rem 1rem 0.75rem 1.25rem;
  }
  .property-row-action { display: none; }
}

/* ── PHASE K.F admin-side interests table ─────────────── */

.link-btn {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.small { font-size: 0.8125rem; }
.link-btn.is-danger { color: var(--danger); }

.lpi-decision-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border-strong);
}
.lpi-decision-pending      { color: var(--text-secondary); }
.lpi-decision-locked       { color: #10b981; border-color: rgba(16, 185, 129, 0.5); background: rgba(16, 185, 129, 0.08); }
.lpi-decision-declined     { color: #ef4444; border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.08); }

.audit-log-viewer {
  margin: 0.5rem 0 0;
}
.audit-log-body {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-1);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
}
.audit-log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}
.audit-log-entry { font-size: 0.875rem; }
.audit-log-row {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  flex-wrap: wrap;
}
.audit-log-action { font-weight: 600; }
.audit-log-note {
  margin-top: 0.125rem;
  white-space: pre-wrap;
}
.audit-log-transition { font-family: monospace; }
