/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: none;
  border-radius: var(--radius-pill);
  padding: 10px 20px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  box-shadow: var(--shadow-sm);
}

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

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
}

.btn-secondary:hover {
  background: var(--color-surface-alt);
}

.btn-secondary.active {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}

.btn-ghost:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.btn-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger);
  color: #fff;
}

.btn-sm {
  padding: 6px 14px;
  font-size: var(--font-size-xs);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
}

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

/* Form controls */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.field label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field .hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
}

input,
select,
textarea {
  font-family: inherit;
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--color-primary);
}

textarea {
  resize: vertical;
  min-height: 72px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
}

/* Pill search bar (mockup reference) */
.search-pill {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 6px 6px 6px 18px;
  box-shadow: var(--shadow-sm);
  flex: 1;
}

.search-pill input {
  border: none;
  padding: 6px 0;
  flex: 1;
}

.search-pill input:focus {
  border: none;
  outline: none;
}

.search-pill .search-icon {
  color: var(--color-text-faint);
  flex-shrink: 0;
}

.search-pill button {
  background: var(--color-accent-green);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

/* Pill tab/category selector */
.pill-tabs {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.pill-tab {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
}

.pill-tab.active {
  background: var(--color-accent-green-dark);
  color: #fff;
  border-color: var(--color-accent-green-dark);
}

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #fff;
  white-space: nowrap;
}

.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.status-badge[data-status="pending_approval"] { background: var(--color-status-pending-approval); }
.status-badge[data-status="for_sale"] { background: var(--color-status-for-sale); }
.status-badge[data-status="off_market_active"] { background: var(--color-status-off-market-active); }
.status-badge[data-status="hold"] { background: var(--color-status-hold); }
.status-badge[data-status="off_market_inactive"] { background: var(--color-status-off-market-inactive); }
.status-badge[data-status="refresh"] { background: var(--color-status-refresh); }
.status-badge[data-status="sold_by_else"] { background: var(--color-status-sold-by-else); }
.status-badge[data-status="sold_by_us"] { background: var(--color-status-sold-by-us); }
.status-badge[data-status="rented"] { background: var(--color-status-rented); }
.status-badge[data-status="for_rent"] { background: var(--color-status-for-rent); }

/* Cards */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

/* Key facts grid — shared by the unit detail page and the Quick View modal */
.facts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-4);
  margin: var(--space-6) 0;
}

.fact-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.fact-card .fact-label {
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}

.fact-card .fact-value {
  font-size: var(--font-size-md);
  font-weight: 700;
}

/* Modal / drawer shell */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 34, 0.4);
  z-index: var(--z-drawer-backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* Centered modal card (e.g. profile editor) — shares .drawer-backdrop for the overlay */
.modal-center-wrap {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  pointer-events: none;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: auto;
  max-height: calc(100vh - var(--space-8));
  display: flex;
  flex-direction: column;
}

.modal-center-wrap.open .modal-card {
  opacity: 1;
  transform: scale(1);
}

/* Shared contact-button pill (agent panel, quick-view modal) */
.agent-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
  color: var(--color-text);
  font-size: var(--font-size-xs);
  font-weight: 700;
}

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

.agent-btn.whatsapp {
  background: var(--color-success-bg);
  color: var(--color-accent-green-dark);
}

/* Quick view modal */
.quick-view-card {
  max-width: 520px;
  overflow: hidden;
  position: relative;
}

.quick-view-close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 2;
  background: rgba(255, 255, 255, 0.85);
}

.quick-view-gallery {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--color-surface-alt);
  flex-shrink: 0;
}

.quick-view-gallery img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.quick-view-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.quick-view-prev {
  left: var(--space-3);
}

.quick-view-next {
  right: var(--space-3);
}

.quick-view-dots {
  position: absolute;
  bottom: var(--space-3);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
}

.quick-view-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
}

.quick-view-dot.active {
  background: #fff;
}

.quick-view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.quick-view-contact-row {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.quick-view-full-link {
  width: 100%;
  margin-top: var(--space-3);
  font-weight: 700;
}

/* Stepped wizard modal (unit add/edit) — centered card, own theme */
.wizard-card {
  max-width: 620px;
  border-radius: 28px;
}

.wizard-card .drawer-header {
  padding: var(--space-6) var(--space-6) var(--space-4);
  border-bottom: none;
  align-items: flex-start;
}

.wizard-card .drawer-header h2 {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: var(--font-size-lg);
  font-weight: 800;
  color: var(--color-primary-dark);
}

.wizard-steps {
  display: flex;
  align-items: flex-start;
  padding: 0 var(--space-6) var(--space-5);
  overflow-x: auto;
}

.wizard-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  cursor: pointer;
  background: none;
  border: none;
  font: inherit;
}

.wizard-step-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: var(--font-size-sm);
  background: var(--color-surface-alt);
  color: var(--color-text-faint);
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.wizard-step-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--color-text-faint);
  white-space: nowrap;
}

.wizard-step.active .wizard-step-circle {
  background: var(--color-primary);
  color: #fff;
}

.wizard-step.active .wizard-step-label {
  color: var(--color-text);
}

.wizard-step.done .wizard-step-circle {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}

.wizard-connector {
  flex: 1 1 24px;
  min-width: 24px;
  height: 2px;
  background: var(--color-border);
  margin: 17px 6px 0;
}

.wizard-connector.done {
  background: var(--color-primary);
}

.wizard-card .drawer-body {
  padding: 0 var(--space-6) var(--space-6);
}

.wizard-card .field label {
  font-size: 10px;
}

.wizard-card input,
.wizard-card select,
.wizard-card textarea {
  background: var(--color-surface-alt);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  padding: 12px 16px;
}

.wizard-card input:focus,
.wizard-card select:focus,
.wizard-card textarea:focus {
  background: var(--color-surface);
  border-color: var(--color-primary);
}

.wizard-card .drawer-footer {
  border-top: 1px solid var(--color-border);
  justify-content: space-between;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(var(--drawer-width), 100vw);
  background: var(--color-surface);
  z-index: var(--z-drawer);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}

.drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.drawer-section {
  margin-bottom: var(--space-8);
}

.drawer-section h3 {
  margin-bottom: var(--space-3);
}

/* Toast */
.toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translate(-50%, 8px);
  background: var(--color-text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.toast-error {
  background: var(--color-danger);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--color-text-muted);
}

.empty-state h3 {
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

/* Coding composer */
.fixed-chips {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.code-chip-static {
  background: var(--color-surface-alt);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-text-muted);
}

.code-override-input {
  font-weight: 700;
  font-size: var(--font-size-md);
  letter-spacing: 0.02em;
}

/* Photo manager */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid transparent;
}

.photo-thumb.is-cover {
  border-color: var(--color-primary);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-thumb .photo-actions {
  position: absolute;
  inset: 0;
  background: rgba(43, 38, 34, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.photo-thumb:hover .photo-actions {
  opacity: 1;
}

.photo-thumb .photo-actions button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}

.photo-thumb .cover-tag {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: var(--color-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
}

.photo-upload-btn {
  aspect-ratio: 1;
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-faint);
  cursor: pointer;
  font-size: var(--font-size-xs);
  text-align: center;
  background: var(--color-surface-alt);
}

/* Owner search (New/Existing toggle) */
.owner-search-list {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-top: var(--space-2);
}

.owner-search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
}

.owner-search-item:last-child {
  border-bottom: none;
}

.owner-search-item:hover {
  background: var(--color-surface-alt);
}

.owner-search-selected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--color-primary);
  background: var(--color-primary-light);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-top: var(--space-2);
  font-size: var(--font-size-sm);
}

/* Lightbox */
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 17, 14, 0.92);
  z-index: var(--z-toast);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.lightbox-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.lightbox-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  max-width: 92vw;
}

.lightbox-image {
  max-width: 86vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

.lightbox-close {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.lightbox-nav {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.22);
}

.lightbox-counter {
  margin-top: var(--space-4);
  color: rgba(255, 255, 255, 0.7);
  font-size: var(--font-size-sm);
}

/* Warning inline */
.inline-warning {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: var(--font-size-xs);
  margin-top: var(--space-2);
}

/* Stat row (bed/car/area icons, from mockup) */
.stat-row {
  display: flex;
  flex-wrap: wrap;
  row-gap: var(--space-1);
  column-gap: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.stat-row .stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-row svg {
  width: 16px;
  height: 16px;
  color: var(--color-text-faint);
}

.missing-flags {
  margin-top: var(--space-2);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.missing-flag {
  font-size: var(--font-size-xs);
  font-weight: 700;
  color: var(--color-warning);
  background: var(--color-warning-bg);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  display: inline-block;
  white-space: nowrap;
}

.card-added-date {
  margin-top: var(--space-2);
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
}

/* Timeline */
.timeline {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.timeline-item {
  display: flex;
  gap: var(--space-3);
  position: relative;
  padding-left: var(--space-5);
  border-left: 2px solid var(--color-border);
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-primary);
}

.timeline-item .timeline-date {
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
}

/* Save-in-progress indicator (unit form modal) */
.save-progress {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border-strong);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  flex-shrink: 0;
  animation: spin 0.7s linear infinite;
}

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

@media (max-width: 640px) {
  /* iOS Safari auto-zooms the page on focus for any input under 16px. */
  input,
  select,
  textarea {
    font-size: 16px;
  }

  h1 {
    font-size: var(--font-size-xl);
  }

  h2 {
    font-size: var(--font-size-lg);
  }

  h3 {
    font-size: var(--font-size-md);
  }

  .btn {
    padding: 9px 16px;
  }

  .btn-sm {
    padding: 6px 12px;
  }

  .btn-icon {
    width: 36px;
    height: 36px;
  }

  .modal-center-wrap {
    padding: var(--space-3);
  }

  .modal-card {
    max-height: calc(100vh - var(--space-6));
  }

  .wizard-card {
    border-radius: var(--radius-lg);
  }

  .wizard-card .drawer-header {
    padding: var(--space-5) var(--space-5) var(--space-3);
  }

  .wizard-card .drawer-body {
    padding: 0 var(--space-5) var(--space-5);
  }

  .drawer {
    width: 100vw;
  }

  .drawer-header,
  .drawer-body,
  .drawer-footer {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}
