/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --bg2:       #1a1d27;
  --bg3:       #22263a;
  --border:    #2e3250;
  --accent:    #f59e0b;
  --green:     #22c55e;
  --red:       #ef4444;
  --blue:      #3b82f6;
  --gray:      #6b7280;
  --text:      #e5e7eb;
  --text-dim:  #9ca3af;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

header h1 a { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: inherit; }
header h1 a:hover { opacity: .85; }

#last-update {
  font-size: 12px;
  color: var(--text-dim);
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Cards de resumo ──────────────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
}

.stat-card .value {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card .unit { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

.stat-card.power  .value { color: var(--accent); }
.stat-card.green  .value { color: var(--green); }
.stat-card.red    .value { color: var(--red); }
.stat-card.blue   .value { color: var(--blue); }

/* ── Seção de fabricante ──────────────────────────────────────────────────── */
.manufacturer-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.mfr-header {
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.mfr-header h2 {
  font-size: .9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.mfr-badge {
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--text-dim);
}

/* ── Tabela de plantas ────────────────────────────────────────────────────── */
.plants-table {
  width: 100%;
  border-collapse: collapse;
}

.plants-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  text-align: left;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.plants-table th:not(:first-child) { text-align: right; }

.plants-table td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.plants-table tr:last-child td { border-bottom: none; }

.plants-table tr:hover td { background: rgba(255,255,255,.02); }

/* Colunas numéricas alinhadas à direita */
.plants-table td:not(:first-child):not(.bar-cell) { text-align: right; }

/* ── Célula de nome ───────────────────────────────────────────────────────── */
.plant-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.generating { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.idle        { background: var(--gray); }
.status-dot.offline     { background: var(--red); }
.status-dot.fault       { background: #f97316; box-shadow: 0 0 6px #f97316; }

.plant-name { font-weight: 500; }
.plant-name a {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.plant-name a:hover { color: var(--accent); }

/* ── Barra de potência ────────────────────────────────────────────────────── */
.bar-cell { min-width: 140px; }

.bar-wrap {
  background: var(--bg3);
  border-radius: 4px;
  height: 8px;
  width: 100%;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--green);
  transition: width .6s ease;
}

.bar-fill.offline { background: var(--red); opacity: .4; }
.bar-fill.fault   { background: #f97316; }
.bar-fill.idle    { background: var(--gray); opacity: .5; }

/* ── Valores numéricos ────────────────────────────────────────────────────── */
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dim { color: var(--text-dim); }
.bold { font-weight: 600; }

/* ── Modal de histórico ───────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(860px, 95vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { font-size: 1rem; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.chart-container { position: relative; height: 280px; }

/* ── Loading state ────────────────────────────────────────────────────────── */
.loading {
  text-align: center;
  color: var(--text-dim);
  padding: 40px;
  font-size: 13px;
}

/* ── Status badge inline ──────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 11px;
  border-radius: 4px;
  padding: 2px 7px;
  font-weight: 500;
}

.badge.generating { background: rgba(34,197,94,.15); color: var(--green); }
.badge.idle        { background: rgba(107,114,128,.15); color: var(--gray); }
.badge.offline     { background: rgba(239,68,68,.15); color: var(--red); }
.badge.fault       { background: rgba(249,115,22,.15); color: #f97316; }

/* ── Push notification button ────────────────────────────────────────────── */
.push-btn {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-dim);
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
  white-space: nowrap;
}
.push-btn:hover { background: var(--card-hover); color: var(--text); }
.push-btn.push-active { border-color: var(--accent); color: var(--accent); }
.push-btn:disabled { opacity: .5; cursor: default; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .plants-table .hide-mobile { display: none; }
  .bar-cell { display: none; }
}

.brand { display:inline-flex; align-items:center; gap:10px; vertical-align:middle;
  font-family:'Archivo',sans-serif; font-weight:800; font-size:22px; letter-spacing:-0.025em; color:var(--text); }
.brand img { height:34px; width:auto; }
.brand-accent { color:#ff6a1a; }

/* ── Botões ─────────────────────────────────────────────────────────────── */
.btn-primary { background: #ff6a1a; color: #fff; border: none; border-radius: 8px; padding: 9px 16px;
  font: inherit; font-weight: 600; cursor: pointer; }
.btn-primary:hover { background: #e0540c; }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-ghost { background: none; border: 1px solid var(--border); color: var(--text); border-radius: 6px;
  padding: 5px 10px; font: inherit; font-size: 12.5px; cursor: pointer; }
.btn-ghost:hover { background: var(--bg3); }
.btn-ghost.danger { color: var(--red); }

/* ── Menu do usuário ────────────────────────────────────────────────────── */
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; white-space: nowrap; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 200px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 6px;
  display: grid; box-shadow: var(--shadow); }
.user-menu-panel a, .user-menu-panel button { display: block; width: 100%; text-align: left; padding: 8px 10px;
  border-radius: 6px; color: var(--text); text-decoration: none; background: none; border: none; font: inherit; cursor: pointer; }
.user-menu-panel a:hover, .user-menu-panel button:hover { background: var(--bg3); }
.user-menu-email { font-size: 12px; color: var(--text-dim); padding: 6px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }

/* ── Login ──────────────────────────────────────────────────────────────── */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px 28px; display: grid; gap: 18px; justify-items: center; }
.login-title { font-size: 15px; font-weight: 500; color: var(--text-dim); margin-top: -8px; }
.login-form { display: grid; gap: 14px; width: 100%; }
.login-form label { display: grid; gap: 6px; font-size: 13px; color: var(--text-dim); }
.login-form input { background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font: inherit; font-size: 15px; }
.login-form input:focus { outline: 2px solid #ff6a1a; outline-offset: 1px; }
.login-error { color: var(--red); font-size: 13px; }
.login-hint { font-size: 12px; color: var(--text-dim); }

@media (max-width: 640px) {
  header { flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
  header h1 { flex: 1 1 100%; }
  .user-menu-panel { right: auto; left: 0; }
}
