/* ============================================================
   PANEL DE CAMPAÑAS — Meta Ads · Colectivo Inmobiliario
   Estilos del dashboard. Extiende los tokens del sistema.
   ============================================================ */
@import url("colors_and_type.css");

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  color: var(--fg-1);
  background: var(--bg-alt);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--ink); color: var(--white); }
button { font-family: inherit; cursor: pointer; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--fg-2);
}

/* ---------- APP SHELL ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- TOPBAR ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px;
  padding: 16px 32px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand img { height: 34px; width: auto; display: block; }
.brand .divider { width: 1px; height: 30px; background: var(--border); }
.brand .titleblock { display: flex; flex-direction: column; gap: 2px; }
.brand .titleblock .k {
  font-size: 14px; font-weight: 700; letter-spacing: -0.01em; line-height: 1;
}
.brand .titleblock .s {
  font-size: 10px; font-weight: 700; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--fg-3);
}

.topbar-right { display: flex; align-items: center; gap: 18px; }
.updated { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.updated .lab {
  font-size: 9px; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--fg-3);
}
.updated .val {
  font-family: var(--font-mono); font-size: 12px; color: var(--fg-1);
  display: inline-flex; align-items: center; gap: 7px;
}
.live-dot {
  width: 6px; height: 6px; border-radius: 999px; background: var(--success);
  box-shadow: 0 0 0 3px rgba(47,122,77,0.14);
}

/* Botón actualizar */
.btn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 11px 18px; border: 1px solid var(--ink);
  font-size: 11px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; background: var(--ink); color: var(--white);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--graphite); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--ink); color: var(--white); }
.btn svg { width: 15px; height: 15px; stroke-width: 1.9; }
.btn.busy svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- SUBBAR: tabs + filtro global ---------- */
.subbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; padding: 0 32px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 67px; z-index: 30;
}
.tabs { display: flex; gap: 4px; }
.tab {
  position: relative; background: none; border: none;
  padding: 16px 4px; margin-right: 22px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  color: var(--fg-3);
  transition: color var(--dur-fast) var(--ease-out);
}
.tab:last-child { margin-right: 0; }
.tab:hover { color: var(--fg-1); }
.tab.on { color: var(--ink); }
.tab.on::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; background: var(--ink);
}
.tab .count {
  font-family: var(--font-mono); font-size: 10px; color: var(--fg-3);
  margin-left: 6px;
}

/* Filtro global de campaña */
.scope { display: flex; align-items: center; gap: 12px; }
.scope .scope-lab {
  font-size: 10px; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--fg-3);
}
.dd { position: relative; }
.dd-btn {
  display: inline-flex; align-items: center; gap: 12px;
  min-width: 268px; justify-content: space-between;
  padding: 9px 12px; background: var(--bg);
  border: 1px solid var(--ink);
  font-size: 13px; font-weight: 600; color: var(--ink);
  transition: background var(--dur-fast) var(--ease-out);
}
.dd-btn:hover { background: var(--paper); }
.dd-btn .lead { display: inline-flex; align-items: center; gap: 9px; min-width: 0; }
.dd-btn .lead .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-btn svg { width: 15px; height: 15px; stroke-width: 2; color: var(--fg-2); flex: none; }
.dot { width: 9px; height: 9px; border-radius: 999px; flex: none; }
.dd-menu {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 320px;
  background: var(--bg); border: 1px solid var(--ink);
  box-shadow: var(--shadow-card); z-index: 50; padding: 4px;
  max-height: 70vh; overflow: auto;
}
.dd-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 10px 12px; background: none; border: none; text-align: left;
  font-size: 13px; color: var(--fg-1);
  transition: background var(--dur-fast) var(--ease-out);
}
.dd-item:hover { background: var(--paper); }
.dd-item.on { background: var(--ink); color: var(--white); }
.dd-item.on .meta { color: rgba(255,255,255,0.6); }
.dd-item .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-item .meta { font-family: var(--font-mono); font-size: 11px; color: var(--fg-3); }
.dd-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ---------- CONTENT ---------- */
.content { padding: 28px 32px 64px; max-width: 1500px; width: 100%; margin: 0 auto; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.view-head h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.view-head .sub { font-size: 13px; color: var(--fg-2); margin-top: 5px; }
.view-head .scope-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border: 1px solid var(--border);
  font-size: 12px; font-weight: 600;
}

/* ---------- KPI CARDS ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi {
  position: relative; background: var(--bg); border: 1px solid var(--border);
  padding: 20px 22px 18px; min-height: 138px;
  display: flex; flex-direction: column; justify-content: space-between;
  transition: border-color var(--dur-fast) var(--ease-out);
}
.kpi.primary { border-color: var(--ink); }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi .kpi-icon { width: 17px; height: 17px; stroke-width: 1.75; color: var(--fg-3); }
.kpi .kpi-val {
  font-family: var(--font-mono); font-weight: 500;
  font-size: 34px; letter-spacing: -0.02em; line-height: 1; color: var(--ink);
  margin: 14px 0 0;
}
.kpi.primary .kpi-val { font-size: 38px; }
.kpi .kpi-val .unit { font-size: 16px; color: var(--fg-3); margin-left: 4px; }
.kpi .kpi-foot { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
}
.delta svg { width: 12px; height: 12px; stroke-width: 2.4; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }
.delta.muted { color: var(--fg-3); }
.kpi .kpi-foot .note { font-size: 11px; color: var(--fg-3); }

/* tira de salud en la tarjeta de CPL */
.kpi .health-strip {
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
}

/* ---------- PANEL / CARD ---------- */
.panel { background: var(--bg); border: 1px solid var(--border); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 14px; font-weight: 700; letter-spacing: 0; margin: 0; }
.panel-head .hint { font-size: 11px; color: var(--fg-3); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.mt { margin-top: 16px; }
.mt-lg { margin-top: 24px; }

/* ---------- SEMÁFORO ---------- */
.sem { display: inline-flex; align-items: center; gap: 8px; }
.sem .bead {
  width: 9px; height: 9px; border-radius: 999px; flex: none;
}
.sem .txt { font-size: 12px; font-weight: 600; }
.sem-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 9px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border);
}
.legend { display: flex; gap: 18px; align-items: center; }
.legend .li { display: inline-flex; align-items: center; gap: 7px; font-size: 11px; color: var(--fg-2); }
.legend .li .bead { width: 8px; height: 8px; border-radius: 999px; }

/* estado chip */
.estado { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; }
.estado .b { width: 6px; height: 6px; border-radius: 999px; }
.estado.activa .b { background: var(--success); }
.estado.pausada .b { background: var(--steel); }
.estado.pausada { color: var(--fg-3); }

/* ---------- TABLA ---------- */
.tbl-wrap { width: 100%; overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl thead th {
  position: sticky; top: 0;
  text-align: right; padding: 12px 16px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--fg-3); background: var(--bg); border-bottom: 1px solid var(--ink);
  white-space: nowrap;
}
table.tbl thead th.l { text-align: left; }
table.tbl tbody td {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  text-align: right; white-space: nowrap;
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
}
table.tbl tbody td.l { text-align: left; font-family: var(--font-sans); }
table.tbl tbody tr { transition: background var(--dur-fast) var(--ease-out); cursor: default; }
table.tbl tbody tr:hover { background: var(--paper); }
table.tbl tbody tr.is-active { background: rgba(0,0,0,0.025); }
table.tbl tbody td .name { font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 10px; }
table.tbl tbody td .name .accent-bar { width: 3px; height: 28px; flex: none; }
table.tbl tbody td .sub { font-size: 11px; color: var(--fg-3); font-family: var(--font-sans); margin-top: 2px; }
table.tbl tfoot td {
  padding: 13px 16px; border-top: 1px solid var(--ink); text-align: right;
  font-family: var(--font-mono); font-weight: 500; font-size: 13px; white-space: nowrap;
}
table.tbl tfoot td.l { text-align: left; font-family: var(--font-sans); font-weight: 700; }
.cpl-cell { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.cpl-cell .bead { width: 8px; height: 8px; border-radius: 999px; }

/* ---------- BARRA DE PROGRESO PRESUPUESTO ---------- */
.bar { height: 5px; background: var(--line); position: relative; min-width: 64px; }
.bar > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--ink); }

/* ---------- COMPARATIVA CONJUNTOS ---------- */
.cmp-row {
  display: grid; grid-template-columns: 1fr; gap: 0;
  border-bottom: 1px solid var(--border); padding: 16px 20px;
}
.cmp-row:last-child { border-bottom: none; }
.cmp-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.cmp-head .nm { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.cmp-head .rk {
  font-family: var(--font-mono); font-size: 11px; color: var(--white);
  background: var(--ink); width: 20px; height: 20px; display: inline-flex;
  align-items: center; justify-content: center; flex: none;
}
.cmp-metrics { display: flex; align-items: center; gap: 22px; }
.cmp-metrics .m { display: flex; flex-direction: column; gap: 2px; }
.cmp-metrics .m .v { font-family: var(--font-mono); font-size: 15px; color: var(--ink); }
.cmp-metrics .m .k { font-size: 9px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--fg-3); }
.cmp-bar-track { flex: 1; height: 8px; background: var(--paper); border: 1px solid var(--line); position: relative; }
.cmp-bar-fill { position: absolute; left: 0; top: 0; bottom: 0; }
.tag-win, .tag-waste {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
}
.tag-win { background: var(--success); color: var(--white); }
.tag-waste { background: var(--danger); color: var(--white); }
.tag-win svg, .tag-waste svg { width: 12px; height: 12px; stroke-width: 2.2; }

/* callout mejor / peor */
.verdict { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.verdict .vc { border: 1px solid var(--border); padding: 18px 20px; position: relative; }
.verdict .vc.best { border-color: var(--success); }
.verdict .vc.worst { border-color: var(--danger); }
.verdict .vc .vtag { margin-bottom: 12px; }
.verdict .vc .vname { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.verdict .vc .vsub { font-size: 12px; color: var(--fg-2); margin-top: 4px; line-height: 1.5; }
.verdict .vc .vstat { display: flex; gap: 28px; margin-top: 16px; }
.verdict .vc .vstat .s .v { font-family: var(--font-mono); font-size: 22px; color: var(--ink); }
.verdict .vc .vstat .s .k { font-size: 9px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--fg-3); margin-top: 3px; }

/* ---------- CHARTS ---------- */
.chart-card { background: var(--bg); border: 1px solid var(--border); padding: 18px 20px 12px; }
.chart-card .ch-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.chart-card .ch-title { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--fg-2); }
.chart-card .ch-now { font-family: var(--font-mono); font-size: 20px; color: var(--ink); letter-spacing: -0.01em; }
.chart-card .ch-now .d { font-size: 12px; margin-left: 8px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-x { fill: var(--fg-3); font-family: var(--font-mono); font-size: 9px; }
.chart .axis-y { fill: var(--fg-3); font-family: var(--font-mono); font-size: 9px; }
.chart .series-line { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.chart .series-area { fill: rgba(17,17,17,0.04); stroke: none; }
.chart .dot-last { fill: var(--ink); }
.chart .hover-x { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 2 3; }

/* tooltip de chart */
.ch-tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--ink); color: var(--white); padding: 8px 11px;
  font-size: 11px; line-height: 1.5; white-space: nowrap; transform: translate(-50%, -120%);
}
.ch-tip .tf { font-family: var(--font-mono); }
.ch-tip .tk { color: rgba(255,255,255,0.6); }

/* ---------- SPARKLINE ---------- */
.spark svg { display: block; }

/* ---------- EMPTY STATE ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 72px 32px; gap: 16px;
  background: var(--bg); border: 1px solid var(--border);
}
.empty .ic {
  width: 56px; height: 56px; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.empty .ic svg { width: 28px; height: 28px; stroke-width: 1.5; color: var(--fg-3); }
.empty h3 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; margin: 4px 0 0; }
.empty p { font-size: 13px; color: var(--fg-2); max-width: 420px; margin: 0; line-height: 1.6; }
.empty .actions { display: flex; gap: 10px; margin-top: 6px; }

/* ---------- MINI BADGE / TIPO ---------- */
.tipo-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--fg-2);
}

/* segmented control (filtro tendencias) */
.seg { display: inline-flex; border: 1px solid var(--border); }
.seg button {
  padding: 8px 14px; background: var(--bg); border: none; border-right: 1px solid var(--border);
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; color: var(--fg-2);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--ink); color: var(--white); }

/* responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr; }
  .verdict { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar, .subbar, .content { padding-left: 18px; padding-right: 18px; }
  .kpis { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .brand .titleblock .s { display: none; }
}
