/* ============================================================
   SMAR — Sistema de Monitoramento Ambiental
   Design system compartilhado
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Paleta — derivada do logo SMAR (gradiente azul-petróleo > verde) */
  --smar-deep:    #07263f;
  --smar-navy:    #0b3a5b;
  --smar-teal:    #0c7c92;
  --smar-green:   #34c38f;
  --smar-alert:   #e8554e;
  --smar-warn:    #f5a623;
  --smar-info:    #4ea1d3;

  --bg:        #eef3f6;
  --surface:   #ffffff;
  --surface-2: #f6f9fb;
  --ink:       #16323f;
  --muted:     #6f8a98;
  --border:    #dbe6ec;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  --shadow-sm: 0 2px 10px rgba(7, 38, 63, 0.06);
  --shadow-md: 0 8px 28px rgba(7, 38, 63, 0.10);

  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .display {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

/* ============================================================
   HEADER GLOBAL (substitui a sidebar)
   ============================================================ */

.smar-header {
  background: linear-gradient(120deg, var(--smar-deep) 0%, var(--smar-navy) 55%, var(--smar-teal) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 28px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 200;
}

.smar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: #fff;
  flex-shrink: 0;
}

.smar-brand img {
  height: 46px;
  width: auto;
  display: block;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.25));
}

.smar-brand-text .smar-brand-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #ffffff, #aef0d6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.smar-brand-text .smar-brand-tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #aecbdb;
  font-weight: 600;
  margin-top: 2px;
}

/* Navegação principal */
.smar-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: center;
}

.smar-nav-item {
  position: relative;
}

.smar-nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  color: #e7f1f6;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: transparent;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.smar-nav-link:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.smar-nav-item.active > .smar-nav-link {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.smar-nav-item.active > .smar-nav-link {
  box-shadow: inset 0 -3px 0 var(--smar-green);
}

.smar-nav-link .chev {
  font-size: 10px;
  opacity: 0.7;
  transition: transform 0.2s;
}

.smar-nav-item.open .chev {
  transform: rotate(180deg);
}

/* Dropdown de submenu */
.smar-submenu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 230px;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 250;
}

.smar-nav-item.open .smar-submenu {
  display: flex;
}

.smar-submenu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.smar-submenu a:hover,
.smar-submenu a.active {
  background: var(--surface-2);
  color: var(--smar-teal);
}

.smar-submenu a .icon {
  font-size: 15px;
  width: 18px;
  text-align: center;
}

/* Lado direito do header: usuário + sair */
.smar-header-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.smar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.smar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--smar-green);
  color: var(--smar-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  border: 2px solid rgba(255,255,255,0.5);
}

.smar-user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.smar-user-name { font-size: 13px; font-weight: 600; }
.smar-user-role { font-size: 11px; color: #aecbdb; }

.smar-logout {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  text-decoration: none;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  transition: background 0.2s;
}

.smar-logout:hover { background: var(--smar-alert); }

/* ============================================================
   CONTEÚDO
   ============================================================ */

.smar-content {
  padding: 22px 28px;
  max-width: 1500px;
  margin: 0 auto;
}

.smar-content.full {
  max-width: none;
  padding: 18px 22px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.page-head h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--smar-deep);
}

.page-head p {
  font-size: 13.5px;
  color: var(--muted);
  margin-top: 4px;
}

/* ============================================================
   BARRA DE FILTROS
   ============================================================ */

.filter-bar {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.filter-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-block.grow { flex: 1; min-width: 220px; }

.filter-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--smar-teal);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.locais-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 34px;
  align-items: center;
}

.local-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--smar-navy);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}

.local-chip:has(input:checked) {
  background: rgba(12, 124, 146, 0.10);
  border-color: var(--smar-teal);
}

.local-chip input { accent-color: var(--smar-teal); cursor: pointer; }

.input-field {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--surface);
}

.input-field:focus { outline: 2px solid var(--smar-teal); outline-offset: 1px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 13px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, transform 0.1s;
  text-decoration: none;
}

.btn-primary {
  background: var(--smar-teal);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--smar-deep); }
.btn-primary:disabled { background: #b7c9d2; cursor: not-allowed; }

.btn-ghost {
  background: var(--surface-2);
  color: var(--smar-navy);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: #e3edf2; }

.btn:active { transform: scale(0.98); }

/* Badge de auto-refresh */
.refresh-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(52, 195, 143, 0.12);
  color: #1b7a5a;
  font-weight: 700;
  font-size: 12.5px;
  padding: 9px 14px;
  border-radius: 999px;
  white-space: nowrap;
}

.refresh-badge.paused {
  background: rgba(245, 166, 35, 0.14);
  color: #946116;
}

.refresh-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--smar-green);
  animation: pulse 2s ease-in-out infinite;
}

.refresh-badge.paused .refresh-dot { background: var(--smar-warn); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* ============================================================
   CARDS / PAINÉIS
   ============================================================ */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  display: flex;
  flex-direction: column;
}

.panel-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--smar-deep);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chart-box {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.msg-status {
  font-size: 13.5px;
  display: block;
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.msg-status.erro { background: rgba(232, 85, 78, 0.10); color: #a8332d; }
.msg-status.ok { background: rgba(52, 195, 143, 0.10); color: #1b7a5a; }

.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  padding: 40px 10px;
}

/* ============================================================
   CARDS DE ALERTAS
   ============================================================ */

.alertas-grid, .ocorrencias-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.alerta-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  border-left: 5px solid var(--smar-alert);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.alerta-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.alerta-local {
  font-weight: 700;
  color: var(--smar-deep);
  font-size: 15px;
}

.alerta-local .id-local { color: var(--muted); font-weight: 500; font-size: 11px; }

.alerta-data {
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface-2);
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.alerta-proposito {
  font-size: 13px;
  font-weight: 600;
  color: var(--smar-teal);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.alerta-valor-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.alerta-valor {
  font-size: 30px;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--smar-alert);
}

.alerta-unidade { font-size: 13px; color: var(--muted); font-weight: 600; }

.alerta-faixa {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.faixa-bar {
  position: relative;
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.faixa-bar .faixa-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--smar-green), var(--smar-warn), var(--smar-alert));
}

/* ============================================================
   OCORRÊNCIAS
   ============================================================ */

.ocorrencia-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  border-left: 5px solid var(--smar-warn);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.ocorrencia-local { font-weight: 700; color: var(--smar-deep); font-size: 15px; }
.ocorrencia-local .id-local { color: var(--muted); font-weight: 500; font-size: 11px; }

.ocorrencia-count {
  font-size: 11px;
  font-weight: 700;
  color: #946116;
  background: rgba(245, 166, 35, 0.14);
  padding: 4px 9px;
  border-radius: 999px;
}

.ocorrencia-lista {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
  padding-right: 4px;
}

.evento-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  background: var(--surface-2);
  border-left: 3px solid var(--smar-warn);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}

.evento-item .evento-data {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  font-weight: 600;
}

.evento-item .evento-texto { color: var(--ink); line-height: 1.4; }

/* ============================================================
   GRELHA DE MONITORAMENTO
   ============================================================ */

.monitor-grid {
  display: grid;
  gap: 18px;
}

.monitor-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.monitor-grid.cols-1 { grid-template-columns: 1fr; }

.monitor-grid.geral {
  grid-template-columns: 1.3fr 1fr;
  grid-template-rows: minmax(360px, 1fr) minmax(300px, 1fr);
}

.monitor-grid .panel.tall { min-height: 380px; }

/* ============================================================
   TELA CHEIA
   ============================================================ */

.btn-fullscreen {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

body.fullscreen-active .smar-header,
body.fullscreen-active .filter-bar,
body.fullscreen-active .page-head {
  display: none !important;
}

body.fullscreen-active .smar-content {
  padding: 16px;
  max-width: none;
}

body.fullscreen-active .monitor-grid {
  height: calc(100vh - 32px);
}

/* ============================================================
   RESPONSIVO
   ============================================================ */

@media (max-width: 1100px) {
  .monitor-grid.cols-2,
  .monitor-grid.geral {
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }
  .smar-nav { display: none; }
}

@media (max-width: 700px) {
  .smar-header { flex-wrap: wrap; padding: 12px 16px; }
  .smar-content { padding: 16px; }
  .alertas-grid, .ocorrencias-grid { grid-template-columns: 1fr; }
}
