:root {
  --bg: #0f1419;
  --surface: #1a222d;
  --surface2: #243040;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d9ee5;
  --accent-dim: #2a6fa3;
  --border: #2f3d4d;
  --campaign: #5ad4a0;
  --adset: #c9a227;
  --ad: #b87fd9;
  --danger: #f07178;
  --radius: 10px;
  --font: "DM Sans", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.campaign-app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* —— Resumen global (números grandes, ancho completo) —— */
.campaign-summary-hero {
  flex-shrink: 0;
  width: 100%;
  padding: 1.25rem 1.5rem 1.5rem;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}

.campaign-summary-hero-title {
  margin: 0 0 1rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.campaign-summary-hero-inner {
  width: 100%;
}

.campaign-summary-hero-inner .tree-totals--strip {
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
}

.campaign-summary-hero-inner .tree-totals-grid--struct,
.campaign-summary-hero-inner .tree-totals-metrics-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  width: 100%;
}

.campaign-summary-hero-inner .tree-totals-grid--metrics {
  margin-top: 0.5rem;
  padding-top: 1rem;
  padding-left: 0;
  margin-left: 0;
  border-top: 1px solid var(--border);
  border-left: none;
}

.campaign-summary-hero-inner .tree-totals-kpi {
  padding: 0.85rem 1rem;
  min-height: 4.25rem;
  justify-content: center;
}

.campaign-summary-hero-inner .tree-totals-kpi-label {
  font-size: 0.68rem;
}

.campaign-summary-hero-inner .tree-totals-kpi-value {
  font-size: clamp(1.35rem, 3vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.campaign-summary-hero-inner .tree-totals-heading {
  font-size: 0.72rem;
  margin-bottom: 0.5rem;
}

/* —— Lista de campañas (ancho completo) —— */
.campaign-explorer {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 1rem 1.5rem 1.5rem;
  width: 100%;
}

.campaign-explorer-title {
  margin: 0 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.campaign-explorer-hint {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 52rem;
}

.campaign-explorer-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 156, 179, 0.22) transparent;
  padding-right: 0.25rem;
}

.campaign-tree-host--wide {
  max-width: none;
  width: 100%;
}

.tree-root--fullwidth {
  width: 100%;
}

.tree-item-wrap--campaign {
  margin: 0 0 0.75rem;
}

.tree-details--block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.tree-details--block > .tree-summary--campaign {
  padding: 0.35rem 0.5rem 0.35rem 0.25rem;
  background: rgba(90, 212, 160, 0.06);
}

.tree-label--block {
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
}

.tree-summary--adset {
  padding: 0.25rem 0.35rem;
}

/* —— Panel lateral derecho —— */
.detail-drawer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  visibility: hidden;
}

.detail-drawer--open {
  pointer-events: auto;
  visibility: visible;
}

.detail-drawer-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  background: rgba(8, 12, 18, 0.62);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.22s ease;
}

.detail-drawer--open .detail-drawer-backdrop {
  opacity: 1;
}

.detail-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(480px, 100vw);
  max-width: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
}

.detail-drawer--open .detail-drawer-panel {
  transform: translateX(0);
}

.detail-drawer-header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.detail-drawer-heading {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.02em;
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.detail-drawer-close {
  flex-shrink: 0;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}

.detail-drawer-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.detail-drawer-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1rem 1.5rem;
  scrollbar-width: thin;
}

body.detail-drawer-active {
  overflow: hidden;
}

.stats-meta--embedded {
  margin: 0 0 1rem;
  font-size: 0.8rem;
}

.app-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-header p {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.campaign-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  align-items: stretch;
  gap: 0;
  flex: 1;
  min-height: 0;
}

@media (max-width: 800px) {
  .campaign-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .campaign-tree-wrap {
    max-width: none;
  }
}

.panel-title {
  margin: 0 0 0.75rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.campaign-tree-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1rem 1rem 1.25rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
  width: 100%;
  max-width: 380px;
}

.campaign-totals-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 1.25rem;
  padding: 0.55rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.campaign-totals-strip-title {
  margin: 0;
  flex: 0 0 auto;
}

.campaign-totals-host {
  flex: 1 1 200px;
  min-width: 0;
}

.tree-totals {
  font-size: 0.82rem;
}

.tree-totals--strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.85rem;
}

.tree-totals--strip .tree-totals-grid--struct {
  flex-direction: row;
}

.tree-totals--strip .tree-totals-grid--metrics {
  margin-top: 0;
  padding-top: 0;
  padding-left: 0.9rem;
  margin-left: 0.1rem;
  border-top: none;
  border-left: 1px solid var(--border);
}

.tree-totals--strip .tree-totals-warn {
  flex-basis: 100%;
  margin: 0.15rem 0 0;
}

.tree-totals--strip .tree-totals-hint {
  margin: 0;
  flex-basis: 100%;
}

.tree-totals-status {
  margin: 0;
  color: var(--muted);
}

.tree-totals-status--error {
  color: var(--danger);
  font-size: 0.8rem;
}

.tree-totals-hint {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.tree-totals-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tree-totals-grid--struct {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tree-totals-grid--metrics {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.tree-totals-heading {
  margin: 0 0 0.35rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.tree-totals-metrics-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tree-totals-kpi {
  flex: 1;
  min-width: 72px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.tree-totals-kpi-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.tree-totals-kpi-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.tree-totals-warn {
  margin: 0.4rem 0 0;
  font-size: 0.72rem;
  color: var(--adset);
}

/* Misma altura útil en ambas columnas: el scroll solo en estas cajas */
.campaign-tree-scroll,
.campaign-stats-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 156, 179, 0.22) transparent;
}

.campaign-tree-scroll::-webkit-scrollbar,
.campaign-stats-scroll::-webkit-scrollbar {
  width: 4px;
}

.campaign-tree-scroll::-webkit-scrollbar-track,
.campaign-stats-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.campaign-tree-scroll::-webkit-scrollbar-thumb,
.campaign-stats-scroll::-webkit-scrollbar-thumb {
  background: rgba(139, 156, 179, 0.22);
  border-radius: 100px;
}

.campaign-tree-scroll::-webkit-scrollbar-thumb:hover,
.campaign-stats-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 156, 179, 0.38);
}

.campaign-stats-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1rem 1.25rem 1.25rem;
  overflow: hidden;
  background: var(--bg);
}

.campaign-stats-scroll {
  padding-bottom: 0.25rem;
}

.campaign-tree-host {
  font-size: 0.9rem;
}

.tree-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.tree-status--error {
  color: var(--danger);
}

.tree-root,
.tree-children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-children {
  margin-left: 0.35rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--border);
}

.tree-item-wrap {
  margin: 0.15rem 0;
}

.tree-item {
  margin: 0.2rem 0;
}

.tree-details {
  border-radius: 8px;
}

.tree-details[open] > .tree-summary {
  background: rgba(36, 48, 64, 0.5);
}

.tree-summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  border-radius: 8px;
  padding: 0.1rem 0;
}

.tree-summary::-webkit-details-marker {
  display: none;
}

.tree-summary::before {
  content: "";
  flex-shrink: 0;
  width: 0.45rem;
  height: 0.45rem;
  margin-left: 0.15rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  opacity: 0.75;
}

.tree-details[open] > .tree-summary::before {
  transform: rotate(45deg);
}

.tree-details-body {
  padding: 0.2rem 0 0.15rem 0.5rem;
}

.tree-row {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.tree-label {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  width: 100%;
  transition: background 0.12s ease, transform 0.08s ease;
}

.tree-label:hover {
  background: var(--surface2);
}

.tree-label:active {
  transform: scale(0.99);
}

.stats-totals-title {
  margin: 0 0 0.75rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.tree-label--campaign {
  border-left: 3px solid var(--campaign);
  font-weight: 600;
}

.tree-label--adset {
  border-left: 3px solid var(--adset);
}

.tree-label--ad {
  border-left: 3px solid var(--ad);
  font-size: 0.88em;
  color: #c5d4e8;
}

.stats-placeholder,
.stats-error {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats-error {
  color: var(--danger);
}

.stats-header {
  margin-bottom: 1.25rem;
}

.stats-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  background: var(--surface2);
  color: var(--accent);
}

.stats-badge--campaign {
  color: var(--campaign);
}

.stats-badge--adset {
  color: var(--adset);
}

.stats-badge--ad {
  color: var(--ad);
}

.stats-title {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stats-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}

.stats-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stats-kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stats-kpi-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stats-kpi-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.stats-section {
  margin-top: 1.5rem;
}

.stats-section h3 {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.stats-sort-block {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stats-sort-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.stats-sort-label {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.6rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.stats-sort-select {
  font: inherit;
  font-size: 0.82rem;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  max-width: min(100%, 22rem);
  cursor: pointer;
}

.stats-sort-hint {
  font-size: 0.75rem;
  color: var(--muted);
  flex: 1 1 12rem;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.stats-table th,
.stats-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.stats-table th {
  background: var(--surface2);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stats-table tr:last-child td {
  border-bottom: none;
}

.stats-table--wide {
  display: block;
  overflow-x: auto;
}

.stats-empty {
  text-align: center;
  color: var(--muted);
}
