/* El atributo `hidden` debe ganar siempre, incluso sobre componentes que
   fijan su propio `display` (.btn, .alert, .empty-state, etc.). Sin esto,
   la igualdad de especificidad entre el estilo de user-agent [hidden] y
   una clase de autor con `display` explícito hace que el elemento se
   renderice visible pese a `element.hidden === true`. */
[hidden] { display: none !important; }

:root {
  --topbar-h: 54px;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f0f2f6;
  --surface-raised: #ffffff;
  --border: #e2e6ed;
  --border-strong: #cdd4e0;
  --text: #1b2430;
  --text-muted: #5b6472;
  --text-faint: #8a92a1;
  --accent: #2f6feb;
  --accent-hover: #2559c4;
  --accent-soft: #e8f0fe;
  --positive: #157a42;
  --positive-bg: #e7f6ec;
  --negative: #b4291c;
  --negative-bg: #fdeceb;
  --warning: #8a5a06;
  --warning-bg: #fff6e0;
  --warning-border: #f0d48a;
  --nd: #8a92a1;
  --nd-bg: #eef0f4;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 4px 14px rgba(20, 30, 50, 0.04);
  --focus-ring: #2f6feb;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b25;
    --surface-alt: #1b2330;
    --surface-raised: #1a2130;
    --border: #262f3f;
    --border-strong: #34405a;
    --text: #e9edf4;
    --text-muted: #9aa7ba;
    --text-faint: #6b7688;
    --accent: #5b8def;
    --accent-hover: #7ba3f5;
    --accent-soft: #1c2b47;
    --positive: #4cc98a;
    --positive-bg: #12291d;
    --negative: #ef7a70;
    --negative-bg: #2e1614;
    --warning: #e3ac4c;
    --warning-bg: #2a2011;
    --warning-border: #4a3a17;
    --nd: #7c8798;
    --nd-bg: #202836;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 18px rgba(0, 0, 0, 0.3);
    --focus-ring: #7ba3f5;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #151b25; --surface-alt: #1b2330; --surface-raised: #1a2130;
  --border: #262f3f; --border-strong: #34405a; --text: #e9edf4; --text-muted: #9aa7ba; --text-faint: #6b7688;
  --accent: #5b8def; --accent-hover: #7ba3f5; --accent-soft: #1c2b47;
  --positive: #4cc98a; --positive-bg: #12291d; --negative: #ef7a70; --negative-bg: #2e1614;
  --warning: #e3ac4c; --warning-bg: #2a2011; --warning-border: #4a3a17;
  --nd: #7c8798; --nd-bg: #202836; --focus-ring: #7ba3f5;
}
:root[data-theme="light"] {
  --bg: #f4f6f9; --surface: #ffffff; --surface-alt: #f0f2f6; --surface-raised: #ffffff;
  --border: #e2e6ed; --border-strong: #cdd4e0; --text: #1b2430; --text-muted: #5b6472; --text-faint: #8a92a1;
  --accent: #2f6feb; --accent-hover: #2559c4; --accent-soft: #e8f0fe;
  --positive: #157a42; --positive-bg: #e7f6ec; --negative: #b4291c; --negative-bg: #fdeceb;
  --warning: #8a5a06; --warning-bg: #fff6e0; --warning-border: #f0d48a;
  --nd: #8a92a1; --nd-bg: #eef0f4; --focus-ring: #2f6feb;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  overflow-x: hidden;
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--surface-alt);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-muted);
}
svg { display: block; flex-shrink: 0; }
button, select, input { font-family: inherit; }
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 8px 0;
  font-weight: 600;
  font-size: 13px;
}
.skip-link:focus {
  left: 0;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}
.badge--active { background: var(--positive-bg); color: var(--positive); }
.badge--paused { background: var(--warning-bg); color: var(--warning); }
.badge--other { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }
.badge--neutral { background: var(--surface-alt); color: var(--text-muted); }
.badge--mode { background: var(--accent-soft); color: var(--accent); }
.badge--negative { background: var(--negative-bg); color: var(--negative); }
.badge--warn { background: var(--warning-bg); color: var(--warning); }
.badge--live { background: var(--positive-bg); color: var(--positive); }
.badge--live-cache { background: var(--warning-bg); color: var(--warning); }
.badge--live-error { background: var(--negative-bg); color: var(--negative); }
.live-timestamp { color: var(--text-faint); font-size: 11px; white-space: nowrap; }

/* ---------- Badge local de fuente por vista ---------- */
.source-badge-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}
.source-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: help;
}
.source-badge--live { background: var(--positive-bg); color: var(--positive); }
.source-badge--mixed { background: var(--accent-soft); color: var(--accent); }
.source-badge--snapshot { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }
.source-badge-subtitle { color: var(--text-faint); font-size: 12px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background-color 120ms ease, border-color 120ms ease, opacity 120ms ease;
}
.btn svg { width: 15px; height: 15px; }
.btn--primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn--secondary:hover { background: var(--surface-alt); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn--sm { padding: 5px 10px; min-height: 30px; font-size: 12px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn--loading { position: relative; color: transparent !important; }
.btn--loading::after {
  content: ''; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent; color: var(--text);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.control {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  min-height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}
.control-label { font-size: 12px; color: var(--text-muted); margin-right: 6px; }

.dropdown { position: relative; }
.dropdown__menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); min-width: 230px; padding: 6px; z-index: 60;
}
.dropdown__menu a, .dropdown__menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 6px; color: var(--text); text-decoration: none;
  font-size: 13px; background: none; border: none; cursor: pointer;
}
.dropdown__menu a:hover, .dropdown__menu button:hover { background: var(--surface-alt); }
.dropdown__group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); padding: 8px 10px 2px; }

/* ---------- Topbar (3 zones) ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}
.topbar__zone { display: flex; align-items: center; gap: 12px; min-width: 0; }
/* Bugfix (AL-META-DASHBOARD-V2-AUTONOMOUS-BROWSER-VISUAL-GATE): esta zona
   originalmente solo tenía menu-toggle+brand+mode-badge+live-timestamp (cabía
   sin wrap a 390px). Fase 4 agregó el selector de cuenta (#account-select-wrap)
   y el badge de estado (#account-status-badge) sin agregar flex-wrap acá -
   a diferencia de --center/--right, que ya lo tenían - así que a mobile el
   contenido se salía del viewport en vez de pasar a una segunda línea
   (664px de ancho real en un viewport de 375px, confirmado en el gate
   visual autónomo). Mismo flex-wrap que ya usan las otras dos zonas. */
.topbar__zone--left { flex: 0 0 auto; flex-wrap: wrap; }
.topbar__zone--center { flex: 1 1 auto; justify-content: center; flex-wrap: wrap; gap: 8px 16px; min-width: 200px; }
.topbar__zone--right { flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }

.menu-toggle {
  display: none;
  background: transparent; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  width: 36px; height: 36px; align-items: center; justify-content: center; cursor: pointer; color: var(--text);
}
.menu-toggle svg { width: 18px; height: 18px; }

.brand { display: flex; align-items: center; gap: 9px; }
.brand__title { font-weight: 700; font-size: 14.5px; line-height: 1.2; }
.brand__subtitle { font-size: 11px; color: var(--text-muted); line-height: 1.2; }

/* Perfil autenticado (prompt §22) — discreto: handle + admin + logout. */
.profile-widget { display: flex; align-items: center; gap: 8px; padding-left: 8px; margin-left: 4px; border-left: 1px solid var(--border); }
.profile-widget__handle { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }

.account-summary { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; justify-content: center; font-size: 12.5px; }
.account-summary__name { font-weight: 700; font-size: 13.5px; color: var(--text); }
.account-summary__meta { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 11.5px; flex-wrap: wrap; justify-content: center; }
.account-summary__updated { color: var(--text-faint); font-size: 11px; }

.period-control { display: flex; flex-direction: column; gap: 2px; }
.period-range-label { font-size: 10.5px; color: var(--text-faint); text-align: right; white-space: nowrap; }

/* ---------- Alert (compact, single) ---------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--warning-bg);
  border-bottom: 1px solid var(--warning-border);
  padding: 10px 20px;
  font-size: 12.5px;
  color: var(--text);
}
.alert__icon { color: var(--warning); margin-top: 1px; }
.alert__icon svg { width: 18px; height: 18px; }
.alert__body { flex: 1; min-width: 0; }
.alert__title { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.alert__title .badge { margin: 0 3px; vertical-align: middle; }
.alert__meta { color: var(--text-muted); font-size: 12px; }
.alert__actions { display: flex; gap: 8px; flex-shrink: 0; flex-wrap: wrap; align-items: flex-start; }
.alert__detail {
  flex-basis: 100%;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--warning-border);
  font-size: 12px;
  color: var(--text-muted);
}
.alert__detail dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; }
.alert__detail dt { color: var(--text-faint); }
.alert__detail dd { margin: 0; }
.alert__detail .original-message { font-style: italic; color: var(--text); }

.toast-region { position: fixed; bottom: 16px; right: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface-raised); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 8px; padding: 10px 14px; font-size: 13px; min-width: 220px; }
.toast--ok { border-left: 3px solid var(--positive); }
.toast--error { border-left: 3px solid var(--negative); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - var(--topbar-h)); position: relative; }
.drawer-overlay { display: none; }

.sidenav {
  width: 210px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  /* Sticky con scroll propio: el sidebar permanece visible bajo el header
     sticky mientras el contenido central se desplaza normalmente, sin
     ocultar los accesos superiores en vistas largas. Anulado en el media
     query de drawer (<1024px) más abajo, donde vuelve a position: fixed. */
  position: sticky;
  top: var(--topbar-h);
  align-self: flex-start;
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.sidenav__item {
  display: flex; align-items: center; gap: 10px;
  text-align: left;
  background: transparent;
  border: none;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  min-height: 40px;
}
.sidenav__item svg { width: 17px; height: 17px; opacity: 0.85; }
.sidenav__item:hover { background: var(--surface-alt); color: var(--text); }
.sidenav__item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidenav__item.is-active svg { opacity: 1; }

.content { flex: 1; padding: 22px 26px 60px; min-width: 0; }
.view { display: none; }
.view.is-active { display: block; }
.view__head { margin-bottom: 18px; }
.view__title { font-size: 19px; margin: 0 0 3px; }
.view__hint { color: var(--text-muted); font-size: 12.5px; margin: 0; }
.view__hint code { font-size: 11px; }
.view__toolbar { margin-bottom: 14px; display: flex; align-items: center; }

/* ---------- KPI groups ---------- */
.kpi-group { margin-bottom: 22px; }
.kpi-group:last-child { margin-bottom: 0; }
.kpi-group__title { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); font-weight: 700; margin: 0 0 10px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.kpi-card {
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi-card--primary { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), var(--surface-raised) 65%); }
.kpi-card__label { font-size: 12px; color: var(--text-muted); display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.kpi-card__value { font-size: 23px; font-weight: 700; margin: 6px 0 4px; letter-spacing: -0.01em; }
.kpi-card__value.state-nd { color: var(--nd); font-size: 17px; font-weight: 600; }
.kpi-card__value.state-no-activity { color: var(--text-faint); font-size: 17px; font-weight: 600; }
.kpi-card__delta { font-size: 12px; font-weight: 600; }
.kpi-card__delta.positive { color: var(--positive); }
.kpi-card__delta.negative { color: var(--negative); }
.kpi-card__delta.neutral { color: var(--text-faint); font-weight: 500; }
.kpi-card__def { color: var(--text-faint); cursor: help; font-size: 12px; flex-shrink: 0; }

/* ---------- Chart ---------- */
.chart-card {
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); position: relative;
  height: 400px; display: flex; flex-direction: column;
}
.chart-card__canvas-wrap { flex: 1; min-height: 0; position: relative; }
.chart-card canvas { max-height: 100%; }

/* ---------- Funnel ---------- */
.funnel { display: flex; flex-direction: column; gap: 10px; max-width: 680px; }
.funnel__stage { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 13px 16px; box-shadow: var(--shadow); }
.funnel__row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.funnel__label { font-weight: 600; font-size: 13.5px; }
.funnel__value { font-size: 16px; font-weight: 700; }
.funnel__meta { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; display: flex; gap: 12px; flex-wrap: wrap; }
.funnel__bar { height: 7px; border-radius: 4px; background: var(--surface-alt); margin-top: 9px; overflow: hidden; }
.funnel__bar > div { height: 100%; background: var(--accent); border-radius: 4px; transition: width 300ms ease; }
.funnel__note { font-size: 12px; color: var(--text-muted); margin-top: 14px; max-width: 680px; }

/* ---------- Tables ---------- */
.table-toolbar { display: flex; gap: 10px; margin-bottom: 6px; align-items: center; flex-wrap: wrap; }
.table-period { font-size: 12px; color: var(--text-muted); margin: 0 0 12px; }
.table-wrap { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 760px; }
.data-table thead th {
  position: sticky; top: 0; background: var(--surface-alt); text-align: left; padding: 10px 12px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted);
  border-bottom: 1px solid var(--border); cursor: pointer; white-space: nowrap; user-select: none;
}
.data-table thead th:focus-visible { outline-offset: -2px; }
.data-table thead th.col-group-start { border-left: 1px solid var(--border); }
.data-table thead th.is-sorted { color: var(--accent); }
.data-table thead th.is-sorted::after { content: " ▾"; }
.data-table thead th.is-sorted[data-dir="asc"]::after { content: " ▴"; }
.data-table th.col-numeric, .data-table td.col-numeric { text-align: right; }
.data-table tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table tbody td.col-group-start { border-left: 1px solid var(--border); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-alt); }
.data-table tbody tr:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.data-table tbody tr.row-inactive { color: var(--text-faint); }
.data-table .row-inactive-tag { font-size: 11px; color: var(--text-faint); font-style: italic; }
.nd { color: var(--nd); }
.no-activity { color: var(--text-faint); }
.metric-zero { color: var(--text); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 13.5px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.empty-state__icon { color: var(--text-faint); margin-bottom: 6px; }
.empty-state__title { font-size: 15px; font-weight: 700; color: var(--text); }
.empty-state__desc { max-width: 440px; margin: 2px 0 4px; color: var(--text-muted); }
.empty-state__meta { display: flex; gap: 18px; margin: 4px 0; font-size: 12px; flex-wrap: wrap; justify-content: center; }
.empty-state__meta dt { color: var(--text-faint); display: inline; }
.empty-state__meta dd { display: inline; margin: 0 0 0 4px; font-weight: 600; color: var(--text); }
.empty-state__meta div { display: flex; gap: 4px; }
.empty-state__cta { margin-top: 6px; }
.empty-state__secondary { font-size: 11.5px; color: var(--text-faint); margin-top: 8px; max-width: 440px; }

/* ---------- Quality view ---------- */
.quality-section { margin-bottom: 24px; }
.quality-section__title { font-size: 13px; font-weight: 700; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.quality-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.quality-card { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); }
.quality-card h3 { margin: 0 0 10px; font-size: 13px; }
.quality-card ul { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--text-muted); }
.quality-card li { margin-bottom: 6px; }
.quality-kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 12.5px; margin: 0; }
.quality-kv dt { color: var(--text-muted); }
.quality-kv dd { margin: 0; font-weight: 600; }
.quality-note { font-size: 12px; color: var(--text-muted); background: var(--surface-alt); border-radius: var(--radius-sm); padding: 10px 12px; margin: 8px 0 0; }

/* ---------- Creatividades ---------- */
.creative-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.creative-card { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.creative-card__thumb { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; height: 120px; background: var(--surface-alt); color: var(--text-faint); }
.creative-card__thumb-label { font-size: 11px; }
.creative-card__body { padding: 14px 16px; }
.creative-card__title { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.creative-card__text { font-size: 12.5px; color: var(--text-muted); margin: 0 0 10px; white-space: pre-line; }
.creative-card__meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

.accordion { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-raised); box-shadow: var(--shadow); overflow: hidden; }
.accordion__trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-alt); border: none; padding: 13px 16px; font-size: 13px; font-weight: 700;
  color: var(--text); cursor: pointer; font-family: inherit;
}
.accordion__trigger svg { width: 16px; height: 16px; transition: transform 180ms ease; }
.accordion__trigger[aria-expanded="true"] svg { transform: rotate(180deg); }
.accordion__panel { padding: 16px; display: none; }
.accordion__panel.is-open { display: block; }

/* ---------- Skeleton ---------- */
.skeleton { display: inline-block; background: var(--surface-alt); border-radius: 4px; animation: pulse 1.4s ease-in-out infinite; }
.skeleton--text { width: 220px; height: 12px; }
@keyframes pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* ==================== Responsive ==================== */

@media (max-width: 1100px) {
  .topbar__zone--center { order: 3; flex-basis: 100%; justify-content: flex-start; }
}

@media (max-width: 1023px) {
  .sidenav {
    width: 240px;
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 70;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: var(--shadow);
  }
  .sidenav.is-open { transform: translateX(0); }
  .menu-toggle { display: inline-flex; }
  .drawer-overlay {
    display: none;
    position: fixed; inset: 0; background: rgba(10, 14, 20, 0.45); z-index: 65;
  }
  .drawer-overlay.is-open { display: block; }
}

@media (max-width: 900px) {
  .content { padding: 18px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .table-toolbar { flex-direction: column; align-items: stretch; }
  .table-toolbar > * { width: 100%; }
  .chart-card { height: 360px; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .topbar__zone--center { display: none; }
  .alert { padding: 10px 14px; flex-wrap: wrap; }
  .alert__actions { width: 100%; }
  .alert__actions .btn { flex: 1; justify-content: center; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  /* Mismo criterio que --right: a este ancho, la zona ocupa el 100% del
     header en vez de competir por espacio horizontal con las otras zonas -
     el account-select-wrap (id=account-select-wrap) queda con su propio
     ancho completo dentro de la zona para que el <select> sea fácil de
     tocar, en vez de comprimirse junto a los badges. */
  .topbar__zone--left { width: 100%; }
  #account-select-wrap { flex: 1 1 100%; }
  .topbar__zone--right { width: 100%; justify-content: space-between; }
  .period-control { flex: 1; }
  #period-select { width: 100%; }
  .chart-card { height: 320px; padding: 12px; }
  /* Objetivos táctiles mínimos de 40px en móvil */
  .btn, .control, .menu-toggle, .sidenav__item { min-height: 40px; }
  .btn--sm { min-height: 40px; padding: 8px 12px; }
  .menu-toggle { width: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}
