:root {
  --bg: #f5f3ed;
  --surface: #ffffff;
  --surface-soft: #f9f6ef;
  --ink: #18201d;
  --muted: #66706b;
  --line: #ded8cc;
  --teal: #166b6b;
  --teal-dark: #0f4f4f;
  --green: #2d7c4b;
  --amber: #b76f16;
  --rose: #b74757;
  --blue: #386c9b;
  --shadow: 0 18px 45px rgba(24, 32, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(22, 107, 107, 0.08), transparent 38%),
    linear-gradient(225deg, rgba(183, 111, 22, 0.09), transparent 34%),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  color: #f7f2e9;
  background: #16211e;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #10201c;
  background: #d8ff80;
  font-weight: 900;
}

.brand-lockup strong,
.brand-lockup span {
  display: block;
}

.brand-lockup span {
  color: rgba(247, 242, 233, 0.62);
  font-size: 0.82rem;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  min-height: 42px;
  padding: 0 10px;
  color: rgba(247, 242, 233, 0.74);
  text-decoration: none;
  border-radius: 8px;
}

.nav-item.active,
.nav-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.nav-icon {
  color: #d8ff80;
}

.sidebar-panel {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-panel span:last-child {
  color: rgba(247, 242, 233, 0.64);
  font-size: 0.86rem;
}

.main {
  width: min(100%, 1440px);
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar h1,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.8rem, 3vw, 3rem);
  line-height: 1.04;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.source-status {
  display: grid;
  gap: 2px;
  min-width: 176px;
  min-height: 42px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.source-status span {
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 900;
}

.source-status small {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-status.real {
  border-color: rgba(45, 124, 75, 0.3);
  background: #edf8ef;
}

.source-status.demo {
  border-color: rgba(183, 111, 22, 0.28);
  background: #fff4e2;
}

.eyebrow {
  display: block;
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(132px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.kpi-card,
.panel,
.campaign-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.kpi-card {
  display: grid;
  gap: 9px;
  min-height: 132px;
  padding: 16px;
  border-top: 4px solid var(--teal);
}

.kpi-card span,
.kpi-card small,
.campaign-card span,
.run-item span,
.run-item small,
.powerbi-empty span {
  color: var(--muted);
}

.kpi-card strong {
  font-size: 2rem;
  line-height: 1;
}

.tone-green { border-top-color: var(--green); }
.tone-amber { border-top-color: var(--amber); }
.tone-rose { border-top-color: var(--rose); }
.tone-blue { border-top-color: var(--blue); }
.tone-teal { border-top-color: var(--teal); }

.dashboard-grid,
.split-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.dashboard-grid {
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.75fr);
}

.split-grid {
  grid-template-columns: minmax(0, 1.3fr) minmax(330px, 0.7fr);
}

.panel {
  padding: 18px;
}

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

.status-pill,
.campaign-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.healthy {
  color: #145230;
  background: #daf1df;
}

.attention {
  color: #74420b;
  background: #ffe4bb;
}

.neutral {
  color: #3a4f62;
  background: #dbe7ef;
}

.funnel-list,
.run-list,
.signal-list {
  display: grid;
  gap: 12px;
}

.funnel-stage {
  display: grid;
  gap: 7px;
}

.funnel-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.funnel-track {
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #ebe5da;
}

.funnel-bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), #84a94b);
}

.maestro-card {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  padding: 16px;
  border-radius: 8px;
  color: #f7f2e9;
  background: #16211e;
}

.maestro-card p {
  margin: 0;
  color: rgba(247, 242, 233, 0.76);
}

.signal-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  color: var(--muted);
  line-height: 1.45;
}

.signal-dot {
  width: 8px;
  height: 8px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--teal);
}

.segmented-control {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.segment,
.ghost-button,
.primary-button,
.icon-button,
.table-action {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.segment {
  min-height: 32px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
}

.segment.active {
  color: #fff;
  background: var(--teal);
}

.primary-button {
  min-height: 42px;
  padding: 0 16px;
  color: #10201c;
  background: #d8ff80;
}

.ghost-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--teal-dark);
  background: #e5f1eb;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: var(--teal-dark);
  background: #e5f1eb;
}

.campaign-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.campaign-card {
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
}

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

.campaign-card dt,
.campaign-card dd {
  margin: 0;
}

.campaign-card dt {
  color: var(--muted);
  font-size: 0.75rem;
}

.campaign-card dd {
  font-weight: 900;
}

.campaign-score {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 66px;
  border-radius: 8px;
  color: #fff;
  background: var(--teal);
}

.campaign-score span {
  color: #fff;
  font-size: 1.45rem;
  font-weight: 900;
}

.campaign-score small {
  color: rgba(255, 255, 255, 0.72);
}

.campaign-status {
  grid-column: 1 / -1;
  justify-self: start;
  color: #70440f;
  background: #ffead1;
}

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

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

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

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

.score-badge {
  display: inline-grid;
  place-items: center;
  min-width: 42px;
  height: 28px;
  border-radius: 999px;
  color: #fff;
  background: var(--teal);
  font-weight: 900;
}

.table-action {
  min-height: 32px;
  padding: 0 10px;
  color: #10201c;
  background: #d8ff80;
}

.lead-panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.approval-status {
  max-width: 360px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: right;
}

.approval-status.success {
  color: var(--green);
}

.approval-status.error {
  color: var(--rose);
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  gap: 4px;
  min-height: 124px;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.empty-state.compact {
  min-height: 80px;
}

.empty-state strong {
  color: var(--ink);
}

.run-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.run-item div {
  display: grid;
  gap: 4px;
}

.run-item div:last-child {
  justify-items: end;
}

.powerbi-panel {
  margin-inline: -6px;
  padding: 20px;
}

.powerbi-panel .panel-header {
  margin-bottom: 14px;
}

.powerbi-panel .status-pill {
  align-self: center;
}

.powerbi-frame {
  min-height: min(78vh, 920px);
  height: min(78vh, 920px);
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #16211e;
}

.powerbi-frame iframe,
.powerbi-frame > iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.powerbi-empty {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 0.8fr);
  align-items: center;
  gap: 30px;
  min-height: 420px;
  padding: 34px;
  color: #f7f2e9;
}

.powerbi-loading {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  min-height: 420px;
  padding: 34px;
  color: #f7f2e9;
  text-align: center;
}

.powerbi-empty strong,
.powerbi-empty span,
.powerbi-empty small,
.powerbi-loading strong,
.powerbi-loading span {
  display: block;
}

.powerbi-empty span,
.powerbi-empty small,
.powerbi-loading span {
  color: rgba(247, 242, 233, 0.68);
}

.powerbi-token-warning {
  margin-top: 10px;
  color: #ffcf87;
}

body.powerbi-route .topbar,
body.powerbi-route .kpi-grid,
body.powerbi-route .dashboard-grid,
body.powerbi-route #campaigns,
body.powerbi-route .split-grid {
  display: none;
}

body.powerbi-route .main {
  width: 100%;
  max-width: none;
  padding: 18px;
}

body.powerbi-route .powerbi-panel {
  min-height: calc(100vh - 36px);
  margin: 0;
}

body.powerbi-route .powerbi-frame {
  height: calc(100vh - 130px);
  max-height: none;
}

.report-preview {
  display: flex;
  align-items: end;
  gap: 18px;
  min-height: 220px;
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.report-preview span {
  flex: 1;
  min-width: 28px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, #d8ff80, #2d7c4b);
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    overflow-x: auto;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }

  .dashboard-grid,
  .split-grid,
  .campaign-board {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 18px;
  }

  .topbar,
  .panel-header,
  .run-item {
    align-items: stretch;
    flex-direction: column;
  }

  .lead-panel-actions {
    align-items: stretch;
    justify-content: stretch;
    width: 100%;
  }

  .approval-status {
    max-width: none;
    text-align: left;
  }

  .source-status {
    width: 100%;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .powerbi-empty {
    grid-template-columns: 1fr;
    padding: 18px;
  }
}

@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

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