:root {
  --navy: #03627b;
  --teal: #008283;
  --amber: #f28c38;
  --red: #c34a4a;
  --ink: #000000;
  --muted: #58666b;
  --line: #d6e2e4;
  --surface: #ffffff;
  --background: #f4f7f7;
  --font-primary: "Poppins", sans-serif;
  --font-text: "Roboto", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--background); }
body { margin: 0; color: var(--ink); background: var(--background); font: 400 14px/1.45 var(--font-text); letter-spacing: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-header { height: 68px; padding: 0 clamp(16px, 3vw, 42px); display: flex; align-items: center; justify-content: space-between; gap: 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand-block { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; background: var(--navy); color: white; font-size: 19px; font-weight: 700; border-radius: 6px; }
.brand-block h1 { margin: 0; color: var(--navy); font-family: var(--font-primary); font-size: 19px; font-weight: 600; line-height: 1.1; }
.brand-block p { margin: 3px 0 0; color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.sync-status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.sync-status svg { width: 15px; color: var(--teal); }
.icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; padding: 0; color: var(--navy); background: white; border: 1px solid var(--line); border-radius: 5px; text-decoration: none; }
.icon-button:hover { border-color: var(--navy); background: #f7fafb; }
.icon-button svg { width: 17px; height: 17px; }

main { width: min(1540px, 100%); margin: 0 auto; padding: 20px clamp(12px, 2.5vw, 36px) 48px; }
.view-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.view-tab { min-height: 40px; display: inline-flex; align-items: center; gap: 7px; padding: 0 14px; color: var(--muted); background: transparent; border: 0; border-bottom: 3px solid transparent; font-weight: 500; }
.view-tab:hover { color: var(--navy); background: #edf5f5; }
.view-tab.active { color: var(--navy); border-bottom-color: var(--amber); font-weight: 500; }
.view-tab svg { width: 16px; height: 16px; }
.filters { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)) auto; gap: 10px; align-items: end; padding: 14px; margin-bottom: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.filters label { min-width: 0; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; }
.filters input, .filters select { width: 100%; height: 36px; margin-top: 5px; padding: 0 9px; color: var(--ink); background: white; border: 1px solid #cbd5dc; border-radius: 4px; text-transform: none; }
.filter-button { height: 36px; display: flex; align-items: center; gap: 7px; padding: 0 15px; color: white; background: var(--navy); border: 1px solid var(--navy); border-radius: 4px; font-weight: 600; }
.filter-button svg { width: 15px; }

.section-heading, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading { margin: 0 0 12px; }
.section-heading span, .panel-heading span { color: var(--teal); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.section-heading h2 { margin: 2px 0 0; color: var(--navy); font-family: var(--font-primary); font-size: 20px; font-weight: 600; }
.section-heading p { color: var(--muted); font-size: 12px; }
.panel-heading { min-height: 42px; padding: 14px 16px 8px; }
.panel-heading h3 { margin: 2px 0 0; color: var(--navy); font-family: var(--font-primary); font-size: 14px; font-weight: 600; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.metric { min-height: 98px; padding: 15px 16px; background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--navy); border-radius: 6px; }
.metric:nth-child(2), .metric:nth-child(6) { border-top-color: var(--amber); }
.metric:nth-child(3), .metric:nth-child(5) { border-top-color: var(--teal); }
.metric:nth-child(4) { border-top-color: var(--red); }
.metric span { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; }
.metric strong { display: block; margin-top: 8px; color: var(--navy); font-family: var(--font-primary); font-size: 22px; font-weight: 600; line-height: 1.1; }

.analytics-grid { display: grid; grid-template-columns: 1.4fr 0.8fr; gap: 12px; margin-bottom: 12px; }
.analytics-grid.equal { grid-template-columns: 1fr 1fr; }
.panel { margin-bottom: 12px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.analytics-grid .panel { margin-bottom: 0; }
.chart-frame { position: relative; height: 300px; padding: 4px 14px 14px; }
.funnel-list { display: grid; gap: 8px; padding: 8px 16px 18px; }
.funnel-row { display: grid; grid-template-columns: minmax(130px, 240px) 1fr 64px 90px; align-items: center; gap: 12px; min-height: 32px; }
.funnel-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.funnel-track { height: 24px; background: #eef2f4; border: 1px solid #dce3e8; border-radius: 4px; overflow: hidden; }
.funnel-fill { min-width: 3px; height: 100%; background: var(--navy); }
.funnel-rate { color: var(--navy); font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }
.funnel-value { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

.table-scroll { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 10px 14px; text-align: left; border-top: 1px solid var(--line); }
th { color: var(--muted); background: #fafbfc; font-size: 10px; text-transform: uppercase; }
td { font-size: 12px; }
tbody tr:hover { background: #f8fafb; }
.rate { color: var(--teal); font-weight: 700; }
.status-pill { display: inline-flex; padding: 3px 7px; border-radius: 4px; background: #edf3f5; color: var(--navy); font-size: 10px; font-weight: 700; }
.status-pill.won { color: #08675f; background: #e5f4f1; }
.status-pill.lost { color: #9f3838; background: #faecec; }
.leads-heading { flex-wrap: wrap; }
.table-filters { display: flex; align-items: end; flex-wrap: wrap; gap: 8px; padding: 8px 16px 14px; }
.table-filters > label:not(.search-box) { min-width: 150px; color: var(--muted); font-size: 10px; font-weight: 500; text-transform: uppercase; }
.table-filters select { width: 100%; height: 36px; margin-top: 4px; padding: 0 8px; color: var(--ink); background: white; border: 1px solid #cbd5dc; border-radius: 4px; text-transform: none; }
.search-box { width: min(330px, 100%); height: 36px; display: flex; align-items: center; gap: 7px; padding: 0 10px; border: 1px solid #cbd5dc; border-radius: 4px; }
.search-box svg { width: 15px; color: var(--muted); }
.search-box input { width: 100%; border: 0; outline: 0; }
.pagination { min-height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.pagination div { display: flex; gap: 6px; }
.pagination button:disabled { opacity: .4; cursor: default; }

.loading-state { min-height: 240px; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); }
.loading-state[hidden] { display: none; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
.error-banner { margin: 14px 0; padding: 12px 14px; color: #8c2f2f; background: #fff1f1; border: 1px solid #edc7c7; border-radius: 5px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .filters { grid-template-columns: repeat(4, 1fr); }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .app-header { height: 62px; }
  .sync-status { display: none; }
  main { padding-top: 12px; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-button { justify-content: center; }
  .analytics-grid, .analytics-grid.equal { grid-template-columns: 1fr; }
  .chart-frame { height: 270px; }
  .funnel-row { grid-template-columns: minmax(100px, 130px) 1fr; }
  .funnel-rate, .funnel-value { display: none; }
}
@media (max-width: 460px) {
  .filters, .metrics-grid { grid-template-columns: 1fr; }
  .view-tabs { overflow-x: auto; }
  .view-tab { flex: 1 0 auto; justify-content: center; }
  .table-filters { align-items: stretch; flex-direction: column; }
  .table-filters > label:not(.search-box) { width: 100%; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading p { margin: 0; }
}
