:root {
  --bg: #f3f6fa;
  --p: #ffffff;
  --p2: #f7f9fc;
  --p3: #edf3fb;
  --l: #dce4ee;
  --t: #122033;
  --m: #65758b;
  --a: #1769d2;
  --a2: #56a8ff;
  --g: #158766;
  --w: #a86508;
  --r: #c7384f;
  --ink: #0e1a2a;
  --s: 0 10px 30px rgba(22, 42, 72, 0.07);
}
body.dark {
  --bg: #08111f;
  --p: #101b2c;
  --p2: #152238;
  --p3: #1a2941;
  --l: #273a55;
  --t: #edf4ff;
  --m: #91a4bf;
  --a: #5fa9ff;
  --a2: #88c3ff;
  --g: #43c89b;
  --w: #f3b75d;
  --r: #ef7181;
  --ink: #f5f8ff;
  --s: 0 16px 36px rgba(0, 0, 0, 0.25);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--t);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  letter-spacing: -0.008em;
}
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.app[hidden], .gate[hidden] { display: none !important; }
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(420px, 100%);
  background: var(--p);
  border: 1px solid var(--l);
  border-radius: 16px;
  box-shadow: var(--s);
  padding: 28px 24px;
}
.gate-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.gate-card h1 { font-size: 20px; margin: 16px 0 8px; }
.gate-card label { display: block; font-size: 12px; color: var(--m); margin: 12px 0 4px; }
.gate-card input {
  width: 100%;
  background: var(--p2);
  color: var(--t);
  border: 1px solid var(--l);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
}
.gate-card .btn.primary { width: 100%; margin-top: 16px; }
.gate-error { color: var(--r); font-size: 12px; margin: 12px 0 0; }
aside {
  background: linear-gradient(180deg, var(--p) 0%, color-mix(in srgb, var(--p) 92%, var(--a) 8%) 100%);
  border-right: 1px solid var(--l);
  padding: 22px 15px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand { font-weight: 900; font-size: 18px; margin: 0 8px; letter-spacing: 0.015em; }
.brand span { color: var(--a); font-weight: 650; }
.env { font-size: 12px; color: var(--m); margin: 7px 8px 16px; }
.navtitle {
  font-size: 10px;
  color: var(--m);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 16px 10px 6px;
}
.nav a {
  display: flex;
  align-items: center;
  min-height: 42px;
  text-decoration: none;
  color: var(--m);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 650;
  margin: 2px 0;
}
.nav a:hover { background: var(--p2); color: var(--t); transform: translateX(2px); }
.nav a.on {
  background: color-mix(in srgb, var(--a) 10%, var(--p));
  color: var(--a);
  box-shadow: inset 3px 0 0 var(--a);
}
.system-box { margin: 0 4px 8px; }
.system-box label { display: block; font-size: 10px; color: var(--m); margin-bottom: 4px; }
.system-box select {
  width: 100%;
  background: var(--p2);
  color: var(--t);
  border: 1px solid var(--l);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  font-size: 12px;
}
main { min-width: 0; }
.top {
  min-height: 72px;
  background: var(--p);
  border-bottom: 1px solid var(--l);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.top h1 { font-size: 19px; margin: 0; }
.sub { font-size: 11px; color: var(--m); margin-top: 2px; }
.acts { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.date-calendar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border: 1px solid var(--l);
  border-radius: 12px;
  background: var(--p2);
}
.date-calendar-label {
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}
.date-picker {
  border: 1px solid var(--l);
  background: var(--p);
  color: var(--t);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  min-width: 132px;
}
.linkish {
  border: 0;
  background: none;
  color: var(--a);
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  padding: 0;
}
.date-arrow {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--l);
  border-radius: 8px;
  background: var(--p);
  color: var(--a);
  cursor: pointer;
  font-size: 21px;
  line-height: 1;
}
.date-arrow:hover:not(:disabled) { border-color: var(--a); background: var(--p3); }
.date-arrow:disabled { color: var(--m); opacity: 0.4; cursor: not-allowed; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--g);
  border: 1px solid color-mix(in srgb, var(--g) 35%, var(--l));
  background: color-mix(in srgb, var(--g) 8%, var(--p));
  padding: 7px 10px;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.health-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--g);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--g) 15%, transparent);
}
.pill.offline {
  color: var(--r);
  border-color: color-mix(in srgb, var(--r) 40%, var(--l));
  background: color-mix(in srgb, var(--r) 8%, var(--p));
}
.pill.offline .health-dot {
  background: var(--r);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--r) 15%, transparent);
}
button, .btn, select, input { font: inherit; }
.btn {
  border: 1px solid var(--l);
  background: var(--p2);
  color: var(--t);
  min-height: 34px;
  padding: 8px 11px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}
.btn:hover {
  border-color: color-mix(in srgb, var(--a) 45%, var(--l));
  background: color-mix(in srgb, var(--a) 5%, var(--p));
}
.btn.primary {
  background: var(--a);
  border-color: var(--a);
  color: white;
  box-shadow: 0 7px 18px color-mix(in srgb, var(--a) 24%, transparent);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.stage { position: relative; min-height: 280px; }
.content { max-width: 1640px; padding: 24px 26px 54px; }
.page-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 18vh;
  gap: 12px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  color: var(--m);
  font-size: 13px;
  font-weight: 650;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--l);
  border-top-color: var(--a);
  border-radius: 50%;
  animation: page-spin 0.7s linear infinite;
}
@keyframes page-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
.head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }
.head h2 { font-size: 21px; margin: 0; }
.head p { font-size: 13px; color: var(--m); margin: 4px 0 0; }
.grid { display: grid; gap: 13px; }
.k5 { grid-template-columns: repeat(5, 1fr); }
.k4 { grid-template-columns: repeat(4, 1fr); }
.r2 { grid-template-columns: 1.4fr 1fr; }
.r2e { grid-template-columns: 1fr 1fr; }
.r3 { grid-template-columns: repeat(3, 1fr); }
.card {
  background: var(--p);
  border: 1px solid var(--l);
  border-radius: 14px;
  box-shadow: var(--s);
  min-width: 0;
}
.card .hd { padding: 14px 16px; border-bottom: 1px solid var(--l); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.card .hd b { font-size: 13px; }
.card .hd-right { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.card .hd-right > span { font-size: 11px; color: var(--m); }
.chart-dl { display: inline-flex; gap: 4px; }
.chart-dl-btn { min-height: 26px; padding: 4px 8px; font-size: 10px; }
.body { padding: 16px; }
.kpi { padding: 16px; position: relative; }
.kpi small { display: block; color: var(--m); font-size: 12px; margin-bottom: 6px; }
.kpi strong { font-size: 24px; }
.delta { font-size: 11px; color: var(--g); margin-top: 5px; }
.warn { color: var(--w); }
.bad { color: var(--r); }
.muted { color: var(--m); }
.chart {
  height: 250px;
  position: relative;
  background: linear-gradient(180deg, color-mix(in srgb, var(--a) 3%, transparent), transparent);
  border-radius: 9px;
  overflow: hidden;
}
.chart svg { width: 100%; height: 100%; }
.gl { stroke: var(--l); stroke-width: 1; }
.time-grid { stroke: var(--m); pointer-events: none; }
.time-grid.major { stroke-width: 1; opacity: .4; }
.time-grid.minor { stroke-width: .6; opacity: .2; stroke-dasharray: 2 3; }
.axis-label {
  fill: var(--m);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0;
}
.y-axis { text-anchor: end; }
.x-axis { text-anchor: middle; }
.bl { stroke: var(--a); fill: none; stroke-width: 3; }
.gr { stroke: var(--g); fill: none; stroke-width: 2.5; }
.yl { stroke: #d6a915; fill: none; stroke-width: 2.5; }
.or { stroke: #e07a2f; fill: none; stroke-width: 2; }
.chart-point { stroke-width: 1.5; }
.chart-point.bl { fill: var(--a); stroke: var(--p); }
.chart-point.gr { fill: var(--g); stroke: var(--p); }
.chart-point.yl { fill: #d6a915; stroke: var(--p); }
.chart-point.or { fill: #e07a2f; stroke: var(--p); }
.y-axis-right { text-anchor: start; }
.barb { fill: var(--a); }
.barg { fill: var(--g); }
.barw { fill: #d6a915; }
.barr { fill: var(--r); }
.barp { fill: var(--a); }
.bara { fill: #d6a915; }
.chart-legend {
  display: flex;
  gap: 12px;
  font-size: 10px;
  color: var(--m);
  margin-top: 6px;
}
.chart-legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: -1px;
}
.chart-legend .plan { background: var(--a); }
.chart-legend .actual { background: #d6a915; }
.chart-legend .observed { background: var(--g); }
.chart-legend .forecast { background: #d6a915; }
.chart-legend .ghi { background: #e07a2f; }
.chart-legend .low { background: #d6a915; }
.chart-legend .high { background: #e07a2f; }
.legend-toggle {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
}
.legend-toggle.off { opacity: 0.35; }
.pv-res-label { display: inline-flex; align-items: center; gap: 6px; }
.pv-res {
  font: inherit;
  color: var(--t);
  background: var(--p);
  border: 1px solid var(--l);
  border-radius: 6px;
  padding: 2px 6px;
}
.assets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.asset { background: var(--p2); border: 1px solid var(--l); border-radius: 11px; padding: 12px; cursor: pointer; }
.asset:hover { border-color: var(--a); }
.asset .a1 { display: flex; justify-content: space-between; }
.asset b { font-size: 12px; }
.asset .meta { font-size: 10px; color: var(--m); margin-top: 3px; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 10px; }
.m { padding: 7px; background: var(--p); border: 1px solid var(--l); border-radius: 7px; }
.m small { font-size: 10px; color: var(--m); display: block; }
.m b { font-size: 12px; }
.tag { font-size: 9px; font-weight: 800; border: 1px solid var(--l); border-radius: 999px; padding: 4px 6px; color: var(--m); }
.tag.g { color: var(--g); }
.tag.w { color: var(--w); }
.tag.r { color: var(--r); }
.tablewrap { overflow: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 760px; }
.tbl th { text-align: left; color: var(--m); padding: 10px 9px; border-bottom: 1px solid var(--l); white-space: nowrap; }
.tbl td { padding: 11px 9px; border-bottom: 1px solid var(--l); }
.tbl tr:hover { background: var(--p2); }
[hidden] { display: none !important; }
.period-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  margin: 14px 0;
}
.period-bar .fr { min-width: 150px; }
.period-bar .btn.on {
  border-color: var(--a);
  color: var(--a);
}
.sched-rows { display: grid; gap: 10px; }
.sched-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr);
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--l);
  border-radius: 10px;
  background: var(--p2);
}
.sched-enable { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 750; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fr.span2 { grid-column: 1 / -1; }
.sg-steps { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.sg-step {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--m);
  border: 1px solid var(--l);
  border-radius: 999px;
  padding: 4px 8px;
}
.sg-step.on { color: var(--g); border-color: var(--g); }
.sg-step i {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-style: normal;
  font-size: 10px;
  font-weight: 800;
  background: var(--p2);
}
.sg-oauth {
  border-top: 1px dashed var(--l);
  padding-top: 10px;
  color: var(--m);
  font-size: 12px;
}
.sg-oauth summary { cursor: pointer; }
.fr label { display: block; font-size: 11px; color: var(--m); margin-bottom: 4px; }
.fr input, .fr select {
  width: 100%;
  background: var(--p2);
  color: var(--t);
  border: 1px solid var(--l);
  border-radius: 7px;
  padding: 8px;
  font-size: 12px;
}
.alerts { display: flex; flex-direction: column; gap: 7px; }
.al { border: 1px solid var(--l); background: var(--p2); border-radius: 9px; padding: 9px; }
.al b { font-size: 12px; }
.al p { font-size: 11px; color: var(--m); margin: 4px 0 0; }
.prog { height: 7px; background: var(--l); border-radius: 99px; overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--a); }
.note {
  font-size: 11px;
  color: var(--m);
  padding: 9px;
  background: var(--p2);
  border: 1px dashed var(--l);
  border-radius: 8px;
  margin-top: 10px;
  line-height: 1.5;
}
.help { position: relative; }
.q {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 17px;
  height: 17px;
  border: 1px solid var(--a);
  color: var(--a);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 10px;
  background: var(--p);
}
.modal {
  position: fixed;
  inset: 0;
  background: #07111d88;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.show { display: flex; }
.mb { width: min(900px, 95vw); max-height: 90vh; overflow: auto; background: var(--p); border: 1px solid var(--l); border-radius: 15px; }
.mh { padding: 13px 15px; border-bottom: 1px solid var(--l); display: flex; justify-content: space-between; }
.mh b { font-size: 14px; }
.close { border: 0; background: none; color: var(--m); font-size: 22px; cursor: pointer; }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--p);
  border: 1px solid var(--l);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 11px;
  box-shadow: var(--s);
  display: none;
  z-index: 11000;
}
.section-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mode-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--l);
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 10px;
  font-weight: 800;
  color: var(--m);
  background: var(--p2);
}
.mode-chip.auto { color: var(--g); }
.mode-chip.manual {
  color: var(--w);
  border-color: color-mix(in srgb, var(--w) 40%, var(--l));
  background: color-mix(in srgb, var(--w) 7%, var(--p));
}
.mode-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  border: 1px solid var(--l);
  border-radius: 11px;
  background: var(--p2);
  margin-bottom: 14px;
}
.mode-strip strong { font-size: 12px; }
.mode-strip span { font-size: 11px; color: var(--m); }
.editor-chart, .dispatch-chart {
  height: 260px;
  display: flex;
  align-items: stretch;
  gap: 5px;
  padding: 14px 10px 8px;
  border-radius: 12px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--a) 5%, var(--p)), var(--p2));
  border: 1px solid var(--l);
  overflow-x: auto;
}
.dispatch-chart { height: 252px; align-items: center; }
.dispatch-shell { display: grid; grid-template-columns: 42px minmax(0, 1fr); }
.dispatch-axis {
  height: 252px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  padding: 15px 7px 17px 0;
  color: var(--m);
  font-size: 9px;
  font-weight: 650;
}
.forecast-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  min-width: 18px;
}
.forecast-col .v { font-size: 9px; color: var(--m); margin-bottom: 5px; writing-mode: vertical-rl; transform: rotate(180deg); max-height: 44px; }
.forecast-col .bar {
  width: 72%;
  min-height: 6px;
  background: linear-gradient(180deg, var(--a2), var(--a));
  border-radius: 5px 5px 2px 2px;
}
.forecast-col .h { font-size: 9px; color: var(--m); margin-top: 6px; }
.forecast-col.changed .bar { background: linear-gradient(180deg, #ffbd59, var(--w)); }
.dispatch-col { height: 210px; flex: 1; position: relative; min-width: 18px; }
.dispatch-col:before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--l); }
.dispatch-col .power { position: absolute; left: 18%; width: 64%; border-radius: 4px; }
.dispatch-col .v {
  position: absolute;
  top: calc(50% - 7px);
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 8px;
  color: var(--m);
  opacity: 0;
}
.dispatch-col:hover .v { opacity: 1; }
.dispatch-col.charge .power { top: 50%; background: linear-gradient(180deg, var(--a), var(--a2)); }
.dispatch-col.discharge .power { bottom: 50%; background: linear-gradient(180deg, #38b68a, var(--g)); }
.dispatch-col.hold .power { top: calc(50% - 2px); height: 4px !important; background: #a5b0bf; }
.dispatch-col.changed .power { box-shadow: 0 0 0 2px var(--w); }
.dispatch-col .h { position: absolute; bottom: -1px; left: 50%; transform: translateX(-50%); font-size: 9px; color: var(--m); }
.edit-grid { display: grid; grid-template-columns: repeat(12, minmax(58px, 1fr)); gap: 7px; margin-top: 12px; }
.edit-cell { padding: 7px; border: 1px solid var(--l); border-radius: 9px; background: var(--p2); }
.edit-cell label { display: block; font-size: 9px; color: var(--m); margin-bottom: 4px; }
.edit-cell input { width: 100%; min-width: 0; border: 0; background: transparent; color: var(--t); font-size: 11px; font-weight: 750; outline: 0; }
.edit-cell:focus-within { border-color: var(--a); box-shadow: 0 0 0 3px color-mix(in srgb, var(--a) 12%, transparent); }
.legend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 11px; font-size: 10px; color: var(--m); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }
.legend .blue { background: var(--a); }
.legend .amber { background: var(--w); }
.legend .orange { background: #e07a2f; }
.legend .green { background: var(--g); }
.legend .gray { background: #a5b0bf; }
.status-flow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.flow-step { padding: 11px; border: 1px solid var(--l); border-radius: 10px; background: var(--p2); }
.flow-step small { display: block; color: var(--m); font-size: 10px; margin-bottom: 4px; }
.flow-step b { font-size: 12px; }
.subtle-link { color: var(--a); font-size: 11px; font-weight: 750; cursor: pointer; text-decoration: none; }
.risk-note {
  border-left: 3px solid var(--w);
  padding: 9px 11px;
  background: color-mix(in srgb, var(--w) 7%, var(--p));
  font-size: 11px;
  color: var(--m);
  border-radius: 0 9px 9px 0;
  margin-top: 10px;
}
.empty { color: var(--m); font-size: 13px; padding: 8px 0; }
@media (max-width: 1200px) {
  .k5 { grid-template-columns: repeat(3, 1fr); }
  .k4 { grid-template-columns: repeat(2, 1fr); }
  .r2, .r2e, .r3 { grid-template-columns: 1fr; }
  .assets { grid-template-columns: 1fr 1fr; }
  .edit-grid { grid-template-columns: repeat(6, 1fr); }
  .status-flow { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  aside { display: none; }
  .content { padding: 18px 14px 40px; }
  .top { padding: 11px 14px; }
  .k5, .k4 { grid-template-columns: 1fr 1fr; }
  .edit-grid { grid-template-columns: repeat(4, 1fr); }
  .status-flow { grid-template-columns: 1fr; }
}

#recalcForm .fr label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  font-size: 14px;
  color: var(--t);
}
#recalcForm input[type="checkbox"] {
  width: auto;
  margin: 0;
  flex: 0 0 auto;
}

.editor-chart, .dispatch-chart { position: relative; }
.editor-time-grid { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
