@font-face {
  font-family: "Magistral";
  src: url("../../fonts/fonnts.com-Magistral_Medium.otf") format("opentype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg0: #f4f7f5;
  --bg1: #ffffff;
  --bg2: #e8eee9;
  --ink: #2a2f2c;
  --muted: #6b756f;
  --line: rgba(42, 47, 44, 0.1);
  --accent: #2f9e5f;
  --accent-dim: #247a49;
  --accent-soft: #e8f6eb;
  --amber: #c48a2a;
  --danger: #c94438;
  --card: #ffffff;
  --surface: #f0f4f1;
  --on-accent: #ffffff;
  --radius: 14px;
  --font: "Magistral", system-ui, sans-serif;
  --display: "Magistral", system-ui, sans-serif;
  --shadow: 0 14px 40px rgba(40, 55, 48, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 8% -8%, rgba(47, 158, 95, 0.1), transparent 55%),
    radial-gradient(900px 480px at 100% 0%, rgba(196, 138, 42, 0.07), transparent 50%),
    linear-gradient(180deg, #eef3f0 0%, var(--bg0) 40%, #f7faf8 100%);
  line-height: 1.5;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(42, 47, 44, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 47, 44, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 28%, transparent 72%);
  opacity: 0.7;
  z-index: 0;
}

.topbar,
.shell,
.footer {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  background: rgba(255, 255, 255, 0.82);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--ink);
}

.brand-logo {
  display: block;
  height: 84px;
  width: auto;
  max-width: min(420px, 78vw);
  object-fit: contain;
  background: transparent;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  transition: color 0.2s, background 0.2s;
}

.nav-link:hover,
.nav-link.is-active {
  color: var(--ink);
  background: var(--accent-soft);
}

.shell {
  width: min(1080px, calc(100% - 2rem));
  margin: 2rem auto 3rem;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 1.5rem;
  border-top: 1px solid var(--line);
}

.hero-title {
  font-family: var(--display);
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  font-weight: 400;
  line-height: 1.1;
  margin: 0 0 0.6rem;
  animation: rise 0.7s ease both;
}

.hero-sub {
  color: var(--muted);
  max-width: 36rem;
  margin: 0 0 1.8rem;
  font-size: 1.05rem;
  animation: rise 0.7s ease 0.08s both;
}

.tipo-switch {
  display: inline-flex;
  gap: 0.35rem;
  padding: 0.3rem;
  margin: 0 0 1.25rem;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.tipo-switch-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin: 0 0 1.25rem;
}

.tipo-switch-row .tipo-switch {
  margin: 0;
}

.tipo-switch-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.15rem;
  border-radius: 9px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.15s, color 0.15s;
}

.tipo-switch-btn:hover {
  color: var(--ink);
  background: rgba(47, 158, 95, 0.08);
}

.tipo-switch-btn.is-active {
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  box-shadow: 0 6px 16px rgba(47, 158, 95, 0.28);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  box-shadow: var(--shadow);
  animation: rise 0.7s ease 0.14s both;
}

.panel + .panel {
  margin-top: 1.25rem;
}

.bess-module.panel {
  margin-top: 1.25rem;
}

.bess-module .section-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.form-grid {
  display: grid;
  gap: 1.1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
.select-control,
select {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg1);
  color: var(--ink);
  font: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
.select-control:focus,
select:focus {
  border-color: rgba(47, 158, 95, 0.55);
  box-shadow: 0 0 0 3px rgba(47, 158, 95, 0.15);
}

.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 1rem;
  top: 50%;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.select-control,
.select-wrap select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.4rem;
  cursor: pointer;
  min-height: 3rem;
}

.select-control option,
select option {
  background: var(--bg1);
  color: var(--ink);
}

.field-select {
  max-width: 42rem;
}

.dropzone {
  position: relative;
  border: 1.5px dashed rgba(47, 158, 95, 0.4);
  border-radius: 12px;
  padding: 2rem 1.25rem;
  text-align: center;
  background: var(--accent-soft);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.dropzone:hover,
.dropzone.is-drag {
  border-color: var(--accent);
  background: #dff3e6;
  transform: translateY(-1px);
}

.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone strong {
  display: block;
  margin-bottom: 0.25rem;
}

.dropzone span {
  color: var(--muted);
  font-size: 0.9rem;
}

.file-name {
  margin-top: 0.75rem;
  color: var(--accent);
  font-size: 0.9rem;
  min-height: 1.2em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  border-radius: 10px;
  padding: 0.9rem 1.3rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: var(--on-accent);
  box-shadow: 0 10px 24px rgba(47, 158, 95, 0.28);
}

.btn-primary:hover {
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: wait;
  transform: none;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.alert-error {
  background: rgba(201, 68, 56, 0.08);
  border: 1px solid rgba(201, 68, 56, 0.28);
  color: #9b2c22;
}

.alert-ok {
  background: var(--accent-soft);
  border: 1px solid rgba(47, 158, 95, 0.3);
  color: var(--accent-dim);
}

.progress {
  display: none;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.progress.is-on {
  display: block;
}

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(42, 47, 44, 0.08);
  overflow: hidden;
  margin-top: 0.65rem;
}

.progress-bar > i {
  display: block;
  height: 100%;
  width: 35%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent), var(--amber));
  animation: slide 1.2s ease-in-out infinite;
}

@keyframes slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

.login-wrap {
  width: min(420px, 100%);
  margin: 4rem auto;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
  margin: 1.25rem 0;
  overflow: visible;
  align-items: start;
}

.metric {
  padding: 1rem;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  animation: rise 0.55s ease both;
  min-width: 0;
}

.metric:nth-child(2) { animation-delay: 0.05s; }
.metric:nth-child(3) { animation-delay: 0.1s; }
.metric:nth-child(4) { animation-delay: 0.15s; }

.metric .label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.metric .value {
  font-family: var(--display);
  font-size: 1.65rem;
  line-height: 1.15;
}

.metric .hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.metric .hint-sub {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.72rem;
  opacity: 0.85;
}

.metric.accent .value { color: var(--accent); }
.metric.amber .value { color: var(--amber); }
.metric.danger .value { color: var(--danger); }

.metrics-charges {
  margin-top: 0.75rem;
}

/* --- Layout Energia na fatura (blocos 1–9) --- */
.ef-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 1rem 0 0.5rem;
}

.ef-row {
  display: grid;
  gap: 0;
  align-items: stretch;
}

.ef-row-hero {
  grid-template-columns: 1fr;
  padding: 0.35rem 0 0.75rem;
  justify-items: center;
}

.ef-block-hero {
  display: grid;
  grid-template-columns: minmax(200px, 260px) minmax(340px, 460px);
  gap: 1rem 2.25rem;
  align-items: center;
  justify-content: center;
  width: min(760px, 100%);
  margin-inline: auto;
  padding: 0.15rem 0;
  min-width: 0;
}

.ef-block-hero .ef-stack {
  justify-content: center;
  gap: 0.85rem;
}

.ef-block-hero .ef-stack > .ef-hero-slot .value {
  font-size: 1.75rem;
}

.ef-block-hero .ef-stack > .ef-hero-slot.accent .value {
  font-size: 1.85rem;
}

.ef-chart-hero.chart-card,
.ef-chart-split.chart-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.85rem 1.1rem;
  align-items: center;
  padding: 0.35rem 0.25rem;
}

.ef-row-detail .ef-chart-split.chart-card {
  padding: 0.25rem 0.35rem;
}

.ef-hero-pie {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.ef-hero-pie .pie-chart {
  width: auto;
}

.ef-hero-pie .pie-svg-wrap,
.ef-hero-pie .pie-svg {
  width: 176px !important;
  height: 176px !important;
  max-width: 176px !important;
  max-height: 176px !important;
  flex-basis: 176px;
}

.ef-row-detail .ef-hero-pie .pie-svg-wrap,
.ef-row-detail .ef-hero-pie .pie-svg {
  width: 140px !important;
  height: 140px !important;
  max-width: 140px !important;
  max-height: 140px !important;
  flex-basis: 140px;
}

.ef-hero-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  justify-content: center;
}

.ef-hero-copy .chart-title {
  margin: 0;
}

.ef-hero-copy .chart-lead {
  margin: 0 0 0.15rem;
}

.ef-hero-slots {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Legenda ao lado do gráfico (bolinha + texto) */
.ef-hero-slots .ef-hero-slot {
  display: grid;
  grid-template-columns: 0.55rem minmax(0, 1fr);
  gap: 0.55rem;
  align-items: start;
  padding: 0.35rem 0.15rem;
}

/* Métrica simples (antes .ef-stat) */
.ef-stack > .ef-hero-slot,
.ef-row-detail > .ef-hero-slot,
.ef-row-detail .ef-stack > .ef-hero-slot {
  display: block;
  position: relative;
  padding: 0.55rem 0.15rem;
  min-width: 0;
  overflow: visible;
  z-index: 1;
}

.ef-hero-slot-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  margin-top: 0.35rem;
}

.ef-hero-slot-body {
  min-width: 0;
}

.ef-hero-slot .label {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.ef-hero-slots .ef-hero-slot .label {
  font-size: 0.72rem;
  margin-bottom: 0.15rem;
}

.ef-hero-slot .value {
  font-family: var(--display);
  font-size: 1.45rem;
  line-height: 1.15;
}

.ef-hero-slots .ef-hero-slot .value {
  font-size: 1.35rem;
}

.ef-row-detail > .ef-hero-slot .value,
.ef-row-detail .ef-stack > .ef-hero-slot .value,
.ef-row-detail .ef-hero-slots .ef-hero-slot .value {
  font-size: 1.2rem;
}

.ef-hero-slot .value small {
  font-size: 0.7em;
  font-weight: 500;
  color: var(--muted);
}

.ef-hero-slot .hint {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.2rem;
}

.ef-hero-slots .ef-hero-slot .hint {
  font-size: 0.76rem;
  margin-top: 0.15rem;
}

.ef-hero-slot.accent .value { color: var(--accent); }
.ef-hero-slot.amber .value { color: var(--amber); }
.ef-hero-slot .value.amber { color: var(--amber); }
.ef-hero-slot .value.danger { color: var(--danger); }

.ef-hero-slot.has-explain {
  cursor: pointer;
}

.ef-hero-slot.has-explain:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.ef-hero-slot.has-explain.is-explain-open {
  z-index: 12;
}

.ef-chart-hero .chart-explain,
.ef-chart-split .chart-explain {
  grid-column: 1 / -1;
}

.ef-row-detail {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr) minmax(0, 1.25fr);
  padding: 0.55rem 0;
}

.ef-row-detail-energia {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.05fr) minmax(0, 1.2fr);
}

.ef-row-detail-demanda {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr);
}

.ef-row-detail > .ef-hero-slot,
.ef-row-detail > .ef-stack,
.ef-row-detail > .ef-chart {
  padding: 0.55rem 1rem;
  min-width: 0;
}

.ef-row-detail > .ef-stack {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.ef-row-detail > .ef-stack > .ef-hero-slot {
  padding: 0;
}

.ef-row-detail + .ef-row-detail {
  border-top: 1px solid rgba(42, 47, 44, 0.14);
}

.ef-divider {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 0.35rem 0 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ef-divider::before,
.ef-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(42, 47, 44, 0.14);
}

.ef-stack {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-width: 0;
}

.ef-stat-dual .ef-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-top: 0.15rem;
}

.ef-stat-dual .ef-dual .value {
  font-size: 1.2rem;
}

.ef-chart.chart-card {
  max-width: none;
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  padding: 0.25rem 0.15rem;
  box-shadow: none;
}

.ef-chart .chart-title {
  font-size: 0.95rem;
}

.ef-chart .chart-lead {
  font-size: 0.78rem;
  margin-bottom: 0.35rem;
}

@media (max-width: 980px) {
  .ef-row-detail {
    grid-template-columns: 1fr 1fr;
  }

  .ef-row-detail > .ef-chart {
    grid-column: 1 / -1;
    border-top: 1px solid rgba(42, 47, 44, 0.1);
    margin-top: 0.35rem;
    padding-top: 0.85rem;
  }
}

@media (max-width: 640px) {
  .ef-block-hero {
    grid-template-columns: 1fr;
    width: 100%;
    gap: 1rem;
  }

  .ef-chart-hero.chart-card,
  .ef-chart-split.chart-card {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: left;
  }

  .ef-hero-copy {
    width: 100%;
  }

  .ef-row-detail {
    grid-template-columns: 1fr;
  }

  .ef-row-detail > .ef-hero-slot + .ef-hero-slot {
    border-top: 1px solid rgba(42, 47, 44, 0.1);
    padding-top: 0.75rem;
  }

  .ef-stat-dual .ef-dual {
    grid-template-columns: 1fr 1fr;
  }
}

.section-title {
  font-family: var(--display);
  font-size: 1.7rem;
  margin: 0 0 0.4rem;
  font-weight: 400;
}

.section-lead {
  color: var(--muted);
  margin: 0 0 1rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th,
td {
  text-align: left;
  padding: 0.85rem 0.7rem;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

tr:hover td {
  background: rgba(47, 158, 95, 0.05);
}

a.link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

a.link:hover {
  text-decoration: underline;
}

.link-btn {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.link-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.link-danger {
  color: var(--danger);
}

.conclusion {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
}

.two-col {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 1rem;
}

.meta-row strong {
  color: var(--ink);
  font-weight: 600;
}

.meta-scor--boa {
  color: var(--accent);
}
.meta-scor--boa strong {
  color: var(--accent);
}

.meta-scor--critica {
  color: var(--amber);
}
.meta-scor--critica strong {
  color: var(--amber);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem;
}

.dropzone-secondary {
  border-color: rgba(230, 179, 90, 0.35);
  background: rgba(230, 179, 90, 0.04);
}

.dropzone-secondary:hover,
.dropzone-secondary.is-drag {
  border-color: var(--amber);
  background: rgba(230, 179, 90, 0.08);
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  vertical-align: middle;
  margin-left: 0.35rem;
}

.badge-fatura,
.badge-medido {
  background: var(--accent-soft);
  color: var(--accent-dim);
}

.badge-estimado {
  background: rgba(196, 138, 42, 0.12);
  color: #8a5f12;
}

.badge-pendente {
  background: rgba(201, 68, 56, 0.1);
  color: #9b2c22;
}

.badge-in_loco,
.badge-in-loco {
  background: rgba(59, 130, 246, 0.1);
  color: #1d4ed8;
}

.inloco-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.inloco-status {
  color: var(--muted);
  font-size: 0.9rem;
}

.inloco-status.is-on {
  color: var(--accent);
}

.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(720px, calc(100vw - 1.5rem));
  width: 100%;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.modal-card {
  margin: 0;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem 1.1rem;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}

.modal-head h2 {
  font-family: var(--display);
  font-size: 1.55rem;
  font-weight: 400;
  margin: 0;
}

.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}

.modal-lead {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0 0 1rem;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.modal-span {
  grid-column: 1 / -1;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.15rem;
}

.chart-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 260px));
  gap: 0.75rem;
  margin-top: 1rem;
  align-items: start;
  justify-content: start;
  max-width: 100%;
}

.chart-pair-1 {
  grid-template-columns: minmax(0, 320px);
}

.chart-pair-1 .chart-card {
  max-width: 320px;
}

.chart-pair-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
  justify-content: stretch;
}

.chart-card {
  display: flex;
  flex-direction: column;
  padding: 0.7rem 0.8rem 0.75rem;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  min-width: 0;
  max-width: 260px;
  position: relative;
  overflow: visible;
}

.chart-card.has-explain,
.metric.has-explain {
  cursor: pointer;
}

.chart-card.has-explain:focus-visible,
.metric.has-explain:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.metric.has-explain {
  position: relative;
  overflow: visible;
  z-index: 1;
}

.metric.has-explain.is-explain-open {
  z-index: 12;
}

.chart-explain {
  position: absolute;
  inset: 0.35rem;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.65rem 0.55rem 0.65rem 0.7rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(196, 138, 42, 0.35);
  box-shadow: 0 10px 28px rgba(40, 55, 48, 0.16);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  overflow: auto;
  max-height: calc(100% - 0.7rem);
  scrollbar-width: thin;
  scrollbar-color: rgba(196, 138, 42, 0.45) transparent;
}

.metric-explain {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
  box-sizing: border-box;
  padding: 0.7rem 0.75rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.99);
  border: 1px solid rgba(196, 138, 42, 0.4);
  box-shadow: 0 14px 32px rgba(40, 55, 48, 0.14);
  max-height: min(280px, 50vh);
  overflow: auto;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  scrollbar-width: thin;
  scrollbar-color: rgba(196, 138, 42, 0.45) transparent;
}

.chart-explain::-webkit-scrollbar,
.metric-explain::-webkit-scrollbar {
  width: 6px;
}

.chart-explain::-webkit-scrollbar-track,
.metric-explain::-webkit-scrollbar-track {
  background: transparent;
  margin: 6px 0;
}

.chart-explain::-webkit-scrollbar-thumb,
.metric-explain::-webkit-scrollbar-thumb {
  background: rgba(196, 138, 42, 0.4);
  border-radius: 999px;
}

.chart-explain::-webkit-scrollbar-thumb:hover,
.metric-explain::-webkit-scrollbar-thumb:hover {
  background: rgba(196, 138, 42, 0.65);
}

.chart-explain::-webkit-scrollbar-button,
.metric-explain::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}

.chart-card.has-explain.is-explain-open .chart-explain,
.metric.has-explain.is-explain-open .metric-explain,
.ef-stat.has-explain.is-explain-open .metric-explain,
.ef-hero-slot.has-explain.is-explain-open .metric-explain {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.chart-explain[hidden],
.metric-explain[hidden] {
  display: none !important;
}

.chart-explain strong,
.metric-explain strong {
  font-size: 0.82rem;
  color: var(--amber);
}

.chart-explain p,
.chart-explain li,
.metric-explain p,
.metric-explain li {
  margin: 0;
  color: var(--ink);
  font-size: 0.72rem;
  line-height: 1.35;
}

.chart-explain ul,
.metric-explain ul {
  margin: 0;
  padding-left: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.chart-explain-sum,
.metric-explain .chart-explain-sum {
  margin-top: 0.15rem !important;
  color: var(--accent) !important;
  font-weight: 600;
}

.chart-explain-muted,
.metric-explain .chart-explain-muted {
  color: var(--muted) !important;
}

.chart-pair-3 .chart-card {
  max-width: none;
  width: 100%;
}

.chart-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 400;
}

.chart-lead {
  margin: 0.1rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.pie-chart {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.pie-svg-wrap {
  width: 112px;
  height: 112px;
  flex: 0 0 112px;
  overflow: hidden;
}

.pie-svg {
  width: 112px !important;
  height: 112px !important;
  max-width: 112px;
  max-height: 112px;
  display: block;
}

.pie-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: grid;
  gap: 0.22rem;
}

.pie-legend li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.4rem;
  font-size: 0.76rem;
  color: var(--ink);
  line-height: 1.2;
}

.pie-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.pie-legend strong {
  font-weight: 600;
}

.pie-pct {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.pie-detail {
  color: var(--muted);
  font-size: 0.72rem;
  margin-left: auto;
}

.chart-empty {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.35rem 0;
}

.chart-legend-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.chart-swatch {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  vertical-align: middle;
}

.chart-swatch-ponta {
  background: var(--amber);
  box-shadow: 0 0 0 1px rgba(230, 179, 90, 0.35);
}

.chart-swatch-fora {
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(47, 158, 95, 0.35);
}

.chart-outros-note {
  margin: 0.55rem 0 0;
  width: 100%;
}

.chart-info-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chart-info-link:hover {
  color: var(--ink);
}

.chart-info-box {
  margin-top: 0.45rem;
  padding: 0.7rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--ink);
}

.chart-info-box[hidden] {
  display: none;
}

.chart-info-box p {
  margin: 0.4rem 0 0;
  color: var(--muted);
}

.chart-info-box strong {
  color: var(--ink);
}

.chart-info-formula {
  font-size: 0.74rem !important;
  word-break: break-word;
}

.chart-legend-muted {
  color: var(--muted);
  opacity: 0.9;
}

@media (max-width: 900px) {
  .chart-pair-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .shell {
    margin-top: 1.25rem;
  }
  .modal-grid {
    grid-template-columns: 1fr;
  }
  .chart-pair {
    grid-template-columns: 1fr;
  }
  .chart-pair-3 {
    grid-template-columns: 1fr;
  }
  .chart-card {
    max-width: 100%;
  }
}

/* —— Load shifting (arbitragem) —— */
.ls-module .ls-scope {
  margin-top: -0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.ls-kpi-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
  margin: 1.1rem 0 1.35rem;
}

.ls-kpi {
  padding: 0.95rem 1.05rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ls-kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.ls-kpi-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}

.ls-kpi-value small {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.ls-kpi-sub {
  font-size: 0.82rem;
  color: var(--muted);
}

.ls-kpi-result.is-ok {
  border-color: rgba(72, 187, 120, 0.45);
  background: rgba(72, 187, 120, 0.08);
}

.ls-kpi-result.is-warn {
  border-color: rgba(237, 137, 54, 0.45);
  background: rgba(237, 137, 54, 0.08);
}

.ls-subtitle {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 0.65rem;
  color: var(--ink);
}

.ls-collapsible {
  margin-bottom: 0.35rem;
}

.ls-collapse-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  margin: 0 0 0.35rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.ls-collapse-toggle:hover {
  border-color: rgba(42, 47, 44, 0.28);
  background: rgba(42, 47, 44, 0.03);
}

.ls-collapse-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ls-collapse-toggle .ls-subtitle {
  margin: 0;
}

.ls-collapse-chevron {
  flex: 0 0 auto;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.22s ease;
  margin-top: -0.15rem;
}

.ls-collapsible.is-open .ls-collapse-chevron {
  transform: rotate(225deg);
  margin-top: 0.2rem;
}

.ls-collapse-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.32s ease;
}

.ls-collapsible.is-open .ls-collapse-panel {
  grid-template-rows: 1fr;
}

.ls-collapse-panel > * {
  overflow: hidden;
  min-height: 0;
}

.ls-steps {
  list-style: none;
  margin: 0.35rem 0 1.1rem;
  padding: 0;
  counter-reset: ls-step;
  display: grid;
  gap: 0.55rem;
}

.ls-steps > li {
  counter-increment: ls-step;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  align-items: baseline;
  padding: 0.7rem 0.9rem 0.7rem 2.6rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  position: relative;
}

.ls-steps > li::before {
  content: counter(ls-step);
  position: absolute;
  left: 0.7rem;
  top: 0.75rem;
  width: 1.35rem;
  height: 1.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent-dim);
}

.ls-step-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ink);
  min-width: 11rem;
}

.ls-step-detail {
  flex: 1 1 14rem;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

.ls-step-detail strong {
  color: var(--ink);
}

.ls-step-detail em {
  font-style: normal;
  opacity: 0.85;
}

.ls-steps > li.ls-step-result {
  border-color: rgba(72, 187, 120, 0.35);
  background: rgba(72, 187, 120, 0.07);
}

.ls-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
  margin-top: 0.35rem;
  margin-bottom: 0.35rem;
}

.ls-bloco + .ls-bloco-investimento,
.ls-grid-2 + .ls-bloco-investimento {
  margin-top: 1.25rem;
}

.ls-kpi-row + .ls-bloco-investimento {
  margin-top: 0.35rem;
  margin-bottom: 1.25rem;
}

.ls-bloco-investimento + .ls-bloco-cadeia {
  margin-top: 0;
}

.ls-bloco-investimento + .ps-bloco-gerador,
.ps-bloco-gerador + .ls-bloco-cadeia,
.ps-bloco-gerador + .ls-kpi-row {
  margin-top: 1.25rem;
}

.ps-bloco-gerador {
  padding: 1rem 1.1rem;
  border: 1px dashed rgba(47, 158, 95, 0.35);
  border-radius: 10px;
  background: rgba(47, 158, 95, 0.04);
}

.ps-gerador-lead {
  margin: 0.25rem 0 0.9rem;
  font-size: 0.88rem;
  opacity: 0.9;
}

.ps-gerador-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem 0.9rem;
}

.ps-gerador-grid-simple {
  grid-template-columns: repeat(2, minmax(10rem, 14rem));
}

.ps-gerador-field label {
  display: block;
  font-size: 0.78rem;
  margin-bottom: 0.3rem;
  opacity: 0.85;
}

.ps-gerador-field .ls-input {
  max-width: none;
  width: 100%;
}

.ps-gerador-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 0.9rem;
  margin-top: 1rem;
}

.ps-gerador-resultado {
  font-size: 0.88rem;
  line-height: 1.35;
}

@media (max-width: 900px) {
  .ps-gerador-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .ps-gerador-grid {
    grid-template-columns: 1fr;
  }
}

.ls-input {
  width: 100%;
  max-width: 9.5rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg1);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
}

.ls-input:focus {
  border-color: rgba(47, 158, 95, 0.55);
  box-shadow: 0 0 0 3px rgba(47, 158, 95, 0.12);
}

.ls-input-invest {
  max-width: 14rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.ls-invest-row {
  display: grid;
  grid-template-columns: minmax(12rem, 1.1fr) minmax(10rem, 1fr) minmax(10rem, 1fr);
  gap: 0.85rem;
  align-items: stretch;
}

.ls-invest-field,
.ls-invest-result,
.ls-invest-meta {
  padding: 0.95rem 1.05rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.ls-invest-result {
  flex-direction: row;
  align-items: flex-start;
  gap: 1rem;
}

.ls-payback-col,
.ls-eco-10a-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ls-eco-10a-col {
  padding-left: 1rem;
  border-left: 1px solid var(--line);
}

.ls-invest-field label {
  margin-bottom: 0.15rem;
}

.ls-invest-result .ls-kpi-value {
  font-size: 1.35rem;
}

.ls-eco-10a-value {
  font-size: 1.15rem !important;
  word-break: break-word;
}

.ls-module.ls-payback-ok #ls-resultado-payback,
.ls-module.ls-payback-ok #ps-resultado-payback {
  border-color: rgba(72, 187, 120, 0.45);
  background: rgba(72, 187, 120, 0.08);
}

.ls-module.ls-payback-warn #ls-resultado-payback,
.ls-module.ls-payback-warn #ps-resultado-payback {
  border-color: rgba(237, 137, 54, 0.45);
  background: rgba(237, 137, 54, 0.08);
}

/* Peak shaving — destaque economia líquida + payback */
#ps-kpi-economia-liquida,
#ps-resultado-payback {
  border-width: 2px;
  box-shadow: 0 0 0 1px rgba(47, 158, 95, 0.06), 0 8px 22px rgba(40, 55, 48, 0.1);
}

#ps-kpi-economia-liquida .ls-kpi-value,
#ps-resultado-payback .ls-kpi-value {
  font-size: 1.65rem;
  letter-spacing: -0.02em;
}

#ps-kpi-economia-liquida.is-ok,
.ls-module.ls-payback-ok #ps-resultado-payback {
  border-color: rgba(72, 187, 120, 0.7);
  background: linear-gradient(165deg, rgba(72, 187, 120, 0.16), rgba(72, 187, 120, 0.05));
}

#ps-kpi-economia-liquida.is-warn,
.ls-module.ls-payback-warn #ps-resultado-payback {
  border-color: rgba(237, 137, 54, 0.7);
  background: linear-gradient(165deg, rgba(237, 137, 54, 0.16), rgba(237, 137, 54, 0.05));
}

#ps-kpi-economia-liquida .ls-kpi-label,
#ps-resultado-payback .ls-kpi-label {
  color: var(--ink);
  opacity: 0.9;
}

/* Config — catálogo BESS */
#config-bess-catalogo input[type="text"],
#config-bess-catalogo input[type="number"] {
  width: 100%;
  min-width: 6rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg1);
  color: var(--ink);
  font: inherit;
}

#config-bess-catalogo .btn-sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
}

#ls-campo-valor-bess .ls-kpi-sub {
  margin-top: 0.35rem;
  line-height: 1.35;
}

#ls-campo-valor-bess .ls-kpi-value {
  font-size: 1.35rem;
}

.ls-viab {
  margin: 0.75rem 0 0;
  font-size: 0.88rem;
  line-height: 1.4;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.ls-viab.is-ok {
  color: var(--accent-dim);
  border-color: rgba(47, 158, 95, 0.35);
  background: var(--accent-soft);
}

.ls-viab.is-warn {
  color: #8a5f12;
  border-color: rgba(196, 138, 42, 0.35);
  background: rgba(196, 138, 42, 0.1);
}

@media (max-width: 900px) {
  .ls-kpi-row,
  .ls-grid-2,
  .ls-invest-row {
    grid-template-columns: 1fr;
  }
  .ls-invest-result {
    flex-direction: column;
  }
  .ls-eco-10a-col {
    padding-left: 0;
    padding-top: 0.55rem;
    border-left: none;
    border-top: 1px solid var(--line);
  }
}
