/* Sierra Homebuyers TC Portal — Styles */
:root {
  --primary: #2E75B6;
  --primary-dark: #1a5a96;
  --primary-light: #e8f0fb;
  --success: #27ae60;
  --warning: #f39c12;
  --danger: #e74c3c;
  --info: #3498db;
  --gray-50: #f8f9fa;
  --gray-100: #f1f3f5;
  --gray-200: #e9ecef;
  --gray-300: #dee2e6;
  --gray-400: #ced4da;
  --gray-500: #adb5bd;
  --gray-600: #868e96;
  --gray-700: #495057;
  --gray-800: #343a40;
  --gray-900: #212529;
  --sidebar-width: 240px;
  --header-height: 56px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  font-size: 14px;
  line-height: 1.5;
}

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

/* ===== LOGIN PAGE ===== */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a5a96 0%, #2E75B6 50%, #4a90d9 100%);
}
.login-card {
  background: white;
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-card h1 {
  text-align: center;
  color: var(--primary);
  margin-bottom: 8px;
  font-size: 24px;
}
.login-card .subtitle {
  text-align: center;
  color: var(--gray-600);
  margin-bottom: 32px;
  font-size: 13px;
}
.login-card .logo-text {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

/* ===== LAYOUT ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--gray-900);
  color: white;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
}
.sidebar-brand {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-700);
  font-weight: 700;
  font-size: 16px;
  color: white;
}
.sidebar-brand span { color: var(--info); }
.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--gray-400);
  font-size: 13px;
  transition: all 0.15s;
}
.sidebar-nav a:hover {
  color: white;
  background: rgba(255,255,255,0.08);
  text-decoration: none;
}
.sidebar-nav a.active {
  color: white;
  background: var(--primary);
}
.sidebar-nav .nav-section {
  padding: 16px 20px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gray-600);
}
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--gray-700);
  font-size: 12px;
  color: var(--gray-500);
}
.sidebar-footer .user-name { color: white; font-weight: 600; }

/* Main content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
}

/* Header */
.page-header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-header h1 {
  font-size: 20px;
  font-weight: 600;
}
.page-header .header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Page body */
.page-body {
  padding: 24px;
}

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--gray-700);
}
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46,117,182,0.15);
}
select.form-control {
  appearance: auto;
}
textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline {
  background: white;
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-100); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 24px; font-size: 15px; }

/* ===== CARDS ===== */
.card {
  background: white;
  border-radius: 8px;
  border: 1px solid var(--gray-200);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--gray-200);
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body { padding: 18px; }

/* ===== STATS GRID ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border-radius: 8px;
  border: 1px solid var(--gray-200);
  padding: 18px;
}
.stat-card .stat-label {
  font-size: 12px;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
}
.stat-card .stat-subtext {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}
.stat-card.danger { border-left: 3px solid var(--danger); }
.stat-card.warning { border-left: 3px solid var(--warning); }
.stat-card.success { border-left: 3px solid var(--success); }
.stat-card.info { border-left: 3px solid var(--info); }
.stat-card.clickable { cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.stat-card.clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

/* ===== MONTH GROUP HEADERS ===== */
.month-group { margin-bottom: 24px; }
.month-group-header {
  font-size: 15px; font-weight: 600; color: var(--gray-700);
  padding: 8px 0; margin-bottom: 8px; border-bottom: 2px solid var(--gray-200);
  display: flex; justify-content: space-between; align-items: center;
}
.month-group-header .count { font-size: 12px; font-weight: 400; color: var(--gray-500); }

/* ===== FILTER PILLS ===== */
.filter-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-pill {
  padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 500;
  background: var(--gray-100); color: var(--gray-600); border: 1px solid var(--gray-200);
  cursor: pointer; transition: all 0.15s;
}
.filter-pill:hover { background: var(--gray-200); }
.filter-pill.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ===== TABLES ===== */
.table-container {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-600);
  font-weight: 600;
  background: var(--gray-50);
}
td { font-size: 13px; }
tr:hover td { background: var(--gray-50); }
tr.clickable { cursor: pointer; }

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
}
.badge-blue { background: #e8f0fb; color: #2E75B6; }
.badge-green { background: #e8f8ef; color: #27ae60; }
.badge-yellow { background: #fef9e7; color: #d4a017; }
.badge-red { background: #fdeaea; color: #e74c3c; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-purple { background: #f0e6f6; color: #8e44ad; }
.badge-cyan { background: #e0f7fa; color: #00838f; }

/* Status badges */
.status-contract_received { background: #e8f0fb; color: #2E75B6; }
.status-escrow_opened { background: #e0f7fa; color: #00838f; }
.status-title_ordered { background: #f0e6f6; color: #8e44ad; }
.status-inspections_ordered { background: #fff3e0; color: #ef6c00; }
.status-title_cleared { background: #e8f5e9; color: #2e7d32; }
.status-contingencies_removed { background: #e8f5e9; color: #1b5e20; }
.status-pre_closing { background: #fef9e7; color: #d4a017; }
.status-closing_scheduled { background: #fce4ec; color: #c62828; }
.status-closed { background: #e8f8ef; color: #27ae60; }
.status-cancelled { background: var(--gray-100); color: var(--gray-600); }
.status-on_hold { background: #fff8e1; color: #f57f17; }

/* Classification badges */
.class-automated { background: #e8f8ef; color: #27ae60; }
.class-ai_assisted { background: #f0e6f6; color: #8e44ad; }
.class-human { background: #e8f0fb; color: #2E75B6; }

/* Task status */
.task-pending { color: var(--gray-500); }
.task-in_progress { color: var(--info); }
.task-waiting_approval { color: var(--warning); }
.task-completed { color: var(--success); }
.task-overdue { color: var(--danger); }
.task-escalated { color: var(--danger); font-weight: 700; }

/* ===== KANBAN ===== */
.kanban-board {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 16px;
}
.kanban-column {
  min-width: 260px;
  max-width: 300px;
  flex-shrink: 0;
  background: var(--gray-100);
  border-radius: 8px;
  padding: 12px;
}
.kanban-column-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-600);
  padding: 4px 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.kanban-column-header .count {
  background: var(--gray-300);
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 11px;
}
.kanban-card {
  background: white;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--gray-200);
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.kanban-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.kanban-card .card-address {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}
.kanban-card .card-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}
.kanban-card .card-meta {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--gray-500);
}
.kanban-card .card-closing {
  font-size: 12px;
  color: var(--gray-600);
  margin-top: 4px;
}
.kanban-card[draggable="true"] { cursor: grab; }
.kanban-card.dragging { opacity: 0.4; transform: rotate(2deg); }
.kanban-column.drag-over { background: var(--primary-light); border: 2px dashed var(--primary); }

/* ===== TASK LIST ===== */
.task-list { list-style: none; }
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
}
.task-item:last-child { border-bottom: none; }
.task-checkbox {
  margin-top: 2px;
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}
.task-info { flex: 1; }
.task-title { font-size: 13px; font-weight: 500; }
.task-title.completed { text-decoration: line-through; color: var(--gray-500); }
.task-meta {
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 2px;
  display: flex;
  gap: 12px;
}
.task-actions { display: flex; gap: 4px; }

/* ===== TASK STAGE GROUPS ===== */
.task-stage-group {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}
.task-stage-group.stage-done { border-color: var(--success); border-left: 3px solid var(--success); }
.task-stage-group.stage-active { border-color: var(--primary); border-left: 3px solid var(--primary); background: var(--primary-light); }
.task-stage-group.stage-future { opacity: 0.7; }
.task-stage-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-100);
}
.task-stage-group.stage-active .task-stage-header { background: rgba(46, 117, 182, 0.08); }
.stage-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--gray-400);
  flex-shrink: 0;
}
.stage-indicator.done { background: var(--success); border-color: var(--success); }
.stage-indicator.active { background: var(--primary); border-color: var(--primary); }
.stage-progress {
  margin-left: auto;
  font-size: 11px;
  color: var(--gray-500);
  font-weight: 500;
}
.task-stage-items {
  list-style: none;
  padding: 4px 14px;
}
.task-stage-group.collapsed .task-stage-items { display: none; }
.task-stage-group.collapsed .task-stage-header { border-bottom: none; }

/* ===== TIMELINE ===== */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--gray-200);
}
.timeline-item {
  position: relative;
  padding-bottom: 16px;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -20px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gray-400);
  border: 2px solid white;
}
.timeline-item.email::before { background: var(--primary); }
.timeline-item.sms::before { background: var(--success); }
.timeline-item.system::before { background: var(--gray-400); }
.timeline-item .timeline-time {
  font-size: 11px;
  color: var(--gray-500);
}
.timeline-item .timeline-content {
  font-size: 13px;
  margin-top: 2px;
}

/* ===== DETAIL PANELS ===== */
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}
.detail-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.detail-field {
  margin-bottom: 10px;
}
.detail-field .field-label {
  font-size: 11px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.detail-field .field-value {
  font-size: 14px;
  font-weight: 500;
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 16px;
}
.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}
.tab:hover { color: var(--gray-900); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== MODALS ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: white;
  border-radius: 12px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-500);
}
.modal-body { padding: 24px; }
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ===== AI REVIEW PANEL ===== */
.ai-review {
  background: #f8f0ff;
  border: 1px solid #d4b5f0;
  border-radius: 8px;
  padding: 14px;
}
.ai-review .ai-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: #8e44ad;
  margin-bottom: 8px;
}
.ai-review .risk-low { color: var(--success); }
.ai-review .risk-medium { color: var(--warning); }
.ai-review .risk-high { color: var(--danger); }
.ai-review .flag-item {
  padding: 4px 0;
  font-size: 13px;
  border-bottom: 1px solid rgba(212,181,240,0.3);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-500);
}
.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.empty-state h3 {
  color: var(--gray-700);
  margin-bottom: 4px;
}

/* ===== LOADING ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: white;
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.3s ease;
  min-width: 280px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== MOBILE HEADER (hamburger menu) ===== */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--gray-900);
  color: white;
  align-items: center;
  padding: 0 16px;
  z-index: 101;
  gap: 12px;
}
.mobile-header .hamburger {
  background: none;
  border: none;
  color: white;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.mobile-header .brand {
  font-weight: 700;
  font-size: 16px;
}
.mobile-header .brand span { color: var(--info); }

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* ===== RESPONSIVE — Tablet (769px–1024px) ===== */
@media (max-width: 1024px) {
  .kanban-column { min-width: 220px; max-width: 260px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-body { padding: 16px; }
}

/* ===== RESPONSIVE — Mobile (≤768px) ===== */
@media (max-width: 768px) {
  /* Show mobile header, slide sidebar */
  .mobile-header { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .sidebar.open {
    transform: translateX(0);
    z-index: 100;
  }

  .main-content {
    margin-left: 0;
    padding-top: var(--header-height);
  }

  /* Page header */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 16px;
  }
  .page-header .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }
  .page-header h1 { font-size: 18px; }

  /* Page body */
  .page-body { padding: 12px; }

  /* Grids → single column on mobile */
  .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Override ALL inline 2/3-column grids inside page-body */
  .page-body [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  .modal-body [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Kanban */
  .kanban-board { padding-bottom: 8px; }
  .kanban-column { min-width: 240px; }

  /* Tabs scroll on mobile */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tab { white-space: nowrap; padding: 10px 14px; font-size: 12px; flex-shrink: 0; }

  /* Filter pills */
  .filter-pills { gap: 6px; }
  .filter-pill { padding: 5px 10px; font-size: 11px; }

  /* Toast */
  .toast-container { right: 10px; left: 10px; }
  .toast { min-width: auto; }

  /* Modal — nearly full width on mobile */
  .modal { width: 95%; max-height: 90vh; }

  /* Tables — smaller padding */
  td, th { padding: 8px 10px; font-size: 12px; }
  th { font-size: 10px; }

  /* Cards */
  .card-header { padding: 12px 14px; font-size: 13px; }
  .card-body { padding: 14px; }

  /* Sidebar footer area (visible when sidebar open) */
  .sidebar-footer { padding: 12px 16px; }
}

/* ===== RESPONSIVE — Small phone (≤480px) ===== */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card .stat-value { font-size: 22px; }
  .page-header h1 { font-size: 16px; }
  .login-card { padding: 24px; margin: 16px; }
  .login-card h1 { font-size: 20px; }
  .login-card .logo-text { font-size: 22px; }
  .kanban-column { min-width: 200px; }
  .filter-pill { padding: 4px 8px; font-size: 10px; }
}
