/* ============================================================================
   NodeSniff Dashboard – Production CSS (final, verified)
   Tabs, legend, last-report label, boot overlay, per-tab loading overlay.
   ========================================================================== */

/* ----------------------------- Design tokens --------------------------------*/
:root {
  --ns-border: #dee2e6;
  --ns-bg: #fff;
  --ns-bg-muted: #f8f9fa;
  --ns-bg-hover: #e9ecef;
  --ns-text: #212529;
  --ns-text-muted: #495057;
  --ns-legend: #6c757d;
  --ns-ok: #198754;
  --ns-warn: #ffc107;
  --ns-crit: #dc3545;

  /* Reserved height for module content/spinner; tune as needed */
  --module-min-h: 200px;
}

/* ------------------------------ Tabs (neutral) ------------------------------*/
.nav-tabs {
  border-bottom: 1px solid var(--ns-border);
}

.nav-tabs .nav-link {
  color: var(--ns-text-muted);
  background-color: var(--ns-bg-muted);
  border: 1px solid var(--ns-border);
  font-weight: 500;
  transition: all 0.2s ease;
  position: relative; /* required for the status dot */
  border-radius: 0 !important;
  margin-right: -1px; /* seamless borders */
  user-select: none;
}

.nav-tabs .nav-link:hover {
  background-color: var(--ns-bg-hover);
  color: var(--ns-text);
}

.nav-tabs .nav-link.active {
  color: var(--ns-text);
  background-color: var(--ns-bg);
  border-color: var(--ns-border) var(--ns-border) transparent;
  font-weight: 600;
}

/* Container for tab panes */
.tab-content {
  border: none;
  background-color: var(--ns-bg);
  border-radius: 0 !important;
  margin-right: -1px;
  font-size: 0.95rem;
  min-height: 0;
}

/* ----------------------------- Status dot in tab ----------------------------*/
.status-dot {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  pointer-events: none;
}
.status-ok {
  background-color: var(--ns-ok);
}
.status-warn {
  background-color: var(--ns-warn);
}
.status-crit {
  background-color: var(--ns-crit);
}

/* --------------------------- Legend on the right side -----------------------*/
.metrics-tabs-wrapper {
  position: relative;
}

.status-legend {
  position: absolute;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  line-height: 1;
  background: var(--ns-bg);
  padding-left: 6px;
  z-index: 5;
}

.status-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  margin-top: 23px; /* aligns with tab border line */
}

.status-legend .status-dot {
  position: static !important;
  display: inline-block !important;
  width: 8px;
  height: 8px;
}

/* ---------------------------- Tab pane & Last report ------------------------*/
.extra-tab-pane {
  position: relative;
  padding-top: 1.5rem;
  overflow: hidden;
}

/* "Last report" label pinned to the top-right inside the pane */
.extra-tab-pane [id$='-lastseen'] {
  position: absolute;
  top: 0px;
  right: 0;
  font-size: 0.75rem;
  line-height: 1;
  font-weight: 400;
  color: var(--ns-legend);
  user-select: none;
  margin: 0;
}

/* Alerts in pane (normal state) */
.extra-tab-pane .alert {
  margin-top: -8px;
  margin-bottom: 0.5rem;
  text-align: center;
}

/* When loading, alerts are suppressed */
.extra-tab-pane.loading .ns-pane-feedback .alert {
  display: none !important;
}

/* ------------------------------- Pane feedback ------------------------------*/
.extra-tab-pane .ns-pane-feedback {
  position: relative;
  display: block;
  min-height: 0;
  padding: 0;
  pointer-events: none;
}
.extra-tab-pane .ns-pane-feedback:empty {
  display: none;
}

/* ------------------------------- Loading overlay ----------------------------*/
.extra-tab-pane.loading .ns-pane-feedback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ns-bg);
  z-index: 1070;
  min-height: var(--module-min-h);
}

/* Spinner node (inserted by JS) */
.ns-spinner-wrapper {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
  text-align: center;
}

/* ---------------------------- Content visibility toggle ---------------------*/
/* ✅ FIXED: prevent empty module-mount from leaving residual height */
.ns-module-mount {
  min-height: 0 !important;
}
.extra-tab-pane .ns-module-mount:empty {
  min-height: 0 !important;
}
.extra-tab-pane.loading .ns-module-mount {
  min-height: var(--module-min-h) !important;
  visibility: hidden;
}

/* ✅ FIXED: also prevent feedback height retention when error is visible */
.extra-tab-pane:not(.loading) .ns-pane-feedback {
  min-height: 0 !important;
}

/* --------------------------- Modal interaction policy -----------------------*/
.modal-open .extra-tab-pane.loading .ns-pane-feedback {
  display: none !important;
}

/* ------------------------------- Boot overlay -------------------------------*/
.boot-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ns-bg);
}

.booting .dashboard-shell {
  visibility: hidden;
}
.booting .tab-pane {
  transition: none !important;
}

/* --------------------------- Optional chart wrappers ------------------------*/
.ns-chart-wrap,
.ns-disks-chart-wrap,
.ns-net-chart-wrap,
.ns-cpu-chart-wrap,
.ns-ram-chart-wrap {
  min-height: var(--module-min-h);
}

/* ------------------------------- A11y polish --------------------------------*/
.nav-tabs .nav-link:focus-visible {
  outline: 2px solid rgba(13, 110, 253, 0.3);
  outline-offset: 2px;
}

.nav-tabs,
.nav-tabs .nav-item,
.nav-tabs .nav-link,
.metrics-tabs-wrapper,
.tab-content {
  user-select: none;
}

/* ============================================================================
   Full-height tab panes (clean solution)
   Always stretch each tab-pane to fill the visible dashboard area.
   ========================================================================== */

/* Ensure the parent card grows naturally */
.card-body {
  display: flex;
  flex-direction: column;
}

/* --------------------------------- Responsive --------------------------------*/
@media (max-width: 576px) {
  .status-legend {
    position: static;
    margin-top: 6px;
    padding-left: 0;
  }
  .extra-tab-pane [id$='-lastseen'] {
    position: static;
    display: block;
    margin-bottom: 4px;
  }
}
