/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #222535;
  --border:    #2e3148;
  --accent:    #4f6ef7;
  --accent-h:  #6b87ff;
  --green:     #22c55e;
  --red:       #ef4444;
  --yellow:    #f59e0b;
  --text:      #e2e8f0;
  --muted:     #8892a4;
  --radius:    8px;
  --font:      'Inter', 'Segoe UI', system-ui, sans-serif;
}

html { font-size: 14px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); text-decoration: underline; }

/* ─── Layout ────────────────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header .logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .5px;
}
.app-header .logo span { color: var(--accent); }

.main-content {
  max-width: 1300px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ─── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ─── Search Bar ─────────────────────────────────────────────── */
.search-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 20px;
}
.search-bar .field { display: flex; flex-direction: column; gap: 4px; }
.search-bar label { font-size: .75rem; color: var(--muted); font-weight: 500; }

select, input[type=text], input[type=tel], input[type=email], input[type=date], input[type=number], textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: .875rem;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
}
select { min-width: 160px; cursor: pointer; }
input[type=text] { min-width: 220px; }
textarea { width: 100%; resize: vertical; min-height: 70px; }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary   { background: var(--accent);  color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-green     { background: var(--green);   color: #fff; }
.btn-green:hover:not(:disabled)  { opacity: .85; }
.btn-red       { background: var(--red);     color: #fff; }
.btn-red:hover:not(:disabled)    { opacity: .85; }
.btn-ghost     { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)  { border-color: var(--accent); }
.btn-sm        { padding: 5px 10px; font-size: .78rem; }

/* ─── Table ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 1px solid var(--border); }
th {
  text-align: left;
  padding: 10px 12px;
  font-size: .73rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  cursor: pointer;
}
tbody tr:hover { background: var(--surface2); }
td { padding: 10px 12px; font-size: .875rem; }

/* ─── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
}
.badge-green  { background: #16a34a22; color: var(--green);  border: 1px solid #16a34a44; }
.badge-blue   { background: #4f6ef722; color: var(--accent); border: 1px solid #4f6ef744; }
.badge-yellow { background: #f59e0b22; color: var(--yellow); border: 1px solid #f59e0b44; }
.badge-red    { background: #ef444422; color: var(--red);    border: 1px solid #ef444444; }
.badge-gray   { background: #ffffff11; color: var(--muted);  border: 1px solid #ffffff22; }

/* ─── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  font-size: .85rem;
  color: var(--muted);
}

/* ─── Property/Owner Detail ──────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-label { font-size: .73rem; color: var(--muted); margin-bottom: 2px; }
.detail-value { font-size: .95rem; font-weight: 500; }

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-bottom: 16px;
}
.stat-item { }
.stat-item .stat-label { font-size: .72rem; color: var(--muted); }
.stat-item .stat-val   { font-size: 1rem;  font-weight: 600; }

/* ─── Notes ──────────────────────────────────────────────────── */
.note-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 10px;
  position: relative;
}
.note-item .note-date { font-size: .72rem; color: var(--muted); margin-bottom: 6px; }
.note-item .note-text { font-size: .875rem; line-height: 1.5; white-space: pre-wrap; }
.note-item .note-actions { margin-top: 8px; display: flex; gap: 8px; }

.note-form { display: flex; gap: 10px; align-items: flex-end; }
.note-form textarea { flex: 1; }

/* ─── Call Log ───────────────────────────────────────────────── */
.call-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
}
.call-item:last-child { border-bottom: none; }
.call-date  { color: var(--muted); min-width: 120px; }
.call-dur   { color: var(--muted); min-width: 50px; }
.call-audio audio { height: 28px; }

/* ─── Dialer Overlay ─────────────────────────────────────────── */
#dialer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(4px);
  z-index: 900;
  align-items: center;
  justify-content: center;
}
#dialer-overlay.open { display: flex; }

#dialer-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
#dialer-box h3 {
  font-size: 1rem;
  margin: -24px -24px 18px -24px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  border-radius: 14px 14px 0 0;
}

/* Status indicator */
.dialer-status {
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: 8px;
  min-height: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Timer */
.dialer-timer {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  margin: 4px 0 12px;
  display: none;
  color: var(--accent);
}

/* Recording indicator */
.dialer-recording {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: .75rem;
  color: var(--red);
  margin-bottom: 10px;
  padding: 6px 12px;
  background: rgba(239, 68, 68, .08);
  border: 1px solid rgba(239, 68, 68, .15);
  border-radius: 6px;
}
.rec-dot {
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

/* Call/hangup controls */
.dialer-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
}
.dialer-controls .btn {
  flex: 1;
  justify-content: center;
  padding: 10px 16px;
  font-size: .9rem;
}

/* Post-call form */
.dialer-post {
  display: none;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 8px;
}
.dialer-post label {
  display: block;
  font-size: .72rem;
  color: var(--muted);
  margin-bottom: 4px;
  margin-top: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  font-weight: 500;
}
.dialer-post label:first-child { margin-top: 0; }
.dialer-post select, .dialer-post textarea { width: 100%; }

/* Saved / CRM prompt section */
#dialer-saved {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 16px;
}

/* Close button */
#dialer-close {
  position: absolute;
  top: 16px; right: 18px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  z-index: 1;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
#dialer-close:hover { color: var(--text); background: var(--surface2); }

@media (max-width: 500px) {
  #dialer-box { width: calc(100vw - 24px); border-radius: 12px; }
  #dialer-box h3 { border-radius: 12px 12px 0 0; }
}

/* ─── Call button ────────────────────────────────────────────── */
.call-btn-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 4px 16px #22c55e44;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s;
  z-index: 800;
}
.call-btn-fab:hover { opacity: .85; }

/* ─── Back link ──────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: .85rem;
  margin-bottom: 18px;
}
.back-link:hover { color: var(--text); text-decoration: none; }

/* ─── Empty state ────────────────────────────────────────────── */
.empty { color: var(--muted); font-size: .875rem; padding: 12px 0; }

/* ─── Loading spinner ────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Toast ──────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: .875rem;
  transition: transform .25s ease;
  z-index: 999;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { background: #ef4444; color: #fff; border-color: #dc2626; }

/* ─── Owner info inline editor ───────────────────────────────── */
.editable-field { display: flex; align-items: center; gap: 8px; }
.editable-field input { width: 200px; }

/* ─── App Nav ────────────────────────────────────────────────── */
.app-nav {
  display: flex;
  gap: 4px;
}
.app-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.app-nav a:hover { background: var(--surface2); color: var(--text); }
.app-nav a.active { background: var(--surface2); color: var(--accent); }

/* ─── Modal overlay ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: #00000088;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* ─── Form helpers ───────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field label { font-size: .73rem; color: var(--muted); font-weight: 500; }
.form-field input, .form-field select, .form-field textarea { width: 100%; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

/* ─── CRM Stats row ──────────────────────────────────────────── */
.crm-stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.crm-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  cursor: pointer;
  transition: border-color .15s;
  min-width: 100px;
  text-align: center;
}
.crm-stat-card:hover { border-color: var(--accent); }
.crm-stat-card.crm-stat-empty { opacity: .5; }
.crm-stat-num   { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.crm-stat-label { font-size: .72rem; color: var(--muted); margin-top: 4px; }

/* ─── Badge extra ────────────────────────────────────────────── */
.badge-orange { background: #f9731622; color: #f97316; border: 1px solid #f9731644; }
.badge-xs { font-size: .65rem; padding: 1px 5px; }

/* ─── CRM status quick-edit ──────────────────────────────────── */
.status-quick-edit {
  font-size: .8rem;
  padding: 4px 10px;
  border-radius: 99px;
  cursor: pointer;
}

/* ─── Info row (key-value) ───────────────────────────────────── */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  font-size: .875rem;
}
.info-row:last-child { border-bottom: none; }
.info-row .detail-label { min-width: 120px; flex-shrink: 0; margin-bottom: 0; }

/* ─── Activity timeline ──────────────────────────────────────── */
.activity-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; flex-shrink: 0;
}
.note-icon { background: #4f6ef722; color: var(--accent); border: 1px solid #4f6ef744; }
.call-icon { background: #22c55e22; color: var(--green);  border: 1px solid #22c55e44; }
.activity-body { flex: 1; min-width: 0; }
.activity-date { font-size: .72rem; color: var(--muted); margin-bottom: 4px; }

/* ─── Tasks ──────────────────────────────────────────────────── */
.task-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.task-item:last-child { border-bottom: none; }
.task-check { width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; accent-color: var(--green); }
.task-body  { flex: 1; min-width: 0; }
.task-title { font-size: .875rem; }
.task-done .task-title    { text-decoration: line-through; color: var(--muted); }
.task-overdue .task-title { color: var(--red); }

/* ─── Tag pills ──────────────────────────────────────────────── */
.tag-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 99px;
  font-size: .75rem; margin: 2px;
}
.tag-pill button {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: .85rem; line-height: 1; padding: 0;
}
.tag-pill button:hover { color: var(--red); }

/* ─── Dialer CRM prompt ──────────────────────────────────────── */
.crm-dialer-prompt {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  font-size: .85rem;
}

/* ─── View Toggle ──────────────────────────────────────────── */
.view-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.view-toggle .btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ─── Interactive Map ──────────────────────────────────────── */
#map-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}
#map {
  width: 100%;
  height: 500px;
}
#map-container.map-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 999;
  border-radius: 0;
  border: none;
  margin: 0;
}
#map-container.map-fullscreen #map {
  height: 100vh;
}

/* Map search control */
.map-search-control {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  margin-top: 10px;
}
.map-search-control input {
  width: 220px;
  padding: 6px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: .85rem;
  outline: none;
}
.map-search-control input:focus {
  border-color: var(--accent);
}
.map-search-control button {
  padding: 6px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: .85rem;
}
.map-search-control button:hover {
  background: var(--accent-h);
}

/* Map fullscreen button */
.map-fs-btn {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  color: var(--text) !important;
  width: 36px !important;
  height: 36px !important;
  font-size: 18px !important;
  cursor: pointer;
  display: flex !important;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.map-fs-btn:hover {
  background: var(--surface2) !important;
}

/* Map popups — dark theme */
.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: 0 4px 20px rgba(0,0,0,.5) !important;
}
.leaflet-popup-tip {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
}
.leaflet-popup-close-button {
  color: var(--muted) !important;
}
.leaflet-popup-close-button:hover {
  color: var(--text) !important;
}

.map-popup-addr {
  font-weight: 600;
  font-size: .95rem;
  margin-bottom: 2px;
}
.map-popup-city {
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.map-popup-details {
  display: flex;
  gap: 10px;
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.map-popup-owner {
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.map-popup-link {
  display: inline-block;
  padding: 4px 12px;
  background: var(--accent);
  color: #fff !important;
  border-radius: 4px;
  font-size: .8rem;
  font-weight: 600;
  text-decoration: none !important;
}
.map-popup-link:hover {
  background: var(--accent-h);
}
.map-popup-loading,
.map-popup-empty {
  font-size: .85rem;
  color: var(--muted);
  padding: 4px 0;
}
