/* Theme aware styling: colours come from Bootstrap 5.3 variables so the light
   and dark switch works without a second stylesheet. */

:root {
  --gh-ok: var(--bs-success);
  --gh-warn: var(--bs-warning);
  --gh-err: var(--bs-danger);
  --gh-blue: var(--bs-primary);
}

body.gh-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  background: var(--bs-body-bg);
}

[data-bs-theme="dark"] body.gh-body {
  background: radial-gradient(1100px 520px at 15% -10%, #16223a 0%, var(--bs-body-bg) 60%) fixed;
}

.gh-navbar {
  background: var(--bs-tertiary-bg);
  border-bottom: 1px solid var(--bs-border-color);
}

/* The brand mark doubles as the page identity, so it carries a little more
   weight than a default navbar link. */
.navbar-brand { padding: 0; margin-right: 12px; }

.gh-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, #2563eb, #22c55e);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: .04em;
  color: #fff;
  box-shadow: 0 8px 20px -12px rgba(37, 99, 235, .9);
}

.gh-main { flex: 1 0 auto; }

.gh-float-btn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1040;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--bs-primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .06em;
  text-decoration: none;
  box-shadow: 0 10px 26px -10px rgba(15, 23, 42, .7);
  transition: transform .15s ease, box-shadow .15s ease;
}
.gh-float-btn-alt {
  background: var(--bs-secondary-color);
}
.gh-float-btn:hover {
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 16px 32px -12px rgba(15, 23, 42, .8);
}
@media (max-width: 768px) {
  .gh-float-btn { right: 12px; bottom: 12px; padding: 8px 14px; font-size: 13px; }
}

.gh-conn {
  font-size: 12px;
  color: var(--bs-secondary-color);
  border: 1px solid var(--bs-border-color);
  border-radius: 999px;
  padding: 2px 10px;
}
.gh-conn.on { color: var(--bs-success); border-color: color-mix(in srgb, var(--bs-success) 45%, transparent); }
.gh-conn.off { color: var(--bs-danger); border-color: color-mix(in srgb, var(--bs-danger) 45%, transparent); }
/* The badge is a button: clicking it retries the connection. */
.gh-conn { user-select: none; }
.gh-conn.retryable { cursor: pointer; }
.gh-conn.retryable:hover { border-color: var(--bs-primary); color: var(--bs-primary); }
.gh-conn:focus-visible { outline: 2px solid var(--bs-primary); outline-offset: 2px; }

.gh-theme-btn { border: 1px solid var(--bs-border-color); color: var(--bs-body-color); background: transparent; }
.gh-theme-btn:hover { background: var(--bs-secondary-bg); color: var(--bs-body-color); }

.gh-card {
  background: var(--bs-tertiary-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 12px;
  padding: 14px 16px;
  height: 100%;
}

.gh-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.gh-label { color: var(--bs-secondary-color); font-size: 12px; letter-spacing: .04em; }

.gh-node-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr));
}

.gh-node-card {
  position: relative;
  overflow: hidden;
  padding: 20px 20px 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--bs-tertiary-bg) 0%, var(--bs-secondary-bg) 100%);
  border: 1px solid var(--bs-border-color);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08), 0 18px 40px -32px rgba(15, 23, 42, .55);
}
/* A node that stopped working is greyed out, content stays readable. */
.gh-node-card.offline {
  filter: grayscale(.9);
  opacity: .55;
}

.gh-node-name { font-size: 19px; font-weight: 650; margin: 0; letter-spacing: .01em; }

.gh-detail-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 9px;
  border: 1px solid var(--bs-border-color);
  border-radius: 8px;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  font-size: 12px;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
}
.gh-detail-btn:hover {
  border-color: var(--bs-primary);
  color: var(--bs-primary);
}

.gh-values {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  margin-top: 16px;
}

.gh-value {
  position: relative;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 14px;
  padding: 12px 14px 8px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.gh-value::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--bs-secondary-color);
  opacity: .75;
}
.gh-value.temp::after { background: #f97316; }
.gh-value.hum::after { background: #3b82f6; }
.gh-value.lux::after { background: #eab308; }
.gh-value.soil::after { background: #14b8a6; }
.gh-value.volt::after { background: #a855f7; }
.gh-value.co2::after { background: #ef4444; }

.gh-value .k {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
  color: var(--bs-secondary-color);
  white-space: nowrap;
  overflow: hidden;
}
.gh-value .k .kl { color: var(--bs-body-color); font-weight: 600; }

.gh-value .v {
  font-size: 27px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.gh-value .v .u { font-size: 12px; font-weight: 400; color: var(--bs-secondary-color); margin-left: 3px; }

.gh-value .spark { display: block; width: 100%; height: 26px; margin-top: 6px; opacity: .85; }
.gh-value.temp { color: #f97316; }
.gh-value.hum { color: #3b82f6; }
.gh-value.lux { color: #eab308; }
.gh-value.soil { color: #14b8a6; }
.gh-value.volt { color: #a855f7; }
.gh-value.co2 { color: #ef4444; }
.gh-value .v, .gh-value .k { color: var(--bs-body-color); }

.gh-value .spark-note { font-size: 11px; color: var(--bs-secondary-color); margin-top: 4px; }
.gh-value.stale { opacity: .55; }
.gh-value.stale .spark { display: none; }

.gh-node-foot {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--bs-border-color);
  color: var(--bs-secondary-color);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.gh-node-foot span { display: inline-flex; align-items: center; gap: 4px; }
.gh-age.ok { color: var(--bs-success); }
.gh-age.warn { color: var(--bs-warning); }
.gh-age.bad { color: var(--bs-danger); }

.gh-alarm-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-left: 3px solid var(--bs-border-color);
  background: var(--bs-secondary-bg);
  border-radius: 8px;
  margin-bottom: 6px;
}
.gh-sev-critical { border-left-color: var(--gh-err); }
.gh-sev-warning { border-left-color: var(--gh-warn); }
.gh-sev-info { border-left-color: var(--gh-blue); }

.gh-table { font-size: 13px; }
.gh-table th { color: var(--bs-secondary-color); font-weight: 500; white-space: nowrap; }
.gh-table td { vertical-align: middle; }

.gh-chart { width: 100%; height: 240px; }

.gh-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.gh-toast-wrap { z-index: 1080; max-width: 340px; }

.gh-scroll { max-height: 320px; overflow: auto; }

.gh-login { min-height: 70vh; display: flex; align-items: center; justify-content: center; }

.gh-tabs .nav-link { color: var(--bs-secondary-color); }
.gh-tabs .nav-link.active { color: var(--bs-body-color); background: var(--bs-tertiary-bg); border-color: var(--bs-border-color) var(--bs-border-color) var(--bs-tertiary-bg); }
.gh-tab-pane { border: 1px solid var(--bs-border-color); border-top: 0; border-radius: 0 0 12px 12px; padding: 16px; background: var(--bs-tertiary-bg); }

.gh-kpi { display: flex; gap: 18px; flex-wrap: wrap; align-items: baseline; }
.gh-kpi .item { color: var(--bs-secondary-color); font-size: 13px; }
.gh-kpi .item b { color: var(--bs-body-color); font-size: 18px; margin-right: 4px; font-variant-numeric: tabular-nums; }

@media (max-width: 768px) {
  body.gh-body { font-size: 13px; }
  .gh-navbar { padding: 6px 10px; }
  .gh-node-grid { grid-template-columns: 1fr; gap: 12px; }
  .gh-card { padding: 14px; border-radius: 12px; }
  .gh-node-card { padding: 16px 16px 12px; border-radius: 15px; }
  .gh-values { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 10px; }
  .gh-value { min-height: 88px; padding: 10px 12px 6px; }
  .gh-value .v { font-size: 22px; }
  .gh-node-name { font-size: 17px; }
  .gh-node-foot { font-size: 11px; gap: 6px; margin-top: 12px; padding-top: 10px; }
  .gh-kpi { gap: 12px; }
  .gh-kpi .item b { font-size: 16px; }
  .gh-chart { height: 200px; }
  .gh-tab-pane { padding: 10px; }
  .btn-sm { padding: 6px 10px; }
  .gh-theme-btn, .gh-conn { font-size: 11px; }
  .gh-logo { width: 40px; height: 40px; font-size: 16px; border-radius: 11px; }
}

@media (max-width: 420px) {
  .gh-values { grid-template-columns: repeat(2, 1fr); }
  .gh-value .v { font-size: 21px; }
  .gh-conn { font-size: 11px; padding: 2px 8px; }
}

.gh-wall {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
}
.gh-wall-card {
  position: relative;
  padding: 22px;
  border-radius: 20px;
  background: linear-gradient(180deg, var(--bs-tertiary-bg), var(--bs-secondary-bg));
  border: 1px solid var(--bs-border-color);
  box-shadow: 0 24px 60px -40px rgba(15, 23, 42, .7);
}
.gh-wall-card.offline { filter: grayscale(.9); opacity: .6; }
.gh-wall-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.gh-wall-name { font-size: 24px; font-weight: 700; }
.gh-wall-values { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.gh-wall-value {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 16px;
  padding: 14px 16px;
}
.gh-wall-value .k { font-size: 14px; color: var(--bs-secondary-color); }
.gh-wall-value .v { font-size: 42px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.gh-wall-value .v .u { font-size: 16px; font-weight: 400; color: var(--bs-secondary-color); margin-left: 4px; }
.gh-wall-value.temp .v { color: #f97316; }
.gh-wall-value.hum .v { color: #3b82f6; }
.gh-wall-value.lux .v { color: #eab308; }
.gh-wall-value.soil .v { color: #14b8a6; }
.gh-wall-value.volt .v { color: #a855f7; }
.gh-wall-value.co2 .v { color: #ef4444; }
.gh-wall-value.stale { opacity: .5; }
.gh-wall-switches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.gh-wall-switch {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 14px;
  background: var(--bs-secondary-bg);
  border: 1px solid var(--bs-border-color);
}
.gh-wall-switch.on { background: rgba(34, 197, 94, .18); border-color: #22c55e; color: #16a34a; }

.gh-actuator-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.gh-actuator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  font-size: 12px;
}
.gh-actuator.on { border-color: #22c55e; background: rgba(34, 197, 94, .12); }
.gh-actuator button { line-height: 1; }
.gh-announce {
  border-left: 3px solid var(--bs-warning);
  background: var(--bs-tertiary-bg);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
}
.gh-map-wrap { position: relative; border-radius: 14px; overflow: hidden; border: 1px solid var(--bs-border-color); }
.gh-map-wrap img { display: block; width: 100%; }
.gh-map-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(15, 23, 42, .82);
  color: #f8fafc;
  border: 1px solid rgba(148, 163, 184, .5);
  border-radius: 10px;
  padding: 3px 8px;
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
}
.gh-map-marker.online { border-color: #22c55e; }
.gh-map-marker.offline { opacity: .75; }

.gh-icon { display: inline-flex; align-items: center; color: var(--bs-primary); }
.gh-icon-svg { display: block; }
.gh-icon-lg { color: var(--bs-primary); }
.gh-icon-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--bs-border-color);
  border-radius: 10px;
}
.gh-icon-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--bs-secondary-color);
  font-size: 10px;
  line-height: 1.1;
}
.gh-icon-choice:hover { background: var(--bs-tertiary-bg); color: var(--bs-body-color); }
.gh-icon-choice.active {
  border-color: var(--bs-primary);
  color: var(--bs-primary);
  background: color-mix(in srgb, var(--bs-primary) 12%, transparent);
}
.gh-map-marker .gh-icon-svg { display: inline-block; vertical-align: -2px; margin-right: 2px; }

.gh-alert {
  border-left: 3px solid var(--bs-secondary-color);
  background: var(--bs-tertiary-bg);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--bs-secondary-color);
}

/* Navigation entries read as buttons: a hairline border plus a filled state for
   the page that is currently open, so they look pressable at a glance. */
.gh-navbar .nav-link.gh-nav-btn {
  padding: 6px 14px;
  margin-right: 4px;
  border: 1px solid var(--bs-border-color);
  border-radius: 9px;
  background: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
  font-weight: 600;
  line-height: 1.3;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}
.gh-navbar .nav-link.gh-nav-btn:hover {
  border-color: var(--bs-primary);
  color: var(--bs-primary);
  transform: translateY(-1px);
}
.gh-navbar .nav-link.gh-nav-btn.active {
  background: var(--bs-primary);
  border-color: var(--bs-primary);
  color: #fff;
  box-shadow: 0 6px 16px -10px rgba(15, 23, 42, .9);
}
@media (max-width: 768px) {
  .gh-navbar .nav-link.gh-nav-btn { padding: 5px 10px; font-size: 13px; }
}

/* Theme button: icon plus label, sized like the other navbar controls. */
.gh-theme-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.gh-theme-icon { display: block; }

/* Collection rate badge: green when the data is complete, amber when reports are
   missing, red when the node is barely delivering. */
.gh-rate {
  display: inline-block;
  min-width: 46px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  border: 1px solid transparent;
}
.gh-rate.ok { color: #16a34a; background: rgba(34, 197, 94, .14); border-color: rgba(34, 197, 94, .5); }
.gh-rate.warn { color: #d97706; background: rgba(245, 158, 11, .14); border-color: rgba(245, 158, 11, .5); }
.gh-rate.bad { color: #dc2626; background: rgba(239, 68, 68, .14); border-color: rgba(239, 68, 68, .5); }
.gh-rate.na { color: var(--bs-secondary-color); background: var(--bs-tertiary-bg); border-color: var(--bs-border-color); }

/* Collection health chips: the headline numbers of one node. */
.gh-collect-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 10px;
}
.gh-collect-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-body-bg);
  font-size: 12px;
  color: var(--bs-secondary-color);
}
.gh-collect-chip b { font-size: 15px; color: var(--bs-body-color); font-variant-numeric: tabular-nums; }
.gh-collect-chip.ok { border-color: rgba(34, 197, 94, .6); }
.gh-collect-chip.ok b { color: #16a34a; }
.gh-collect-chip.warn { border-color: rgba(245, 158, 11, .6); }
.gh-collect-chip.warn b { color: #d97706; }
.gh-collect-chip.bad { border-color: rgba(239, 68, 68, .6); }
.gh-collect-chip.bad b { color: #dc2626; }

/* Phone layout */

/* The console has a dozen tabs; on a phone they scroll sideways instead of
   wrapping into a wall of buttons. */
.gh-tabs {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 2px;
}
.gh-tabs::-webkit-scrollbar { height: 4px; }
.gh-tabs::-webkit-scrollbar-thumb { background: var(--bs-border-color); border-radius: 2px; }
.gh-tabs .nav-link {
  white-space: nowrap;
  padding: 6px 12px;
  border-radius: 8px 8px 0 0;
}
.gh-tabs .nav-link.active { font-weight: 600; }

@media (max-width: 768px) {
  /* Tables become stacked cards: every cell shows its column name, which keeps
     a ten column table readable on a 390 pixel wide screen. */
  .gh-table-stack thead { display: none; }
  .gh-table-stack tr {
    display: block;
    margin-bottom: 10px;
    border: 1px solid var(--bs-border-color);
    border-radius: 12px;
    background: var(--bs-body-bg);
    padding: 6px 10px;
  }
  .gh-table-stack td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 0;
    padding: 5px 0;
    font-size: 13px;
  }
  .gh-table-stack td + td { border-top: 1px dashed var(--bs-border-color); }
  .gh-table-stack td::before {
    content: attr(data-label);
    color: var(--bs-secondary-color);
    font-size: 12px;
    flex: 0 0 auto;
  }
  .gh-table-stack td[data-label=""]::before { content: ""; }
  .gh-table-stack td[data-label=""] { justify-content: flex-start; }
  .gh-table-stack .btn { min-height: 36px; }

  /* iOS zooms the page when a focused input is smaller than 16 pixels. */
  .form-control, .form-select, .form-control-sm, .form-select-sm { font-size: 16px; }
  .gh-node-card .gh-value .v { font-size: 24px; }
  .gh-actuator button { min-height: 34px; min-width: 46px; }

  /* Room for the floating button so it never covers the last card. */
  .gh-main { padding-bottom: 74px; }
  .gh-toast-wrap { padding-bottom: 78px !important; }
  .gh-conn { font-size: 11px; padding: 3px 8px; }
  .gh-navbar .navbar-brand { margin-right: 8px; }
  .gh-card-head { flex-wrap: wrap; gap: 6px; }
}

@media (max-width: 420px) {
  .gh-collect-chip { padding: 5px 9px; font-size: 11px; }
  .gh-collect-chip b { font-size: 13px; }
  .gh-tabs .nav-link { padding: 6px 9px; font-size: 13px; }
}

/* Sortable table headers: a CSS triangle marks the active column, so no glyph
   characters are needed in the markup. */
th.gh-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.gh-sortable:hover { color: var(--bs-primary); }
th.gh-sortable::after {
  content: "";
  display: inline-block;
  margin-left: 5px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0;
  vertical-align: middle;
}
th.gh-sortable.sorted { color: var(--bs-primary); }
th.gh-sortable.sorted::after { opacity: .8; }
th.gh-sortable.sorted-asc::after { transform: rotate(180deg); }

/* Keyboard focus stays visible on every interactive element. */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
.nav-link:focus-visible {
  outline: 2px solid var(--bs-primary);
  outline-offset: 2px;
  border-radius: 6px;
}
