:root {
  --bg: #0f1419;
  --surface: #1a2129;
  --surface-2: #222c37;
  --text: #e8edf2;
  --muted: #8a97a6;
  --accent: #f5a623;
  --green: #2ecc71;
  --red: #e74c3c;
  --yellow: #f1c40f;
  --border: #2a3540;
}

/* tema claro: sobrescreve as variaveis quando o body tem .theme-light */
body.theme-light {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f1f4f8;
  --text: #1a2129;
  --muted: #5b6b7a;
  --border: #d9e0e7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.15rem; }
.topbar nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar nav a:hover { color: var(--accent); }

.badge { font-size: .7rem; padding: 3px 8px; border-radius: 999px; font-weight: 700; }
.badge-demo { background: var(--accent); color: #1a1200; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }
.footer { text-align: center; color: var(--muted); padding: 24px; font-size: .85rem; }

h1 { font-size: 1.6rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 28px 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.notice {
  background: rgba(245, 166, 35, .12);
  border: 1px solid rgba(245, 166, 35, .4);
  color: #ffd98a;
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 20px;
  font-size: .9rem;
}
code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-size: .85em; }
.notice-error {
  background: rgba(231,76,60,.12);
  border-color: rgba(231,76,60,.45);
  color: #ff9b8f;
}

/* cartoes de resumo */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
.card-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 1.8rem; font-weight: 700; margin-top: 6px; }
.card-sub { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.unit { font-size: .9rem; color: var(--muted); font-weight: 400; }

/* cards com icone + acento de cor */
.card { position: relative; overflow: hidden; }
.card-icon { position: absolute; top: 14px; right: 16px; font-size: 1.5rem; opacity: .55; }
.card.accent-amber  { border-left: 3px solid #f5a623; }
.card.accent-green  { border-left: 3px solid #2ecc71; }
.card.accent-blue   { border-left: 3px solid #3498db; }
.card.accent-violet { border-left: 3px solid #9b59b6; }
.card-sub .dot-online, .card-sub .dot-offline {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 3px;
}
.card-sub .dot-online { background: var(--green); }
.card-sub .dot-offline { background: var(--red); }

/* ranking de geração por usina */
.ranking { display: flex; flex-direction: column; margin-top: 16px; }
.rank-item { padding: 11px 0; border-bottom: 1px solid var(--border); }
.rank-item:last-child { border-bottom: none; }
.rank-top { display: grid; grid-template-columns: minmax(130px, 1.3fr) 2fr auto; align-items: center; gap: 12px; }
.rank-pos { color: var(--muted); font-size: .8rem; font-weight: 700; margin-right: 3px; }
.rank-name { display: flex; align-items: center; gap: 7px; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.rank-bar { background: var(--surface-2); border-radius: 999px; height: 10px; overflow: hidden; }
.rank-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.rank-val { font-weight: 700; font-size: .9rem; text-align: right; white-space: nowrap; }
.rank-val small { display: block; color: var(--muted); font-weight: 400; font-size: .72rem; }
.rank-sub { color: var(--muted); font-size: .76rem; margin-top: 6px; padding-left: 2px; }

@media (max-width: 720px) {
  .rank-top { grid-template-columns: 1fr auto; }
  .rank-top .rank-bar { grid-column: 1 / -1; order: 3; }
}

/* acento de status nos cards de usina */
.plant-card.accent-status-online  { border-left: 3px solid var(--green); }
.plant-card.accent-status-offline { border-left: 3px solid var(--red); }
.plant-card.accent-status-alert   { border-left: 3px solid var(--yellow); }
.plant-card.accent-status-unknown { border-left: 3px solid var(--border); }

/* alertas */
.alerts { margin-top: 8px; }
.alert {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: .9rem;
}
.alert-critical { border-left-color: var(--red); }
.alert-warning { border-left-color: var(--yellow); }
.alert-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.alert-critical .alert-dot { color: var(--red); }
.alert-warning .alert-dot { color: var(--yellow); }

/* grade de usinas */
.plant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.plant-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  transition: transform .12s, border-color .12s;
}
.plant-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.plant-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.plant-name { font-weight: 600; }
.plant-power { font-size: 1.6rem; font-weight: 700; margin: 10px 0 6px; }
.plant-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .82rem; }

/* pills de status */
.status-pill {
  font-size: .7rem; padding: 3px 9px; border-radius: 999px;
  text-transform: uppercase; font-weight: 700; letter-spacing: .03em;
}
.status-online { color: var(--green); }
.status-pill.status-online { background: rgba(46,204,113,.15); }
.status-offline { color: var(--red); }
.status-pill.status-offline { background: rgba(231,76,60,.15); }
.status-pill.status-alert { background: rgba(241,196,15,.18); color: var(--yellow); }
.status-pill.status-unknown { background: var(--surface-2); color: var(--muted); }

/* pagina de detalhe */
.back { color: var(--muted); font-size: .9rem; }
.back:hover { color: var(--accent); }
.detail-head { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.detail-head h1 { margin: 0; }
.muted { color: var(--muted); font-size: .9rem; }
.detail-grid { display: grid; grid-template-columns: 1fr 1.4fr; gap: 16px; margin-top: 8px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.panel h2 { margin-top: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 14px; font-size: .82rem; font-weight: 600; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); color: #1a1200; border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); color: #1a1200; }

/* estado vazio — usuário sem nenhum portal conectado */
.empty-state {
  text-align: center; max-width: 460px; margin: 48px auto;
  padding: 40px 28px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px;
}
.empty-state .empty-icon { font-size: 2.6rem; margin-bottom: 8px; }
.empty-state h2 { margin: 0 0 8px; font-size: 1.15rem; }
.empty-state p { color: var(--muted); margin: 0 0 22px; line-height: 1.5; }

/* formulario de credenciais (Portais) */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; font-size: .85rem; color: var(--muted); }
.field input, .field select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 1rem;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.form-actions { margin-top: 4px; }

/* cartao de selecao (usinas no relatorio) */
.select-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; cursor: pointer;
}
.select-card input { width: 18px; height: 18px; accent-color: var(--accent); }
.select-card:hover { border-color: var(--accent); }

/* lista de usuarios */
.user-list { list-style: none; padding: 0; margin: 8px 0 0; }
.user-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--border);
}
.user-row:last-child { border-bottom: none; }
.user-name { font-size: .9rem; }
.user-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form { display: inline; }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-danger:hover { border-color: var(--red); color: var(--red); }
.role-badge {
  font-size: .68rem; padding: 2px 8px; border-radius: 999px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .03em; margin-left: 4px;
}
.role-badge.role-admin { background: rgba(245,166,35,.18); color: var(--accent); }
.role-badge.role-viewer { background: var(--surface-2); color: var(--muted); }
.kv { list-style: none; padding: 0; margin: 0; }
.kv li { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); }
.kv li:last-child { border-bottom: none; }
.kv span { color: var(--muted); }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.tab {
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 14px; cursor: pointer; font-size: .85rem;
}
.tab.active { background: var(--accent); color: #1a1200; border-color: var(--accent); font-weight: 700; }

/* indicador de usuario no topo */
.topbar .user { color: var(--muted); font-size: .85rem; }
.topbar nav a[href="/logout"]:hover { color: var(--accent); }

/* pagina de login */
.login-body {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; gap: 8px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-brand { font-size: 1.4rem; font-weight: 700; text-align: center; }
.login-sub { text-align: center; margin: -8px 0 4px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
.login-card input {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 1rem;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-btn {
  background: var(--accent); color: #1a1200;
  border: none; border-radius: 8px;
  padding: 11px; font-size: 1rem; font-weight: 700; cursor: pointer;
  margin-top: 4px;
}
.login-btn:hover { filter: brightness(1.05); }
.login-error {
  background: rgba(231,76,60,.12);
  border: 1px solid rgba(231,76,60,.4);
  color: #ff9b8f;
  padding: 10px 12px; border-radius: 8px; font-size: .88rem; text-align: center;
}
.login-ok {
  background: rgba(46,204,113,.12);
  border: 1px solid rgba(46,204,113,.4);
  color: #9be8bd;
  padding: 10px 12px; border-radius: 8px; font-size: .88rem; text-align: center;
}
.login-forgot { display: block; text-align: center; margin-top: 14px; color: var(--muted); font-size: .85rem; }
.login-forgot:hover { color: var(--accent); }
.login-link-btn {
  width: 100%; background: none; border: none; color: var(--muted);
  font-size: .82rem; cursor: pointer; text-decoration: underline; padding: 4px;
}
.login-link-btn:hover { color: var(--accent); }
.login-register { text-align: center; margin-top: 16px; color: var(--muted); font-size: .88rem; }
.login-register a { color: var(--accent); font-weight: 600; }

.tab-ghost { margin-left: auto; }

/* seletor de intervalo de datas */
.range-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 4px 0 10px; font-size: .85rem; color: var(--muted);
}
.range-row input[type="date"] {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: .85rem; color-scheme: dark;
}
.gen-title { font-size: .85rem; margin: 0 0 10px; min-height: 1.1em; }

/* resumo do periodo (intervalo de datas) */
.range-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin: 4px 0 16px;
}
.rs-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.rs-card span { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; }
.rs-card strong { font-size: 1.15rem; }
.rs-card small { color: var(--muted); font-size: .75rem; }

/* container responsivo dos graficos: altura fixa que escala no mobile */
.chart-box { position: relative; width: 100%; height: 300px; }
.chart-hint { font-size: .78rem; margin-top: 10px; opacity: .85; }

@media (max-width: 720px) {
  .topbar { padding: 12px 16px; }
  .container { padding: 16px 14px; }
  .detail-grid { grid-template-columns: 1fr; }
  .chart-box { height: 240px; }
  .tab-ghost { margin-left: 0; }
  h1 { font-size: 1.35rem; }
  .card-value { font-size: 1.5rem; }
}

/* diagrama de fluxo de energia (usina ↔ indústria ↔ rede) */
.energy-flow { width: 100%; max-width: 420px; margin: 4px auto 0; }
.ef-svg { width: 100%; height: auto; display: block; }
.ef-cable line { stroke: var(--border); stroke-width: 2.5; }
.ef-hub { fill: var(--accent); }
.ef-hub-ring { fill: none; stroke: var(--accent); stroke-width: 2; opacity: .45; }
.ef-dot.ef-green { fill: var(--green); }
.ef-dot.ef-amber { fill: var(--accent); }
.ef-dot.ef-violet { fill: #9b59b6; }
.ef-node-bg { fill: var(--surface-2); stroke: var(--border); stroke-width: 1.5; transition: stroke .3s; }
.ef-node-bg.on { stroke: var(--green); }
.ef-emoji { font-size: 26px; text-anchor: middle; dominant-baseline: middle; }
.ef-label { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.ef-val { fill: var(--text); font-size: 12px; font-weight: 600; text-anchor: middle; }
/* diagrama isométrico (novo) */
.ef-cable2 { stroke: rgba(255,255,255,.20); stroke-width: 2.5; }
body.theme-light .ef-cable2 { stroke: rgba(20,30,45,.18); }
body.theme-light .energy-flow ellipse[fill^="url"] { fill: rgba(20,30,45,.05); }
.ef2-label { fill: var(--muted); font-size: 13px; font-weight: 500; text-anchor: middle; }
.ef2-val { fill: var(--text); font-size: 16px; font-weight: 700; text-anchor: middle; }
.ef-badge { font-size: .74rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.ef-badge-online { color: #2ecc71; background: rgba(46,204,113,.14); }
.ef-badge-offline { color: var(--red); background: rgba(231,76,60,.14); }
.ef-badge-alert { color: var(--accent); background: rgba(245,166,35,.16); }
.ef-badge-unknown { color: var(--muted); background: var(--surface-2); }

/* fluxo de energia via GIF/WebP animado + valores ao vivo sobrepostos */
.energy-flow-gif {
  position: relative; max-width: 720px; margin: 6px auto 0;
  background: #f3f6fb; border-radius: 14px; overflow: hidden;
}
.energy-flow-gif img { display: block; width: 100%; height: auto; }
.efg-badge {
  position: absolute; top: 12px; left: 14px; font-size: .76rem; font-weight: 700;
  padding: 4px 11px; border-radius: 999px; background: #e7f7ee; color: #1f9d57;
}
.efg-offline { background: #fdecea; color: #d9362b; }
.efg-alert { background: #fff3e0; color: #c77800; }
.efg-unknown { background: #eef1f5; color: #6b7888; }
.efg-v {
  position: absolute; transform: translateX(-50%); text-align: center;
  font-size: 1.15rem; font-weight: 700; color: #1f2b3a; white-space: nowrap;
}
.efg-v i { font-style: normal; font-weight: 500; font-size: .78rem; color: #6b7888; }
.efg-solar { top: 15.5%; left: 73%; }
.efg-carga { top: 16.5%; left: 18%; }
@media (max-width: 520px) { .efg-v { font-size: .9rem; } .efg-badge { font-size: .66rem; } }

/* impacto ambiental (CO2 / árvores / petróleo) */
/* logo (ícone da marca) inline ao lado do nome */
.brand-logo { height: 1.3em; width: 1.3em; vertical-align: -0.3em; border-radius: 5px; }

.impact-note { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .6px; }
.impact-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.impact-item {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px 12px; text-align: center;
}
.impact-icon { font-size: 2rem; line-height: 1; }
.impact-val { font-size: 1.5rem; font-weight: 700; margin-top: 10px; letter-spacing: -.5px; }
.impact-val .unit { font-size: .85rem; font-weight: 500; color: var(--muted); margin-left: 3px; }
.impact-lbl { color: var(--muted); font-size: .8rem; margin-top: 4px; }
@media (max-width: 520px) {
  .impact-grid { gap: 8px; }
  .impact-icon { font-size: 1.5rem; }
  .impact-val { font-size: 1.05rem; margin-top: 6px; }
  .impact-lbl { font-size: .68rem; }
}
