/* ─── CSS Custom Properties ────────────────────────────────────────────────── */
:root {
  --color-primary:      #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-bg:           #f8fafc;
  --color-surface:      #ffffff;
  --color-border:       #e2e8f0;
  --color-text:         #1e293b;
  --color-muted:        #64748b;
  --color-success:      #16a34a;
  --color-warning:      #d97706;
  --color-danger:       #dc2626;
  --color-info:         #0284c7;
  --sidebar-width:      240px;
  --radius:             6px;
  --shadow:             0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:          0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

/* ─── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ───────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-text);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
}
.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-brand-text {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}
.sidebar-logo {
  max-height: 36px;
  max-width: 180px;
  object-fit: contain;
}
.sidebar-nav {
  list-style: none;
  padding: 0.75rem 0;
  flex: 1;
}
.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  color: #cbd5e1;
  font-size: 0.875rem;
  border-radius: 0;
  transition: background .15s, color .15s;
}
.sidebar-nav li a svg {
  width: 16px; height: 16px; flex-shrink: 0;
}
.sidebar-nav li a:hover,
.sidebar-nav li.active > a {
  background: rgba(255,255,255,.08);
  color: #fff;
  text-decoration: none;
}
.nav-divider {
  height: 1px;
  background: rgba(255,255,255,.1);
  margin: 0.4rem 0;
}
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}
.user-avatar {
  width: 32px; height: 32px;
  background: var(--color-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem; color: #fff;
  flex-shrink: 0;
}
.user-name  { font-size: 0.8rem; font-weight: 600; color: #e2e8f0; }
.user-role  { font-size: 0.7rem; color: #94a3b8; }
.btn-logout {
  display: block;
  text-align: center;
  padding: 0.35rem;
  background: rgba(255,255,255,.08);
  color: #cbd5e1;
  border-radius: var(--radius);
  font-size: 0.8rem;
}
.btn-logout:hover { background: rgba(255,255,255,.15); color: #fff; text-decoration: none; }

/* ─── Main content ─────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 1.5rem 2rem;
  max-width: 100%;
}

/* ─── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}
.back-link {
  display: block;
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-bottom: 0.25rem;
}
.back-link:hover { color: var(--color-primary); }

/* ─── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  overflow: hidden;
}
.card-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header-link {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--color-primary);
}
.card-form { max-width: 720px; }
.card-form form { padding: 1.25rem; }

/* ─── Metric grid ──────────────────────────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.metric-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}
.metric-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); }
.metric-value { font-size: 2rem; font-weight: 700; color: var(--color-text); line-height: 1.1; }
.metric-sub   { font-size: 0.75rem; color: var(--color-muted); }

/* ─── Pipeline ─────────────────────────────────────────────────────────────── */
.pipeline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  padding: 1rem;
  gap: 0.75rem;
}
.pipeline-item {
  text-align: center;
  padding: 0.75rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  text-decoration: none;
  transition: box-shadow .15s;
}
.pipeline-item:hover { box-shadow: var(--shadow-md); text-decoration: none; }
.pipeline-count { font-size: 1.75rem; font-weight: 700; color: var(--color-text); }
.pipeline-label { font-size: 0.72rem; color: var(--color-muted); text-transform: capitalize; }

/* ─── Tables ───────────────────────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.table th {
  text-align: left;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-muted);
  background: #f8fafc;
}
.table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-footer {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--color-muted);
  border-top: 1px solid var(--color-border);
}
.row-inactive { opacity: 0.5; }

/* ─── Status badges ────────────────────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 0.2em 0.6em;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: .03em;
}
.status-new             { background: #dbeafe; color: #1d4ed8; }
.status-contacted       { background: #dcfce7; color: #15803d; }
.status-scheduled       { background: #d1fae5; color: #065f46; }
.status-not_interested  { background: #fef9c3; color: #a16207; }
.status-spam            { background: #fee2e2; color: #991b1b; }

/* ─── Inline status select (lead list) ─────────────────────────────────────── */
.status-select {
  -webkit-appearance: none;
  appearance: none;
  padding: 0.25rem 1.75rem 0.25rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  transition: box-shadow .15s;
}
.status-select:focus { outline: none; box-shadow: 0 0 0 2px rgba(37,99,235,.2); }
.status-select-new            { background-color: #dbeafe; color: #1d4ed8; border-color: #bfdbfe; }
.status-select-contacted      { background-color: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.status-select-scheduled      { background-color: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.status-select-not_interested { background-color: #fef9c3; color: #a16207; border-color: #fde68a; }
.status-select-spam           { background-color: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ─── Role badges ──────────────────────────────────────────────────────────── */
.role-badge {
  display: inline-block;
  padding: 0.15em 0.5em;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}
.role-admin    { background: #ede9fe; color: #5b21b6; }
.role-location { background: #e0f2fe; color: #0369a1; }
.location-badge {
  display: inline-block;
  padding: 0.2em 0.65em;
  background: #f1f5f9;
  color: var(--color-muted);
  border-radius: 4px;
  font-size: 0.78rem;
}

/* ─── Status dots (outbound messages) ──────────────────────────────────────── */
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; margin-top: 4px; }
.status-dot-sent    { background: var(--color-success); }
.status-dot-failed  { background: var(--color-danger); }
.status-dot-pending { background: var(--color-warning); }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.btn-secondary { background: #f1f5f9; color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-success   { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.btn-warning   { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.btn-info      { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }
.btn-danger    { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.btn-ghost     { background: transparent; color: var(--color-muted); border-color: transparent; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-block     { width: 100%; justify-content: center; }
.btn-sm        { padding: 0.25rem 0.65rem; font-size: 0.8rem; }

/* Quick action buttons in list view */
.quick-actions { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.btn-action {
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  border-radius: 4px;
  border: 1px solid;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
}
.btn-action-contact  { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }
.btn-action-schedule { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.btn-action-lost     { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ─── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--color-text);
}
.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
textarea.form-control { resize: vertical; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-help { font-size: 0.75rem; color: var(--color-muted); margin-top: 0.3rem; }
.form-actions { display: flex; gap: 0.75rem; align-items: center; padding-top: 0.5rem; }
.inline-form  { display: flex; gap: 0.75rem; align-items: center; padding: 0.75rem 1rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; cursor: pointer; }
.toggle-label   { display: flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; cursor: pointer; }
.required { color: var(--color-danger); }
.color-input-row { display: flex; align-items: center; gap: 0.5rem; }
.color-picker    { width: 40px; height: 36px; border: 1px solid var(--color-border); border-radius: var(--radius); cursor: pointer; padding: 2px; }

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}
.filter-search { flex: 1; min-width: 180px; }
.filter-select { width: auto; min-width: 140px; }
.filter-date   { width: auto; }

/* ─── Lead detail ──────────────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.25rem;
  align-items: start;
}
.contact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
  padding: 1rem;
}
.contact-item-full { grid-column: 1 / -1; }
.contact-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); display: block; }
.contact-value { font-size: 0.875rem; color: var(--color-text); }
.action-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem 1rem; }

/* Notes */
.notes-list   { padding: 0 1rem; }
.note-item    { border-bottom: 1px solid #f1f5f9; padding: 0.75rem 0; }
.note-item:last-child { border-bottom: 0; }
.note-meta    { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 0.25rem; }
.note-body    { font-size: 0.875rem; color: var(--color-text); white-space: pre-wrap; }
.note-form    { padding: 0.75rem 1rem; border-top: 1px solid var(--color-border); }
.note-form textarea { margin-bottom: 0.5rem; }

/* Timeline */
.timeline { list-style: none; padding: 1rem; }
.timeline-item {
  display: flex;
  gap: 0.75rem;
  padding-bottom: 1rem;
  position: relative;
}
.timeline-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 6px; top: 14px; bottom: 0;
  width: 2px; background: var(--color-border);
}
.timeline-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid var(--color-surface);
  flex-shrink: 0; margin-top: 1px;
  box-shadow: 0 0 0 2px var(--color-primary);
}
.timeline-content { flex: 1; }
.timeline-action  { font-size: 0.8rem; font-weight: 600; text-transform: capitalize; }
.timeline-detail  { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.2rem; }
.timeline-meta    { margin-top: 0.2rem; }

/* Outbound messages */
.outbound-list { list-style: none; }
.outbound-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f1f5f9;
}
.outbound-item:last-child { border-bottom: 0; }

/* ─── Admin links ──────────────────────────────────────────────────────────── */
.admin-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.admin-link-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-decoration: none;
  transition: box-shadow .15s;
  box-shadow: var(--shadow);
}
.admin-link-card:hover { box-shadow: var(--shadow-md); text-decoration: none; }
.admin-link-card h3 { font-size: 1rem; font-weight: 600; color: var(--color-text); margin-bottom: 0.25rem; }
.admin-link-card p  { font-size: 0.8rem; color: var(--color-muted); }

/* ─── Auth page ────────────────────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}
.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}
.auth-header  { text-align: center; margin-bottom: 1.75rem; }
.auth-logo    { max-height: 48px; margin-bottom: 1rem; }
.auth-title   { font-size: 1.4rem; font-weight: 700; color: var(--color-text); }
.auth-subtitle { font-size: 0.875rem; color: var(--color-muted); margin-top: 0.3rem; }
.auth-form    { margin-top: 1rem; }
.auth-help    { text-align: center; font-size: 0.8rem; color: var(--color-muted); margin-top: 1.25rem; }

/* ─── Error page ───────────────────────────────────────────────────────────── */
.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.error-box {
  text-align: center;
  padding: 2rem;
}
.error-box h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem; }
.error-box p  { color: var(--color-muted); margin-bottom: 1.5rem; }

/* ─── Flash messages ───────────────────────────────────────────────────────── */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  border: 1px solid transparent;
}
.flash-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.flash-error   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.flash-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }

/* ─── Utilities ────────────────────────────────────────────────────────────── */
.text-sm     { font-size: 0.8rem; }
.text-muted  { color: var(--color-muted); }
.text-success { color: var(--color-success); }
.text-error  { color: var(--color-danger); }
.lead-name   { font-weight: 600; }
.empty-state { padding: 1.5rem 1rem; color: var(--color-muted); font-size: 0.875rem; text-align: center; }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { width: 200px; }
  .main-content { margin-left: 200px; padding: 1rem; }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 1rem; }
  .detail-grid  { grid-template-columns: 1fr; }
  .form-row     { grid-template-columns: 1fr; }
  .metric-grid  { grid-template-columns: 1fr 1fr; }
  .contact-grid { grid-template-columns: 1fr; }
}
