:root {
  --bg-0:#edf2f0;
  --bg-1:#f7f9f8;
  --ink:#101719;
  --muted:#667479;
  --line:#dce5e1;
  --surface:#ffffff;
  --surface-2:#f6f9f8;
  --black:#111718;
  --green:#00b050;
  --green-dark:#08703c;
  --green-deep:#0a3e28;
  --green-soft:#e3f6ea;
  --teal:#0e5b63;
  --teal-soft:#e7f3f3;
  --red-soft:#ffb9b9;
  --red-text:#741d1d;
  --warn:#f4ca4c;
  --alert:#ed8a4c;
  --urgent:#e44c4c;
  --shadow:0 12px 32px rgba(16,39,31,.10);
  --radius:17px;
}

*{box-sizing:border-box}
html,body{margin:0;width:100%;height:100%;overflow:hidden}
body{
  display:flex;
  align-items:center;
  justify-content:center;
  background:
    radial-gradient(circle at 85% 8%, rgba(0,176,80,.10), transparent 26%),
    linear-gradient(145deg,var(--bg-1),var(--bg-0));
  color:var(--ink);
  font-family:"Montserrat","Avenir Next","Segoe UI","Helvetica Neue",Arial,sans-serif;
}

#stage{position:relative;flex:none}
#dashboard{
  position:absolute;
  inset:0 auto auto 0;
  width:1840px;
  height:1000px;
  padding:18px;
  transform-origin:top left;
  display:grid;
  grid-template-rows:104px 440px 316px 62px;
  gap:14px;
}

.premium-header{
  min-width:0;
  border-radius:22px;
  padding:15px 20px;
  display:grid;
  grid-template-columns:minmax(550px,1fr) 880px;
  align-items:center;
  gap:26px;
  color:#fff;
  overflow:hidden;
  position:relative;
  background:
    linear-gradient(115deg,#101617 0%,#12201b 38%,#0a4c30 72%,#08703c 100%);
  box-shadow:0 15px 34px rgba(8,36,24,.20);
}
.premium-header:after{
  content:"";
  position:absolute;
  width:360px;height:360px;right:-70px;top:-150px;
  border:1px solid rgba(255,255,255,.10);
  border-radius:50%;
  box-shadow:0 0 0 54px rgba(255,255,255,.025),0 0 0 108px rgba(255,255,255,.02);
}
.brand{display:flex;align-items:center;gap:18px;min-width:0;z-index:1}
.logo-box{
  height:67px;width:224px;flex:none;
  border-radius:15px;background:#fff;
  display:flex;align-items:center;justify-content:center;
  box-shadow:0 8px 24px rgba(0,0,0,.18);
}
.logo-box img{width:194px;height:auto;display:block}
.brand-copy{min-width:0}
.eyebrow{
  font-size:11px;font-weight:800;letter-spacing:.19em;text-transform:uppercase;
  color:#7fe8ac;margin-bottom:5px
}
#plantTitle{
  margin:0;font-size:31px;line-height:1;font-weight:800;letter-spacing:-.035em;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
.brand-note{margin-top:7px;font-size:12px;color:rgba(255,255,255,.68);font-weight:600}

.header-meta{
  display:grid;
  grid-template-columns:minmax(360px,1fr) 175px 250px;
  gap:9px;
  z-index:1;
}
.meta{
  height:62px;border-radius:13px;padding:9px 12px;
  background:rgba(255,255,255,.085);
  border:1px solid rgba(255,255,255,.13);
  display:flex;flex-direction:column;justify-content:center;min-width:0
}
.meta-label{font-size:9px;letter-spacing:.13em;text-transform:uppercase;font-weight:800;color:rgba(255,255,255,.56);margin-bottom:5px}
.meta-value{font-size:12px;font-weight:800;color:#fff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#connectionState{
  color:#8df0b7;
  white-space:normal;
  overflow:visible;
  text-overflow:clip;
  line-height:1.08;
  font-size:12px;
}
#connectionState.is-error{color:#ffb9b9}

.card{
  background:rgba(255,255,255,.98);
  border:1px solid rgba(205,218,212,.88);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  overflow:hidden;
  min-width:0;
}
.card-head{
  height:70px;padding:12px 14px;
  display:flex;align-items:center;justify-content:space-between;gap:18px;
  border-bottom:1px solid var(--line);
  background:linear-gradient(180deg,#fff,#f8fbfa);
}
.head-left{min-width:0}

/* Cabecera del balance:
   misma geometría exacta que la tabla inferior:
   48% Concepto | 26% Periodo | 26% Actual. */
.balance-card .card-head{
  display:grid;
  grid-template-columns:48% 26% 26%;
  gap:0;
  padding:0;
}
.balance-card .head-left{
  min-width:0;
  padding:10px 14px;
  text-align:left;
}
.balance-card .head-left .section-kicker,
.balance-card .head-left .section-title{
  width:100%;
  text-align:left !important;
}
.balance-card .balance-chip{
  min-width:0;
  height:100%;
  padding:6px 10px;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:flex-start;
  border-left:1px solid var(--line);
}
.balance-card .balance-chip small{
  display:block;
  width:100%;
  font-size:8px;
  letter-spacing:.12em;
  text-transform:uppercase;
  font-weight:800;
  color:var(--muted);
  margin-bottom:3px;
  text-align:center;
}
.balance-card .balance-chip strong{
  display:block;
  width:100%;
  font-size:11px;
  line-height:1.15;
  color:var(--ink);
  text-align:center;
}

/* Primera columna: encabezado y datos alineados a la izquierda. */
.energy-table thead th:first-child{
  text-align:left !important;
  padding-left:14px !important;
  padding-right:14px !important;
}
.energy-table tbody td:first-child{
  padding-left:14px;
}
.section-kicker{font-size:10px;letter-spacing:.16em;text-transform:uppercase;font-weight:900;color:var(--green-dark);margin-bottom:3px}
.section-title{font-size:20px;line-height:1.05;font-weight:850;letter-spacing:-.025em}
.head-chips{display:flex;align-items:center;gap:8px}
.head-chip{
  min-width:205px;max-width:295px;
  padding:8px 11px;border-radius:10px;
  background:var(--surface-2);border:1px solid var(--line);
}
.head-chip small{display:block;font-size:8px;letter-spacing:.12em;text-transform:uppercase;font-weight:800;color:var(--muted);margin-bottom:3px}
.head-chip strong{display:block;font-size:11px;line-height:1.15;color:var(--ink)}

.balance-card{
  height:440px;
  width:1180px;
  justify-self:center;
}
.energy-table{width:100%;height:370px;border-collapse:collapse;table-layout:fixed}
.energy-table thead th{
  height:31px;background:#f1f6f4;color:#62716d;
  font-size:9px;letter-spacing:.12em;text-transform:uppercase;font-weight:900;
  border-bottom:1px solid var(--line);padding:0 14px;text-align:right;
}
.energy-table thead th:nth-child(2),
.energy-table thead th:nth-child(3){
  text-align:center !important;
  padding-left:0 !important;
  padding-right:0 !important;
}
.energy-table thead th:first-child{text-align:left!important;width:48%;padding-left:14px!important;padding-right:14px!important}
.energy-table thead th:nth-child(2){width:26%}
.energy-table thead th:nth-child(3){width:26%}
.energy-table thead th#month{
  color:var(--green-dark);
  font-size:10px;
  letter-spacing:.08em;
}
.energy-table tbody tr{height:28px}
.energy-table td{
  padding:0 14px;border-bottom:1px solid #edf2ef;
  font-size:12px;font-weight:700;line-height:1.05
}
.energy-table tbody tr:last-child td{border-bottom:none}
.energy-table td.label{
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

/* Jerarquía visual de conceptos, según la referencia aportada:
   nivel 0 = total
   nivel 1 = conceptos de planta
   nivel 2 = bloques de generación / auxiliares / exportación
   nivel 3 = equipos concretos */
.energy-table td.label.level-0{padding-left:14px;font-weight:900;}
.energy-table td.label.level-1{padding-left:30px;font-weight:800;}
.energy-table td.label.level-2{padding-left:58px;font-weight:800;}
.energy-table td.label.level-3{padding-left:92px;font-weight:800;}
.energy-table td.value{
  text-align:right;
  font-size:15px;
  font-variant-numeric:tabular-nums;
  font-weight:850;
  padding-right:14px;
}

/* Sangría inversa en las columnas de datos:
   cuanto mayor es el nivel jerárquico, más se desplaza el valor hacia la izquierda. */
.energy-table tr.level-0 td.value{padding-right:14px}
.energy-table tr.level-1 td.value{padding-right:28px}
.energy-table tr.level-2 td.value{padding-right:46px}
.energy-table tr.level-3 td.value{padding-right:64px}
.energy-table tr.total td{
  background:linear-gradient(90deg,#11191a,#123528);color:#fff;font-weight:850
}
.energy-table tr.total td.value{color:#abf3c9;font-size:17px}
.energy-table tr.grid td{background:#f7faf9}
.energy-table tr.generation td{background:var(--green-soft)}
.energy-table tr.aux td{background:#f3f8f5}
.energy-table tr.negative td.value{color:#c62e35}
.energy-table tr.export td{background:var(--teal-soft)}

/* Escala cromática Evolutia por niveles.
   Se toma como referencia el verde profundo de la cabecera general
   y se aclara progresivamente manteniendo el mismo matiz.
   Cada fila usa SIEMPRE un único color sólido en todas sus columnas. */
:root{
  --level-0-bg:#0f3d2c;
  --level-1-bg:#3f735b;
  --level-2-bg:#8fb7a3;
  --level-3-bg:#dbe9e2;
}

.energy-table tr.level-0 > td{
  background:var(--level-0-bg) !important;
  color:#ffffff !important;
  font-weight:850;
}
.energy-table tr.level-0 > td.value{
  color:#c9f5db !important;
}

.energy-table tr.level-1 > td{
  background:var(--level-1-bg) !important;
  color:#ffffff !important;
}
.energy-table tr.level-1 > td.value{
  color:#ffffff !important;
}

.energy-table tr.level-2 > td{
  background:var(--level-2-bg) !important;
  color:#102019 !important;
}
.energy-table tr.level-2 > td.value{
  color:#102019 !important;
}

.energy-table tr.level-3 > td{
  background:var(--level-3-bg) !important;
  color:#102019 !important;
}
.energy-table tr.level-3 > td.value{
  color:#102019 !important;
}

/* Valores negativos/especiales: solo cambia el color del texto.
   El fondo conserva exactamente el color correspondiente a su nivel. */
.energy-table tr.negative > td.value{
  color:#d92d35 !important;
}

.ops-grid{
  height:316px;
  display:grid;
  grid-template-columns:1.31fr .92fr .67fr;
  gap:14px;
  min-width:0
}
.op-card{height:316px}
.op-head{
  height:56px;padding:10px 14px;color:#fff;
  display:flex;align-items:center;justify-content:space-between;gap:12px;
  background:linear-gradient(115deg,#11191a,#103e31 65%,#0d5d3b);
}
.op-head .section-kicker{color:#82e9ae;margin-bottom:2px}
.op-head .section-title{font-size:16px}
.op-note{font-size:9px;color:rgba(255,255,255,.66);font-weight:700;text-align:right}

.power-table,.status-table{width:100%;height:260px;border-collapse:collapse;table-layout:fixed}
.power-table thead th,.status-table thead th{
  height:31px;background:#edf5f1;color:#60706b;font-size:9px;letter-spacing:.10em;
  text-transform:uppercase;font-weight:900;border-bottom:1px solid var(--line);padding:0 10px
}
.power-table thead th:first-child,.status-table thead th:first-child{text-align:left}
.power-table th:first-child{width:64%}
.power-table th:nth-child(2),.power-table th:nth-child(3){width:18%}
.power-table tbody tr,.status-table tbody tr{height:38px}
.power-table td,.status-table td{
  border-bottom:1px solid #e8eeeb;padding:4px 10px;font-size:11px;font-weight:750
}
.power-table tbody tr:last-child td,.status-table tbody tr:last-child td{border-bottom:none}
.power-table td.key,.status-table td.device{
  line-height:1.13;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:800
}
.power-table td.val{
  text-align:center;font-size:12px;font-style:italic;font-weight:900;
  background:#8fb7a3;color:#071a0d;border:4px solid #fff;border-radius:9px;
  font-variant-numeric:tabular-nums
}
.power-table td.val.zero-light{background:var(--red-soft)!important;color:var(--red-text)}

.status-table th:first-child{width:62%}
.status-table th:nth-child(2),.status-table th:nth-child(3){width:19%}
.status-table td.state{
  text-align:center;font-size:10px;font-weight:900;letter-spacing:.02em;border-left:4px solid #fff;border-right:4px solid #fff
}
.status-table td.status-ok{background:#dff4e7;color:#08703c}
.status-table td.status-warn{background:#fff1b8;color:#725300}
.status-table td.status-alert{background:#ffd7bd;color:#883e00}
.status-table td.status-urgent{background:#ffc7c7;color:#861f1f}
.status-table td.status-empty{background:#f4f7f6;color:#a7b0ad}

.legend-card{height:316px}
.legend-body{height:260px;padding:11px;display:grid;grid-template-rows:repeat(4,1fr);gap:8px}
.legend-item{
  display:grid;grid-template-columns:98px 1fr;align-items:center;gap:9px;
  padding:7px 8px;border-radius:11px;background:#f7faf9;border:1px solid #e8efec
}
.legend-tag{
  border-radius:8px;padding:8px 6px;text-align:center;font-size:9px;font-weight:900;letter-spacing:.035em
}
.legend-desc{font-size:10px;line-height:1.2;color:#5f6d69;font-weight:700}
.legend-tag.urgent{background:#ffc7c7;color:#861f1f}
.legend-tag.alert{background:#ffd7bd;color:#883e00}
.legend-tag.warn{background:#fff1b8;color:#725300}
.legend-tag.good{background:#dff4e7;color:#08703c}



/* =========================================================
   ADAPTACIÓN FULL VIEWPORT
   Mantiene toda la estructura y la lógica original.
   ========================================================= */

body{
  display:block !important;
  overflow:hidden !important;
}

#stage{
  position:relative !important;
  width:100vw !important;
  height:100vh !important;
  overflow:hidden !important;
  flex:none !important;
}

#dashboard{
  position:relative !important;
  inset:auto !important;
  width:100% !important;
  height:100% !important;
  padding:10px 14px 9px !important;
  transform:none !important;
  transform-origin:initial !important;
  display:grid !important;
  grid-template-rows:
    94px
    minmax(0,1.52fr)
    minmax(0,1fr)
    48px !important;
  gap:9px !important;
  overflow:hidden !important;
}

/* Cabecera */
.premium-header{
  height:100% !important;
  min-height:0 !important;
  padding:11px 17px !important;
  border-radius:19px !important;
  grid-template-columns:minmax(500px,1fr) minmax(680px,.98fr) !important;
  gap:18px !important;
}

.logo-box{
  width:202px !important;
  height:58px !important;
}

.logo-box img{
  width:174px !important;
}

#plantTitle{
  font-size:27px !important;
}

.header-meta{
  grid-template-columns:minmax(330px,1fr) 165px 235px !important;
  gap:8px !important;
}

.meta{
  height:55px !important;
  padding:7px 11px !important;
}

/* Balance: mismo contenido, ahora ocupa todo el ancho disponible */
.balance-card{
  width:100% !important;
  height:100% !important;
  min-height:0 !important;
  justify-self:stretch !important;
}

.card-head{
  height:62px !important;
  padding:10px 13px !important;
}

.energy-table{
  width:100% !important;
  height:calc(100% - 62px) !important;
}

.energy-table tbody tr{
  height:auto !important;
}

/* Zona inferior */
.ops-grid{
  width:100% !important;
  height:100% !important;
  min-height:0 !important;
  gap:9px !important;
}

.op-card,
.legend-card{
  height:100% !important;
  min-height:0 !important;
}

.op-head{
  height:50px !important;
  padding:8px 12px !important;
}

.power-table,
.status-table{
  height:calc(100% - 50px) !important;
}

.power-table tbody tr,
.status-table tbody tr{
  height:auto !important;
}

.legend-body{
  height:calc(100% - 50px) !important;
  padding:8px !important;
  gap:6px !important;
}

/* Compactación vertical para navegadores con menor alto útil */
@media (max-height:850px){
  #dashboard{
    padding:7px 10px !important;
    grid-template-rows:
      82px
      minmax(0,1.50fr)
      minmax(0,.96fr)
      42px !important;
    gap:7px !important;
  }

  .premium-header{
    padding:8px 13px !important;
    border-radius:16px !important;
  }

  .logo-box{
    width:178px !important;
    height:50px !important;
  }

  .logo-box img{
    width:154px !important;
  }

  #plantTitle{
    font-size:23px !important;
  }

  .eyebrow{
    font-size:9px !important;
    margin-bottom:3px !important;
  }

  .brand-note{
    margin-top:4px !important;
    font-size:10px !important;
  }

  .meta{
    height:48px !important;
    padding:6px 9px !important;
  }

  .meta-label{
    font-size:8px !important;
    margin-bottom:3px !important;
  }

  .meta-value,
  #connectionState{
    font-size:10px !important;
  }

  .card-head{
    height:55px !important;
  }

  .energy-table{
    height:calc(100% - 55px) !important;
  }

  .section-title{
    font-size:16px !important;
  }

  .energy-table thead th{
    height:26px !important;
    font-size:8px !important;
  }

  .energy-table td{
    font-size:10px !important;
  }

  .energy-table td.value{
    font-size:13px !important;
  }

  .energy-table tr.total td.value{
    font-size:14px !important;
  }

  .op-head{
    height:44px !important;
  }

  .power-table,
  .status-table{
    height:calc(100% - 44px) !important;
  }

  .legend-body{
    height:calc(100% - 44px) !important;
  }

  .op-head .section-title{
    font-size:13px !important;
  }

  .power-table thead th,
  .status-table thead th{
    height:26px !important;
    font-size:8px !important;
  }

  .power-table td,
  .status-table td{
    padding:2px 8px !important;
    font-size:9px !important;
  }

  .power-table td.val{
    border-width:3px !important;
    font-size:10px !important;
  }

  .status-table td.state{
    font-size:8px !important;
  }

  .legend-item{
    padding:4px 6px !important;
  }

  .legend-tag{
    padding:5px 4px !important;
    font-size:8px !important;
  }

  .legend-desc{
    font-size:8px !important;
  }
}

/* Ajuste horizontal manteniendo las tres columnas inferiores */
@media (max-width:1300px){
  .premium-header{
    grid-template-columns:minmax(430px,1fr) minmax(570px,.95fr) !important;
    gap:14px !important;
  }

  .header-meta{
    grid-template-columns:minmax(270px,1fr) 135px 190px !important;
  }

  .ops-grid{
    grid-template-columns:1.25fr .90fr .72fr !important;
    gap:7px !important;
  }
}


/* =========================================================
   BALANCE CENTRADO + ACCESO A GRÁFICAS
   Conserva la proporción original:
   1180 / 1840 = 64,13 % del ancho de referencia.
   ========================================================= */

.balance-zone{
  position:relative;
  width:100%;
  height:100%;
  min-height:0;
  display:flex;
  justify-content:center;
  align-items:stretch;
  overflow:visible;
}

.balance-zone .balance-card{
  width:min(1180px, 64.13vw) !important;
  max-width:1180px !important;
  height:100% !important;
  min-height:0 !important;
  justify-self:auto !important;
  flex:none;
}

.balance-actions{
  position:absolute;
  left:4px;
  top:10px;
  z-index:5;
  display:flex;
  flex-direction:column;
  align-items:stretch;
  gap:8px;
}

.generation-link{
  position:relative;

  min-width:205px;
  min-height:41px;
  padding:0 15px;

  display:flex;
  align-items:center;
  justify-content:center;

  border:2px solid #08703c;
  border-radius:9px;
  background:#111718;
  color:#ffffff;

  text-decoration:none;
  font-size:15px;
  line-height:1;
  font-weight:800;
  letter-spacing:-.01em;

  box-shadow:0 5px 14px rgba(16,39,31,.10);
  transition:
    background .15s ease,
    border-color .15s ease,
    transform .15s ease;
}

.generation-link:hover{
  background:#0a3e28;
  border-color:#00b050;
  transform:translateY(-1px);
}

.generation-link:focus-visible{
  outline:3px solid rgba(0,176,80,.25);
  outline-offset:2px;
}

/* En pantallas más estrechas se conserva el balance centrado,
   reduciendo únicamente el botón para evitar solapamientos. */
@media (max-width:1100px){
  .generation-link{
    min-width:155px;
    padding:0 10px;
    font-size:12px;
  }
}

@media (max-height:850px){
  .balance-actions{
    top:7px;
    gap:6px;
  }

  .generation-link{
    min-height:35px;
    min-width:180px;
    font-size:13px;
  }
}
#connectionState.is-warning{color:#f4ca4c}
