/* DashAds components. Built only on role variables from tokens.css (no raw hex). */

*, *::before, *::after { box-sizing: border-box; }
h1, h2, h3, h4, p, ul, dl, figure, blockquote { margin: 0; }
a { color: var(--primary); }
img, svg { flex-shrink: 0; }
.icon { display: inline-block; vertical-align: -0.2em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: var(--sp-2); top: -40px; background: var(--surface); color: var(--text); padding: var(--sp-2) var(--sp-3); z-index: var(--z-toast); border-radius: var(--radius-sm); }
.skip-link:focus { top: var(--sp-2); }
.muted { color: var(--text-2); }
.mono, code { font-family: var(--mono); font-size: .92em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ul.plain { list-style: none; padding: 0; }

/* typography scale 12/14/16/18/24/32 */
.h1 { font-size: var(--fs-24); font-weight: 600; line-height: 1.25; }
.h2 { font-size: var(--fs-24); font-weight: 600; margin-bottom: var(--sp-4); }
.h3 { font-size: var(--fs-18); font-weight: 600; }
.h4 { font-size: var(--fs-16); font-weight: 500; margin: var(--sp-4) 0 var(--sp-2); }

/* ---- layout ------------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.topbar { display: none; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--sp-4);
  background: var(--surface); border-right: 1px solid var(--border); padding: var(--sp-4) var(--sp-3); z-index: var(--z-nav); }
.brand { font-weight: 600; font-size: var(--fs-18); color: var(--primary); }
.brand-side { padding: var(--sp-1) var(--sp-3) var(--sp-3); }
.nav { list-style: none; padding: 0; display: flex; flex-direction: column; gap: var(--sp-1); }
.nav-item { display: flex; align-items: center; gap: var(--sp-3); min-height: 40px; padding: 0 var(--sp-3);
  border-radius: var(--radius-sm); color: var(--text-2); text-decoration: none; border-left: 3px solid transparent;
  transition: background var(--dur) var(--ease-out), color var(--dur) var(--ease-out); }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { color: var(--text); font-weight: 600; border-left-color: var(--primary); background: var(--primary-soft); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--sp-2); border-top: 1px solid var(--border); padding-top: var(--sp-3); }
.user { display: flex; flex-direction: column; padding: 0 var(--sp-3); font-size: var(--fs-12); }
.user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { color: var(--text-2); }
.main { padding: var(--sp-6) var(--sp-8); max-width: 1440px; width: 100%; min-width: 0; display: flex; flex-direction: column; gap: var(--sp-6); }
.main:focus { outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }

.theme-ic { display: none; }
:root:not([data-theme-choice]) .theme-ic-system,
:root[data-theme-choice="system"] .theme-ic-system,
:root[data-theme-choice="light"] .theme-ic-light,
:root[data-theme-choice="dark"] .theme-ic-dark { display: inline-flex; }

@media (max-width: 1023px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .topbar { display: flex; align-items: center; gap: var(--sp-2); position: sticky; top: 0; z-index: var(--z-nav);
    background: var(--surface); border-bottom: 1px solid var(--border); padding: var(--sp-1) var(--sp-3); }
  .sidebar { position: fixed; left: 0; top: 0; width: var(--sidebar-w); transform: translateX(-100%);
    transition: transform var(--dur) var(--ease-out); box-shadow: var(--shadow-2); }
  .nav-open .sidebar { transform: none; }
  .main { padding: var(--sp-4); }
  .btn, .nav-item, input, select { min-height: 44px; }
}

/* ---- cards / kpis ------------------------------------------------------------------ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-1);
  padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-4); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: var(--sp-4); }
.kpi { gap: var(--sp-2); padding: var(--sp-4); }
.kpi-title { font-size: var(--fs-14); font-weight: 500; color: var(--text-2); }
.kpi-value { font-size: var(--fs-32); font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-link { font-size: var(--fs-14); }
.empty-state { flex-direction: row; align-items: flex-start; color: var(--text-2); }
.empty-state .h3 { color: var(--text); margin-bottom: var(--sp-1); }

/* ---- filters (single sticky row) ------------------------------------------------------ */
.filters { position: sticky; top: 0; z-index: var(--z-sticky); display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3);
  background: var(--bg); padding: var(--sp-2) 0; border-bottom: 1px solid var(--border); }
.field-inline { display: flex; flex-direction: column; gap: var(--sp-1); font-size: var(--fs-12); color: var(--text-2); }
@media (max-width: 1023px) { .filters { top: 53px; } }

/* ---- forms ------------------------------------------------------------------------------ */
.form { display: flex; flex-direction: column; gap: var(--sp-4); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.span-2 { grid-column: 1 / -1; }
@media (max-width: 767px) { .grid-2 { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: var(--sp-1); border: 0; padding: 0; margin: 0; min-width: 0; }
.field label, .field legend { font-weight: 500; font-size: var(--fs-14); }
input, select, textarea { font: inherit; font-size: var(--fs-16); color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); min-height: 36px; padding: var(--sp-1) var(--sp-3); }
input[type="checkbox"] { min-height: 0; width: 16px; height: 16px; accent-color: var(--primary); }
input[type="file"] { padding: var(--sp-2); }
input:user-invalid { border-color: var(--danger); }
.help { font-size: var(--fs-12); color: var(--text-2); }
.check { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; padding: var(--sp-1) 0; }
.actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: flex-end; }
.recovery summary { color: var(--text-2); font-size: var(--fs-14); }
.recovery .field { margin-top: var(--sp-3); }

/* ---- buttons ------------------------------------------------------------------------ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: 36px; padding: 0 var(--sp-4);
  font: inherit; font-weight: 500; font-size: var(--fs-14); border-radius: var(--radius-sm); border: 1px solid transparent;
  text-decoration: none; transition: background var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); justify-content: flex-start; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: var(--surface); }
.btn-danger-text { color: var(--danger); }
.btn-icon { padding: 0; width: 36px; justify-content: center; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.is-loading::after { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor;
  border-right-color: transparent; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- alerts / badges / toasts ----------------------------------------------------------- */
.alert { display: flex; gap: var(--sp-2); align-items: flex-start; padding: var(--sp-3); border-radius: var(--radius-sm); border: 1px solid; }
.alert-danger { color: var(--danger); background: var(--danger-bg); }
.alert-warn { color: var(--warn); background: var(--warn-bg); }
.alert-ok { color: var(--ok); background: var(--ok-bg); align-items: center; }
.alert span, .alert ul { color: var(--text); }
.badge { display: inline-flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-12); font-weight: 500; padding: 2px var(--sp-2);
  border-radius: 999px; border: 1px solid; white-space: nowrap; }
.badge-ok { color: var(--ok); background: var(--ok-bg); }
.badge-warn { color: var(--warn); background: var(--warn-bg); }
.badge-danger { color: var(--danger); background: var(--danger-bg); }
.badge-info { color: var(--primary); background: var(--primary-soft); }
.badge-muted { color: var(--text-2); background: var(--surface-2); }
.toasts { position: fixed; right: var(--sp-4); bottom: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); z-index: var(--z-toast); }
.toast { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--ok); box-shadow: var(--shadow-2); }
.toast-danger { border-left-color: var(--danger); }

/* ---- tables --------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-14); font-variant-numeric: tabular-nums; }
.table th, .table td { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { position: sticky; top: 0; background: var(--surface-2); font-weight: 500; color: var(--text-2); z-index: 1; }
.table th.num, .table td.num { text-align: right; }
.table tbody tr:hover { background: var(--surface-2); }
.th-sort { all: unset; cursor: pointer; display: inline-flex; gap: var(--sp-1); }
.th-sort:focus-visible { outline: 2px solid var(--focus); }
th[aria-sort="ascending"] .th-sort::after { content: "▲"; font-size: .7em; }
th[aria-sort="descending"] .th-sort::after { content: "▼"; font-size: .7em; }

/* ---- code ---------------------------------------------------------------------------- */
.code-block { display: block; font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: var(--sp-2) var(--sp-3); overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.code-row { display: flex; gap: var(--sp-2); align-items: flex-start; }
.code-row .code-block { flex: 1; }
.preview { display: flex; flex-direction: column; gap: var(--sp-1); }
.preview .label { font-size: var(--fs-12); color: var(--text-2); }
.template + .template { border-top: 1px solid var(--border); padding-top: var(--sp-2); }
.codes { columns: 2; padding: 0; list-style: none; font-size: var(--fs-18); }
.secret { font-size: var(--fs-18); letter-spacing: .05em; }

/* ---- approvals ------------------------------------------------------------------------- */
.meta { display: flex; flex-wrap: wrap; gap: var(--sp-4) var(--sp-8); }
.meta dt { font-size: var(--fs-12); color: var(--text-2); }
.meta dd { margin: 0; }
.diff { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2); font-size: var(--fs-18); padding: var(--sp-3);
  background: var(--surface-2); border-radius: var(--radius-sm); }
.diff-old { text-decoration: line-through; color: var(--text-2); }
.diff-new { font-weight: 500; }
.exec { display: flex; gap: var(--sp-2); align-items: flex-start; margin: var(--sp-2) 0; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); }
.exec svg { flex: none; margin-top: 2px; }
.exec-ok { background: var(--ok-bg); }
.exec-ok svg { color: var(--ok); }
.exec-warn { background: var(--warn-bg); }
.exec-warn svg { color: var(--warn); }
.exec-bad { background: var(--danger-bg); }
.exec-bad svg { color: var(--danger); }
.checklist { list-style: none; padding: 0; display: grid; gap: var(--sp-1); }
.checklist li { display: flex; gap: var(--sp-2); align-items: flex-start; }
.check-ok .icon { color: var(--ok); }
.check-bad { color: var(--danger); }
.check-bad span { color: var(--text); }
.ai-text { border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: var(--sp-3); background: var(--surface-2); }
.ai-text figcaption { display: flex; gap: var(--sp-2); font-size: var(--fs-12); color: var(--text-2); margin-bottom: var(--sp-2); }
.ai-text blockquote { white-space: pre-wrap; }
.modal { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: var(--sp-6); width: min(420px, 92vw); box-shadow: var(--shadow-2); }
.modal::backdrop { background: rgb(0 0 0 / .45); }

/* ---- auth ------------------------------------------------------------------------------ */
.auth-main { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-4); }
.auth-card { width: min(440px, 100%); }
.qr { align-self: center; background: var(--surface); padding: var(--sp-3); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.qr svg { display: block; width: 200px; height: auto; }
.freshness { display: flex; flex-wrap: wrap; gap: var(--sp-3); font-size: var(--fs-12); color: var(--text-2); }
.fresh-item { display: inline-flex; align-items: center; gap: var(--sp-1); }

/* GA4 per-report data-quality list (Conexiones > Google) */
.quality-list { margin: 0; padding-left: 1rem; }

/* 0006 alerts: open-alert count in the sidebar */
.nav-item .nav-count { margin-left: auto; }

/* ---- dashboards (routes_dashboards / charts.js) ------------------------------------------ */
.dash-panel { display: flex; flex-direction: column; gap: var(--sp-6); transition: opacity var(--dur) var(--ease-out); }
.dash-panel.htmx-request { opacity: .55; }  /* refetch keeps the frame, no skeleton flash */
.dash-period { display: flex; align-items: center; gap: var(--sp-2); color: var(--text-2); font-size: var(--fs-14); }
.dash-notes { display: flex; flex-direction: column; gap: var(--sp-2); }
.filters [hidden] { display: none; }
.freshness-strip { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-12); color: var(--text-2); }
.fresh-src { color: var(--text); font-weight: 500; }
.kpi-line { display: flex; flex-direction: column; gap: 2px; }
.kpi-line + .kpi-line { border-top: 1px solid var(--border); padding-top: var(--sp-2); }
/* KPI amounts never wrap ("ARS $" + number on one line): the size follows the card width
   (container query units), 16-24 px, tabular figures */
.kpi { container-type: inline-size; }
.kpi .kpi-value { font-variant-numeric: tabular-nums; font-size: clamp(var(--fs-16), 10.5cqi, var(--fs-24));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value-empty { color: var(--text-2); }
.kpi-delta { display: inline-flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-12); font-weight: 500; }
.kpi-delta-good { color: var(--ok); }
.kpi-delta-bad { color: var(--danger); }
.kpi-delta-neutral { color: var(--text-2); }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: var(--sp-4); }
@media (max-width: 767px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card { margin: 0; min-width: 0; }
.chart-box { position: relative; }
.chart { width: 100%; height: 280px; }
.chart-md .chart { height: 280px; }
.chart-lg .chart { height: 380px; }
.chart-skeleton { height: 100%; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--border) 50%, var(--surface-2) 100%);
  background-size: 200% 100%; animation: dash-shimmer 1.2s linear infinite; }
@keyframes dash-shimmer { to { background-position: -200% 0; } }
.chart-error { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); color: var(--danger); padding: var(--sp-3);
  background: var(--danger-bg); border-radius: var(--radius-sm); }
.chart-error span { color: var(--text); }
.chart-error[hidden], .chart-table[hidden] { display: none; }
.chart-empty { display: flex; align-items: center; gap: var(--sp-3); color: var(--text-2); min-height: 120px; padding: var(--sp-4);
  border: 1px dashed var(--border); border-radius: var(--radius-sm); flex-direction: row; }
.chart-empty p { color: var(--text); }
.chart-table { display: flex; flex-direction: column; gap: var(--sp-2); }
.platform-key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: var(--sp-2); vertical-align: 0; }
.platform-key-meta { background: var(--s-meta); }
.platform-key-google { background: var(--s-google); }
.cell-bar-cell { white-space: nowrap; }
.cell-bar { appearance: none; -webkit-appearance: none; width: 80px; height: 8px; border: 0; border-radius: 4px; vertical-align: middle;
  margin-right: var(--sp-2); background: var(--surface-2); color: var(--primary); }
.cell-bar::-webkit-progress-bar { background: var(--surface-2); border-radius: 4px; }
.cell-bar::-webkit-progress-value { background: var(--primary); border-radius: 4px; }
.cell-bar::-moz-progress-bar { background: var(--primary); border-radius: 4px; }
.row-unattributed td { color: var(--text-2); }
.funnel-steps { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-6); padding-left: var(--sp-6); }
/* ECharts tooltip content (built by charts.js with classes only: no inline styles under CSP) */
.dash-tt { font: var(--fs-12)/1.4 var(--font); color: var(--text); min-width: 140px; }
.dash-tt-head { color: var(--text-2); margin-bottom: var(--sp-1); }
.dash-tt-row { display: flex; align-items: center; gap: var(--sp-2); }
.dash-tt-val { font-weight: 600; font-variant-numeric: tabular-nums; margin-left: auto; padding-left: var(--sp-3); }
.dash-tt-key { display: inline-block; width: 12px; height: 2px; border-radius: 1px; background: var(--s-otros); }
.dash-tt-key-rect { height: 10px; width: 10px; border-radius: 2px; }
.dash-tt-key-meta { background: var(--s-meta); } .dash-tt-key-google { background: var(--s-google); }
.dash-tt-key-tiktok { background: var(--s-tiktok); } .dash-tt-key-chatgpt { background: var(--s-chatgpt); }
.dash-tt-key-pinterest { background: var(--s-pinterest); } .dash-tt-key-organico { background: var(--s-organico); }
.dash-tt-key-directo { background: var(--s-directo); } .dash-tt-key-otros { background: var(--s-otros); }
.dash-tt-key-primary { background: var(--primary); }
.dash-panel .table td.num { white-space: nowrap; }

/* the "Ver tabla" toggle never wraps next to a long chart title */
[data-table-toggle] { white-space: nowrap; flex-shrink: 0; }
