/* ─── Perotto CRM ─── Brand: Black, Blue, Mushroom ─── */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');

:root {
  --charcoal: #1A1A1A;
  --charcoal-light: #2a2a2a;
  --charcoal-lighter: #3a3a3a;
  --cyan: #0FE4EA;
  --cyan-dark: #0bc5ca;
  --cyan-light: #5eedf1;
  --cyan-bg: rgba(15, 228, 234, 0.08);
  --white: #ffffff;
  --off-white: #f5f2ec;
  --gray-50: #f5f2ec;
  --gray-100: #ece8e0;
  --gray-200: #ddd8cf;
  --gray-300: #c5c0b7;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.1);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.1);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.1);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.1);
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --transition: 150ms ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; }
body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: var(--off-white);
  color: var(--charcoal);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--cyan-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ─── */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: var(--charcoal);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.sidebar::-webkit-scrollbar { display: none; }
.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--charcoal-light);
}
.sidebar-logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--white);
}
.sidebar-logo span { color: var(--cyan); }
.sidebar-subtitle {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 20px;
  color: var(--gray-300);
  font-size: 0.85rem; font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--charcoal-light); color: var(--white); text-decoration: none; }
.nav-item.active {
  background: var(--charcoal-light);
  color: var(--cyan);
  border-left-color: var(--cyan);
}
.nav-item .icon { width: 20px; text-align: center; font-size: 1.1rem; }
.nav-divider { height: 1px; background: var(--charcoal-light); margin: 4px 16px; }
.nav-label {
  padding: 10px 20px 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--gray-500);
  font-weight: 600;
}
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--charcoal-light);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 32px; height: 32px;
  background: var(--cyan);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem; color: var(--white);
}
.user-info { flex: 1; }
.user-name { font-size: 0.85rem; font-weight: 600; color: var(--white); }
.user-role { font-size: 0.7rem; color: var(--gray-400); text-transform: capitalize; }

.main-content {
  flex: 1;
  margin-left: 240px;
  min-height: 100vh;
}
.page-header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 20px 32px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: 1.4rem; font-weight: 700; color: var(--charcoal); }
.page-subtitle { font-size: 0.85rem; color: var(--gray-500); margin-top: 2px; }
.page-body { padding: 24px 32px; }

/* ─── Cards ─── */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 1rem; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ─── Stats ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 0.8rem; color: var(--gray-500); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 1.8rem; font-weight: 700; margin-top: 4px; color: var(--charcoal); }
.stat-value.cyan { color: var(--cyan-dark); }
.stat-sub { font-size: 0.8rem; color: var(--gray-400); margin-top: 4px; }

/* ─── Pipeline ─── */
.pipeline {
  display: flex; gap: 2px;
  margin-bottom: 24px;
  background: var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.pipeline-stage {
  flex: 1;
  padding: 14px 12px;
  text-align: center;
  cursor: pointer;
  background: var(--white);
  transition: all var(--transition);
  position: relative;
}
.pipeline-stage:hover { background: var(--cyan-bg); }
.pipeline-stage.active { background: var(--cyan-bg); }
.pipeline-stage.active::after {
  content: '';
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 3px; background: var(--cyan);
}
.pipeline-stage-name { font-size: 0.75rem; font-weight: 600; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.5px; }
.pipeline-stage-count { font-size: 1.5rem; font-weight: 700; color: var(--charcoal); margin-top: 2px; }
.pipeline-stage-value { font-size: 0.75rem; color: var(--gray-400); margin-top: 2px; }

/* ─── Table ─── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--gray-50); }
th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
  vertical-align: middle;
}
tr { cursor: pointer; transition: background var(--transition); }
tbody tr:hover { background: var(--gray-50); }
.ref-link { font-variant-numeric: tabular-nums; font-size: 0.85rem; font-weight: 500; color: var(--cyan-dark); }
.borrower-name { font-weight: 600; }
.amount { font-variant-numeric: tabular-nums; font-weight: 500; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--gray-400); }
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }

/* ─── Badges ─── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-stage {
  background: var(--cyan-bg); color: var(--cyan-dark);
}
.badge-enquiry { background: var(--blue-bg); color: var(--blue); }
.badge-terms { background: var(--amber-bg); color: var(--amber); }
.badge-application { background: #f3e8ff; color: #7c3aed; }
.badge-offer { background: #cffafe; color: #0891b2; }
.badge-pre_completion { background: #fce7f3; color: #db2777; }
.badge-completed { background: var(--green-bg); color: var(--green); }
.badge-live { background: var(--green-bg); color: var(--green); }
.badge-redeemed { background: var(--gray-100); color: var(--gray-500); }
.badge-declined { background: var(--red-bg); color: var(--red); }
.badge-withdrawn { background: var(--gray-100); color: var(--gray-600); }

.badge-priority-urgent { background: var(--red-bg); color: var(--red); }
.badge-priority-high { background: var(--amber-bg); color: var(--amber); }
.badge-priority-normal { background: var(--gray-100); color: var(--gray-500); }
.badge-priority-low { background: var(--gray-50); color: var(--gray-400); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: #1a1a1a; color: var(--white); }
.btn-primary:hover { background: #1a1a1a; }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: var(--red); color: var(--white); }
.btn-success { background: var(--green-bg); color: var(--green); }
.btn-success:hover { background: var(--green); color: var(--white); }
.btn-ghost { background: transparent; color: var(--gray-500); }
.btn-ghost:hover { background: var(--gray-100); color: var(--charcoal); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; }

/* ─── Forms ─── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  color: var(--charcoal);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px var(--cyan-bg);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-hint { font-size: 0.75rem; color: var(--gray-400); margin-top: 4px; }
.form-error { font-size: 0.75rem; color: var(--red); margin-top: 4px; }
.form-section {
  margin-bottom: 28px;
}
.form-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--charcoal);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--cyan-bg);
}

/* ─── Tasks ─── */
.task-list { list-style: none; }
.task-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
  transition: background var(--transition);
}
.task-item:hover { background: var(--gray-50); }
.task-item:last-child { border-bottom: none; }
.task-checkbox {
  width: 22px; height: 22px;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.task-checkbox:hover { border-color: var(--cyan); }
.task-checkbox.completed {
  background: var(--green);
  border-color: var(--green);
  color: var(--white);
}
.task-checkbox.blocked {
  background: var(--red-bg);
  border-color: var(--red);
}
.task-checkbox.in_progress {
  background: var(--cyan-bg);
  border-color: var(--cyan);
}
.task-content { flex: 1; min-width: 0; }
.task-title { font-size: 0.9rem; font-weight: 500; }
.task-title.completed { text-decoration: line-through; color: var(--gray-400); }
.task-description { font-size: 0.8rem; color: var(--gray-400); margin-top: 2px; }
.task-meta { display: flex; gap: 12px; align-items: center; flex-shrink: 0; }
.task-stage-group { margin-bottom: 20px; }
.task-stage-header {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gray-500);
  padding: 8px 16px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

/* ─── Activity / Timeline ─── */
.timeline { list-style: none; position: relative; }
.timeline::before {
  content: '';
  position: absolute;
  left: 19px; top: 0; bottom: 0;
  width: 2px;
  background: var(--gray-200);
}
.timeline-item {
  display: flex; gap: 12px;
  padding: 8px 0;
  position: relative;
}
.timeline-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--gray-300);
  margin-top: 5px;
  flex-shrink: 0;
  z-index: 1;
  border: 2px solid var(--white);
}
.timeline-dot.stage { background: var(--cyan); width: 14px; height: 14px; margin-top: 3px; margin-left: -2px; }
.timeline-content { flex: 1; }
.timeline-text { font-size: 0.85rem; color: var(--gray-600); }
.timeline-text strong { color: var(--charcoal); }
.timeline-time { font-size: 0.75rem; color: var(--gray-400); margin-top: 2px; }

/* ─── Notes ─── */
.note-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
}
.note-item:last-child { border-bottom: none; }
.note-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.note-author { font-size: 0.8rem; font-weight: 600; color: var(--gray-600); }
.note-time { font-size: 0.75rem; color: var(--gray-400); }
.note-body { font-size: 0.9rem; color: var(--charcoal); line-height: 1.5; white-space: pre-wrap; }

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  transform: translateY(20px);
  transition: transform var(--transition);
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-title { font-size: 1.15rem; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: var(--gray-100);
  border-radius: var(--radius);
  cursor: pointer; font-size: 1.2rem;
  color: var(--gray-500);
}
.modal-close:hover { background: var(--gray-200); color: var(--charcoal); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
  display: flex; justify-content: flex-end; gap: 8px;
  background: var(--gray-50);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  flex-shrink: 0;
}

/* ─── Progress indicator ─── */
.stage-progress {
  display: flex; align-items: center; gap: 0;
  margin-bottom: 24px;
}
.stage-step {
  display: flex; align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-400);
}
.stage-step.completed { color: var(--green); }
.stage-step.current { color: var(--cyan-dark); }
.stage-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  margin-right: 6px;
  border: 2px solid var(--gray-300);
  background: var(--white);
}
.stage-step.completed .stage-dot { background: var(--green); border-color: var(--green); color: var(--white); }
.stage-step.current .stage-dot { background: var(--cyan); border-color: var(--cyan); color: var(--white); }
.stage-connector { width: 32px; height: 2px; background: var(--gray-200); margin: 0 4px; }
.stage-step.completed + .stage-connector { background: var(--green); }

/* ─── Detail page layout ─── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
}
.detail-main { min-width: 0; }
.detail-sidebar { display: flex; flex-direction: column; gap: 16px; }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
}
.field-item {}
.field-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.field-value {
  font-size: 0.9rem;
  color: var(--charcoal);
  font-weight: 500;
}
.field-value.mono { font-variant-numeric: tabular-nums; }
.field-value.empty { color: var(--gray-300); font-style: italic; font-weight: 400; }

/* ─── Tabs ─── */
.tabs { display: flex; border-bottom: 2px solid var(--gray-200); margin-bottom: 20px; }
.tab {
  padding: 10px 20px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
}
.tab:hover { color: var(--charcoal); }
.tab.active { color: var(--cyan-dark); border-bottom-color: var(--cyan); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Search / Toolbar ─── */
.toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-input {
  flex: 1; min-width: 200px;
  padding: 9px 12px 9px 36px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  background: var(--white);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}
.search-input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px var(--cyan-bg); }

/* ─── Toast notifications ─── */
.toast-container {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 10000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease;
  max-width: 360px;
}
.toast-success { background: var(--green); color: var(--white); }
.toast-error { background: var(--red); color: var(--white); }
.toast-info { background: var(--charcoal); color: var(--white); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── Login page ─── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--charcoal);
}
.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--charcoal);
}
.login-logo h1 span { color: var(--cyan); }
.login-logo p {
  color: var(--gray-400);
  font-size: 0.85rem;
  margin-top: 4px;
}

/* ─── Responsive ─── */
@media (max-width: 1024px) {
  .detail-grid { grid-template-columns: 1fr; }
  .detail-sidebar { order: -1; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .page-header { padding: 16px 20px; }
  .page-body { padding: 16px 20px; }
  .pipeline { flex-direction: column; }
  .field-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ─── Utility ─── */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--gray-400); }
.text-sm { font-size: 0.8rem; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
