/* =========================================================
   Project Controls — Jana Construcciones
   Design tokens + shell + navegación

   NOTA DE ESCALA: la etapa mide 1600x900 (16:9) y se escala para
   caber en la ventana. Se eligio 1600 en vez de 1920 para que al
   reducirse en pantallas de laptop la tipografia siga siendo legible;
   la exportacion PNG re-escala a 1920x1080 reales.
   ========================================================= */
/* Los tokens crudos viven en /assets/css/jana-ds.css. Aqui solo se reapuntan
   los nombres heredados del tablero para no reescribir 4.000 lineas de JS que
   los referencian por string. La rampa, el tipo y la elevacion son los mismos
   del sitio: una sola identidad, dos superficies.

   DECISION DE PRODUCTO: el shell (sidebar / topbar / mesa) va oscuro, pero el
   LIENZO del tablero se queda claro. Estos tableros existen para exportarse a
   PNG y proyectarse en comite o pegarse en un informe: un entregable claro se
   imprime y se lee; uno oscuro, no. Documento claro sobre mesa oscura. */
:root {
  --navy-900: var(--n-900);
  --navy-800: var(--n-800);
  --navy-700: var(--oliva-700);
  --navy-600: var(--n-500);
  --blue-accent: var(--oliva-500);
  --alert: var(--riesgo-600);
  --red-dark: var(--riesgo-600);
  --green-ok: var(--exito-600);
  --amber-warn: var(--alerta-600);
  --gray-050: var(--n-50);
  --gray-100: var(--n-100);
  --gray-200: var(--n-200);
  --gray-400: var(--n-400);
  --gray-600: var(--n-600);
  --ink: var(--n-800);
  --white: #ffffff;
  --mushroom: var(--n-50);

  --font-serif: var(--fuente-display);
  --font-sans: var(--fuente-ui);

  --stage-w: 1600px;
  --stage-h: 900px;
  --radius: 12px;
  --hair: rgba(29, 28, 22, 0.12);
  --shadow-card: var(--sombra-2);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--n-950);
  font-family: var(--font-sans);
  color: var(--ink);
  overflow: hidden;
}

#app { display: flex; height: 100vh; width: 100vw; }

/* ---------------- Sidebar ---------------- */
#sidebar {
  width: 190px; flex: 0 0 190px;
  background: var(--navy-900);
  color: var(--white);
  display: flex; flex-direction: column;
  padding: 14px 0;
  overflow: hidden;
}
#sidebar .brand {
  display: flex; flex-direction: column; gap: 7px;
  padding: 0 14px 14px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 8px;
}
#sidebar .brand img { height: 20px; width: auto; display: block; }
#sidebar .brand .name { font-size: 10.5px; line-height: 1.3; opacity: 0.72; white-space: nowrap; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  margin: 1px 8px;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--n-400);
  cursor: pointer;
  border-left: 2px solid transparent;
  user-select: none;
  white-space: nowrap;
  transition: background var(--v-rapido) var(--curva), color var(--v-rapido) var(--curva);
}
.nav-item .num {
  width: 19px; height: 19px; border-radius: var(--r-xs);
  background: rgba(255,255,255,0.10);
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 700; flex: 0 0 19px;
  font-variant-numeric: tabular-nums;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: var(--n-50); }
/* El item activo es el unico punto de mantequilla del shell: uno por pantalla. */
.nav-item.active {
  background: rgba(255,245,138,0.12);
  color: var(--n-25);
  border-left-color: var(--mant-300);
  font-weight: 600;
}
.nav-item.active .num { background: var(--mant-300); color: var(--n-950); }

#sidebar .foot {
  margin-top: auto; padding: 10px 14px 0 14px;
  font-size: 10px; color: rgba(255,255,255,0.4);
  border-top: 1px solid rgba(255,255,255,0.1);
  white-space: nowrap;
}

/* ---------------- Main column ---------------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  height: 52px; flex: 0 0 52px;
  background: var(--n-900);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center;
  padding: 0 16px; gap: 12px;
  overflow: hidden;
}
#topbar .title { font-family: var(--font-serif); font-size: 15px; color: var(--n-25); font-weight: 700; letter-spacing: -0.012em; white-space: nowrap; }
#topbar .subtitle { font-size: 11.5px; color: var(--n-400); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar .spacer { flex: 1; min-width: 0; }
#topbar .logo-cliente { height: 19px; width: auto; flex: 0 0 auto; }
#topbar button {
  font-family: var(--font-sans);
  font-size: 12.5px; font-weight: 600;
  border: 1px solid rgba(255,255,255,0.16);
  background: transparent;
  color: var(--n-100);
  border-radius: var(--r-full);
  padding: 8px 15px;
  cursor: pointer;
  white-space: nowrap; flex: 0 0 auto;
  transition: background var(--v-rapido) var(--curva), border-color var(--v-rapido) var(--curva), color var(--v-rapido) var(--curva);
}
#topbar button:hover { background: var(--mant-300); color: var(--n-950); border-color: transparent; }
#topbar button:focus-visible { outline: 2px solid var(--mant-300); outline-offset: 2px; }
#topbar #data-status { font-size: 10.5px; color: var(--n-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; }

/* ---------------- Stage (16:9 viewport) ---------------- */
#stage-outer {
  flex: 1;
  /* La "mesa": una veladura muy tenue de oliva para que el lienzo claro flote
     en vez de recortarse contra un plano muerto. */
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(130,123,49,0.16) 0%, transparent 62%),
    var(--n-950);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  position: relative;
}
#stage-fit {
  width: var(--stage-w); height: var(--stage-h);
  transform-origin: center center;
  position: relative;
  flex: 0 0 auto;
}
.dashboard {
  position: absolute; inset: 0;
  width: var(--stage-w); height: var(--stage-h);
  background: var(--n-25);
  border-radius: var(--r-lg);
  box-shadow: 0 24px 80px rgba(0,0,0,0.55);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-size: 15px;
}
.dashboard.active { display: flex; }
/* Engineering section temporarily withdrawn from reporting by request. The
   section markup, its data and its render logic are all intact — removing this
   rule and restoring its nav item brings it back unchanged. */
.dashboard.section-hidden { display: none !important; }

.dash-head {
  flex: 0 0 76px;
  background: var(--n-900);
  color: var(--white);
  display: flex; align-items: center;
  padding: 0 30px;
  gap: 16px;
}
.dash-head .idx {
  font-family: var(--font-serif); font-size: 32px; font-weight: 700;
  color: var(--mant-300); opacity: 0.9;
  font-variant-numeric: tabular-nums;
}
.dash-head h1 { font-family: var(--font-serif); font-size: 25px; margin: 0; font-weight: 700; text-transform: none; letter-spacing: -0.018em; }
.dash-head .tag { font-size: 12.5px; opacity: 0.82; margin-top: 2px; }
.dash-head .head-spacer { flex: 1; }
.dash-head .export-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.24);
  color: var(--n-50);
  font-size: 12.5px; font-weight: 600;
  padding: 8px 15px; border-radius: var(--r-full); cursor: pointer;
  transition: background var(--v-rapido) var(--curva), color var(--v-rapido) var(--curva), border-color var(--v-rapido) var(--curva);
}
.dash-head .export-btn:hover { background: var(--mant-300); color: var(--n-950); border-color: transparent; }

.dash-body {
  flex: 1;
  padding: 16px 24px 12px 24px;
  display: grid;
  gap: 13px;
  min-height: 0;
}

/* ---------------- Pie corporativo (sale en el PNG exportado) ---------------- */
.dash-foot {
  flex: 0 0 44px;
  background: var(--white);
  border-top: 2px solid var(--navy-800);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  font-size: 12px; color: var(--gray-600);
}
.dash-foot .logo {
  display: block; height: 20px; width: 128px;
  background-repeat: no-repeat; background-position: left center; background-size: contain;
}

.dash-foot .sep { width: 1px; height: 20px; background: var(--gray-200); }
.dash-foot .proyecto { font-weight: 600; color: var(--navy-800); }
.dash-foot .grow { flex: 1; }
.dash-foot .fecha { color: var(--gray-400); }

/* ---------------- Componentes genericos ---------------- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--hair);
  padding: 12px 14px;
  min-height: 0;
  display: flex; flex-direction: column;
}
.card h3 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--navy-800); margin: 0 0 9px 0; font-weight: 700;
}
.card h3 .info { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--gray-600); font-size: 12px; }

.kpi-row { display: grid; gap: 11px; }
.kpi {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--hair);
  padding: 12px 14px;
  display: flex; flex-direction: column; justify-content: center;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--navy-700);
}
.kpi.warn::before { background: var(--amber-warn); }
.kpi.bad::before { background: var(--alert); }
.kpi.ok::before { background: var(--green-ok); }
.kpi.placeholder { opacity: 0.55; }
.kpi.placeholder::before { background: var(--gray-400); }
.kpi .label { font-size: 12px; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.02em; font-weight: 700; line-height: 1.2; }
.kpi .value { font-family: var(--font-serif); font-size: 32px; font-weight: 700; color: var(--navy-800); line-height: 1.15; margin-top: 3px; }
.kpi .sub { font-size: 12px; color: var(--gray-600); margin-top: 3px; line-height: 1.25; }
.kpi.bad .value { color: var(--alert); }
.kpi.ok .value { color: var(--green-ok); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em;
  padding: 3px 8px; border-radius: 100px;
}
.badge.green { background: #EAEFEB; color: var(--green-ok); }
.badge.amber { background: #F1EDE8; color: var(--amber-warn); }
.badge.red { background: #F4E9E7; color: var(--alert); }
.badge.gray { background: var(--gray-100); color: var(--gray-600); }
.badge.navy { background: #F4F4F2; color: var(--navy-700); }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 10px; }
.dot.green { background: var(--green-ok); }
.dot.amber { background: var(--amber-warn); }
.dot.red { background: var(--alert); }
.dot.gray { background: var(--gray-400); }
.dot.navy { background: var(--navy-700); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.02em;
  color: var(--gray-600); border-bottom: 2px solid var(--gray-200);
  padding: 6px 8px; position: sticky; top: 0; background: var(--white); z-index: 1;
}
table.data-table tbody td { padding: 6px 8px; border-bottom: 1px solid var(--gray-100); color: var(--ink); }
table.data-table tbody tr:hover { background: var(--gray-050); }
.table-scroll { overflow-y: auto; flex: 1; min-height: 0; }

.progress-track { background: var(--gray-100); border-radius: 100px; height: 9px; overflow: hidden; width: 100%; }
.progress-fill { height: 100%; border-radius: 100px; background: var(--navy-700); }
.progress-fill.red { background: var(--alert); }
.progress-fill.green { background: var(--green-ok); }
.progress-fill.amber { background: var(--amber-warn); }

.placeholder-box {
  border: 1.5px dashed var(--gray-400);
  border-radius: var(--radius);
  color: var(--gray-600);
  display: flex; align-items: center; justify-content: center; text-align: center;
  flex: 1; font-size: 13.5px; padding: 18px; background: repeating-linear-gradient(135deg, #fff, #fff 10px, #F4F4F2 10px, #F4F4F2 20px);
}

.legend-row { display: flex; gap: 13px; flex-wrap: wrap; font-size: 12px; color: var(--gray-600); align-items: center; }
.legend-row .item { display: flex; align-items: center; gap: 5px; }
.legend-swatch { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }

.note { font-size: 11.5px; color: var(--gray-600); line-height: 1.35; }
.note.unvalidated { color: var(--amber-warn); }

/* Modo exportacion: quita el scale() de la etapa y libera el recorte del
   contenedor, para que html2canvas capture el dashboard a su tamanio natural
   1600x900. Capturarlo escalado producia un PNG encogido y con bandas grises. */
body.exporting #stage-outer {
  align-items: flex-start;
  justify-content: flex-start;
  overflow: visible;
}
body.exporting #stage-fit { transform: none !important; }
/* el boton de exportar no debe aparecer dentro de la imagen exportada */
body.exporting .export-btn { visibility: hidden; }

/* ---------------- Impresion / PDF ----------------
   Ruta de MAXIMA calidad: al imprimir, el texto sale vectorial en vez de
   rasterizado, asi que no pixela a ningun zoom — mejor que cualquier PNG.
   Se imprime SOLO el dashboard activo, a pagina completa apaisada.

   El factor 0.70 lleva la etapa de 1600x900 px al ancho util de una hoja
   apaisada (A4/Letter a 96 dpi ~ 1123 px): 1600 x 0.70 = 1120 px. El alto
   resultante (630 px) entra de sobra en los ~794 px de la hoja. */
@media print {
  @page { size: landscape; margin: 0; }

  body.printing { background: #fff; }
  body.printing #sidebar,
  body.printing #topbar { display: none !important; }
  body.printing #app,
  body.printing #main { display: block; height: auto; }
  body.printing #stage-outer {
    display: block; background: #fff; overflow: visible;
    height: auto; padding: 0;
  }
  body.printing #stage-fit {
    transform: scale(0.70) !important;
    transform-origin: top left;
    width: var(--stage-w); height: var(--stage-h);
  }
  /* solo el dashboard activo, y sin el boton de exportar dentro de la hoja */
  body.printing .dashboard { display: none !important; }
  body.printing .dashboard.active { display: flex !important; position: static; }
  body.printing .export-btn { visibility: hidden; }

  /* los fondos de tarjeta y las barras deben imprimirse, no salir en blanco */
  body.printing * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
