/* ===================================================================
   VARIAVEIS / TEMA
   =================================================================== */
:root {
  --bg: #0e1117;
  --card: #1d212b;
  --card-2: #242938;
  --text: #e8ebf1;
  --text-dim: #9aa2b1;
  --ctrl-bg: #2b3144;
  --border: #333a4d;

  --red: #ef4444;
  --yellow: #f5c518;
  --green: #10b981;
  --grey: #6b7280;
  --blue: #38bdf8;
  --violet: #8b5cf6;
  --white: #f4f6fb;

  --radius: 10px;
  --radius-sm: 6px;
}

body.light-theme {
  --bg: #eef0f4;
  --card: #ffffff;
  --card-2: #f4f5f8;
  --text: #1c2230;
  --text-dim: #5c6270;
  --ctrl-bg: #e3e6ec;
  --border: #d7dae1;
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  transition: background .3s, color .3s;
}

/* ===================================================================
   HEADER
   =================================================================== */
.header-bar {
  position: sticky;
  top: 0;
  z-index: 500;
  background: var(--bg);
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.btn {
  background: var(--ctrl-bg);
  color: var(--text);
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  box-shadow: 1px 1px 4px rgba(0,0,0,.25);
  transition: background .15s, transform .1s;
}
.btn:hover { transform: translateY(-3px); }
.btn.active { background: var(--blue); color: #04202b; }

.hamburger-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--ctrl-bg);
  border: none;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.sync-info {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.3;
  text-align: right;
}

.fs-btn {
  background: var(--blue);
  color: #04202b;
  font-size: 16px;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: none; font-weight: bold;
}

/* ===================================================================
   MENU LATERAL (HAMBURGUER)
   =================================================================== */
#side-menu {
  position: fixed;
  top: 0; right: 0;
  height: 100%;
  width: 320px;
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0,0,0,.4);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 900;
  overflow-y: auto;
  padding: 16px;
}
#side-menu.open { transform: translateX(0); }

.side-menu-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.side-menu-header h2 { font-size: 15px; margin: 0; }
.side-close { background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; }

.side-section {
  border-top: 1px solid var(--border);
  padding: 14px 0;
}
.side-section:first-of-type { border-top: none; }
.side-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-dim); margin: 0 0 10px;
}
.side-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; font-size: 12px;
}
.side-row select, .side-row .btn { font-size: 12px; }
.side-row select {
  background: var(--ctrl-bg);
  color: var(--text);
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  box-shadow: 1px 1px 4px rgba(0,0,0,.25);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'><path d='M0 0l5 6 5-6z' fill='%239aa2b1'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 9px 6px;
  padding-right: 24px;
}
.side-row select option { background: var(--ctrl-bg); color: var(--text); }

/* Legenda */
.legend-list { list-style: none; padding: 0; margin: 0; font-size: 11px; }
.legend-list li { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 4px var(--text); }

/* Gateways */
.gw-list { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.gw-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.gw-item:last-child { border-bottom: none; }
.gw-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.gw-dot.ok { background: var(--green); box-shadow: 0 0 6px var(--green); }
.gw-dot.bad { background: var(--red); box-shadow: 0 0 6px var(--red); }
.gw-name { flex: 1; }
.gw-status-txt { font-size: 10px; color: var(--text-dim); }

.side-empty { font-size: 11px; color: var(--text-dim); font-style: italic; }

/* ===================================================================
   GRID / CARDS
   =================================================================== */
#container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 10px;
  padding: 14px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 6px 15px 6px 10px;
  border-top: 6px solid var(--grey);
  box-shadow: 3px 3px 10px rgba(0,0,0,.3);
  position: relative;
  transition: border-color .3s;
}
.card.prio-1 { border-top-color: var(--violet); }
.card.prio-2 { border-top-color: var(--red); background: rgba(239,68,68,.05); }
.card.prio-3 { border-top-color: var(--yellow); }
.card.prio-4, .card.prio-5 { border-top-color: var(--green); }

.card.has-stale-blue::after {
  content: "";
  position: absolute; top: 0; right: 0;
  border-style: solid; border-width: 0 26px 26px 0;
  border-color: transparent var(--blue) transparent transparent;
}

.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-header-left { min-width: 0; }
.m-area { font-size: 10px; text-transform: uppercase; color: var(--blue); font-weight: 700; letter-spacing: .04em; }
.m-name { font-size: 17px; text-transform: uppercase; margin: 2px 0 2px; overflow: hidden; text-overflow: ellipsis; }
.m-desc { font-size: 10px; color: var(--text-dim); font-weight: 500; margin: -1px 0 4px; font-style: italic; }

/* ===================================================================
   GRUPOS DE SENSOR (estilo usuario/senha)
   =================================================================== */
.sensors-wrap { display: flex; flex-wrap: wrap; gap: 4px; }

.sensor-group {
  position: relative;
  background: var(--card);
  border: 1.5px solid var(--grey);
  border-radius: var(--radius-sm);
  padding: 9px 8px 6px;
  margin-top: 8px;
  min-width: 128px;
  cursor: default;
}
.sensor-group.bat-good { border-color: var(--green); }
.sensor-group.bat-warn { border-color: var(--yellow); }
.sensor-group.bat-crit { border-color: var(--red); }
.sensor-group.bat-none { border-color: var(--grey); }

/* Rotulo do sensor - flutua sobre a borda superior esquerda, igual um
   floating label de input (fundo igual ao card para "cortar" a linha) */
.sensor-label-float {
  position: absolute;
  top: -8px; left: 3px;
  background: var(--card);
  padding: 1px 1px;
  font-size: 9px;
  font-weight: 300;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
  cursor: help;
}

/* Bateria - flutua sobre a borda superior direita, mesmo estilo */
.sensor-battery-float, .sensor-cabled-float {
  position: absolute;
  top: -8px; right: 2px;
  background: var(--card);
  padding: 1px 1px;
  display: flex; align-items: center; gap: 3px;
  font-size: 9px;
  color: var(--text-dim);
  cursor: help;
}
.sensor-battery-float svg { width: 14px; height: 8px; }
.sensor-cabled-float { font-size: 10px; opacity: 1; }

.sensor-pontos { display: flex; gap: 8px; flex-wrap: wrap; }

.pt-btn {
  border: none; color: #fff; cursor: crosshair;
  font-weight: 700; box-shadow: 1px 1px 3px rgba(0,0,0,.5);
  text-shadow: 1px 1px 2px #000;
  transition: transform .12s;
}
.pt-btn:hover { transform: scale(1.08); }

.pt-btn.mode-0 {
  width: 20px; height: 20px; border-radius: 50%; font-size: 0; padding: 0; min-width: 20px;
  display: flex; align-items: center; justify-content: center;
}

/* Triangulo de tendencia dentro da bolinha - so aparece se o desvio
   for positivo (acima da media). Mesmas 3 cores do modo detalhado. */
.pt-trend-dot {
  display: block;
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 6px solid #fff;
  filter: drop-shadow(1px 1px 2px rgba(0,0,0,.90));
}
.pt-trend-dot.trend-warn { border-bottom-color: var(--yellow); }
.pt-trend-dot.trend-crit { border-bottom-color: var(--red); }

.pt-btn.mode-1 {
  padding: 4px 7px; border-radius: 5px; font-size: 10px; text-align: left;
  display: flex; flex-direction: column; min-width: 58px;
}
.pt-btn span.pt-label { font-size: 8px; opacity: .85; white-space: nowrap; }
.pt-val { font-size: 10px; white-space: nowrap; display: flex; align-items: center; gap: 3px; }
.pt-sep { opacity: .5; font-size: 9px; }
.pt-trend { font-size: 9px; opacity: 1; font-weight: 500; text-shadow: 0px 0px 0px #000; }
.pt-trend.trend-crit { color: #2a0000; background: var(--red); border-radius: 3px; padding: 0 3px; opacity: 1; }
.pt-trend.trend-warn { color: #2a2200; background: var(--yellow); border-radius: 3px; padding: 0 3px; opacity: 1; }
.pt-trend.trend-normal { color: inherit; opacity: .7; }

/* Lista de excecoes (modo 2) */
.exception-list { font-size: 11px; list-style: none; padding: 0; margin: 8px 0 0; }
.exception-item { margin-bottom: 6px; padding: 8px; border-radius: 4px; background: rgba(0,0,0,.2); display: flex; flex-direction: column; gap: 2px; }
.exc-header { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.exc-reason { font-size: 10px; opacity: .9; padding-left: 18px; }

.footer-ts { font-size: 10px; color: var(--text-dim); margin-top: 4px; font-weight: 600; }

/* ===================================================================
   FLASH DE ATUALIZACAO (transicao suave quando o valor muda)
   =================================================================== */
@keyframes flashRing {
  0%   { box-shadow: 0 0 0 0 rgba(56,189,248,.95); }
  100% { box-shadow: 0 0 0 9px rgba(56,189,248,0); }
}
@keyframes flashText {
  0%   { color: var(--blue); }
  100% { color: inherit; }
}
.value-flash { animation: flashRing 1.3s ease-out infinite; }
.value-flash .pt-val, .value-flash.pt-val { animation: flashText 1.3s ease-out infinite; }

/* ===================================================================
   BOTAO DE ANOTACOES (+) E PAINEL
   =================================================================== */
.nota-toggle {
  flex-shrink: 0;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--ctrl-bg); color: var(--text); border: none;
  font-size: 14px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.nota-toggle.has-notes { background: var(--yellow); color: #241d00; }

.nota-panel {
  display: none;
  margin-top: 10px;
  background: var(--card-2);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 11px;
}
.nota-panel.open { display: block; }

.nota-item {
  display: flex; align-items: flex-start; gap: 6px;
  padding: 5px 0; border-bottom: 1px solid var(--border);
}
.nota-item:last-of-type { border-bottom: none; }
.nota-icon { font-size: 13px; }
.nota-txt { flex: 1; }
.nota-date { color: var(--text-dim); font-size: 9px; }
.nota-remove { background: none; border: none; color: var(--red); cursor: pointer; font-weight: 700; font-size: 13px; }

.nota-form { display: flex; gap: 5px; margin-top: 8px; }
.nota-form select { font-size: 11px; background: var(--ctrl-bg); color: var(--text); border: none; border-radius: 4px; padding: 4px; }
.nota-form input { flex: 1; font-size: 11px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 4px 6px; }
.nota-form button { font-size: 11px; background: var(--green); color: #012; border: none; border-radius: 4px; padding: 4px 8px; cursor: pointer; font-weight: 700; }

/* ===================================================================
   TOOLTIP
   =================================================================== */
#tooltip {
  position: fixed; display: none; background: #000; color: #fff; padding: 10px;
  border-radius: 6px; white-space: pre; font-size: 11px; z-index: 9999;
  border: 1px solid #555; pointer-events: none; box-shadow: 5px 5px 15px rgba(0,0,0,.5);
  max-width: 320px; white-space: pre-wrap;
}

/* ===================================================================
   MODAL (LOG / STATUS IMPLEMENTACAO)
   =================================================================== */
#modal-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 2000; align-items: center; justify-content: center;
}
#modal-overlay.open { display: flex; }

#modal-box {
  background: var(--card);
  border-radius: var(--radius);
  width: min(760px, 92vw);
  max-height: 82vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; }

.log-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.log-table th, .log-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.log-table th { color: var(--text-dim); font-size: 10px; text-transform: uppercase; }
.log-tag { padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.log-tag.alarm { background: var(--red); color: #fff; }
.log-tag.warning { background: var(--yellow); color: #241d00; }

.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.status-tile { background: var(--card-2); border-radius: var(--radius-sm); padding: 12px; text-align: center; }
.status-tile .num { font-size: 26px; font-weight: 800; color: var(--blue); }
.status-tile .lbl { font-size: 10px; color: var(--text-dim); text-transform: uppercase; margin-top: 4px; }

.status-subtable { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 10px; }
.status-subtable th, .status-subtable td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); }

/* ===================================================================
   RESPONSIVO
   =================================================================== */
@media (max-width: 640px) {
  #container { grid-template-columns: 1fr; padding: 8px; }
  #side-menu { width: 88vw; }
  .header-right { display: none; }
}
