/* ============================================================
   style.css  —  Tema dark "centro de controle"
   ============================================================ */

:root {
  --bg-deep: #0a0e14;
  --bg: #0d1219;
  --bg-panel: rgba(18, 24, 32, 0.92);
  --bg-panel-solid: #121820;
  --bg-card: #161d27;
  --bg-hover: rgba(255,255,255,0.04);
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.18);
  --text: #e8ecf1;
  --text-muted: #8a95a3;
  --text-dim: #5a6573;
  --accent: #4FB3FF;
  --ok: #1FD198;
  --warn: #FFB347;
  --crit: #FF5E5E;
  --tab-h: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ LOADING ============ */
.loading-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-deep); z-index: 100;
  transition: opacity 0.5s ease;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-pulse {
  font-size: 14px; color: var(--accent);
  letter-spacing: 0.15em;
  animation: blink 1.4s infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ============ TOP BAR ============ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--tab-h);
  background: var(--bg-panel); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; z-index: 50;
}
.brand {
  display: flex; align-items: baseline; gap: 12px;
  margin-right: 32px;
}
.brand-mark {
  font-weight: 800; font-size: 16px;
  letter-spacing: 0.18em; color: var(--accent);
}
.brand-sub { font-size: 11px; color: var(--text-muted); }
@media (max-width: 800px) { .brand-sub { display: none; } }

.tabs { display: flex; gap: 2px; flex: 1; }
.tab-btn {
  background: transparent; border: none; color: var(--text-muted);
  padding: 0 16px; height: var(--tab-h);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border-bottom: 2px solid transparent;
  display: flex; align-items: center; gap: 6px;
  font-family: inherit;
}
.tab-btn:hover { color: var(--text); background: var(--bg-hover); }
.tab-btn.active {
  color: var(--accent); border-bottom-color: var(--accent);
  background: rgba(79,179,255,0.06);
}

.topbar-right {
  display: flex; gap: 18px; align-items: center;
  font-size: 12px;
}
.alarm-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 12px;
  background: rgba(255,94,94,0.15); color: var(--crit);
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.alarm-badge.zero { background: rgba(31,209,152,0.15); color: var(--ok); }
.alarm-badge::before { content: '⚠'; font-size: 11px; }
.alarm-badge.zero::before { content: '✓'; }
.clock { color: var(--text); font-variant-numeric: tabular-nums; }
.online {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ok); font-weight: 500;
}
.online::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 8px var(--ok);
  animation: blink 2s infinite;
}

/* ============ MAIN/PANELS ============ */
main {
  position: fixed; top: var(--tab-h); left: 0; right: 0; bottom: 0;
  background: var(--bg);
}
.tab-panel { display: none; height: 100%; }
.tab-panel.active { display: block; }

/* Dashboard scrollável; mapa não */
.tab-panel.dashboard { overflow-y: auto; padding: 24px; }

/* ============ MAPA TAB ============ */
#tab-mapa { position: relative; }
#map { position: absolute; inset: 0; background: var(--bg-deep); }

/* Painel detalhe esquerdo */
.detail-panel {
  position: absolute; top: 20px; left: 20px;
  width: 300px; background: var(--bg-panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 15; overflow: hidden;
}
.detail-header {
  padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 1px solid var(--border);
}
.detail-type {
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.1em;
  margin-bottom: 2px;
}
.detail-title { font-size: 15px; font-weight: 600; }
.detail-close {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 22px; cursor: pointer; line-height: 1;
  padding: 0; width: 24px; height: 24px;
}
.detail-close:hover { color: var(--text); }
.detail-body { padding: 10px 16px 14px; }
.detail-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row .lbl { color: var(--text-muted); }
.detail-row .val { font-weight: 500; font-variant-numeric: tabular-nums; }
.detail-meter {
  height: 4px; background: var(--border); border-radius: 2px;
  overflow: hidden; margin-top: 2px; margin-bottom: 6px;
}
.detail-meter-fill {
  height: 100%; background: var(--accent);
  transition: width 0.6s ease;
}
.detail-meter-fill.sev-crit { background: var(--crit); }
.detail-meter-fill.sev-warn { background: var(--warn); }
.detail-meter-fill.sev-ok   { background: var(--ok); }

/* Painel direito (camadas + alarmes) */
.side-panel {
  position: absolute; top: 20px; right: 20px;
  width: 260px; background: var(--bg-panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 15; max-height: calc(100vh - var(--tab-h) - 120px);
  overflow-y: auto;
}
.side-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.side-section:last-child { border-bottom: none; }
.side-title {
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.12em;
  font-weight: 600; margin: 0 0 10px;
}
.toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; font-size: 13px; cursor: pointer;
  user-select: none;
}
.toggle input { accent-color: var(--accent); cursor: pointer; }
.legend-bar {
  height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, #1FD198 0%, #FFB347 50%, #FF5E5E 100%);
}
.legend-labels {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-muted);
  font-variant-numeric: tabular-nums; margin-top: 4px;
}
.alarm-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 240px; overflow-y: auto;
}
.alarm-item {
  display: flex; gap: 8px; align-items: stretch;
  padding: 8px; background: rgba(255,255,255,0.03);
  border-radius: 6px; font-size: 12px;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
.alarm-sev { width: 4px; flex-shrink: 0; border-radius: 2px; }
.alarm-sev.sev-warn { background: var(--warn); }
.alarm-sev.sev-crit { background: var(--crit); box-shadow: 0 0 5px var(--crit); }
.alarm-content { flex: 1; min-width: 0; }
.alarm-msg { line-height: 1.3; margin-bottom: 2px; }
.alarm-time { font-size: 10px; color: var(--text-dim); }
.empty-state-small {
  font-size: 12px; color: var(--text-dim);
  text-align: center; padding: 12px;
}

/* Controles inferior (sliders) */
.view-controls {
  position: absolute; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel); backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  z-index: 15;
  display: flex; gap: 20px; padding: 10px 18px;
}
.ctrl-group { display: flex; align-items: center; gap: 8px; }
.ctrl-group label {
  font-size: 10px; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.ctrl-group input[type=range] { width: 110px; accent-color: var(--accent); }
.ctrl-group span {
  font-size: 11px; color: var(--text);
  font-variant-numeric: tabular-nums; min-width: 32px;
}
.hint {
  position: absolute; bottom: 80px; left: 20px;
  font-size: 11px; color: var(--text-dim);
  background: var(--bg-panel); backdrop-filter: blur(12px);
  padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border); z-index: 14;
}

/* ============ DASHBOARD COMUM ============ */
.page-header { margin-bottom: 24px; max-width: 1200px; margin-left: auto; margin-right: auto; }
.page-header h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
.page-header .page-sub { color: var(--text-muted); font-size: 13px; margin: 0; }

.tab-panel.dashboard > * { max-width: 1200px; margin-left: auto; margin-right: auto; }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 16px;
}
.panel-title {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.1em;
  font-weight: 600; margin: 0 0 14px;
}

.metric-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.metric-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric-grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 900px) { .metric-grid, .metric-grid-3, .metric-grid-5 { grid-template-columns: repeat(2, 1fr); } }

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.panel .metric-card { background: rgba(255,255,255,0.02); }
.metric-lbl {
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.metric-val {
  font-size: 22px; font-weight: 600; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.metric-val.bad { color: var(--crit); }
.metric-val.good { color: var(--ok); }
.metric-unit {
  font-size: 12px; color: var(--text-muted);
  margin-left: 3px; font-weight: 400;
}
.metric-delta {
  font-size: 11px; color: var(--text-muted); margin-top: 4px;
}
.metric-delta.good { color: var(--ok); }
.metric-delta.bad  { color: var(--crit); }

.two-col {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ============ DATA TABLE ============ */
.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.data-table th {
  text-align: left; font-weight: 600;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }

/* ============ SEVERITY PILL ============ */
.sev-pill {
  display: inline-block; padding: 2px 9px; border-radius: 10px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
}
.sev-pill.sev-ok   { background: rgba(31,209,152,0.15); color: var(--ok); }
.sev-pill.sev-warn { background: rgba(255,179,71,0.15); color: var(--warn); }
.sev-pill.sev-crit { background: rgba(255,94,94,0.18); color: var(--crit); }

/* ============ SECTOR GRID (overview) ============ */
.sector-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.sector-cell {
  padding: 10px; border-radius: 6px;
  font-size: 12px; line-height: 1.3;
}
.sector-cell.sev-ok   { background: rgba(31,209,152,0.10); border: 1px solid rgba(31,209,152,0.25); }
.sector-cell.sev-warn { background: rgba(255,179,71,0.10); border: 1px solid rgba(255,179,71,0.25); }
.sector-cell.sev-crit { background: rgba(255,94,94,0.10);  border: 1px solid rgba(255,94,94,0.25); }
.sec-name { font-weight: 600; margin-bottom: 2px; }
.sec-perdas { font-size: 11px; color: var(--text-muted); }

/* ============ TANK VISUAL (Água) ============ */
.tank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
}
.tank-wrap { text-align: center; }
.tank {
  position: relative; height: 100px;
  border: 1px solid var(--border-strong); border-radius: 4px;
  background: rgba(255,255,255,0.03); overflow: hidden;
}
.tank-fill {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--accent);
  transition: height 0.6s ease;
}
.tank-fill.sev-ok   { background: var(--accent); }
.tank-fill.sev-warn { background: var(--warn); }
.tank-fill.sev-crit { background: var(--crit); }
.tank-pct {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.tank-name { font-size: 13px; font-weight: 600; margin-top: 8px; }
.tank-sub { font-size: 11px; color: var(--text-muted); }

/* ============ CHART CONTAINER ============ */
.chart-box {
  position: relative; width: 100%;
}

/* ============ EMPTY STATE ============ */
.empty-state {
  padding: 32px; text-align: center; color: var(--text-muted);
  font-size: 13px;
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* maptalks override */
.maptalks-msgBox { font-family: inherit !important; }
