:root {
  --bg: #f4efe7;
  --card: rgba(255, 250, 245, 0.9);
  --ink: #1f2933;
  --muted: #52606d;
  --line: rgba(82, 96, 109, 0.16);
  --instagram: #ff9f43;
  --google: #0f766e;
  --ly-ads: #06c755;
  --tiktok: #111827;
  --accent: #0f766e;
  --shadow: 0 30px 60px rgba(31, 41, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Avenir Next", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 159, 67, 0.28), transparent 22%),
    radial-gradient(circle at top right, rgba(15, 118, 110, 0.16), transparent 25%),
    linear-gradient(135deg, #f7f2eb 0%, #eef5f1 100%);
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 48px 20px 64px;
}

.hero,
.panel,
.summary {
  margin-bottom: 24px;
}

.is-hidden {
  display: none;
}

.hero,
.panel,
.metric-card,
.allocation-card,
.trend-metric,
.timeline-card,
.trend-stage,
.connection-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.hero {
  padding: 28px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 720px;
  font-size: clamp(2rem, 3vw, 3.5rem);
  line-height: 1.05;
}

.lede,
.campaign-meta,
.allocation-card p,
th,
td,
span {
  color: var(--muted);
}

.primary {
  border: 0;
  background: var(--ink);
  color: white;
  padding: 14px 20px;
  border-radius: 999px;
  font-size: 1rem;
  cursor: pointer;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.metric-card,
.panel {
  padding: 24px;
}

.connect-panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.94)),
    radial-gradient(circle at top left, rgba(39, 39, 217, 0.1), transparent 32%);
}

.momentum-panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.9)),
    radial-gradient(circle at top right, rgba(15, 118, 110, 0.12), transparent 30%);
}

.rebalance-preview-panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.94)),
    radial-gradient(circle at top right, rgba(255, 92, 138, 0.1), transparent 30%);
}

.metric-card strong {
  display: block;
  margin-top: 10px;
  font-size: 1.8rem;
  color: var(--ink);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}

.connect-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

.primary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.oauth-link-secondary {
  background: #111827;
}

.oauth-link-tertiary {
  background: var(--ink);
}

.oauth-link-tiktok {
  background: var(--tiktok);
}

.form-status {
  margin: 0;
}

.form-status.is-success {
  color: var(--accent);
}

.form-status.is-error,
.connection-error {
  color: #b42318;
}

.tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  border-bottom: 1px dotted currentColor;
  cursor: help;
}

.tooltip::after {
  content: "?";
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(82, 96, 109, 0.12);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
}

.tooltip-bubble {
  position: absolute;
  z-index: 10;
  bottom: calc(100% + 10px);
  left: 50%;
  width: min(280px, 72vw);
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  box-shadow: 0 12px 24px rgba(31, 41, 51, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.tooltip:hover .tooltip-bubble,
.tooltip:focus .tooltip-bubble,
.tooltip:focus-within .tooltip-bubble {
  opacity: 1;
  transform: translate(-50%, 0);
}

.connection-card-header,
.ad-account-item,
.connection-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.connection-card-header {
  align-items: baseline;
}

.connection-cards {
  display: grid;
  gap: 16px;
}

.connection-card {
  padding: 18px;
}

.connection-card-empty {
  text-align: center;
}

.connection-platform,
.connection-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.08);
  color: var(--google);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.connection-meta {
  flex-wrap: wrap;
  margin: 16px 0 10px;
}

.connection-detail,
.ad-account-item p {
  margin-bottom: 0;
}

.ad-account-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.campaign-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.campaign-chip {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(17, 24, 39, 0.05);
}

.campaign-chip strong {
  display: block;
}

.campaign-action {
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--ink);
  color: white;
  cursor: pointer;
}

.campaign-action:disabled {
  opacity: 0.65;
  cursor: wait;
}

.campaign-create-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.campaign-create-form label {
  display: grid;
  gap: 8px;
  color: #344054;
  font-weight: 700;
}

.campaign-create-form input,
.campaign-create-form select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  background: #fff;
  color: #101828;
  padding: 12px 14px;
  font: inherit;
}

.campaign-create-form small {
  color: #667085;
  font-weight: 400;
}

.form-span-2 {
  grid-column: 1 / -1;
}

.campaign-create-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.campaign-create-actions .form-status {
  margin: 0;
}

.ad-account-item {
  align-items: center;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid rgba(82, 96, 109, 0.12);
}

.ad-account-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: end;
}

.trend-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.trend-metric {
  padding: 18px;
}

.trend-metric strong,
.trend-stage strong,
.timeline-card strong {
  display: block;
  color: var(--ink);
}

.trend-metric strong {
  font-size: 1.8rem;
  margin: 10px 0 8px;
}

.trend-metric p,
.timeline-item p {
  margin-bottom: 0;
}

.momentum-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.9fr);
  gap: 16px;
}

.trend-stage,
.timeline-card {
  padding: 20px;
}

.trend-stage-header,
.timeline-card-header,
.timeline-item-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
}

.trend-label {
  display: inline-block;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}

.trend-delta {
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 600;
  background: rgba(82, 96, 109, 0.12);
  color: var(--muted);
}

.rebalance-action {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(82, 96, 109, 0.12);
  color: var(--muted);
  font-weight: 700;
}

.rebalance-action.is-rebalance {
  background: rgba(15, 118, 110, 0.12);
  color: var(--accent);
}

.rebalance-preview-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.85fr);
  gap: 16px;
  margin-top: 18px;
}

.rebalance-change-list,
.rebalance-driver-list {
  display: grid;
  gap: 10px;
}

.rebalance-change,
.rebalance-explain-card {
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(82, 96, 109, 0.12);
}

.rebalance-change {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.rebalance-change strong,
.rebalance-change span {
  display: block;
}

.rebalance-change-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.rebalance-change-formula {
  max-width: 680px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.rebalance-math-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.rebalance-math-grid span {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(82, 96, 109, 0.1);
  color: var(--muted);
  font-size: 0.78rem;
}

.rebalance-change-delta {
  text-align: right;
  min-width: 94px;
}

.rebalance-change-delta strong,
.rebalance-change-delta span {
  display: block;
}

.rebalance-change-delta strong {
  font-weight: 700;
}

.rebalance-change.is-increase .rebalance-change-delta {
  color: var(--accent);
}

.rebalance-change.is-decrease .rebalance-change-delta {
  color: #b42318;
}

.rebalance-driver-list p {
  margin: 0;
  padding-left: 12px;
  border-left: 3px solid rgba(15, 118, 110, 0.28);
}

.decision-logic-button {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  margin-bottom: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.decision-logic-button .trend-label {
  margin-bottom: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 41, 51, 0.42);
}

.modal-backdrop.is-hidden {
  display: none;
}

.modal {
  width: min(900px, 100%);
  max-height: min(820px, calc(100vh - 48px));
  overflow: auto;
  padding: 24px;
  border-radius: 24px;
  background: #fffaf5;
  box-shadow: 0 40px 90px rgba(31, 41, 51, 0.28);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: start;
  margin-bottom: 18px;
}

.modal-close {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(82, 96, 109, 0.12);
  color: var(--ink);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.modal-body {
  display: grid;
  gap: 16px;
}

.modal-body h3,
.modal-body p {
  margin-bottom: 0;
}

.modal-body pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  border-radius: 14px;
  background: #111827;
  color: #f8fafc;
}

.modal-body code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.55;
}

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

.algorithm-flow article,
.algorithm-chart {
  border: 1px solid rgba(82, 96, 109, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.68);
}

.algorithm-flow article {
  display: grid;
  gap: 8px;
  align-content: start;
  padding: 14px;
}

.algorithm-flow span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(15, 118, 110, 0.12);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
}

.algorithm-flow strong,
.algorithm-chart strong {
  color: var(--ink);
}

.algorithm-flow p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.algorithm-chart {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.algorithm-chart-header,
.algorithm-chart-row {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) 54px;
  gap: 12px;
  align-items: center;
}

.algorithm-chart-header {
  grid-template-columns: minmax(0, 1fr) auto;
}

.algorithm-chart-header span {
  color: var(--muted);
  font-size: 0.88rem;
}

.algorithm-chart-row > span {
  color: var(--muted);
}

.algorithm-chart-row strong {
  text-align: right;
}

.algorithm-chart-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(82, 96, 109, 0.12);
}

.algorithm-chart-fill {
  height: 100%;
  min-width: 8px;
  border-radius: inherit;
}

.algorithm-chart-fill.is-meta {
  background: var(--instagram);
}

.algorithm-chart-fill.is-google {
  background: var(--google);
}

.algorithm-chart-fill.is-ly-ads {
  background: var(--ly-ads);
}

.algorithm-chart-fill.is-tiktok {
  background: var(--tiktok);
}

.trend-delta.is-positive {
  background: rgba(15, 118, 110, 0.12);
  color: var(--accent);
}

.trend-chart {
  margin-top: 12px;
  border-radius: 20px;
  padding: 12px;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.06), transparent 65%),
    rgba(255, 255, 255, 0.72);
}

.trend-chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.trend-grid {
  stroke: rgba(82, 96, 109, 0.12);
  stroke-width: 1;
}

.trend-path {
  fill: none;
  stroke: url(#trendStroke);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trend-point {
  fill: white;
  stroke: var(--accent);
  stroke-width: 3;
}

.trend-value,
.trend-tick {
  fill: var(--muted);
  font-family: inherit;
  font-size: 12px;
}

.timeline-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.timeline-marker {
  width: 14px;
  height: 14px;
  margin-top: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b, #0f766e);
  box-shadow: 0 0 0 5px rgba(15, 118, 110, 0.12);
}

.timeline-item.is-current .timeline-marker {
  box-shadow: 0 0 0 7px rgba(15, 118, 110, 0.18);
}

.allocation-bars {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.budget-distribution {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 24px;
  align-items: center;
  margin-bottom: 20px;
  padding: 18px;
  border: 1px solid rgba(82, 96, 109, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.62);
}

.budget-pie {
  width: min(100%, 260px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(82, 96, 109, 0.14);
}

.budget-pie-center {
  width: 48%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  background: rgba(255, 250, 245, 0.96);
  border: 1px solid rgba(82, 96, 109, 0.12);
}

.budget-pie-center span,
.budget-pie-item span {
  font-size: 0.86rem;
}

.budget-pie-center strong,
.budget-pie-item strong {
  color: var(--ink);
}

.budget-pie-legend {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.budget-pie-item {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-width: 0;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
}

.budget-pie-item strong,
.budget-pie-item span {
  display: block;
}

.budget-pie-swatch {
  width: 14px;
  height: 14px;
  margin-top: 4px;
  border-radius: 50%;
}

.platform-comparison {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.comparison-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(82, 96, 109, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
}

.comparison-card.is-winner {
  border-color: rgba(15, 118, 110, 0.38);
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), rgba(255, 255, 255, 0.76));
}

.comparison-card-header,
.comparison-score,
.comparison-bar-row > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.comparison-rank,
.comparison-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-bottom: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(82, 96, 109, 0.12);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.comparison-badge {
  background: rgba(15, 118, 110, 0.12);
  color: var(--accent);
}

.comparison-card h3,
.comparison-card p {
  margin-bottom: 0;
}

.comparison-score strong {
  color: var(--ink);
  font-size: 2rem;
}

.comparison-bars {
  display: grid;
  gap: 10px;
}

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

.comparison-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(82, 96, 109, 0.12);
}

.comparison-fill {
  height: 100%;
  min-width: 8px;
  border-radius: inherit;
}

.allocation-card {
  padding: 18px;
}

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

.bar-track {
  height: 14px;
  background: rgba(82, 96, 109, 0.12);
  border-radius: 999px;
  overflow: hidden;
  margin: 14px 0 12px;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
}

.platform-instagram .bar-fill,
.platform-meta .bar-fill {
  background: linear-gradient(90deg, #f97316, var(--instagram));
}

.platform-google .bar-fill {
  background: linear-gradient(90deg, #059669, var(--google));
}

.platform-ly_ads .bar-fill {
  background: linear-gradient(90deg, #16a34a, var(--ly-ads));
}

.platform-tiktok .bar-fill {
  background: linear-gradient(90deg, #111827, var(--tiktok));
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 900px) {
  .hero,
  .panel-header {
    flex-direction: column;
    align-items: start;
  }

  .summary,
  .allocation-bars,
  .budget-distribution,
  .budget-pie-legend,
  .platform-comparison,
  .algorithm-flow,
  .trend-summary,
  .rebalance-preview-layout,
  .momentum-layout {
    grid-template-columns: 1fr;
  }

  .algorithm-chart-header,
  .algorithm-chart-row {
    grid-template-columns: 72px minmax(0, 1fr) 48px;
  }

  .algorithm-chart-header {
    grid-template-columns: 1fr;
  }

  .connection-card-header,
  .ad-account-item,
  .connection-meta,
  .campaign-chip {
    flex-direction: column;
    align-items: start;
  }

  .ad-account-stats {
    justify-content: start;
  }
}
