/* ==========================================================================
   SlimNOC2 — Dashboard com widgets arrastáveis (GridStack)
   ========================================================================== */

.dash-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.dash-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.dash-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}
.dash-tab:hover { color: var(--text); background: var(--bg-surface-2); }
.dash-tab.is-active {
  background: var(--primary-soft);
  color: #7fb2ff;
  font-weight: 600;
}
.dash-tab__close {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  opacity: .55;
}
.dash-tab__close:hover { opacity: 1; background: var(--danger-soft); color: var(--danger); }

.edit-flag {
  display: none;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border-radius: 20px;
  background: var(--warning-soft);
  border: 1px solid rgba(245,166,35,.3);
  color: #fbbf24;
  font-size: 14px;
  font-weight: 600;
}
.dash.is-editing .edit-flag { display: flex; }

/* --------------------------------------------------------------------------
   Grid
   -------------------------------------------------------------------------- */
.grid-stack {
  background: transparent;
  margin: 0 -8px;
}

.dash.is-editing .grid-stack {
  background-image:
    linear-gradient(to right, var(--border-soft) 1px, transparent 1px),
    linear-gradient(to bottom, var(--border-soft) 1px, transparent 1px);
  background-size: calc(100% / 12) 70px;
  background-position: 8px 0;
  border-radius: var(--radius);
}

.grid-stack-item-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.grid-stack-item-content:hover { border-color: var(--border-strong); }

.dash.is-editing .grid-stack-item-content {
  border-style: dashed;
  border-color: var(--border-strong);
}

.grid-stack > .grid-stack-item > .ui-resizable-handle { z-index: 12; }

/* Placeholder ao arrastar */
.grid-stack > .grid-stack-placeholder > .placeholder-content {
  background: var(--primary-soft);
  border: 1px dashed var(--primary);
  border-radius: var(--radius-lg);
}

.grid-stack-item.ui-draggable-dragging .grid-stack-item-content {
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
  opacity: .95;
}
.grid-stack-item.ui-resizable-resizing .grid-stack-item-content {
  border-color: var(--primary);
}

/* Alça de redimensionar (canto inferior direito) */
.dash.is-editing .grid-stack > .grid-stack-item > .ui-resizable-handle {
  display: block !important;
}
.dash.is-editing .grid-stack > .grid-stack-item > .ui-resizable-se {
  width: 16px;
  height: 16px;
  right: 4px;
  bottom: 4px;
  background-image: none;
  border-right: 2px solid var(--primary);
  border-bottom: 2px solid var(--primary);
  border-bottom-right-radius: 4px;
  opacity: .7;
  transform: none;
}
.dash:not(.is-editing) .grid-stack > .grid-stack-item > .ui-resizable-handle { display: none !important; }

/* --------------------------------------------------------------------------
   Widget
   -------------------------------------------------------------------------- */
.widget { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.widget__head {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: none;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border-soft);
}
.dash.is-editing .widget__head { cursor: move; }

.widget__icon { color: var(--text-dim); flex: none; }
.widget__title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.widget__tools {
  margin-left: auto;
  display: flex;
  gap: 3px;
  opacity: 0;
  transition: var(--transition);
}
.grid-stack-item-content:hover .widget__tools,
.dash.is-editing .widget__tools { opacity: 1; }

.widget__tool {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
}
.widget__tool:hover { background: var(--bg-surface-3); color: var(--text); }
.widget__tool--danger:hover { background: var(--danger-soft); color: var(--danger); }
.widget__tool.edit-only { display: none; }
.dash.is-editing .widget__tool.edit-only { display: grid; }

.widget__body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 13px;
}
.widget__body--flush { padding: 0; }
.widget__body--center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Widget: métrica grande */
.metric { display: flex; flex-direction: column; height: 100%; justify-content: center; }
.metric__top { display: flex; align-items: center; gap: 12px; }
.metric__value { font-size: 37.5px; font-weight: 700; line-height: 1; letter-spacing: -1px; }
.metric__unit { font-size: 17.5px; font-weight: 600; color: var(--text-muted); }
.metric__delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}
.metric__delta--up { background: var(--success-soft); color: #4ade80; }
.metric__delta--down { background: var(--danger-soft); color: #f87171; }
.metric__label { font-size: 14px; color: var(--text-muted); margin-top: 8px; }
.metric__spark { margin-top: auto; }

/* Tráfego agregado: download e upload separados */
.metric__traffic { display: flex; gap: 16px; }
.metric__traffic-col { flex: 1; min-width: 0; }
.metric__traffic-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-dim);
}
.metric__traffic-label svg { opacity: .8; }
.metric__traffic-value {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -.5px;
  margin-top: 5px;
  white-space: nowrap;
}
.metric__traffic-value--down { color: #4ade80; }
.metric__traffic-value--up { color: #2f7cf6; }
.metric__traffic-value .metric__unit { font-size: 13px; }

/* Widgets "Top Roteadores" e "Top Links" */
.cell-unit { font-size: 11.5px; color: var(--text-dim); font-weight: 400; }

/*
 * SLIMNOC_V2_ONU_HISTORY_WIDGETS_V1
 * Widgets clicáveis (Sinal Crítico / Rompimento / Desligada) + tooltip
 * flutuante do sparkline histórico (mesma ideia da v1, tooltip único
 * reaproveitado, position:fixed seguindo o mouse).
 */
.metric--clickable { cursor: pointer; border-radius: 10px; transition: var(--transition); margin: -8px; padding: 8px; }
.metric--clickable:hover { background: var(--bg-surface-2); }
.spark-empty { font-size: 12.5px; color: var(--text-dim); padding-top: 4px; }

.spark-tooltip {
  position: fixed;
  z-index: 400;
  pointer-events: none;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s, transform .12s;
  white-space: nowrap;
}
.spark-tooltip.is-visible { opacity: 1; transform: none; }
.spark-tooltip__title { font-weight: 600; color: var(--text-soft); }
.spark-tooltip__date { color: var(--text-dim); }
.spark-tooltip__value { font-weight: 700; font-size: 14.5px; margin-top: 1px; }

/* Widget: gráficos SVG */
.chart { width: 100%; height: 100%; display: block; }
.chart-wrap { position: relative; flex: 1; min-height: 0; }

/* Widget: relógio */
.clock__time {
  font-family: var(--font-mono);
  font-size: 44px;
  font-weight: 700;
  letter-spacing: 1px;
  line-height: 1;
}
.clock__date { font-size: 14.5px; color: var(--text-muted); margin-top: 8px; text-transform: capitalize; }

/* Widget: lista de alertas */
.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 13px;
  border-bottom: 1px solid var(--border-soft);
}
.alert-item:last-child { border-bottom: 0; }
.alert-item__sev {
  width: 3px;
  align-self: stretch;
  border-radius: 3px;
  flex: none;
}
.alert-item__sev--crit { background: var(--danger); }
.alert-item__sev--warn { background: var(--warning); }
.alert-item__sev--info { background: var(--primary); }
.alert-item__title { font-size: 14.5px; font-weight: 500; }
.alert-item__meta { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.alert-item__time { margin-left: auto; font-size: 12.5px; color: var(--text-dim); white-space: nowrap; }

/* Widget: tabela compacta */
.mini-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.mini-table th {
  text-align: left;
  padding: 8px 13px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-inset);
  position: sticky;
  top: 0;
}
.mini-table td {
  padding: 8px 13px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-soft);
  white-space: nowrap;
}
.mini-table tr:last-child td { border-bottom: 0; }

/* Widget: mapa de calor / status POPs */
.pop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 9px;
}
.pop {
  padding: 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-surface-2);
}
.pop__name { font-size: 13px; font-weight: 600; }
.pop__val { font-size: 18.5px; font-weight: 700; margin-top: 3px; }
.pop__bar { margin-top: 7px; }

/* --------------------------------------------------------------------------
   Modal: adicionar widget
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 9, 18, 0.66);
  backdrop-filter: blur(2px);
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop.is-open { display: flex; }

.modal {
  width: min(680px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modal-in 180ms ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(.99); }
  to { opacity: 1; transform: none; }
}
.modal__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.modal__title { font-size: 17.5px; font-weight: 600; }
.modal__body { padding: 18px; overflow-y: auto; }
.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 14px 18px;
  border-top: 1px solid var(--border-soft);
}

.widget-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 11px;
}
.widget-card {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface-2);
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
}
.widget-card:hover { border-color: var(--primary); background: var(--primary-soft); }
.widget-card__icon {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: #62a0ff;
}
.widget-card__name { font-size: 14.5px; font-weight: 600; }
.widget-card__desc { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }

/* Estado vazio do dashboard */
.dash-empty {
  padding: 60px 20px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
}
.dash-empty h3 { font-size: 17.5px; color: var(--text-soft); margin-bottom: 6px; }

/* --------------------------------------------------------------------------
   Responsivo — celular
   SLIMNOC_V2_MOBILE_LAYOUT_V1

   O GridStack posiciona cada widget com x/y/w/h absolutos pensados pra
   uma grade de 12 colunas — numa tela de celular isso resulta em cards
   minúsculos e picotados. Em vez de reconfigurar o GridStack (mexeria
   no arrastar/redimensionar), força cada item a virar um bloco normal,
   empilhado em 1 coluna e com altura fixa (os widgets internamente já
   são flex/scroll, então continuam funcionando dentro dessa altura).
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .grid-stack { margin: 0; }
  .grid-stack-item {
    position: static !important;
    width: 100% !important;
    transform: none !important;
    margin-bottom: 10px;
  }
  .grid-stack-item-content {
    position: static !important;
    height: 300px !important;
  }
}

/* --------------------------------------------------------------------------
   Filtro de interfaces — Tráfego do Backbone
   SLIMNOC_V2_BACKBONE_FILTER_V1
   -------------------------------------------------------------------------- */
.bb-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px;
  border: 1px solid color-mix(in srgb, var(--bb-color, #2f7cf6) 55%, transparent);
  border-radius: 20px;
  background: color-mix(in srgb, var(--bb-color, #2f7cf6) 16%, var(--bg-surface));
  color: var(--bb-color, #2f7cf6);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  line-height: 1;
  white-space: nowrap;
}
.bb-chip:hover {
  filter: brightness(1.15);
  border-color: var(--bb-color, #2f7cf6);
}
.bb-chip.is-hidden {
  opacity: .38;
  text-decoration: line-through;
  border-color: var(--border-soft);
  background: var(--bg-surface-2);
}
.bb-chip--action {
  border-color: var(--border-strong);
  background: var(--bg-surface-2);
  color: var(--text-muted);
}
.bb-chip--action:hover {
  color: var(--text);
  background: var(--bg-surface-3);
}
.bb-chip-hint {
  align-self: center;
  font-size: 12px;
  color: var(--text-dim);
  margin-left: 2px;
}

/* --------------------------------------------------------------------------
   Widget Monitoramento Energia Ping
   SLIMNOC_V2_ENERGIA_PING_WIDGET_V1
   -------------------------------------------------------------------------- */
.ep-toggle {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  cursor: pointer;
  background: var(--bg-surface-2);
  vertical-align: middle;
  transition: var(--transition);
}
.ep-toggle.is-on {
  background: #22c55e;
  border-color: #22c55e;
}
.ep-toggle:hover { border-color: #22c55e; }
