/* =============================================================
   DIPRENA · Portal CMS — Dashboard de Ejecución Presupuestaria
   Hereda tokens y tipografía de styles.css (Inter + Lora, paleta navy).
   ============================================================= */

.dashboard-page {
  padding-bottom: 56px;
}

.breadcrumb {
  font-size: 12px;
  color: var(--blue);
  padding: 24px 0 8px;
  letter-spacing: 0.3px;
}
.breadcrumb a { color: var(--blue); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.dash-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 8px 0 28px;
  flex-wrap: wrap;
}
.dash-header h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}
.dash-lead {
  font-size: 14px;
  color: var(--text-mute);
  max-width: 680px;
  line-height: 1.6;
}
.dash-header__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Badge "En vivo" */
.badge-live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(20,167,108,0.08);
  border: 1px solid rgba(20,167,108,0.35);
  color: var(--pos);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 20px;
}
.dot-live {
  width: 8px; height: 8px;
  background: var(--pos);
  border-radius: 50%;
  animation: blink 1.5s infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* Botones */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: .15s;
}
.btn-secondary:hover { border-color: var(--blue); color: var(--blue); }

.btn-apply,
.btn-reset,
.btn-link {
  display: inline-flex; align-items: center; justify-content: center;
  border: none;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  border-radius: var(--r-sm);
  transition: .15s;
}
.btn-apply {
  background: var(--blue);
  color: var(--white);
  padding: 9px 18px;
  font-size: 13px;
}
.btn-apply:hover { background: #1862C8; }
.btn-reset {
  background: var(--white);
  color: var(--text-mute);
  border: 1px solid var(--border);
  padding: 8px 14px;
  font-size: 13px;
}
.btn-reset:hover { border-color: var(--blue); color: var(--blue); }
.btn-link {
  background: transparent;
  color: var(--text-mute);
  padding: 8px 0;
  width: 100%;
  justify-content: flex-start;
  font-size: 13px;
}
.btn-link:hover { color: var(--blue); }

/* Layout: sidebar + main */
.dash-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: start;
}
/* Sin esto, los items del grid heredan min-width: auto (= ancho de contenido)
   y la tabla ancha empuja la pagina entera. Forzandolo a 0 hace que cada
   item respete el ancho del padre y deja que overflow-x interno funcione. */
.dash-layout > * { min-width: 0; }

.dash-sidebar {
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.filter-card {
  background: var(--white);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: 20px;
  box-shadow: var(--shadow-xs);
}
.filter-card__title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-mute);
  margin-bottom: 14px;
}

.filter-group { margin-bottom: 14px; }
.filter-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--text-mute);
  margin-bottom: 6px;
  text-transform: uppercase;
}
.filter-group select,
.filter-group input[type="text"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: .15s;
}
.filter-group select:focus,
.filter-group input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-bg); }

.filter-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.filter-actions .btn-apply { flex: 1; }
.filter-actions .btn-reset { flex: 1; }

/* MAIN: KPIs + Charts + Tabla */
.dash-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* KPIs: reutiliza .kpi-grid + .kpi-ciclo de styles.css.
   Aquí solo añadimos los deltas y micro-progresos. */
.dash-kpis .kpi-ciclo { position: relative; }
.dash-kpis .kpi-ciclo__delta {
  position: absolute; top: 18px; right: 18px;
  font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 12px;
  background: var(--pos-bg); color: var(--pos);
}
.dash-kpis .kpi-ciclo__delta.is-down { background: rgba(215,32,39,.08); color: var(--neg); }

/* Cards genéricas */
.card {
  background: var(--white);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.card__header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 22px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.card__title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--navy);
}
.card__sub {
  font-size: 13px;
  color: var(--text-mute);
  margin-top: 4px;
}

.chart-area {
  padding: 12px 18px 18px;
  height: 320px;
  width: 100%;
}

.dash-charts {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}
.dash-charts > * { min-width: 0; }

/* Tabla */
.table-search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  max-width: 260px;
  width: 100%;
}
.table-search-icon {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  fill: var(--text-faint);
  pointer-events: none;
}
.table-search {
  padding: 7px 12px 7px 32px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  width: 100%;
  font-family: inherit;
}
.table-search:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-bg); }
.btn-link-icon {
  width: 14px;
  height: 14px;
  fill: currentColor;
  margin-right: 6px;
  vertical-align: -2px;
}
.dash-table-wrap {
  overflow-x: auto;
}
.dash-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.dash-table thead th {
  background: var(--bg-soft);
  color: var(--text-mute);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 12px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.dash-table tbody td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.dash-table tbody tr:hover td { background: var(--blue-bg); }
.dash-table .col-rank,
.dash-table .col-amount,
.dash-table .col-pct,
.dash-table .col-status { white-space: nowrap; }
.dash-table .col-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.dash-table .col-rank { color: var(--text-faint); font-weight: 600; font-variant-numeric: tabular-nums; width: 40px; }
.dash-table .pct-cell { display: inline-flex; align-items: center; gap: 10px; }
.dash-table .pct-bar { display: inline-block; width: 110px; height: 6px; border-radius: 3px; background: var(--border-soft); overflow: hidden; }
.dash-table .pct-bar > span { display: block; height: 100%; }
.dash-table .pct-num { font-variant-numeric: tabular-nums; font-weight: 600; }

.badge-status {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 10px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.badge-status.alta  { background: var(--pos-bg);  color: var(--pos); }
.badge-status.media { background: var(--warn-bg); color: var(--warn); }
.badge-status.baja  { background: rgba(215,32,39,.10); color: var(--red); }

.tbl-empty {
  text-align: center;
  color: var(--text-mute);
  padding: 28px;
}

.dash-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 4px 0;
  font-size: 12px;
  color: var(--text-mute);
  gap: 12px;
}
.dash-footer svg { vertical-align: -2px; margin-right: 4px; }

/* Responsive */
@media (max-width: 1100px) {
  .dash-charts { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .dash-layout { grid-template-columns: 1fr; }
  .dash-sidebar { position: static; }
}
@media (max-width: 720px) {
  /* Header del dashboard: titulo y acciones se apilan */
  .dash-header { flex-direction: column; align-items: stretch; gap: 16px; }
  .dash-header h1 { font-size: 24px; }
  .dash-header__actions { flex-wrap: wrap; }

  /* Header de las cards: titulo arriba, acciones (busqueda) debajo */
  .card__header { flex-direction: column; align-items: stretch; gap: 12px; }
  .table-search-wrap { max-width: 100%; }

  /* Footer del dashboard: items apilados */
  .dash-footer { flex-direction: column; align-items: flex-start; gap: 8px; }

  /* Chart area un poco mas baja en mobile para no robar tanto scroll */
  .chart-area { height: 280px; padding: 8px 10px 12px; }

  /* La tabla puede seguir scrolleando horizontal DENTRO de su wrap,
     pero le bajamos el padding para que cada columna pese menos. */
  .dash-table thead th,
  .dash-table tbody td { padding: 10px 12px; }
  .dash-table .pct-bar { width: 70px; }
}
