/* Vistas Villa CRM - design tokens */
:root {
  --cream: #F4EFE6;
  --cream-light: #FBFAF6;
  --cream-dark: #E8DDC9;
  --ink: #2D2D2D;
  --ink-soft: #5C5C5C;
  --ink-mute: #8A8A8A;
  --accent: #B8754D;
  --accent-hover: #A05F38;
  --accent-soft: #E8C9B5;
  --success: #5C7048;
  --warn: #C29038;
  --danger: #B04030;
  --line: #E5DDD0;
  --shadow: 0 1px 3px rgba(45,45,45,0.05), 0 1px 2px rgba(45,45,45,0.04);
  --shadow-md: 0 4px 16px rgba(45,45,45,0.08);
  --radius: 6px;
  --radius-lg: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--cream-light);
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }

/* === Login === */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--cream-light) 0%, var(--cream) 100%);
  padding: 24px;
}
.login-card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  border-top: 4px solid var(--accent);
}
.login-logo {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 800;
  font-size: 24px;
  letter-spacing: 2px;
  color: var(--ink);
  margin-bottom: 4px;
  text-align: center;
}
.login-tagline {
  text-align: center;
  color: var(--ink-mute);
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 32px;
}
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.form-input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--cream-light);
  font-size: 14px;
  transition: border-color 0.15s, background 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
  background: white;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.5px;
  transition: background 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: var(--ink-mute); cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--cream); color: var(--ink); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn-danger:hover { background: rgba(176,64,48,0.06); }
.btn-full { width: 100%; padding: 13px; font-size: 14px; }
.error-msg {
  background: rgba(176,64,48,0.08);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  border-left: 3px solid var(--danger);
}

/* === App layout === */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: white;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 12px;
}
.brand-mark {
  width: 32px; height: 32px;
  background: var(--accent);
  color: white;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  letter-spacing: 0;
}
.brand-name {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 1.5px;
  color: var(--ink);
}
.brand-sub {
  font-size: 10px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-top: 1px;
}
.tabs {
  display: flex; gap: 4px;
}
.tab {
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-mute);
  border-radius: var(--radius);
  letter-spacing: 0.5px;
}
.tab:hover { background: var(--cream); color: var(--ink); }
.tab.active { background: var(--cream); color: var(--ink); }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: var(--cream-light);
  font-size: 13px;
}
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 12px;
}

.app-main { flex: 1; padding: 24px 28px; max-width: 1400px; margin: 0 auto; width: 100%; }

/* === Stats === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.stat-label {
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 600;
  margin-bottom: 6px;
}
.stat-value {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 700;
  font-size: 28px;
  color: var(--ink);
  letter-spacing: -0.5px;
}
.stat-foot {
  font-size: 11px;
  color: var(--ink-mute);
  margin-top: 4px;
}

/* === Toolbar === */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.toolbar-left { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 8px; }
.search-input {
  padding: 9px 14px 9px 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  font-size: 13px;
  width: 260px;
  position: relative;
}
.search-wrap { position: relative; }
.search-wrap::before {
  content: '⌕';
  position: absolute;
  left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--ink-mute);
  font-size: 14px;
}
.filter-select {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  font-size: 13px;
  font-weight: 500;
}

/* === Leads table === */
.card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; }
.table th {
  background: var(--cream-light);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.table tbody tr { border-bottom: 1px solid var(--line); cursor: pointer; transition: background 0.1s; }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--cream-light); }
.table td { font-size: 13px; }
.table .lead-name { font-weight: 600; color: var(--ink); }
.table .lead-meta { font-size: 11px; color: var(--ink-mute); margin-top: 2px; }
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.badge-new { background: rgba(184,117,77,0.12); color: var(--accent-hover); }
.badge-contacted { background: rgba(92,112,72,0.12); color: var(--success); }
.badge-visit_scheduled { background: rgba(194,144,56,0.12); color: var(--warn); }
.badge-visit_done { background: rgba(92,112,72,0.18); color: var(--success); }
.badge-offer { background: rgba(184,117,77,0.18); color: var(--accent-hover); }
.badge-won { background: var(--success); color: white; }
.badge-lost { background: rgba(176,64,48,0.1); color: var(--danger); }
.source-tag {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-mute);
  font-weight: 600;
}

/* === Modal === */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(45,45,45,0.4);
  display: flex; align-items: flex-start; justify-content: center;
  z-index: 100;
  padding: 40px 20px;
  overflow-y: auto;
}
.modal {
  background: white;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  max-height: calc(100vh - 80px);
  display: flex; flex-direction: column;
}
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
}
.modal-body { padding: 24px; overflow-y: auto; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  display: flex; gap: 10px; justify-content: flex-end;
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-mute);
  font-size: 18px;
}
.modal-close:hover { background: var(--cream); color: var(--ink); }

/* Lead detail */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; margin-bottom: 24px; }
.detail-field { }
.detail-field-label { font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--ink-mute); font-weight: 600; margin-bottom: 4px; }
.detail-field-value { font-size: 14px; color: var(--ink); }
.section-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 24px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.timeline { }
.timeline-item {
  display: flex; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.timeline-item:last-child { border-bottom: 0; }
.timeline-dot {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.timeline-meta { font-size: 11px; color: var(--ink-mute); margin-bottom: 2px; }
.timeline-text { font-size: 13px; color: var(--ink); }
.timeline-text .from-to { color: var(--ink-mute); font-size: 12px; }

/* Calendar */
.calendar-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.visit-card {
  background: white;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex; align-items: center; gap: 16px;
}
.visit-time {
  text-align: center;
  min-width: 70px;
}
.visit-time-day { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-mute); font-weight: 600; }
.visit-time-hour { font-family: 'Plus Jakarta Sans', sans-serif; font-weight: 700; font-size: 22px; color: var(--ink); }
.visit-time-date { font-size: 11px; color: var(--ink-mute); margin-top: 2px; }
.visit-info { flex: 1; }
.visit-lead { font-weight: 600; color: var(--ink); }
.visit-meta { font-size: 12px; color: var(--ink-mute); margin-top: 2px; }
.visit-status { font-size: 11px; padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.vs-scheduled { background: rgba(194,144,56,0.12); color: var(--warn); }
.vs-completed { background: rgba(92,112,72,0.12); color: var(--success); }
.vs-cancelled { background: rgba(176,64,48,0.08); color: var(--danger); text-decoration: line-through; }
.vs-no_show { background: rgba(176,64,48,0.12); color: var(--danger); }

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-mute);
}
.empty-icon { font-size: 32px; margin-bottom: 12px; opacity: 0.4; }

/* Conversion bars */
.conversion-bar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
.conversion-bar-label { font-size: 12px; color: var(--ink-soft); min-width: 160px; font-weight: 500; }
.conversion-bar-track { flex: 1; background: var(--cream); height: 8px; border-radius: 999px; overflow: hidden; }
.conversion-bar-fill { background: var(--accent); height: 100%; border-radius: 999px; transition: width 0.3s; }
.conversion-bar-value { font-size: 12px; color: var(--ink); min-width: 70px; text-align: right; font-weight: 600; }

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

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--ink);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: slideUp 0.2s ease-out;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } }

.row-flex { display: flex; gap: 10px; align-items: center; }
.gap-sm { gap: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }

@media (max-width: 768px) {
  .detail-grid { grid-template-columns: 1fr; }
  .app-main { padding: 16px; }
  .app-header { padding: 12px 16px; }
  .tabs { display: none; }
  .search-input { width: 100%; }
  .toolbar { flex-direction: column; align-items: stretch; }
}