/* Trang /server/grafana — giao diện lấy đúng màu và tiết tấu của Grafana dark theme
   (bảng màu trích từ file CSS trong dashboard mẫu), nội dung thì đọc từ API của site. */

.gd {
  --gd-bg: #111217;
  --gd-panel: #181b1f;
  --gd-panel-hover: #1f2227;
  --gd-border: #22252b;
  --gd-border-strong: #363940;
  --gd-grid: rgba(204, 204, 220, 0.13);
  --gd-text: #ccccdc;
  --gd-strong: #f4f5f8;
  --gd-muted: #8e8e96;
  --gd-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;

  background: var(--gd-bg);
  border-top: 1px solid var(--gd-border);
  border-bottom: 1px solid var(--gd-border);
  color: var(--gd-text);
  font-size: 14px;
  padding-block: 1rem 1.5rem;
}

.gd-wrap {
  width: 100%;
  max-width: 1500px;
  margin-inline: auto;
  padding-inline: 0.9rem;
}

/* ── thanh trên: tên bảng, ô chọn khoảng thời gian, nhịp làm mới ─ */
.gd-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  padding: 0.35rem 0.2rem 0.9rem;
}

.gd-title {
  font-size: 1.22rem;
  font-weight: 600;
  color: var(--gd-strong);
  letter-spacing: 0.01em;
  margin: 0;
  margin-inline-end: auto;
}

.gd-sub {
  display: block;
  font-size: 0.76rem;
  font-weight: 400;
  color: var(--gd-muted);
  letter-spacing: 0.02em;
  margin-top: 0.15rem;
}

.gd-ctl {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--gd-panel);
  border: 1px solid var(--gd-border);
  border-radius: 2px;
  padding: 2px;
}

.gd-ctl button {
  appearance: none;
  background: none;
  border: 0;
  color: var(--gd-text);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.62rem;
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
}

.gd-ctl button:hover {
  background: var(--gd-border);
  color: var(--gd-strong);
}

.gd-ctl button[aria-pressed="true"] {
  background: #3d4249;
  color: #fff;
}

.gd-ctl select {
  appearance: none;
  background: none;
  border: 0;
  color: var(--gd-text);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
}

.gd-live {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--gd-muted);
  font-family: var(--gd-mono);
}

.gd-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #73bf69;
  box-shadow: 0 0 0 3px rgba(115, 191, 105, 0.18);
}

.gd-dot.warn {
  background: #ff9830;
  box-shadow: 0 0 0 3px rgba(255, 152, 48, 0.18);
}

.gd-dot.crit {
  background: #f2495c;
  box-shadow: 0 0 0 3px rgba(242, 73, 92, 0.18);
}

/* ── lưới panel 24 cột như Grafana ─ */
.gd-grid {
  display: grid;
  grid-template-columns: repeat(24, minmax(0, 1fr));
  gap: 8px;
  align-items: start;
}

.gd-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--gd-border);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.02);
  padding: 0.34rem 0.6rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gd-strong);
  cursor: pointer;
  user-select: none;
}

.gd-row:hover {
  background: var(--gd-panel-hover);
}

.gd-row::after {
  content: "";
  flex: 1;
  border-top: 1px dashed var(--gd-border-strong);
}

.gd-row .gd-fold {
  transition: transform 0.15s ease;
  color: var(--gd-muted);
  font-size: 0.72rem;
}

.gd-row[data-collapsed="yes"] .gd-fold {
  transform: rotate(-90deg);
}

.gd-panel {
  grid-column: span var(--w, 8);
  min-width: 0;
  height: calc(var(--h, 8) * 30px);
  background: var(--gd-panel);
  border: 1px solid transparent;
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.gd-panel:hover {
  border-color: var(--gd-border);
  background: #1a1d21;
}

.gd-panel:hover .gd-ptitle {
  color: var(--gd-strong);
}

.gd-panel:hover .gd-expr {
  opacity: 1;
}

.gd-panel.is-hidden {
  display: none;
}

.gd-ptitle {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.34rem 0.6rem 0.2rem;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.005em;
  color: #c7cad2;
  border-bottom: 1px solid transparent;
}

.gd-ptitle .gd-expr {
  margin-inline-start: auto;
  font-family: var(--gd-mono);
  font-size: 0.66rem;
  color: #5b6169;
  max-width: 58%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.gd-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.3rem 0.55rem 0.45rem;
  display: flex;
  flex-direction: column;
}

/* ── stat tile ─ */
.gd-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  text-align: center;
}

.gd-stat b {
  font-size: clamp(1.6rem, 3.1vw, 2.4rem);
  font-weight: 600;
  line-height: 1.05;
  color: var(--gd-strong);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.gd-stat i {
  font-style: normal;
  font-size: 0.74rem;
  color: var(--gd-muted);
}

.gd-stat.tiny b {
  font-size: 1.15rem;
}

/* ── gauge vòng ─ */
.gd-gauge {
  flex: 1;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
}

.gd-gauge svg {
  width: 100%;
  height: 100%;
  max-height: 150px;
}

/* ── biểu đồ đường ─ */
.gd-plot {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.gd-plot svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.gd-axis {
  font-family: var(--gd-mono);
  font-size: 10px;
  fill: var(--gd-muted);
}

.gd-series {
  fill: none;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  transition: opacity 0.12s ease;
}

.gd-series.dim {
  opacity: 0.16;
}

.gd-marks {
  pointer-events: none;
}

.gd-cross {
  stroke: rgba(204, 204, 220, 0.45);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.gd-tip {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  background: rgba(21, 24, 28, 0.97);
  border: 1px solid #30333b;
  border-radius: 3px;
  padding: 0.42rem 0.55rem;
  font-size: 0.82rem;
  min-width: 168px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.1s ease;
}

.gd-tip.on {
  opacity: 1;
}

.gd-tip header {
  color: #b9bcc7;
  font-family: var(--gd-mono);
  font-size: 0.7rem;
  letter-spacing: 0.01em;
  margin-bottom: 0.3rem;
}

.gd-tip p {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 2px 0;
  color: var(--gd-text);
}

.gd-tip p span:first-child {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: 0 0 auto;
}

.gd-tip p b {
  margin-inline-start: auto;
  padding-inline-start: 1.1rem;
  font-weight: 600;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

/* ── bảng chú giải: Name / Mean / Max / Last, đúng như mẫu ─ */
.gd-legend {
  flex: 0 0 auto;
  margin-top: 0.3rem;
  font-size: 0.82rem;
  max-height: 40%;
  overflow: auto;
}

.gd-legend table {
  width: 100%;
  border-collapse: collapse;
}

.gd-legend th {
  text-align: right;
  font-weight: 400;
  color: var(--gd-muted);
  font-size: 0.68rem;
  padding: 0 0.3rem 0.15rem;
  white-space: nowrap;
}

.gd-legend th:first-child {
  text-align: left;
}

.gd-legend td {
  padding: 1px 0.3rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--gd-text);
  white-space: nowrap;
}

.gd-legend td:first-child {
  text-align: left;
  width: 100%;
}

.gd-legend tr:hover td {
  background: rgba(255, 255, 255, 0.05);
}

.gd-key {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-inline-end: 0.4rem;
  vertical-align: baseline;
}

.gd-nodata {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--gd-muted);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

.gd-note {
  grid-column: 1 / -1;
  background: var(--gd-panel);
  border: 1px solid var(--gd-border);
  border-radius: 2px;
  padding: 0.7rem 0.9rem;
  font-size: 0.8rem;
  line-height: 1.6;
  color: #a9adba;
}

.gd-note a {
  color: #5794f2;
  text-decoration: none;
}

.gd-note a:hover {
  text-decoration: underline;
}

.gd-note strong {
  color: var(--gd-strong);
  font-weight: 600;
}

.gd-skel {
  height: 100%;
  background: linear-gradient(90deg, #181b1f 25%, #1f2227 37%, #181b1f 63%);
  background-size: 400% 100%;
  animation: gd-shimmer 1.4s ease infinite;
  border-radius: 2px;
}

@keyframes gd-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

@media (max-width: 1100px) {
  .gd-panel { grid-column: span 12; }
  .gd-panel[data-narrow="wide"] { grid-column: span 24; }
}

@media (max-width: 640px) {
  .gd-panel { grid-column: span 24; }
  .gd-title { font-size: 1.05rem; margin-inline-end: 0; }
  .gd-topbar { gap: 0.45rem; }
  .gd-ptitle .gd-expr { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .gd-skel { animation: none; }
  .gd-series, .gd-row .gd-fold { transition: none; }
}
