:root {
  --bg-color: #f3f5f9;
  --card-bg: #ffffff;
  --card-border: #e3e8f0;
  --text-color: #1a202c;
  --subtle-text: #6b7280;
  --accent: #377dff;
  --positive: #16a34a;
  --negative: #dc2626;
  --goal: #f59e0b;
  --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-family);
  background: #ebedf0;
  color: var(--text-color);
}

.leads-page {
  background: #ebedf0;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  padding: 2.5rem 1.5rem;
}

.metric-card {
  width: min(960px, 100%);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 1.75rem;
  box-shadow: 0 20px 60px -25px rgba(40, 60, 90, 0.25);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: relative;
}

.leads-card {
  gap: 1.75rem;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.76);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  z-index: 5;
  transition: opacity 0.2s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 4px solid rgba(55, 125, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}

.loading-text {
  font-weight: 600;
  color: var(--subtle-text);
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.lead-summary-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.lead-summary-tiles .summary-block {
  background: rgba(59, 130, 246, 0.04);
  border-radius: 14px;
  padding: 1rem 1.2rem;
}

.lead-summary-tiles .summary-label {
  font-size: 0.75rem;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--subtle-text);
}

.lead-summary-tiles .summary-amount {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-color);
}

.summary-help-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.35rem;
}

.summary-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 0.35rem;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  background: rgba(37, 99, 235, 0.15);
  color: #1d4ed8;
  cursor: pointer;
  user-select: none;
  border: none;
}

.summary-help:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.summary-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  min-width: 220px;
  max-width: 260px;
  background: #0f172a;
  color: #f8fafc;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  font-size: 0.75rem;
  line-height: 1.4;
  box-shadow: 0 12px 30px -18px rgba(15, 23, 42, 0.45);
  z-index: 10;
}

.summary-tooltip::after {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: transparent transparent #0f172a transparent;
}

.summary-help-wrapper:hover .summary-tooltip,
.summary-help-wrapper:focus-within .summary-tooltip {
  display: block;
}

.leads-chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 1.5rem;
}

.lead-bar-card,
.lead-donut-card {
  min-height: 300px;
  display: flex;
  flex-direction: column;
}

.lead-bar-card canvas,
.lead-donut-card canvas {
  flex: 1 1 auto;
}

.lead-channel-cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2rem;
  margin-top: 0.75rem;
}

.lead-channel-value-card,
.lead-channel-weight-card {
  min-height: 440px;
  display: flex;
  flex-direction: column;
  padding-bottom: 0.75rem;
}

.lead-channel-value-card canvas,
.lead-channel-weight-card canvas {
  flex: 1 1 auto;
  min-height: 380px;
  display: block;
}

.lead-channel-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.lead-channel-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.12);
  color: #1f2937;
  border: 1px solid rgba(59, 130, 246, 0.25);
}

.lead-channel-tag-call {
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(37, 99, 235, 0.28);
}

.lead-channel-tag-form {
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(5, 150, 105, 0.28);
}

.lead-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.25rem 0;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.lead-filters .filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 160px;
}

.lead-filters .filter-group.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  min-width: auto;
}

.lead-filters label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--subtle-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lead-filters select,
.lead-filters input[type='search'] {
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-color);
  background: #f8fafc;
}

.lead-filters select:focus,
.lead-filters input[type='search']:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.lead-table {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.lead-table-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.lead-table-total {
  font-size: 0.85rem;
  color: var(--subtle-text);
}

.lead-table-wrapper {
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 14px;
  overflow: hidden;
  background: #f9fbfd;
}

.lead-table table {
  width: 100%;
  border-collapse: collapse;
}

.lead-table thead {
  background: rgba(15, 23, 42, 0.05);
}

.lead-table th,
.lead-table td {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  text-align: left;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.lead-table tbody tr:last-child td {
  border-bottom: none;
}

.lead-table-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--subtle-text);
}

.lead-row .status-won {
  color: #15803d;
  font-weight: 600;
}

.lead-row .status-lost {
  color: #dc2626;
  font-weight: 600;
}

.lead-row .status-open {
  color: #0f172a;
  font-weight: 600;
}

.lead-detail-toggle {
  border: 1px solid rgba(37, 99, 235, 0.45);
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
}

.lead-detail-toggle:hover {
  background: rgba(37, 99, 235, 0.15);
}

.lead-detail-row {
  background: rgba(59, 130, 246, 0.04);
}

.lead-detail-row.hidden {
  display: none;
}

.lead-detail-wrapper {
  display: grid;
  gap: 1rem;
}

.lead-detail-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--subtle-text);
}

.lead-channel-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  box-shadow: 0 12px 25px -18px rgba(15, 23, 42, 0.25);
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.lead-channel-heading {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.45rem;
}

.lead-channel-type {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #1d4ed8;
}

.lead-channel-key {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-color);
}

.lead-channel-summary {
  margin: 0;
  font-size: 0.8rem;
  color: var(--subtle-text);
  line-height: 1.5;
}

.lead-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
}

.lead-pagination .refresh-button {
  font-size: 0.8rem;
  padding: 0.4rem 1rem;
}

.lead-page-info {
  font-size: 0.85rem;
  color: var(--subtle-text);
  min-width: 120px;
  text-align: center;
}

.lead-detail-toggle:disabled,
.lead-pagination .refresh-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .leads-chart-grid {
    grid-template-columns: 1fr;
  }

  .lead-summary-tiles {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }

  .lead-filters {
    gap: 0.75rem;
  }
}

@media (max-width: 720px) {
  .lead-table th,
  .lead-table td {
    padding: 0.6rem 0.75rem;
  }

  .lead-summary-tiles .summary-amount {
    font-size: 1.2rem;
  }

  .lead-detail-wrapper {
    grid-template-columns: 1fr;
  }
}


.goal-control {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 220px;
}

.refresh-button {
  align-self: flex-start;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 12px 25px -15px rgba(37, 99, 235, 0.7);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.refresh-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px -14px rgba(37, 99, 235, 0.8);
}

.refresh-button:active {
  transform: translateY(0);
}

.goal-control-title {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.73rem;
  color: var(--subtle-text);
  font-weight: 600;
}

.goal-select-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.goal-select {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1 1 120px;
}

.goal-select-label {
  font-size: 0.75rem;
  color: var(--subtle-text);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.goal-control select {
  appearance: none;
  border: 1px solid rgba(55, 125, 255, 0.35);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-weight: 600;
  font-size: 0.9rem;
  background: linear-gradient(135deg, rgba(55, 125, 255, 0.12), rgba(55, 125, 255, 0.2));
  color: var(--accent);
  cursor: pointer;
}

.goal-control select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(55, 125, 255, 0.15);
}

.metric-title-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.metric-header h1 {
  font-size: 1.5rem;
  margin: 0;
}

.metric-subtitle {
  margin: 0.25rem 0 0;
  color: var(--subtle-text);
  font-size: 0.95rem;
}

.metric-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  background: rgba(55, 125, 255, 0.12);
  border-radius: 16px;
  font-size: 1.6rem;
}

.metric-pill {
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  background: rgba(55, 125, 255, 0.12);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
}

.metric-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  align-items: start;
}

.branch-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.branch-tile {
  background: linear-gradient(135deg, #ffffff 0%, #f3f6ff 100%);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 16px;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.branch-name {
  font-weight: 600;
  color: var(--text-color);
}

.branch-chart {
  height: 340px;
}

.branch-metric-rows {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.branch-metric-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.branch-metric-label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--subtle-text);
}


.branch-metric-value {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-color);
}

.branch-metric-change {
  font-size: 0.72rem;
  font-weight: 600;
}

.latest-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.summary-block {
  background: linear-gradient(135deg, #f9fbff 0%, #eef4ff 100%);
  border-radius: 18px;
  padding: 1rem 1.2rem;
  border: 1px solid rgba(55, 125, 255, 0.12);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.summary-period,
.latest-label,
#latest-ytd-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.73rem;
  color: var(--subtle-text);
  font-weight: 600;
}

.summary-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.73rem;
  color: var(--subtle-text);
  font-weight: 600;
}

.summary-amount {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.summary-caption {
  color: var(--subtle-text);
  font-size: 0.95rem;
}

.summary-stat {
  background: linear-gradient(135deg, #f9fbff 0%, #eef4ff 100%);
  border-radius: 18px;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border: 1px solid rgba(55, 125, 255, 0.1);
}

.chart-card {
  background: #f9fbff;
  border-radius: 24px;
  padding: 1.5rem;
  border: 1px solid rgba(55, 125, 255, 0.12);
  height: 320px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.chart-card canvas {
  flex: 1;
  width: 100%;
  height: 100% !important;
}

#sparkline {
  max-height: 100%;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.chart-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.chart-header p {
  margin: 0;
  color: var(--subtle-text);
  font-size: 0.9rem;
}



@media (max-width: 640px) {
  .metric-card {
    border-radius: 16px;
    padding: 1.5rem;
  }

  .metric-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .metric-summary {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
}


.summary-figure {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-color);
}

.summary-subscript {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--subtle-text);
}

.summary-figure .summary-subscript {
  color: inherit;
}

.summary-subscript.positive {
  color: var(--positive);
}

.summary-subscript.negative {
  color: var(--negative);
}

.summary-subscript.neutral {
  color: var(--subtle-text);
}

.metric-summary.goals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.branch-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.branch-trend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}

.branch-trend-card {
  background: linear-gradient(135deg, #ffffff 0%, #f9fbff 100%);
  border: 1px solid rgba(55, 125, 255, 0.12);
  border-radius: 18px;
  padding: 0.85rem 1rem 1rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

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

.branch-trend-subtitle {
  font-size: 0.72rem;
  color: var(--subtle-text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.branch-trend-canvas {
  width: 100%;
  height: 160px !important;
}

.empty-state {
  color: var(--subtle-text);
  font-size: 0.9rem;
}
