:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #111114;
  --muted: #696b73;
  --line: #e4e6eb;
  --red: #d70712;
  --red-dark: #a8050d;
  --graphite: #24252a;
  --soft-red: #fff1f2;
  --good: #0f766e;
  --warn: #b45309;
  --bad: #b91c1c;
  --shadow: 0 18px 45px rgba(17, 17, 20, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(215, 7, 18, 0.08), transparent 34%),
    linear-gradient(180deg, #ffffff 0, var(--bg) 420px);
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 180ms ease;
}

.app-shell.is-sidebar-collapsed {
  grid-template-columns: 92px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 24px;
  color: #fff;
  background: #09090b;
  overflow: auto;
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(122deg, transparent 0 45%, rgba(215, 7, 18, 0.34) 45% 53%, transparent 53%),
    linear-gradient(122deg, transparent 0 66%, rgba(215, 7, 18, 0.18) 66% 73%, transparent 73%);
  pointer-events: none;
}

.sidebar > * {
  position: relative;
}

.brand {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
}

.brand img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  background: #fff;
  border-radius: 8px;
  padding: 6px;
}

.brand strong,
.brand small {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.brand strong {
  font-size: 22px;
  line-height: 1;
}

.brand small {
  margin-top: 5px;
  color: rgba(255, 255, 255, 0.72);
}

.sidebar-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-left: auto;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-toggle span {
  font-size: 26px;
  line-height: 1;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-link {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 10px;
  color: rgba(255, 255, 255, 0.74);
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.nav-link.is-active {
  color: #fff;
  border-color: rgba(215, 7, 18, 0.72);
  background: linear-gradient(135deg, rgba(215, 7, 18, 0.36), rgba(255, 255, 255, 0.06));
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  border-radius: 8px;
  background: rgba(215, 7, 18, 0.86);
}

.nav-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.app-shell.is-sidebar-collapsed .sidebar {
  align-items: center;
  padding: 20px 14px;
  overflow: visible;
}

.app-shell.is-sidebar-collapsed .brand {
  grid-template-columns: 1fr;
}

.app-shell.is-sidebar-collapsed .brand span,
.app-shell.is-sidebar-collapsed .nav-link span:last-child,
.app-shell.is-sidebar-collapsed .source-card {
  display: none;
}

.app-shell.is-sidebar-collapsed .nav-link {
  grid-template-columns: 1fr;
  justify-items: center;
  width: 56px;
  padding: 10px;
}

.app-shell.is-sidebar-collapsed .sidebar-toggle {
  margin: 0;
}

.source-card {
  margin-top: auto;
  display: grid;
  gap: 5px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.source-card span,
.source-card small {
  color: rgba(255, 255, 255, 0.68);
}

.dashboard {
  min-width: 0;
  padding: 28px;
}

.hero-band {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  min-height: 210px;
  padding: 32px;
  color: #fff;
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(8, 8, 10, 0.92), rgba(8, 8, 10, 0.72)),
    url("assets/ctrc/hero-ctrc-team.jpeg") center / cover;
  box-shadow: var(--shadow);
}

.hero-band::after {
  content: "";
  position: absolute;
  inset: auto -60px -80px auto;
  width: 360px;
  height: 260px;
  transform: skewX(-24deg);
  background: rgba(215, 7, 18, 0.78);
}

.hero-band > * {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--red);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-band .eyebrow {
  color: #ff3b45;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 42px;
  line-height: 1;
}

h2 {
  margin: 0;
  font-size: 28px;
}

h3 {
  margin: 0;
  font-size: 17px;
}

.hero-copy {
  max-width: 620px;
  margin: 12px 0 0;
  color: rgba(255, 255, 255, 0.76);
  font-size: 16px;
}

.hero-actions {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.primary-button,
.ghost-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  color: #fff;
  border: 1px solid var(--red);
  background: var(--red);
}

.ghost-button {
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.08);
}

.context-toolbar {
  display: grid;
  grid-template-columns: 220px minmax(260px, 1.1fr) repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.field {
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

.field label,
.field span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field strong {
  display: block;
  min-width: 0;
  font-size: 14px;
  overflow-wrap: anywhere;
}

select,
.search-input,
input[type="date"] {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  border: 0;
  outline: 0;
  background: transparent;
  font-weight: 800;
}

.custom-period-field[hidden] {
  display: none;
}

.date-inputs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.date-inputs label {
  display: grid;
  gap: 4px;
}

.date-inputs small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.date-inputs input {
  min-height: 28px;
}

.notice {
  margin: 0 0 18px;
  padding: 14px 16px;
  color: #7f1d1d;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff1f2;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin: 22px 0 14px;
}

.section-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  color: var(--red-dark);
  border: 1px solid rgba(215, 7, 18, 0.2);
  border-radius: 999px;
  background: var(--soft-red);
  font-size: 12px;
  font-weight: 850;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 30px rgba(17, 17, 20, 0.04);
}

.kpi-card {
  padding: 18px;
}

.kpi-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi-card strong {
  display: block;
  margin-top: 8px;
  font-size: 29px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.kpi-card small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.85fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.chart-panel {
  position: relative;
  min-height: 360px;
  overflow: visible;
  z-index: 2;
}

canvas {
  width: 100%;
  max-width: 100%;
  display: block;
  border-radius: 18px;
}

.chart-tooltip {
  position: absolute;
  z-index: 40;
  min-width: 212px;
  padding: 12px 14px;
  color: #121216;
  border: 1px solid rgba(215, 7, 18, 0.16);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 46px rgba(17, 17, 20, 0.16);
  font-size: 12px;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 14px));
  backdrop-filter: blur(12px);
}

.chart-tooltip.is-below {
  transform: translate(-50%, 0);
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  color: #07070a;
}

.chart-tooltip span {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  line-height: 1.7;
}

.chart-tooltip em {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-style: normal;
}

.chart-tooltip b {
  font-variant-numeric: tabular-nums;
}

.tooltip-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #d70712;
}

.tooltip-dot.is-bar {
  border-radius: 2px;
  background: rgba(215, 7, 18, 0.32);
}

.tooltip-dot.is-cpl {
  background: #16161a;
}

.insight-list,
.creative-list {
  display: grid;
  gap: 10px;
}

.insight-item {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
}

.insight-item strong {
  display: block;
  margin-bottom: 5px;
}

.insight-item p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.bar-list {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: #edeff3;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), #111114);
}

.section-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.status-filter {
  display: inline-flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 24px rgba(17, 17, 20, 0.06);
}

.status-filter-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}

.status-filter-button span {
  display: grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  border-radius: 999px;
  background: #eef0f3;
  font-size: 10px;
}

.status-filter-button:hover,
.status-filter-button:focus-visible {
  color: var(--ink);
  background: var(--soft-red);
  outline: none;
}

.status-filter-button.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  box-shadow: 0 8px 18px rgba(215, 7, 18, 0.22);
}

.status-filter-button.is-active span {
  color: var(--red-dark);
  background: #fff;
}

.campaign-funnel-layout {
  display: grid;
  grid-template-columns: minmax(200px, 1.2fr) minmax(110px, 0.8fr);
  align-items: center;
  gap: clamp(12px, 2vw, 22px);
  min-height: 280px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: radial-gradient(circle at 15% 20%, rgba(215, 7, 18, 0.1), transparent 34%), linear-gradient(145deg, #fbfbfc, #f2f3f6);
}

.funnel-visual {
  display: grid;
  justify-items: center;
  min-width: 0;
}

.funnel-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
  color: #fff;
  clip-path: polygon(4% 0, 96% 0, 86% 100%, 14% 100%);
  filter: drop-shadow(0 12px 16px rgba(17, 17, 20, 0.14));
}

.funnel-stage.is-impressions { width: 100%; background: linear-gradient(90deg, #7d060d, #ed1823 55%, #a8050d); }
.funnel-stage.is-clicks { width: 76%; background: linear-gradient(90deg, #24252a, #4b4d54 55%, #17181c); }
.funnel-stage.is-leads { width: 50%; background: linear-gradient(90deg, #94050c, #d70712 55%, #7c050a); }

.funnel-stage-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
}

.funnel-stage-icon svg { width: 20px; height: 20px; }
.funnel-stage span:last-child { display: grid; line-height: 1.05; }
.funnel-stage small { color: rgba(255, 255, 255, 0.76); font-size: 10px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.funnel-stage strong { margin-top: 4px; font-size: clamp(19px, 2vw, 27px); font-variant-numeric: tabular-nums; }

.funnel-conversion {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  color: var(--muted);
  font-size: 10px;
}

.funnel-conversion::before { content: "↓"; color: var(--red); font-size: 17px; font-weight: 900; }
.funnel-conversion strong { color: var(--ink); font-size: 12px; }

.funnel-support {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 7px;
}

.funnel-kpi {
  display: grid;
  min-height: 58px;
  padding: 9px 11px;
  border: 1px solid rgba(215, 7, 18, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 28px rgba(17, 17, 20, 0.06);
}

.funnel-kpi span { color: var(--red-dark); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.funnel-kpi strong { align-self: center; font-size: clamp(17px, 1.6vw, 23px); font-variant-numeric: tabular-nums; }
.funnel-kpi small { display: none; color: var(--muted); font-size: 10px; line-height: 1.3; }

.search-input {
  max-width: 320px;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.campaign-card-list {
  display: none;
}

.campaign-adset-summary,
.adset-cell span {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.adset-cell {
  display: grid;
  min-width: 180px;
  gap: 3px;
}

.adset-cell strong {
  font-size: 12px;
}

.campaign-summary-row {
  background: #fff;
}

.campaign-summary-row td {
  font-weight: 850;
}

.adset-detail-row {
  background: #fafbfc;
}

.adset-detail-row td:first-child {
  color: var(--muted);
  font-size: 12px;
}

.adset-cell.is-detail {
  padding-left: 8px;
}

.adset-cell.is-detail strong {
  color: var(--ink);
}

.adset-mobile-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.adset-mobile-list > strong {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.adset-mobile-row {
  display: grid;
  gap: 3px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.adset-mobile-row span {
  font-weight: 850;
}

.adset-mobile-row small {
  color: var(--muted);
  font-weight: 750;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1080px;
}

th,
td {
  padding: 13px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
}

.badge.good {
  color: #115e59;
  background: #ccfbf1;
}

.badge.warn {
  color: #92400e;
  background: #fef3c7;
}

.badge.bad {
  color: #991b1b;
  background: #fee2e2;
}

.badge.neutral {
  color: #374151;
  background: #f3f4f6;
}

.creative-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.creative-thumb {
  width: 112px;
  aspect-ratio: 1.2;
  object-fit: cover;
  border-radius: 8px;
  background: #111;
}

.creative-thumb-empty {
  display: grid;
  place-items: center;
  color: #6b7280;
  border: 1px dashed #cfd2d8;
  background: #f3f4f6;
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.creative-title {
  margin: 0 0 4px;
  font-weight: 850;
}

.creative-title-row {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.creative-status {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.1;
}

.creative-status.is-active {
  color: #047857;
  background: #d1fae5;
}

.creative-status.is-inactive {
  color: #991b1b;
  background: #fee2e2;
}

.creative-status.is-unknown {
  color: #4b5563;
  background: #eef0f3;
}

.creative-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.creative-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.stat-pill {
  padding: 6px 8px;
  border-radius: 8px;
  background: #f3f4f6;
  font-size: 12px;
  font-weight: 800;
}

.creative-link {
  color: var(--red-dark);
  font-weight: 850;
  text-decoration: none;
}

.campaign-mobile-card {
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.campaign-mobile-card strong {
  display: block;
  margin-bottom: 8px;
}

.campaign-mobile-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.campaign-mobile-card dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.campaign-mobile-card dd {
  margin: 2px 0 0;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed #cfd2d8;
  border-radius: 8px;
  background: #fafafa;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    padding: 16px;
  }

  .sidebar-toggle {
    display: none;
  }

  .app-shell.is-sidebar-collapsed .sidebar {
    align-items: stretch;
    padding: 16px;
  }

  .app-shell.is-sidebar-collapsed .brand span,
  .app-shell.is-sidebar-collapsed .nav-link span:last-child {
    display: block;
  }

  .app-shell.is-sidebar-collapsed .nav-link {
    grid-template-columns: 38px minmax(0, 1fr);
    justify-items: stretch;
    width: auto;
  }

  .nav-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .source-card {
    display: none;
  }

  .dashboard {
    padding: 16px;
  }

  .hero-band,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-controls {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .campaign-funnel-layout {
    grid-template-columns: 1fr;
  }

  .funnel-support {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .funnel-kpi {
    min-height: 84px;
  }

  .funnel-kpi small {
    display: block;
  }

  .context-toolbar,
  .kpi-grid,
  .grid-two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  h1 {
    font-size: 34px;
  }

  h2 {
    font-size: 23px;
  }

  .hero-band {
    padding: 24px;
  }

  .hero-actions {
    width: 100%;
  }

  .primary-button,
  .ghost-button {
    flex: 1;
  }

  .nav-link {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    font-size: 12px;
  }

  .status-filter {
    width: 100%;
  }

  .status-filter-button {
    flex: 1;
    justify-content: center;
    padding-inline: 6px;
  }

  .search-input {
    width: 100%;
    max-width: none;
  }

  .campaign-funnel-layout {
    padding: 12px;
  }

  .funnel-support {
    grid-template-columns: 1fr 1fr;
  }

  .creative-card {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .creative-thumb {
    width: 82px;
  }

  .creative-link {
    grid-column: 1 / -1;
  }

  .campaign-card-list {
    display: grid;
    gap: 10px;
  }

  .table-panel .table-wrap {
    display: none;
  }
}
