:root {
  color-scheme: dark;
  --ink-950: #03050a;
  --ink-900: #070b12;
  --ink-850: #0a101a;
  --ink-800: #0d1420;
  --ink-700: #152132;
  --ink-600: #213149;
  --line: #1b2c43;
  --line-strong: #294664;
  --text: #f4f8fc;
  --text-soft: #a8b7c8;
  --text-muted: #71849a;
  --blue-600: #1474e5;
  --blue-500: #2389ff;
  --blue-400: #5aabff;
  --blue-300: #8bc5ff;
  --blue-200: #c4e1ff;
  --success: #25a7ff;
  --danger: #ff6577;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.3);
  --sidebar-width: 248px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--ink-950);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  color: inherit;
  font: inherit;
}

button,
a,
select,
input {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

button,
select {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

:focus-visible {
  outline: 2px solid var(--blue-400);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  transform: translateY(-150%);
  border-radius: var(--radius-sm);
  background: var(--blue-500);
  color: var(--ink-950);
  padding: 10px 14px;
  font-weight: 750;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: #05080e;
  padding: 28px 20px 24px;
}

.brand-lockup {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 4px;
  min-height: 46px;
  padding: 0 8px;
}

.brand-logo {
  display: block;
  width: 128px;
  height: 32px;
  object-fit: contain;
  object-position: left center;
}

.brand-domain,
.eyebrow,
.section-kicker,
.page-intro,
.sidebar-principle,
.section-note,
footer p,
.error-panel p {
  margin: 0;
}

.brand-domain {
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
}

.sidebar nav {
  display: grid;
  gap: 6px;
  margin-top: 54px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.nav-link:hover {
  border-color: var(--line);
  background: var(--ink-800);
  color: var(--text);
}

.nav-link.is-active {
  border-color: #17395d;
  background: #0c1a2a;
  color: var(--blue-300);
}

.nav-icon {
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
}

.sidebar-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink-850);
  padding: 13px;
}

.sidebar-note strong,
.sidebar-note span {
  display: block;
}

.sidebar-note strong {
  font-size: 12px;
}

.sidebar-note div > span {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 11px;
}

.status-dot {
  display: inline-block;
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--blue-400);
  box-shadow: 0 0 0 4px rgba(35, 137, 255, 0.12);
}

.sidebar-principle {
  margin-top: 18px;
  padding: 0 8px;
  color: #56677a;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.08em;
  line-height: 1.65;
  text-transform: uppercase;
}

main {
  width: min(100%, 1540px);
  margin: 0 auto;
  padding: 40px clamp(24px, 4vw, 64px) 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
  padding-bottom: 30px;
}

.eyebrow,
.section-kicker {
  color: var(--blue-400);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: -0.025em;
}

h1 {
  max-width: 720px;
  margin-top: 9px;
  font-size: clamp(27px, 3.2vw, 43px);
  font-weight: 760;
  line-height: 1.08;
}

h2 {
  margin-top: 4px;
  font-size: 17px;
  font-weight: 700;
}

.page-intro {
  max-width: 680px;
  margin-top: 13px;
  color: var(--text-soft);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--ink-850);
  color: var(--text-soft);
  padding: 0 13px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.mode-pill .status-dot {
  margin-top: 0;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0 15px;
  font-size: 12px;
  font-weight: 760;
  text-decoration: none;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button svg {
  width: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.button-primary {
  background: var(--blue-500);
  color: #02060b;
}

.button-primary:hover {
  background: var(--blue-400);
}

.button-secondary {
  border-color: var(--line-strong);
  background: var(--ink-800);
}

.filter-panel,
.panel,
.kpi-card {
  border: 1px solid var(--line);
  background: var(--ink-900);
  box-shadow: var(--shadow);
}

.filter-panel {
  border-radius: var(--radius-lg);
  padding: 18px 20px 20px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 23px;
}

.section-heading.compact {
  align-items: center;
  margin-bottom: 15px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--blue-400);
  padding: 4px;
  font-size: 11px;
  font-weight: 720;
}

.text-button:hover {
  color: var(--blue-200);
}

#filters-form {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 12px;
}

.field {
  min-width: 0;
}

.field label {
  display: block;
  margin: 0 0 6px 2px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.field select,
.field input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background-color: var(--ink-800);
  color: var(--text-soft);
  padding: 0 11px;
  font-size: 12px;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.field select:hover,
.field input:hover,
.field select:focus,
.field input:focus {
  border-color: var(--line-strong);
  background-color: #101a28;
}

.field input::-webkit-calendar-picker-indicator {
  filter: invert(1);
  opacity: 0.6;
}

.error-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 18px;
  border: 1px solid rgba(255, 101, 119, 0.5);
  border-radius: var(--radius);
  background: #160b11;
  padding: 16px 18px;
}

.error-panel[hidden] {
  display: none;
}

.error-panel p {
  margin-top: 3px;
  color: #dcaeb5;
  font-size: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.kpi-card {
  position: relative;
  min-height: 128px;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 17px 17px 14px;
}

.kpi-card::before {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--blue-600);
  content: "";
  opacity: 0.72;
}

.kpi-label {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.kpi-value {
  display: block;
  margin-top: 14px;
  font-size: clamp(25px, 2.3vw, 34px);
  font-variant-numeric: tabular-nums;
  font-weight: 740;
  letter-spacing: -0.045em;
  line-height: 1;
}

.kpi-context {
  display: block;
  margin-top: 11px;
  color: var(--text-muted);
  font-size: 10px;
}

.kpi-context strong {
  color: var(--blue-300);
  font-weight: 700;
}

.skeleton {
  min-height: 128px;
  background: #0c131d;
}

.skeleton::after {
  position: absolute;
  inset: 18px;
  border-radius: 6px;
  background: #111d2b;
  content: "";
  animation: skeleton-pulse 1.2s ease-in-out infinite alternate;
}

@keyframes skeleton-pulse {
  to { opacity: 0.38; }
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.panel {
  min-width: 0;
  border-radius: var(--radius-lg);
  padding: 21px;
}

.panel-wide {
  grid-column: span 2;
}

.panel-span-two {
  grid-column: span 2;
}

.chart-legend {
  display: flex;
  gap: 14px;
  color: var(--text-muted);
  font-size: 10px;
}

.chart-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-line {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--blue-500);
}

.legend-line.conversions {
  background: var(--blue-200);
}

.chart-frame {
  min-height: 250px;
}

#trend-chart {
  display: block;
  width: 100%;
  height: 250px;
  overflow: visible;
}

.chart-grid-line {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-label {
  fill: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 9px;
}

.chart-line {
  fill: none;
  stroke: var(--blue-500);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.3;
  vector-effect: non-scaling-stroke;
}

.chart-line.conversion-line {
  stroke: var(--blue-200);
  stroke-width: 1.7;
}

.chart-point {
  fill: var(--ink-900);
  stroke: var(--blue-400);
  stroke-width: 2;
}

.empty-state {
  display: grid;
  min-height: 160px;
  place-items: center;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

.funnel-chart,
.rank-list,
.channel-list {
  display: grid;
  gap: 15px;
}

.funnel-row-header,
.rank-header,
.channel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 6px;
  font-size: 11px;
}

.funnel-row-header span,
.rank-header span,
.channel-header span {
  color: var(--text-soft);
}

.funnel-row-header strong,
.rank-header strong,
.channel-header strong {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.funnel-track,
.rank-track,
.channel-track {
  height: 7px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--ink-700);
}

.funnel-fill,
.rank-fill,
.channel-fill {
  width: 0;
  height: 100%;
  background: var(--blue-500);
  transition: width 260ms ease;
}

.funnel-row:nth-child(2) .funnel-fill { background: #1d83ee; }
.funnel-row:nth-child(3) .funnel-fill { background: #4a9ff7; }
.funnel-row:nth-child(4) .funnel-fill { background: var(--blue-200); }

.rank-meta,
.channel-meta {
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 9px;
}

.table-panel {
  margin-top: 14px;
}

.section-note {
  align-self: center;
  color: var(--text-muted);
  font-size: 10px;
}

.table-scroll {
  overflow-x: auto;
  scrollbar-color: var(--line-strong) transparent;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 14px;
  text-align: right;
}

th:first-child,
td:first-child {
  padding-left: 0;
  text-align: left;
}

th:last-child,
td:last-child {
  padding-right: 0;
}

th {
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td {
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr {
  transition: background-color 130ms ease;
}

tbody tr:hover {
  background: #0b1420;
}

.compact-table th,
.compact-table td {
  padding-top: 10px;
  padding-bottom: 10px;
}

.table-primary {
  display: block;
  color: var(--text);
  font-weight: 650;
}

.table-secondary {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 9px;
}

.value-positive {
  color: var(--blue-300);
  font-weight: 700;
}

.outcome-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 23px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--ink-800);
  padding: 0 8px;
  color: var(--text-soft);
  font-size: 9px;
  font-weight: 720;
  letter-spacing: 0.03em;
  text-transform: capitalize;
}

.outcome-pill.converted {
  border-color: #24639a;
  background: #0d2438;
  color: var(--blue-200);
}

.outcome-pill.booked {
  color: var(--blue-300);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
  padding-top: 15px;
  color: var(--text-muted);
  font-size: 10px;
}

.page-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--ink-800);
  padding: 0 12px;
  color: var(--text-soft);
  font-size: 10px;
  font-weight: 700;
}

.page-button:not(:disabled):hover {
  border-color: var(--line-strong);
  color: var(--text);
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-top: 1px solid var(--line);
  margin-top: 28px;
  padding: 19px 2px 0;
  color: var(--text-muted);
  font-size: 9px;
}

footer strong {
  color: var(--text-soft);
  letter-spacing: 0.12em;
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #filters-form {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .insight-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-wide,
  .panel-span-two {
    grid-column: span 2;
  }
}

@media (max-width: 920px) {
  :root {
    --sidebar-width: 84px;
  }

  .sidebar {
    align-items: center;
    padding-inline: 12px;
  }

  .brand-lockup {
    padding: 0;
  }

  .brand-domain,
  .nav-link:not(.is-active) .nav-icon,
  .nav-link.is-active .nav-icon,
  .nav-link { font-size: 0; }

  .brand-logo {
    width: 32px;
    object-fit: cover;
    object-position: left center;
  }

  .nav-link {
    justify-content: center;
    width: 48px;
    padding: 0;
  }

  .nav-icon {
    font-size: 10px;
  }

  .sidebar-note {
    justify-content: center;
    width: 42px;
    padding: 12px;
  }

  .sidebar-note div,
  .sidebar-principle {
    display: none;
  }

  .sidebar-note .status-dot {
    margin: 0;
  }

  .topbar {
    flex-direction: column;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    display: flex;
    flex-direction: row;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 13px 18px;
  }

  .brand-domain {
    display: block;
  }

  .brand-logo {
    width: 128px;
    object-fit: contain;
  }

  .sidebar nav {
    display: none;
  }

  .sidebar-note {
    width: auto;
    margin: 0 0 0 auto;
    border: 0;
    background: transparent;
    padding: 10px;
  }

  main {
    padding: 26px 16px 24px;
  }

  .topbar {
    gap: 20px;
    padding-bottom: 22px;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .button {
    flex: 1;
  }

  #filters-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-card {
    min-height: 116px;
  }

  .insight-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel-wide,
  .panel-span-two {
    grid-column: auto;
  }

  .panel {
    padding: 18px;
  }

  .chart-legend {
    display: none;
  }

  .error-panel,
  footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .activity-heading {
    align-items: flex-end;
  }
}

@media (max-width: 480px) {
  .mode-pill {
    display: none;
  }

  #filters-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .kpi-grid {
    gap: 9px;
  }

  .kpi-card {
    padding: 15px 13px;
  }

  .kpi-value {
    font-size: 26px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
