/* ============================================================
   Revela CRM — Internal application styles
   Clean, functional, information-dense.
   ============================================================ */

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

:root {
  /* Sidebar */
  --sidebar-bg:      #0f172a;
  --sidebar-text:    #cbd5e1;
  --sidebar-active:  #1e40af;
  --sidebar-hover:   #1e293b;
  --sidebar-border:  #1e293b;
  --sidebar-width:   220px;

  /* Content */
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --border-focus: #2563eb;

  /* Text */
  --text:      #0f172a;
  --text-muted:#64748b;
  --text-sm:   0.8125rem;

  /* Accent */
  --blue:    #2563eb;
  --blue-dk: #1d4ed8;

  /* Status */
  --green:   #16a34a;
  --amber:   #d97706;
  --red:     #dc2626;
  --gray:    #6b7280;

  /* Spacing */
  --gap:  1.25rem;
  --r:    6px;
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

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

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

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 10;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
}
.brand-name {
  display: block;
  font-weight: 700;
  font-size: 1rem;
  color: #f8fafc;
  letter-spacing: 0.02em;
}
.brand-sub {
  display: block;
  font-size: 0.7rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 2px;
}

.sidebar-nav {
  list-style: none;
  padding: 0.75rem 0;
  flex: 1;
}
.sidebar-nav li { }
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1.25rem;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.1s, color 0.1s;
}
.nav-link:hover {
  background: var(--sidebar-hover);
  color: #f8fafc;
  text-decoration: none;
}
.nav-link--active {
  background: var(--sidebar-hover);
  color: #f8fafc;
  border-left-color: #3b82f6;
}
.nav-icon {
  width: 16px; height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-user {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.sidebar-username {
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.logout-form { }
.logout-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 0.8125rem;
  cursor: pointer;
  padding: 0;
}
.logout-btn:hover { color: #f8fafc; }

/* ── Main content ── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  padding: 1.75rem var(--gap);
  max-width: 1200px;
}

/* ── Auth layout ── */
.auth-body {
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.auth-card {
  background: var(--surface);
  border-radius: var(--r);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.2);
}
.auth-card--wide { max-width: 460px; }
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-title { font-size: 1.125rem; font-weight: 700; color: var(--text); }
.auth-subtitle { font-size: 0.875rem; color: var(--text-muted); margin-top: 0.25rem; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-help {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 1rem;
  text-align: center;
}
.auth-help--warning { color: var(--amber); }
.mfa-qr-block { text-align: center; margin: 1rem 0; }
.mfa-manual-block { background: var(--bg); border-radius: var(--r); padding: 0.75rem; margin-bottom: 1rem; }
.mfa-manual-label { font-size: 0.8125rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.mfa-secret {
  display: block;
  font-family: monospace;
  font-size: 0.875rem;
  word-break: break-all;
  color: var(--text);
  background: var(--surface);
  padding: 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}
.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.page-header__left { }
.page-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.back-link {
  display: inline-block;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.back-link:hover { color: var(--text); }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 1.25rem;
  margin-bottom: var(--gap);
}
.card--full { }
.card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.875rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.875rem;
}
.card-header .card-title { margin-bottom: 0; }
.card-footer-link {
  margin-top: 0.75rem;
  font-size: 0.8125rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--r);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.btn--primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.btn--primary:hover { background: var(--blue-dk); border-color: var(--blue-dk); text-decoration: none; color: #fff; }
.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn--secondary:hover { background: var(--bg); text-decoration: none; }
.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn--ghost:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.btn--success {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.btn--success:hover { filter: brightness(0.9); text-decoration: none; color: #fff; }
.btn--sm  { padding: 0.3125rem 0.75rem; font-size: 0.8125rem; }
.btn--xs  { padding: 0.2rem 0.5rem; font-size: 0.75rem; }
.btn--full { width: 100%; }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-label { font-size: 0.875rem; font-weight: 500; color: var(--text); }
.required { color: var(--red); }
.form-input {
  padding: 0.5rem 0.75rem;
  font-size: 0.9375rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
textarea.form-input { resize: vertical; }
.form-input--sm { padding: 0.375rem 0.625rem; font-size: 0.875rem; }
.form-input--code {
  font-family: monospace;
  font-size: 1.25rem;
  letter-spacing: 0.15em;
  text-align: center;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-section {
  border: none;
  padding: 0;
  margin-bottom: 1.25rem;
}
.form-section-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.875rem;
  display: block;
}
.form-section-optional { font-weight: 400; }
.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
}
.form-container { max-width: 640px; }
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.inline-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.filter-input {
  padding: 0.375rem 0.625rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
}
.filter-input--search { min-width: 200px; }
.filter-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
}

/* ── Tables ── */
.table-scroll { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.table-link { font-weight: 500; }

.row--overdue { background: #fff5f5 !important; }
.row--overdue:hover { background: #fee2e2 !important; }
.row--done { opacity: 0.55; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2em 0.6em;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  white-space: nowrap;
  text-transform: capitalize;
}
.badge--lg { font-size: 0.875rem; padding: 0.3em 0.8em; }

/* Pipeline stage badges */
.badge--stage-new_lead        { background: #ede9fe; color: #4f46e5; }
.badge--stage-outreach_sent   { background: #e0f2fe; color: #0369a1; }
.badge--stage-engaged         { background: #cffafe; color: #0e7490; }
.badge--stage-qualified       { background: #d1fae5; color: #065f46; }
.badge--stage-proposal_sent   { background: #fef3c7; color: #92400e; }
.badge--stage-payment_pending { background: #ffedd5; color: #9a3412; }
.badge--stage-converted       { background: #dcfce7; color: #166534; }
.badge--stage-disqualified    { background: #f1f5f9; color: #475569; }
.badge--stage-suppressed      { background: #fee2e2; color: #991b1b; }

/* Client pipeline stage badges */
.badge--client-onboarding        { background: #ede9fe; color: #4f46e5; }
.badge--client-in_review         { background: #dbeafe; color: #1e40af; }
.badge--client-awaiting_qa       { background: #fef3c7; color: #92400e; }
.badge--client-report_delivered  { background: #d1fae5; color: #065f46; }
.badge--client-follow_up_pending { background: #e0f2fe; color: #0369a1; }
.badge--client-active_oversight  { background: #dcfce7; color: #166534; }
.badge--client-renewal_due       { background: #ffedd5; color: #9a3412; }
.badge--client-churned           { background: #f1f5f9; color: #475569; }

/* Report status badges */
.badge--report-not_started { background: #f1f5f9; color: #475569; }
.badge--report-in_progress { background: #dbeafe; color: #1e40af; }
.badge--report-draft_ready { background: #fef3c7; color: #92400e; }
.badge--report-qa          { background: #ede9fe; color: #4f46e5; }
.badge--report-delivered   { background: #dcfce7; color: #166534; }
.badge--report-closed      { background: #f1f5f9; color: #6b7280; }

/* Flag badges */
.badge--flag-alert   { background: #fee2e2; color: #991b1b; }
.badge--flag-renewal { background: #ffedd5; color: #9a3412; }
.badge--matched      { background: #d1fae5; color: #065f46; }
.badge--unmatched    { background: #fff7ed; color: #9a3412; }

/* Task status badges */
.badge--status-open        { background: #dbeafe; color: #1e40af; }
.badge--status-in_progress { background: #fef3c7; color: #92400e; }
.badge--status-complete    { background: #dcfce7; color: #166534; }
.badge--status-blocked     { background: #fee2e2; color: #991b1b; }
.badge--status-cancelled   { background: #f1f5f9; color: #475569; }

/* Priority badges */
.badge--priority-high   { background: #fee2e2; color: #991b1b; }
.badge--priority-medium { background: #fef3c7; color: #92400e; }
.badge--priority-low    { background: #f1f5f9; color: #475569; }

/* ── Scorecard risk bands ── */
.badge--risk-high     { background: #fee2e2; color: #991b1b; }
.badge--risk-moderate { background: #fef3c7; color: #92400e; }
.badge--risk-lower    { background: #d1fae5; color: #065f46; }

/* ── Alerts ── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--r);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.alert--error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert--info  { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Dashboard layout ── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}
.card--full { grid-column: 1 / -1; }

/* Stage tiles */
.stage-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.stage-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.875rem 1.25rem;
  border-radius: var(--r);
  border: 1px solid var(--border);
  text-decoration: none;
  min-width: 100px;
  transition: transform 0.1s, box-shadow 0.1s;
}
.stage-tile:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.08); text-decoration: none; }
.stage-tile__count { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stage-tile__label { font-size: 0.75rem; margin-top: 0.3rem; color: var(--text-muted); text-align: center; }
.stage-tile--new_lead        { border-color: #c4b5fd; }
.stage-tile--outreach_sent   { border-color: #7dd3fc; }
.stage-tile--engaged         { border-color: #67e8f9; }
.stage-tile--qualified       { border-color: #6ee7b7; }
.stage-tile--proposal_sent   { border-color: #fcd34d; }
.stage-tile--payment_pending { border-color: #fdba74; }

/* Client delivery pipeline stage tiles */
.stage-tile--client-onboarding        { border-color: #a5b4fc; }
.stage-tile--client-in_review         { border-color: #7dd3fc; }
.stage-tile--client-awaiting_qa       { border-color: #fcd34d; }
.stage-tile--client-report_delivered  { border-color: #6ee7b7; }
.stage-tile--client-follow_up_pending { border-color: #fdba74; }
.stage-tile--client-active_oversight  { border-color: #34d399; }
.stage-tile--client-renewal_due       { border-color: #f87171; }

/* ── Detail layout ── */
.detail-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: var(--gap);
  align-items: start;
}
.detail-main  { }
.detail-side  { }

/* Info grid (definition list) */
.info-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.5rem 1rem;
  font-size: 0.875rem;
}
.info-grid dt { color: var(--text-muted); font-weight: 500; }
.info-grid dd { color: var(--text); }

/* ── Activity log ── */
.activity-list { list-style: none; display: flex; flex-direction: column; gap: 0; }
.activity-item {
  display: flex;
  gap: 0.625rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.15em 0.5em;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  flex-shrink: 0;
  height: fit-content;
  margin-top: 2px;
}
.activity-badge--manual        { background: #dbeafe; color: #1e40af; }
.activity-badge--stage_change  { background: #ede9fe; color: #4f46e5; }
.activity-badge--system        { background: #f1f5f9; color: #475569; }
.activity-badge--stripe_event  { background: #d1fae5; color: #065f46; }
.activity-badge--task_created        { background: #fef3c7; color: #92400e; }
.activity-badge--task_completed      { background: #dcfce7; color: #166534; }
.activity-badge--calendly_booking    { background: #d1fae5; color: #065f46; }
.activity-badge--calendly_cancellation { background: #fee2e2; color: #991b1b; }
.activity-badge--form_submission     { background: #ede9fe; color: #4f46e5; }
.activity-body { flex: 1; min-width: 0; }
.activity-content {
  font-size: 0.875rem;
  color: var(--text);
  margin: 0;
  word-break: break-word;
}
.activity-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.pagination-count { font-size: 0.8125rem; color: var(--text-muted); }

/* ── Empty states ── */
.empty-state { color: var(--text-muted); font-size: 0.875rem; font-style: italic; }
.empty-block {
  text-align: center;
  padding: 3rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
}

/* ── Utilities ── */
.text-muted   { color: var(--text-muted); }
.text-sm      { font-size: var(--text-sm); }
.text-mono    { font-family: monospace; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .detail-layout   { grid-template-columns: 1fr; }
  .dashboard-grid  { grid-template-columns: 1fr; }
  .form-row        { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  :root { --sidebar-width: 0px; }
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 1rem; }
}
