/* ============================================================
   APTIBOT — Design System v2
   Color principal: #303D53 (navy)
   ============================================================ */

:root {
  /* Brand */
  --navy: #303D53;
  --navy-light: #3d4d66;
  --navy-dark: #232e3f;
  --navy-50: #f0f2f5;
  --navy-100: #dce1e8;
  --navy-200: #b8c3d1;

  /* Surfaces */
  --bg-main: #f5f7fa;
  --bg-card: #ffffff;
  --bg-sidebar: #1e2a3a;
  --bg-hover: #f0f2f5;

  /* Text */
  --text-primary: #1a1d23;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --text-on-dark: #f5f7fa;

  /* Accent */
  --accent: #303D53;
  --accent-hover: #3d4d66;
  --accent-light: rgba(48, 61, 83, 0.08);

  /* Semantic */
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --info: #2563eb;
  --info-bg: #eff6ff;

  /* Borders */
  --border: #e5e7eb;
  --border-light: #f3f4f6;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 12px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.1), 0 4px 8px -2px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 40px -8px rgba(0, 0, 0, 0.12), 0 8px 16px -4px rgba(0, 0, 0, 0.06);

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-2xl: 24px;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }

/* Page load animation */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.main-content > *:first-child { animation: fadeInUp 0.35s var(--ease-out) both; }
.main-content > *:nth-child(2) { animation: fadeInUp 0.35s var(--ease-out) 0.06s both; }
.main-content > *:nth-child(3) { animation: fadeInUp 0.35s var(--ease-out) 0.12s both; }
.main-content > *:nth-child(4) { animation: fadeInUp 0.35s var(--ease-out) 0.18s both; }

/* ============================================================
   LAYOUT — App Shell
   ============================================================ */
.app {
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  background: linear-gradient(180deg, #1e2a3a 0%, #263347 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0 20px;
  gap: 4px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 68px;
  z-index: 50;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.sidebar-logo img {
  width: 32px;
  height: 32px;
}

.sidebar-logo-text {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, rgba(255,255,255,0.18), rgba(255,255,255,0.08));
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  color: white;
  margin-bottom: 24px;
  letter-spacing: -0.5px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.sidebar-item {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.45);
  font-size: 1.15rem;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  position: relative;
}

.sidebar-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  transform: scale(1.08);
}

.sidebar-item.active {
  background: rgba(255, 255, 255, 0.14);
  color: white;
  box-shadow: 0 0 12px rgba(255,255,255,0.06);
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: white;
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 8px rgba(255,255,255,0.3);
}

/* Sidebar tooltips */
.sidebar-item::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  background: var(--navy-dark);
  color: white;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s var(--ease-out);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 100;
}

.sidebar-item:hover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.sidebar-spacer { flex: 1; }

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(255,255,255,0.18), rgba(255,255,255,0.08));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
  color: white;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  border: 2px solid rgba(255,255,255,0.1);
}

.sidebar-avatar:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.08);
  border-color: rgba(255,255,255,0.2);
}

/* ---- Main Content ---- */
.main-content {
  margin-left: 68px;
  overflow-y: auto;
  padding: 28px 32px;
  min-height: 100vh;
  max-width: 1440px;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  gap: 16px;
}

.page-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.025em;
}

.page-header p {
  color: var(--text-secondary);
  margin-top: 4px;
  font-size: 0.9rem;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-primary);
  transition: all 0.2s var(--ease-out);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-family: inherit;
  line-height: 1.4;
}

.btn:hover {
  border-color: var(--navy-200);
  background: var(--bg-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn-primary {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
  box-shadow: 0 1px 3px rgba(48, 61, 83, 0.2);
}

.btn-primary:hover {
  background: var(--navy-light);
  border-color: var(--navy-light);
  box-shadow: 0 4px 12px rgba(48, 61, 83, 0.25);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-outline:hover {
  background: var(--bg-hover);
  border-color: var(--navy-200);
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 600;
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease-out), border-color 0.2s var(--ease-out);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.card-subtitle {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* ============================================================
   STATS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  transition: all 0.25s var(--ease-out);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--navy-200);
  opacity: 0;
  transition: opacity 0.25s var(--ease-out);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--navy-100);
}

.stat-card:hover::before {
  opacity: 1;
}

.stat-card:nth-child(1)::before { background: var(--navy); }
.stat-card:nth-child(2)::before { background: var(--success); }
.stat-card:nth-child(3)::before { background: var(--info); }
.stat-card:nth-child(4)::before { background: var(--warning); }

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  margin-bottom: 14px;
}

.stat-icon.navy   { background: var(--navy-100); color: var(--navy); }
.stat-icon.green  { background: var(--success-bg); color: var(--success); }
.stat-icon.blue   { background: var(--info-bg); color: var(--info); }
.stat-icon.orange { background: var(--warning-bg); color: var(--warning); }
.stat-icon.red    { background: var(--danger-bg); color: var(--danger); }

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stat-trend {
  font-size: 0.75rem;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}

.stat-trend.up   { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ============================================================
   CHARTS AREA
   ============================================================ */
.charts-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}

.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease-out);
}

.chart-card:hover {
  box-shadow: var(--shadow);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.chart-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.chart-placeholder {
  height: 180px;
  background: var(--bg-main);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ---- Pipeline list ---- */
.pipeline-list { display: flex; flex-direction: column; }
.pipeline-color {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}
.pipeline-color.new       { background: var(--navy); }
.pipeline-color.contacted { background: var(--info); }
.pipeline-color.visit     { background: var(--warning); }
.pipeline-color.proposal  { background: #8b5cf6; }
.pipeline-color.won       { background: var(--success); }
.pipeline-color.lost      { background: var(--danger); }
.pipeline-label { flex: 1; font-size: 0.85rem; }
.pipeline-value { font-weight: 600; font-size: 0.9rem; min-width: 24px; text-align: right; }

.pipeline-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-main);
  border-radius: 4px;
  overflow: hidden;
  flex-basis: 100%;
  margin-top: 4px;
}

.pipeline-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s var(--ease-out);
  min-width: 2px;
}

.pipeline-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
}
.pipeline-item:last-child { border: none; }

/* ---- Recent items ---- */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border-radius: var(--radius);
  transition: all 0.15s var(--ease-out);
}

.item-row:hover {
  background: var(--bg-hover);
  transform: translateX(2px);
}

.item-thumb {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--navy-100);
  color: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.item-info { flex: 1; min-width: 0; }
.item-name {
  font-weight: 600;
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 1px;
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.01em;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-info    { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--bg-main); color: var(--text-secondary); }
.badge-navy    { background: var(--navy-100); color: var(--navy); }

/* ============================================================
   TABLE
   ============================================================ */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

.table th {
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.table tbody tr:hover { background: var(--bg-hover); }

/* ============================================================
   KANBAN
   ============================================================ */
.kanban-board {
  display: flex;
  gap: 16px;
  padding-bottom: 24px;
  overflow-x: auto;
  flex: 1;
}

.kanban-column {
  min-width: 300px;
  max-width: 300px;
  background: var(--bg-main);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 140px);
  transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.kanban-column.drag-over {
  border-color: var(--navy-200);
  box-shadow: 0 0 0 3px rgba(48,61,83,0.08);
}

.column-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.column-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.column-dot.new        { background: var(--navy); }
.column-dot.contacted  { background: var(--info); }
.column-dot.visit      { background: var(--warning); }
.column-dot.proposal   { background: #8b5cf6; }
.column-dot.won        { background: var(--success); }
.column-dot.lost       { background: var(--danger); }
.column-dot.default    { background: var(--text-muted); }

.column-title {
  font-weight: 600;
  font-size: 0.875rem;
  flex: 1;
}

.column-count {
  background: var(--bg-main);
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.column-cards {
  padding: 10px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kanban-card {
  display: block;
  background: white;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
  text-decoration: none;
  color: inherit;
  border-left: 3px solid transparent;
  box-shadow: var(--shadow-sm);
}

.kanban-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-light);
  transform: translateY(-2px);
}

.kanban-card[style*="opacity: 0.5"] {
  transform: rotate(2deg) scale(0.95);
}

.card-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.65rem;
  font-weight: 600;
  flex-shrink: 0;
}

.card-client {
  font-weight: 600;
  font-size: 0.85rem;
}

.card-project {
  font-size: 0.85rem;
  font-weight: 500;
  margin-top: 8px;
  margin-bottom: 4px;
}

.card-details {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-budget {
  font-weight: 700;
  color: var(--navy);
  font-size: 0.85rem;
}

.card-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-tags {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.card-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--bg-main);
  color: var(--text-secondary);
}

/* ============================================================
   PROPERTIES — Grid
   ============================================================ */
.properties-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.property-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: all 0.25s var(--ease-out);
}

.property-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--navy-200);
  transform: translateY(-4px);
}

.property-card:hover .property-image img {
  transform: scale(1.05);
}

.property-image {
  height: 180px;
  background: linear-gradient(135deg, var(--navy-50), var(--navy-100));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.property-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s var(--ease-out);
}

.property-image i {
  font-size: 2.5rem;
  color: var(--navy-200);
}

.property-badge {
  position: absolute;
  top: 12px;
  right: 12px;
}

.property-content {
  padding: 16px 18px 18px;
}

.property-type {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 4px;
}

.property-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.property-location {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
}

.property-specs {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.property-specs span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.property-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}

.property-price {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
}

.property-code {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============================================================
   PROPERTY FILTERS
   ============================================================ */
.prop-filters-card {
  margin-bottom: 20px;
  padding: 16px;
}

.prop-filters-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.prop-filter-search {
  width: 100%;
}

.prop-filters-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.prop-filter-select {
  flex: 1;
  min-width: 0;
}

.prop-filter-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.prop-filter-clear {
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: color 0.15s;
}

.prop-filter-clear:hover {
  color: var(--text-primary);
}

@media (max-width: 600px) {
  .prop-filters-card {
    padding: 12px;
    margin-bottom: 14px;
  }

  .prop-filters-row {
    flex-wrap: wrap;
  }

  .prop-filter-select {
    flex: 1 1 calc(50% - 4px);
  }

  .prop-filter-btn {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================================
   CALENDAR
   ============================================================ */
.calendar-wrapper {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
}

.calendar-grid {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  padding: 16px;
}

.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-day {
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  min-height: 88px;
  padding: 8px;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.15s var(--ease-out);
}

.calendar-day:hover {
  background: var(--bg-hover);
  border-color: var(--navy-200);
  transform: scale(1.02);
}
.calendar-day.inactive { color: var(--text-muted); background: var(--bg-main); opacity: 0.6; }
.calendar-day.today {
  border-color: var(--navy);
  background: var(--navy-50);
  box-shadow: inset 0 0 0 1px var(--navy);
}

.calendar-day.today strong {
  background: var(--navy);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.calendar-event {
  background: var(--navy-100);
  color: var(--navy);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 0.7rem;
  font-weight: 500;
  border-left: 2px solid var(--navy);
  transition: background 0.15s;
}

.calendar-event:hover {
  background: var(--navy-200);
}

.calendar-weekdays {
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.calendar-weekdays div {
  text-align: center;
  padding: 8px 0;
}

.calendar-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

input, select, textarea {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-primary);
  background: white;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(48, 61, 83, 0.1);
}

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

/* Form group pattern (lead create modal, etc.) */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #4b5563;
}

.form-input {
  width: 100%;
  box-sizing: border-box;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  background-color: #fff;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  color: #1f2937;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input::placeholder {
  color: #9ca3af;
}
.form-input:focus {
  outline: none;
  border-color: #303D53;
  box-shadow: 0 0 0 2px rgba(48, 61, 83, 0.1);
}
select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.75rem center;
  background-repeat: no-repeat;
  background-size: 1.25em 1.25em;
  padding-right: 2.5rem;
}
textarea.form-input {
  resize: vertical;
}

.input-error {
  border-color: var(--danger) !important;
}

.field-error {
  font-size: 0.8rem;
  color: var(--danger);
}

/* Modal overlay */
[x-cloak] { display: none !important; }

/* ============================================================
   SETTINGS
   ============================================================ */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-wrapper {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-brand {
  background: linear-gradient(135deg, #1e2a3a 0%, #303D53 50%, #3d4d66 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: white;
  position: relative;
  overflow: hidden;
}

.auth-brand::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 70%, rgba(255,255,255,0.04) 0%, transparent 60%);
  pointer-events: none;
}

.auth-brand h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 32px;
  letter-spacing: -0.02em;
}

.auth-brand p {
  margin-top: 12px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1rem;
  max-width: 340px;
  text-align: center;
  line-height: 1.6;
}

.auth-form-side {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  background: var(--bg-main);
}

.auth-card {
  width: min(440px, 100%);
  background: var(--bg-card);
  padding: 36px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-card .subtitle {
  color: var(--text-secondary);
  margin-top: 6px;
  font-size: 0.9rem;
}

.auth-card form {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-card .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 0.95rem;
  margin-top: 4px;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.auth-footer a {
  color: var(--navy);
  font-weight: 600;
}

/* ============================================================
   ONBOARDING
   ============================================================ */
.onboarding-wrapper {
  min-height: 100vh;
  background: var(--bg-main);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.onboarding-card {
  width: min(640px, 100%);
  background: var(--bg-card);
  padding: 40px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
}

.onboarding-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.onboarding-steps {
  display: flex;
  gap: 8px;
  margin: 24px 0;
}

.onboarding-step {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: var(--border);
}

.onboarding-step.active { background: var(--navy); }
.onboarding-step.done   { background: var(--success); }

/* ============================================================
   PORTAL / LANDING PÚBLICA
   ============================================================ */
.portal-header {
  background: var(--navy);
  color: white;
  padding: 20px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.portal-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.portal-hero {
  background: var(--navy);
  color: white;
  padding: 48px 32px 56px;
  text-align: center;
}

.portal-hero h2 {
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.portal-hero p {
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.05rem;
  max-width: 500px;
  margin: 0 auto;
}

.portal-filters {
  background: white;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.portal-filters select,
.portal-filters input {
  font-size: 0.85rem;
  padding: 8px 12px;
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
  padding: 32px;
  max-width: 1200px;
  margin: 0 auto;
}

.portal-footer {
  background: var(--navy);
  color: rgba(255, 255, 255, 0.7);
  padding: 32px;
  text-align: center;
  font-size: 0.85rem;
}

/* WhatsApp CTA Button */
.wa-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #25d366;
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}

.wa-button:hover { background: #20bd5a; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 3rem;
  color: var(--navy-200);
  margin-bottom: 16px;
  opacity: 0.7;
}

.empty-state .btn {
  margin-top: 8px;
}

.empty-state h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-state p {
  max-width: 360px;
  margin: 0 auto 20px;
  font-size: 0.9rem;
}

/* ============================================================
   UTILITIES
   ============================================================ */
.text-navy    { color: var(--navy); }
.text-muted   { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-sm      { font-size: 0.85rem; }
.text-xs      { font-size: 0.75rem; }
.font-bold    { font-weight: 700; }
.mt-4         { margin-top: 16px; }
.mb-4         { margin-bottom: 16px; }
.gap-3        { gap: 12px; }
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1       { flex: 1; }
.w-full       { width: 100%; }
.truncate     { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Utility: hide on mobile / show on mobile */
.mobile-only { display: none !important; }

@media (max-width: 1100px) {
  .stats-grid     { grid-template-columns: repeat(2, 1fr); }
  .charts-grid    { grid-template-columns: 1fr; }
  .calendar-wrapper { grid-template-columns: 1fr; }
}

/* ============================================================
   TABLET + MOBILE (≤900px): Bottom nav, layout shifts
   ============================================================ */
@media (max-width: 900px) {
  .mobile-only { display: flex !important; }
  .desktop-only { display: none !important; }

  .app {
    grid-template-columns: 1fr;
  }

  /* ---- Bottom Navigation ---- */
  .sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    justify-content: space-around;
    padding: 6px 4px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 100;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-right: none;
    background: linear-gradient(180deg, #1e2a3a 0%, #1a2535 100%);
    gap: 0;
  }

  .sidebar-logo-text,
  .sidebar-spacer,
  .sidebar-avatar { display: none; }

  .sidebar-item {
    width: auto;
    height: auto;
    flex-direction: column;
    gap: 3px;
    padding: 6px 8px;
    font-size: 1.1rem;
    border-radius: 8px;
    min-width: 50px;
  }

  /* Show text labels on mobile nav */
  .sidebar-item::after {
    content: attr(data-label);
    position: static;
    transform: none;
    background: none;
    color: inherit;
    font-size: 0.6rem;
    font-weight: 500;
    padding: 0;
    border-radius: 0;
    opacity: 1;
    pointer-events: none;
    box-shadow: none;
    white-space: nowrap;
    letter-spacing: 0.02em;
  }

  .sidebar-item:hover::after {
    transform: none;
  }

  .sidebar-item.active {
    background: rgba(255, 255, 255, 0.12);
    color: white;
    box-shadow: none;
  }

  .sidebar-item.active::before { display: none; }

  .sidebar-item:hover {
    transform: none;
    background: rgba(255, 255, 255, 0.08);
  }

  /* ---- Main Content ---- */
  .main-content {
    margin-left: 0;
    padding: 20px 16px;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  /* ---- Page Header ---- */
  .page-header {
    margin-bottom: 20px;
  }

  .page-header h1 {
    font-size: 1.35rem;
  }

  /* ---- Stats ---- */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
    font-size: 0.95rem;
    margin-bottom: 10px;
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .stat-label {
    font-size: 0.78rem;
  }

  /* ---- Charts ---- */
  .charts-grid {
    gap: 12px;
    margin-bottom: 20px;
  }

  /* ---- Properties ---- */
  .properties-grid { grid-template-columns: 1fr; gap: 14px; }

  .property-image { height: 160px; }

  /* ---- Auth ---- */
  .auth-wrapper { grid-template-columns: 1fr; }
  .auth-brand   { display: none; }

  /* ---- Portal ---- */
  .portal-grid { grid-template-columns: 1fr; padding: 20px 16px; }

  /* ---- Kanban: better mobile scroll ---- */
  .kanban-board {
    gap: 12px;
    padding-bottom: 16px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .kanban-column {
    min-width: 280px;
    max-width: 280px;
    scroll-snap-align: center;
    flex-shrink: 0;
  }

  /* ---- Calendar: more compact ---- */
  .calendar-day {
    min-height: 72px;
    padding: 6px;
    font-size: 0.75rem;
  }

  .calendar-event {
    font-size: 0.6rem;
    padding: 2px 4px;
  }
}

/* ============================================================
   PHONE (≤600px): Full mobile-first redesign
   ============================================================ */
@media (max-width: 600px) {
  /* ---- Page Header ---- */
  .page-header {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
  }

  .page-header h1 {
    font-size: 1.25rem;
  }

  .header-actions {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .header-actions .btn {
    flex: 1;
    justify-content: center;
    min-height: 44px;
  }

  .empty-state .btn {
    min-height: auto;
    flex: none;
    width: auto;
    display: inline-flex;
    font-size: 0.875rem;
    padding: 10px 20px;
  }

  /* ---- Stats: 2x2 compact grid ---- */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
  }

  .stat-card {
    padding: 12px;
  }

  .stat-icon {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
    margin-bottom: 8px;
  }

  .stat-value { font-size: 1.25rem; }
  .stat-label { font-size: 0.72rem; }
  .stat-trend { display: none; }

  /* ---- Kanban Mobile: Stage tabs + vertical cards ---- */
  .kanban-board {
    flex-direction: column;
    overflow-x: visible;
    gap: 0;
    scroll-snap-type: none;
  }

  .kanban-column {
    min-width: 100%;
    max-width: 100%;
    max-height: none;
    border: none;
    background: transparent;
    border-radius: 0;
    display: none;
  }

  .kanban-column.mobile-active {
    display: flex;
  }

  .kanban-column .column-header {
    display: none;
  }

  .kanban-column .column-cards {
    padding: 0;
    gap: 10px;
    overflow-y: visible;
  }

  .kanban-card {
    border-left-width: 4px;
  }

  /* Stage tabs for mobile kanban */
  .mobile-stage-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 0 14px;
    scrollbar-width: none;
    margin: 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .mobile-stage-tabs::-webkit-scrollbar { display: none; }

  .mobile-stage-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    transition: all 0.2s var(--ease-out);
    flex-shrink: 0;
  }

  .mobile-stage-tab.active {
    background: var(--navy);
    color: white;
    border-color: var(--navy);
    box-shadow: 0 2px 8px rgba(48,61,83,0.25);
  }

  .mobile-stage-tab .tab-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .mobile-stage-tab .tab-count {
    font-weight: 700;
    font-size: 0.72rem;
    background: rgba(0,0,0,0.1);
    padding: 1px 6px;
    border-radius: 10px;
  }

  .mobile-stage-tab.active .tab-count {
    background: rgba(255,255,255,0.2);
  }

  /* ---- Calendar Mobile ---- */
  .calendar-grid {
    padding: 10px;
  }

  .calendar-day {
    min-height: 48px;
    padding: 4px;
    font-size: 0.7rem;
    border-radius: 6px;
  }

  .calendar-day strong {
    font-size: 0.75rem;
  }

  .calendar-event {
    font-size: 0;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    padding: 0;
    border: none;
    background: var(--navy);
    display: inline-block;
    margin: 1px;
  }

  .calendar-day.today strong {
    width: 22px;
    height: 22px;
    font-size: 0.7rem;
  }

  .calendar-weekdays div {
    font-size: 0.65rem;
    padding: 4px 0;
  }

  /* ---- Properties Mobile ---- */
  .property-image { height: 180px; }

  .property-content { padding: 14px; }

  .property-specs { gap: 10px; font-size: 0.75rem; }

  /* ---- Settings ---- */
  .settings-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* ---- Pipeline Stages ---- */
  .stages-layout { max-width: none; }
  .stages-card { padding: 16px; }
  .stage-row { padding: 10px 12px; gap: 8px; }
  .new-stage-row { flex-direction: column; align-items: stretch; }

  /* ---- Modal fullscreen on phone ---- */
  .modal-overlay {
    align-items: flex-end;
  }

  .modal-content {
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 24px 20px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlideUp 0.3s var(--ease-spring);
  }

  @keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
  }

  .modal-title {
    font-size: 1.1rem;
    font-weight: 600;
  }

  /* ---- Forms on phone ---- */
  .form-row,
  .form-row-flex {
    flex-direction: column;
    gap: 0;
  }

  .form-group-flex {
    flex: none;
    width: 100%;
  }

  /* Prevent iOS zoom on focus */
  input, select, textarea, .form-input {
    font-size: 16px !important;
  }

  .form-input,
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="search"],
  select,
  textarea {
    min-height: 46px;
    padding: 12px 14px;
  }

  .form-actions {
    flex-direction: column-reverse;
    gap: 10px;
  }

  .form-actions .btn {
    width: 100%;
    justify-content: center;
    min-height: 48px;
    font-size: 0.95rem;
  }

  /* ---- Buttons: bigger tap targets ---- */
  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }

  .btn:hover {
    transform: none;
  }

  .btn-sm {
    min-height: 38px;
    padding: 8px 14px;
  }

  /* ---- Search input ---- */
  .search-input {
    min-height: 46px;
    font-size: 16px;
    padding: 12px 14px;
  }

  /* ---- Pagination ---- */
  .pagination-controls {
    gap: 8px;
    padding: 14px 12px;
    flex-wrap: wrap;
  }

  .pagination-controls .btn,
  .pagination-controls .btn-disabled {
    min-height: 44px;
    min-width: 44px;
    padding: 8px 14px;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .pagination-info {
    font-size: 0.8rem;
    width: 100%;
    text-align: center;
    order: -1;
  }
}

/* ============================================================
   QUICK ACTIONS — Mobile field agent shortcuts
   ============================================================ */
.quick-actions {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.quick-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s var(--ease-out);
  text-decoration: none;
  white-space: nowrap;
}

.quick-action-btn i {
  font-size: 0.9rem;
}

.quick-action-btn.wa {
  background: #25d366;
  color: white;
  border-color: #25d366;
}

.quick-action-btn.wa:hover { background: #20bd5a; }

.quick-action-btn.call {
  background: var(--info-bg);
  color: var(--info);
  border-color: var(--info);
}

.quick-action-btn.email-btn {
  background: var(--navy-50);
  color: var(--navy);
  border-color: var(--navy-200);
}

/* Floating Action Button */
.fab {
  display: none;
}

@media (max-width: 600px) {
  .fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 20px;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--navy);
    color: white;
    font-size: 1.3rem;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(48,61,83,0.35);
    z-index: 90;
    transition: all 0.2s var(--ease-out);
  }

  .fab:active {
    transform: scale(0.92);
    box-shadow: 0 2px 8px rgba(48,61,83,0.3);
  }
}

/* ============================================================
   CRM TABLE
   ============================================================ */
.crm-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.crm-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.crm-table th {
  position: sticky;
  top: 0;
  background: var(--bg-main);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.crm-table td {
  padding: 12px 14px;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.crm-table tbody tr {
  transition: all 0.15s var(--ease-out);
}

.crm-table tbody tr:hover td {
  background: var(--bg-hover);
}

.crm-table tbody tr:hover {
  transform: scale(1.002);
}

.crm-table .lead-name {
  color: var(--navy);
  font-weight: 600;
  text-decoration: none;
}

.crm-table .lead-name:hover {
  color: var(--navy-light);
  text-decoration: underline;
}

.crm-table .text-muted-cell {
  color: var(--text-secondary);
}

.lead-phone-link {
  color: var(--text-primary);
  text-decoration: none;
}

@media (max-width: 600px) {
  .lead-phone-link {
    color: var(--info);
    font-weight: 500;
  }
}

/* ============================================================
   CONTACTS — Mobile card view
   ============================================================ */
.contacts-mobile-list {
  display: none;
}

@media (max-width: 600px) {
  .crm-table-wrapper { display: none; }
  .contacts-mobile-list { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; }

  .contact-mobile-card {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 14px;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s var(--ease-out);
  }

  .contact-mobile-card:active {
    background: var(--bg-hover);
  }

  .contact-mobile-top {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
  }

  .contact-mobile-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--navy);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
  }

  .contact-mobile-info {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .contact-mobile-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .contact-mobile-actions {
    display: flex;
    gap: 8px;
  }

  .contact-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s;
    flex: 1;
    justify-content: center;
  }

  .contact-action-btn.call {
    background: var(--info-bg);
    color: var(--info);
  }

  .contact-action-btn.call:active { background: #dbeafe; }

  .contact-action-btn.wa {
    background: #dcfce7;
    color: #16a34a;
    flex: 0;
    padding: 8px 12px;
  }

  .contact-action-btn.wa:active { background: #bbf7d0; }
}

/* ---- Stage Badges ---- */
.stage-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  letter-spacing: 0.01em;
  transition: all 0.15s var(--ease-out);
}

.stage-badge:hover {
  filter: brightness(0.95);
}

.stage-badge.stage-new         { background: var(--navy-100); color: var(--navy); }
.stage-badge.stage-contacted   { background: var(--info-bg); color: var(--info); }
.stage-badge.stage-visit       { background: var(--warning-bg); color: var(--warning); }
.stage-badge.stage-negotiation { background: #f3f0ff; color: #8b5cf6; }
.stage-badge.stage-won         { background: var(--success-bg); color: var(--success); }
.stage-badge.stage-lost        { background: var(--danger-bg); color: var(--danger); }

/* ============================================================
   DJANGO MESSAGES
   ============================================================ */
.messages {
  list-style: none;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.messages li {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  animation: slideInDown 0.3s var(--ease-out);
  display: flex;
  align-items: center;
  gap: 8px;
}

.messages li::before {
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.messages .success { background: var(--success-bg); color: var(--success); border-left: 3px solid var(--success); }
.messages .success::before { content: '\f058'; }
.messages .error   { background: var(--danger-bg); color: var(--danger); border-left: 3px solid var(--danger); }
.messages .error::before { content: '\f06a'; }
.messages .warning { background: var(--warning-bg); color: var(--warning); border-left: 3px solid var(--warning); }
.messages .warning::before { content: '\f071'; }
.messages .info    { background: var(--info-bg); color: var(--info); border-left: 3px solid var(--info); }
.messages .info::before { content: '\f05a'; }

@keyframes slideInDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.messages li.fade-out {
  animation: fadeOutUp 0.3s var(--ease-out) forwards;
}

@keyframes fadeOutUp {
  to { opacity: 0; transform: translateY(-8px); height: 0; padding: 0; margin: 0; overflow: hidden; }
}

/* ============================================================
   LEAD DETAIL
   ============================================================ */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
  transition: color 0.15s;
}

.back-link:hover {
  color: var(--navy);
}

.lead-detail-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  align-items: start;
}

.lead-summary-panel {
  position: sticky;
  top: 28px;
}

.summary-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.summary-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  font-size: 0.875rem;
}

.summary-row a:hover {
  text-decoration: underline;
}

.summary-meta {
  line-height: 1.4;
}

.lead-form-main {
  min-width: 0;
}

.lead-form-section {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease-out), border-color 0.2s var(--ease-out);
}

.lead-form-section:hover {
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.lead-form-section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}

@media (max-width: 900px) {
  .lead-detail-layout {
    grid-template-columns: 1fr;
  }
  .lead-summary-panel {
    position: static;
  }
}

/* ============================================================
   TIMELINE
   ============================================================ */
.timeline-section {
  margin-top: 8px;
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.timeline-item {
  display: flex;
  gap: 14px;
  padding: 14px 0;
  position: relative;
  border-left: 2px solid var(--border-light);
  margin-left: 7px;
  padding-left: 20px;
}

.timeline-item:last-child {
  border-left-color: transparent;
}

.timeline-dot {
  position: absolute;
  left: -6px;
  top: 18px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--bg-card);
  flex-shrink: 0;
}

.timeline-dot-blue   { background: var(--info); }
.timeline-dot-purple { background: #8b5cf6; }
.timeline-dot-orange { background: var(--warning); }
.timeline-dot-green  { background: var(--success); }
.timeline-dot-teal   { background: #0d9488; }
.timeline-dot-gray   { background: var(--text-muted); }

.timeline-content {
  flex: 1;
  min-width: 0;
}

.timeline-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.timeline-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.timeline-badge i { font-size: 0.65rem; }

.timeline-badge-blue   { background: var(--info-bg); color: var(--info); }
.timeline-badge-purple { background: #f3f0ff; color: #8b5cf6; }
.timeline-badge-orange { background: var(--warning-bg); color: var(--warning); }
.timeline-badge-green  { background: var(--success-bg); color: var(--success); }
.timeline-badge-teal   { background: #f0fdfa; color: #0d9488; }
.timeline-badge-gray   { background: var(--bg-main); color: var(--text-secondary); }

.timeline-timestamp {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.timeline-description {
  font-size: 0.875rem;
  color: var(--text-primary);
  margin-top: 4px;
}

.timeline-detail {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.timeline-actor {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.timeline-actor i { font-size: 0.65rem; }

.timeline-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

.timeline-empty i {
  font-size: 2rem;
  margin-bottom: 10px;
  display: block;
  color: var(--navy-200);
}

.timeline-empty p {
  font-size: 0.875rem;
  margin: 0;
}

/* ============================================================
   CONTACTS — Responsive Classes
   (Extracted from inline styles for media-query overridability)
   ============================================================ */

/* contacts.html — search bar wrapper */
.contacts-search-wrapper {
  padding: 16px 16px 0;
}

/* contacts.html — modal overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: modalOverlayIn 0.2s var(--ease-out);
}

@keyframes modalOverlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* contacts.html — modal content box */
.modal-content {
  background: var(--bg-card, #fff);
  border-radius: var(--radius-xl);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-xl);
  animation: modalSlideIn 0.3s var(--ease-spring);
  border: 1px solid var(--border-light);
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* contacts.html — modal title */
.modal-title {
  margin: 0 0 16px;
  font-size: 18px;
}

/* contacts.html — icon spacing in buttons */
.btn-icon-left {
  margin-right: 6px;
}

/* lead_detail.html — h1 top spacing */
.detail-heading {
  margin-top: 8px;
}

/* lead_detail.html — stage badge wrapper */
.summary-stage {
  margin: 12px 0;
}

/* lead_detail.html — fixed-width icon in summary rows */
.summary-icon {
  width: 18px;
}

/* lead_detail.html — section divider in summary panel */
.summary-divider {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 16px 0;
}

/* lead_detail.html — stacked meta with top spacing */
.summary-meta-spaced {
  margin-top: 8px;
}

/* lead_detail.html + lead_create_form.html — required asterisk */
.required-mark {
  color: #f87171;
}

/* lead_detail.html — classification flex row */
.form-row-flex {
  display: flex;
  gap: 16px;
}

/* lead_detail.html + lead_create_form.html — flex child that fills available space */
.form-group-flex {
  flex: 1;
}

/* lead_detail.html — save/submit button row */
.form-submit-row {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

/* lead_create_form.html — form row (smaller gap variant) */
.form-row {
  display: flex;
  gap: 12px;
}

/* lead_create_form.html — form actions row */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* lead_create_form.html — cancel button styling */
.btn-cancel {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

/* contacts_table_rows.html — empty state cell padding override */
.empty-state-cell {
  padding: 32px;
  text-align: center;
}

/* contacts_table_rows.html — pagination controls */
.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}

/* contacts_table_rows.html — disabled pagination button */
.btn-disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* contacts_table_rows.html — pagination info text */
.pagination-info {
  font-size: 14px;
  color: var(--text-muted, #6b7280);
}

/* ============================================================
   CONTACTS — Responsive (≤900px)
   ============================================================ */
@media (max-width: 900px) {
  .crm-table .col-source,
  .crm-table .col-updated {
    display: none;
  }
}

/* ============================================================
   CONTACTS — Responsive (≤600px): Card layout
   ============================================================ */
@media (max-width: 600px) {
  .crm-table thead { display: none; }

  .crm-table,
  .crm-table tbody { display: block; }

  .crm-table tbody tr {
    display: block;
    padding: 14px 16px;
    margin: 0 0 10px;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
  }

  .crm-table tbody tr:hover td { background: transparent; }
  .crm-table tbody tr:hover { transform: none; }

  .crm-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: none;
    font-size: 0.85rem;
  }

  .crm-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
    margin-right: 12px;
  }

  .crm-table .col-source,
  .crm-table .col-updated { display: none; }

  /* Name: prominent */
  .crm-table td[data-label="Nombre"] {
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 8px;
    margin-bottom: 4px;
  }

  .crm-table td[data-label="Nombre"]::before { display: none; }
  .crm-table td[data-label="Nombre"] .lead-name { font-size: 1rem; }

  /* Phone: make it tappable */
  .crm-table td[data-label="Teléfono"] {
    font-weight: 500;
    color: var(--navy);
  }

  .crm-table .empty-state-cell {
    display: block;
    text-align: center;
    margin: 0;
    border: none;
    box-shadow: none;
  }

  .crm-table .empty-state-cell::before { display: none; }

  .contacts-search-wrapper { padding: 12px 0 0; }

  /* Remove card wrapper on mobile contacts */
  .contacts-card-mobile {
    border: none;
    box-shadow: none;
    padding: 0;
    background: transparent;
  }
}

/* ============================================================
   LEAD DETAIL — Responsive (≤600px)
   ============================================================ */
@media (max-width: 600px) {
  /* Summary as compact header card */
  .lead-summary-panel.card {
    padding: 16px;
    border-radius: var(--radius-lg);
  }

  .summary-name { font-size: 1.15rem; }

  /* Quick actions in summary */
  .quick-actions {
    margin: 10px 0 4px;
    flex-wrap: wrap;
  }

  .quick-action-btn {
    flex: 1;
    justify-content: center;
    min-height: 42px;
    font-size: 0.78rem;
    padding: 8px 10px;
  }

  /* Form sections */
  .lead-form-main .form-row-flex {
    flex-direction: column;
    gap: 0;
  }

  .lead-form-main .form-group-flex {
    flex: none;
    width: 100%;
  }

  .lead-form-section {
    padding: 16px 14px;
    margin-bottom: 10px;
  }

  .lead-form-section:hover {
    box-shadow: var(--shadow-sm);
  }

  .lead-form-section-title {
    font-size: 0.82rem;
    margin-bottom: 12px;
    padding-bottom: 8px;
  }

  /* Save button: sticky at bottom */
  .form-submit-row {
    position: sticky;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    justify-content: center;
    margin-top: 16px;
    background: var(--bg-main);
    padding: 12px 0;
    margin-left: -14px;
    margin-right: -14px;
    padding-left: 14px;
    padding-right: 14px;
    border-top: 1px solid var(--border-light);
  }

  .form-submit-row .btn {
    width: 100%;
    justify-content: center;
    min-height: 48px;
    font-size: 1rem;
  }

  /* Timeline */
  .timeline-item {
    padding-left: 16px;
    gap: 10px;
  }

  .timeline-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .timeline-description {
    font-size: 0.85rem;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .timeline-detail {
    font-size: 0.78rem;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .timeline-section {
    margin-bottom: 24px;
  }

  /* Messages */
  .messages-container { margin-left: 0; margin-right: 0; }

  .alert {
    font-size: 0.82rem;
    padding: 10px 12px;
    word-break: break-word;
  }

  .detail-heading { font-size: 1.2rem; }
  .back-link { font-size: 0.8rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--navy-200); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--navy); }

/* Focus ring for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Search input */
.search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: var(--white);
  color: var(--text);
  transition: border-color 0.15s ease;
  box-sizing: border-box;
}
.search-input:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.08);
}
.search-input::placeholder {
  color: var(--text-muted);
}

/* Form validation errors */
.form-error {
  display: block;
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 4px;
}
.form-input.is-invalid {
  border-color: var(--danger);
}
.form-input.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

/* Alert messages */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success);
}
.alert-error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.messages-container {
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   PIPELINE STAGES MANAGEMENT
   ============================================================ */
.stages-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  max-width: 720px;
}

.stages-card {
  padding: 24px;
}

.stages-card-header {
  margin-bottom: 16px;
}

.stages-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.stages-card-title i {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.stages-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background: var(--bg-card);
  transition: all 0.2s var(--ease-out);
  flex-wrap: wrap;
}

.stage-row:hover {
  border-color: var(--navy-200);
  box-shadow: var(--shadow);
  transform: translateX(2px);
}

.stage-row.dragging {
  opacity: 0.5;
  border-color: var(--navy);
  transform: rotate(1deg);
}

.stage-row-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 2px 4px;
}

.stage-row-handle:active {
  cursor: grabbing;
}

.stage-row-color {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stage-row-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.stage-row-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

.stage-row-slug {
  font-size: 0.75rem;
}

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

.stage-btn-edit,
.stage-btn-delete {
  background: none;
  border: none;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.8rem;
  transition: background 0.15s, color 0.15s;
}

.stage-btn-edit:hover {
  background: var(--navy-50);
  color: var(--primary);
}

.stage-btn-delete:hover {
  background: #fef2f2;
  color: var(--danger);
}

.stage-edit-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  flex-basis: 100%;
  padding-top: 8px;
}

.stage-edit-fields {
  display: flex;
  gap: 10px;
  align-items: center;
}

.stage-edit-fields .form-input {
  flex: 1;
}

.stage-color-picker {
  width: 40px;
  height: 38px;
  padding: 2px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  background: white;
}

.stage-edit-actions {
  display: flex;
  gap: 8px;
}

.new-stage-form {
  margin-top: 12px;
}

.new-stage-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

@media (max-width: 600px) {
  .stages-layout { max-width: none; }
  .stages-card { padding: 16px; }
  .stage-row { padding: 10px 12px; gap: 8px; }
  .new-stage-row { flex-direction: column; align-items: stretch; }
}
