/* eLynx — dual theme (light = mockup default, dark = field) */

/* ---------- Shared non-color tokens ---------- */
:root {
  --harmony-touch-min: 48px;
  /* Content row only (safe-area is added separately). Tall enough for 2-line titles. */
  --harmony-header-height: 64px;
  /* Taller to clear raised center FAB + labels (mockup) */
  --harmony-nav-height: 84px;
  --harmony-fab-size: 58px;
  --harmony-radius: 0.75rem;
  /* Shared with #app content and bottom nav bar */
  --harmony-content-max-width: 1400px;
  /* uPlot plot area — keep in sync with CHART_PLOT_HEIGHT in chart-range.js */
  --harmony-chart-height: 240px;
  --harmony-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --harmony-brand: #e53935;
  --harmony-brand-pressed: #c62828;
  --harmony-success: #2e7d32;
  --harmony-danger: #c62828;
  --harmony-warning: #ed6c02;
}

/* ---------- Light (mockup-aligned default) ---------- */
html[data-theme="light"],
html:not([data-theme]) {
  color-scheme: light;
  --harmony-bg: #f7f8fa;
  --harmony-surface: #ffffff;
  --harmony-surface-elevated: #ffffff;
  --harmony-border: #e2e6ee;
  --harmony-border-strong: #c5cddb;
  --harmony-text: #1a2744;
  --harmony-text-muted: #6b7a94;
  --harmony-text-inverse: #ffffff;
  --harmony-accent: #1a2744;
  --harmony-accent-soft: rgba(26, 39, 68, 0.08);
  --harmony-nav-bg: #ffffff;
  --harmony-nav-icon: #2c3e5a;
  --harmony-nav-icon-active: #15233f;
  --harmony-nav-shadow: 0 -8px 28px rgba(26, 39, 68, 0.1);
  --harmony-card-shadow: 0 1px 3px rgba(26, 39, 68, 0.06);
  --harmony-row-hover: rgba(26, 39, 68, 0.04);
  --harmony-pill-bg: #1a2744;
  --harmony-pill-text: #ffffff;
  --harmony-input-bg: #ffffff;
  --harmony-chart-grid: #e8ecf2;
  --harmony-rail-good: #2e7d32;
  --harmony-rail-bad: #c62828;
  --harmony-theme-color: #f7f8fa;
}

/* ---------- Dark (field / low-light) ---------- */
html[data-theme="dark"] {
  color-scheme: dark;
  --harmony-bg: #0d1117;
  --harmony-surface: #161b22;
  --harmony-surface-elevated: #1c2330;
  --harmony-border: #30363d;
  --harmony-border-strong: #484f58;
  --harmony-text: #e6edf3;
  --harmony-text-muted: #8b949e;
  --harmony-text-inverse: #0d1117;
  --harmony-accent: #58a6ff;
  --harmony-accent-soft: rgba(88, 166, 255, 0.12);
  --harmony-nav-bg: #161b22;
  --harmony-nav-icon: #8b949e;
  --harmony-nav-icon-active: #f0f6fc;
  --harmony-nav-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
  --harmony-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  --harmony-row-hover: rgba(88, 166, 255, 0.08);
  --harmony-pill-bg: #30363d;
  --harmony-pill-text: #e6edf3;
  --harmony-input-bg: #0d1117;
  --harmony-chart-grid: #30363d;
  --harmony-rail-good: #3fb950;
  --harmony-rail-bad: #f85149;
  --harmony-theme-color: #0d1117;
}

/* Brand red stays vivid in both themes (mockup FAB / alarms) */
html {
  --harmony-brand: #d32f2f;
  --harmony-brand-pressed: #b71c1c;
}

/*
 * Shell scroll model (mobile / iOS PWA):
 * - html + body are locked to the viewport (no document scroll).
 * - #app is position:fixed and pinned between the real header bottom and
 *   bottom-nav top (CSS vars from syncShellLayoutOffsets). That is the ONLY
 *   scroll surface — content cannot slide under fixed chrome.
 * - Short pages do not get a phantom page scrollbar.
 */
html {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--harmony-bg);
}

html,
body {
  background-color: var(--harmony-bg);
  color: var(--harmony-text);
  font-family: var(--harmony-font);
}

body {
  box-sizing: border-box;
  margin: 0;
  /* Kill Bootstrap min-vh-100 (100vh is often taller than the visible iOS viewport) */
  min-height: 100% !important;
  min-height: 100dvh !important;
  height: 100% !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
  overscroll-behavior: none;
  /* No vertical padding for chrome — #app is inset with top/bottom instead */
  padding: 0;
}

/* Login: no top/bottom chrome; #app fills the viewport (still the scroll surface). */
body.login-mode {
  /* flags only; offsets set to 0 in syncShellLayoutOffsets */
}

/*
 * Main content pane — fixed between header and bottom nav.
 * top/bottom use measured pixel offsets (not body padding), so short and long
 * pages both stay clear of the bars.
 */
#app {
  position: fixed;
  z-index: 1;
  top: var(
    --harmony-shell-header-offset,
    calc(var(--harmony-header-height) + env(safe-area-inset-top, 0px))
  );
  bottom: var(
    --harmony-shell-nav-offset,
    calc(var(--harmony-nav-height) + env(safe-area-inset-bottom, 0px))
  );
  left: env(safe-area-inset-left, 0px);
  right: env(safe-area-inset-right, 0px);
  width: auto;
  max-width: var(--harmony-content-max-width);
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  /* flex-grow from Bootstrap is irrelevant when position:fixed */
  flex: none;
}

/* Bootstrap bridge: keep components on our tokens */
.bg-body,
.navbar {
  background-color: var(--harmony-nav-bg) !important;
  color: var(--harmony-text);
}

.navbar {
  border-color: var(--harmony-border) !important;
}

/*
 * Top app bar — position:fixed. #app.top tracks this bar’s bottom edge in px
 * (syncShellLayoutOffsets). Bootstrap .navbar Y padding is zeroed.
 */
#shell-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1030;
  box-sizing: border-box;
  --bs-navbar-padding-y: 0;
  height: auto;
  min-height: calc(var(--harmony-header-height) + env(safe-area-inset-top, 0px));
  max-height: none;
  padding-top: env(safe-area-inset-top, 0px) !important;
  padding-bottom: 0 !important;
  /* Landscape notch: keep title/back out of the unsafe side insets (with px-3 floor) */
  padding-left: max(0.75rem, env(safe-area-inset-left, 0px)) !important;
  padding-right: max(0.75rem, env(safe-area-inset-right, 0px)) !important;
  /* Full-bleed bar; center title/back column like #app and .bottom-nav-bar */
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--harmony-nav-bg) !important;
  border-bottom: 1px solid var(--harmony-border) !important;
  box-shadow: 0 1px 0 rgba(26, 39, 68, 0.04), 0 4px 12px rgba(26, 39, 68, 0.04);
}

html[data-theme="dark"] #shell-header {
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* Rare fallback brand link: same content column width as title/back row */
#shell-header .navbar-brand {
  line-height: 1.2;
  padding-top: 0;
  padding-bottom: 0;
  margin: 0;
  width: 100%;
  max-width: var(--harmony-content-max-width);
}

.navbar-brand,
.navbar .nav-link {
  color: var(--harmony-text) !important;
}

/*
 * Shell header content (set by setShellChrome):
 * - Tab roots: title only
 * - Drill-in: <a.shell-back-link> wrapping ‹ + h1 (whole row is back)
 * - Drill-in, no history: same markup as a non-link with .is-disabled
 * Max width matches #app and bottom nav so back+title align with page content.
 */
.shell-header-bar {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  width: 100%;
  max-width: var(--harmony-content-max-width);
  min-width: 0;
  min-height: var(--harmony-header-height);
  /* height:auto so 2-line titles are not clipped; body offset tracks real height */
  height: auto;
  color: var(--harmony-text);
  text-decoration: none;
}

/* Clickable back row: class page-back + data-nav-back handled in nav-history.js */
a.shell-back-link {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

a.shell-back-link:hover,
a.shell-back-link:focus-visible {
  color: var(--harmony-text);
  text-decoration: none;
  outline: none;
}

a.shell-back-link:focus-visible {
  box-shadow: inset 0 0 0 2px var(--harmony-accent-soft);
  border-radius: 0.35rem;
}

a.shell-back-link:active .shell-title {
  opacity: 0.75;
}

/* Direct deep-link / empty SPA stack: show ‹ + title but do not navigate */
.shell-back-link.is-disabled,
.shell-back-link[aria-disabled="true"] {
  opacity: 0.55;
  pointer-events: none;
  cursor: default;
}

.shell-back-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: var(--harmony-touch-min);
  min-height: var(--harmony-touch-min);
  font-size: 1.75rem;
  font-weight: 400;
  line-height: 1;
}

.shell-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0.15rem 0;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.25;
  color: inherit;
  /* Up to two lines, then ellipsis (matches product decision) */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  word-break: break-word;
}

.navbar.fixed-bottom {
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: var(--harmony-nav-shadow);
  border-top: 1px solid var(--harmony-border);
  z-index: 1030;
}

/*
 * Bottom tab bar (mockup: scooped bar + raised red FAB).
 * Outer .bottom-nav is full-bleed (incl. iOS safe-area); inner .bottom-nav-bar
 * is the rounded interactive strip. Background on the outer shell fills the
 * home-indicator gap so scrolling content does not show through.
 */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1030;
  pointer-events: none;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  /* Landscape notch / home indicator corners */
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background-color: var(--harmony-nav-bg);
  /* Center bar so max-width matches #app content column */
  display: flex;
  justify-content: center;
}

.bottom-nav-bar {
  pointer-events: auto;
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 1.15fr 1fr 1fr;
  align-items: end;
  width: 100%;
  max-width: var(--harmony-content-max-width);
  min-height: var(--harmony-nav-height);
  padding: 0.35rem 0.35rem 0.45rem;
  background: var(--harmony-nav-bg);
  border-top: 1px solid var(--harmony-border);
  box-shadow: var(--harmony-nav-shadow);
  /* Soft upward curve / shelf under the FAB */
  border-radius: 1.25rem 1.25rem 0 0;
}

/* Circular “scoop” cutout feel behind the FAB */
.bottom-nav-bar::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -18px;
  transform: translateX(-50%);
  width: 86px;
  height: 42px;
  background: var(--harmony-nav-bg);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  box-shadow: 0 -6px 16px rgba(26, 39, 68, 0.06);
  z-index: 0;
}

html[data-theme="dark"] .bottom-nav-bar::before {
  box-shadow: 0 -6px 16px rgba(0, 0, 0, 0.35);
}

.bottom-nav-item {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 3.5rem;
  padding: 0.4rem 0.2rem 0.35rem;
  color: var(--harmony-nav-icon);
  text-decoration: none;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item:hover,
.bottom-nav-item:focus {
  color: var(--harmony-nav-icon-active);
}

.bottom-nav-item.active {
  color: var(--harmony-nav-icon-active);
}

.bottom-nav-item.active .bottom-nav-icon {
  transform: translateY(-1px);
}

.bottom-nav-icon {
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  flex-shrink: 0;
  line-height: 1;
}

.bottom-nav-icon i {
  font-size: 2rem;
  line-height: 1;
  width: 1em;
  height: 1em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.bottom-nav-label {
  display: block;
  width: 100%;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.15;
  color: inherit;
  white-space: nowrap;
  text-align: center;
}

.bottom-nav-item-center {
  justify-content: flex-end;
  gap: 0.3rem;
  min-height: 4.75rem;
  margin-top: -1.65rem;
  padding-bottom: 0.35rem;
}

.bottom-nav-item-center .bottom-nav-label {
  margin-top: 0;
}

/* Raised brand FAB — eLynx circular mark (same size as previous red circle) */
.fab-brand {
  width: var(--harmony-fab-size);
  height: var(--harmony-fab-size);
  border-radius: 50%;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  border: 4px solid var(--harmony-nav-bg);
  box-shadow: 0 6px 16px rgba(211, 57, 42, 0.4);
  text-decoration: none;
  flex-shrink: 0;
  overflow: hidden;
  padding: 0;
}

.fab-brand-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center;
  border-radius: 50%;
  pointer-events: none;
  user-select: none;
}

.bottom-nav-item-center:hover .fab-brand,
.bottom-nav-item-center:focus .fab-brand,
.bottom-nav-item-center.active .fab-brand {
  box-shadow: 0 8px 20px rgba(211, 57, 42, 0.55);
  transform: scale(1.04);
}

.bottom-nav-item-center:hover .fab-brand-img,
.bottom-nav-item-center:focus .fab-brand-img,
.bottom-nav-item-center.active .fab-brand-img {
  filter: brightness(0.95);
}

/* Legacy class hooks (if any remaining) */
.nav-link {
  color: var(--harmony-nav-icon) !important;
  min-height: var(--harmony-touch-min);
  text-decoration: none;
}

.nav-link.active,
.nav-link:hover,
.nav-link:focus {
  color: var(--harmony-nav-icon-active) !important;
}

.nav-icon {
  font-size: 1.25rem;
  line-height: 1.2;
}

.card-harmony {
  background-color: var(--harmony-surface);
  border: 1px solid var(--harmony-border);
  border-radius: var(--harmony-radius);
  box-shadow: var(--harmony-card-shadow);
  color: var(--harmony-text);
}

.card-harmony .card-body {
  min-height: var(--harmony-touch-min);
}

.touch-row {
  min-height: var(--harmony-touch-min);
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--harmony-border);
  color: inherit;
  text-decoration: none;
  background: var(--harmony-surface);
}

.touch-row:active,
.touch-row:hover {
  background-color: var(--harmony-row-hover);
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--harmony-text);
}

.muted {
  color: var(--harmony-text-muted);
}

.text-success-harmony {
  color: var(--harmony-success) !important;
}

.text-danger-harmony {
  color: var(--harmony-danger) !important;
}

/* Network status on Profile (not header) — wifi vs wifi-slash, no caution icon */
.profile-network {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.profile-network-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.5rem;
  background: var(--harmony-accent-soft);
  flex-shrink: 0;
}

.profile-network-icon i {
  font-size: 1.15rem;
  line-height: 1;
}

.profile-network.is-online .profile-network-icon {
  color: var(--harmony-success);
}

.profile-network.is-offline .profile-network-icon {
  color: var(--harmony-text-muted);
}

.profile-network-label {
  font-weight: 600;
}

.profile-network-hint {
  font-size: 0.8rem;
  color: var(--harmony-text-muted);
}

.offline-banner {
  background: rgba(237, 108, 2, 0.12);
  color: var(--harmony-text);
  border: 1px solid rgba(237, 108, 2, 0.35);
  border-radius: 0.5rem;
  padding: 0.45rem 0.75rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
}

html[data-theme="dark"] .offline-banner {
  background: rgba(237, 108, 2, 0.18);
}

/* Alarms + nav badge */
.nav-badge {
  position: absolute;
  top: 0.15rem;
  right: calc(50% - 1.35rem);
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.28rem;
  border-radius: 999px;
  background: var(--harmony-brand);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.alarm-status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.alarm-chip {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--harmony-text-muted);
}

.alarm-chip i {
  font-size: 0.55rem;
  margin-right: 0.25rem;
  vertical-align: middle;
}

.alarm-chip-active i {
  color: var(--harmony-danger);
}

.alarm-chip-ack i {
  color: var(--harmony-success);
}

.alarm-chip-off i {
  color: var(--harmony-text-muted);
}

.alarm-card {
  background: var(--harmony-surface);
  border: 1px solid var(--harmony-border);
  border-radius: var(--harmony-radius);
  box-shadow: var(--harmony-card-shadow);
  padding: 0.75rem 0.85rem;
}

.alarm-card.alarm-active {
  border-left: 4px solid var(--harmony-danger);
}

.alarm-card.alarm-acked {
  border-left: 4px solid var(--harmony-success);
}

.alarm-card.alarm-disabled {
  border-left: 4px solid var(--harmony-border-strong);
  opacity: 0.9;
}

.alarm-card-top {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
}

.alarm-card-icon {
  color: var(--harmony-danger);
  width: 1.5rem;
  text-align: center;
  flex-shrink: 0;
}

.alarm-card.alarm-acked .alarm-card-icon {
  color: var(--harmony-success);
}

.alarm-card.alarm-disabled .alarm-card-icon {
  color: var(--harmony-text-muted);
}

.alarm-card-main {
  flex: 1;
  min-width: 0;
}

.alarm-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.alarm-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--harmony-border);
}

.alarm-action {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--harmony-nav-icon-active);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 36px;
}

.alarm-action-btn {
  cursor: pointer;
  color: var(--harmony-success);
}

.alarm-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.alarm-detail-actions .btn {
  min-height: 44px;
}

/* Theme control (Profile / header) */
.theme-option-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.theme-option {
  flex: 1 1 30%;
  min-height: var(--harmony-touch-min);
  border: 1px solid var(--harmony-border);
  border-radius: var(--harmony-radius);
  background: var(--harmony-surface);
  color: var(--harmony-text);
  font-size: 0.875rem;
  font-weight: 600;
}

.theme-option[aria-pressed="true"] {
  border-color: var(--harmony-brand);
  background: var(--harmony-accent-soft);
  box-shadow: inset 0 0 0 1px var(--harmony-brand);
}

.theme-option:focus-visible {
  outline: 2px solid var(--harmony-brand);
  outline-offset: 2px;
}

/* Status rail (mockup entity cards) — works on both themes */
.rail-good {
  border-left: 4px solid var(--harmony-rail-good);
}

.rail-bad {
  border-left: 4px solid var(--harmony-rail-bad);
}

/* Go To tree: type + count pill cluster (right of row label) */
.tree-pills {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex: 0 0 auto;
  margin-left: 0.25rem;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 2.25rem;
  height: 1.35rem;
  background: var(--harmony-pill-bg);
  color: var(--harmony-pill-text);
  border-radius: 0.35rem;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-width: 2.25rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1;
  white-space: nowrap;
  border-radius: 0.35rem;
  border: 1px solid rgba(127, 127, 127, 0.22);
  color: #a8b0bc;
  background: rgba(127, 127, 127, 0.12);
}

.type-pill--group {
  color: #a8b0bc;
  background: rgba(127, 127, 127, 0.12);
  border-color: rgba(127, 127, 127, 0.22);
}

.type-pill--tank_battery {
  color: #c9a0e8;
  background: rgba(150, 100, 200, 0.12);
  border-color: rgba(150, 100, 200, 0.28);
}

.type-pill--well {
  color: #7eb8ff;
  background: rgba(90, 150, 230, 0.12);
  border-color: rgba(90, 150, 230, 0.28);
}

.type-pill--device {
  color: #9ad4a8;
  background: rgba(80, 160, 100, 0.12);
  border-color: rgba(80, 160, 100, 0.28);
}

.type-pill--tank {
  color: #e0b87a;
  background: rgba(200, 150, 60, 0.12);
  border-color: rgba(200, 150, 60, 0.28);
}



/* Form controls on dual theme */
.form-control,
.form-select {
  background-color: var(--harmony-input-bg);
  border-color: var(--harmony-border);
  color: var(--harmony-text);
}

.form-control:focus,
.form-select:focus {
  background-color: var(--harmony-input-bg);
  color: var(--harmony-text);
  border-color: var(--harmony-brand);
  box-shadow: 0 0 0 0.2rem rgba(211, 47, 47, 0.15);
}

code {
  color: var(--harmony-text);
  background: var(--harmony-accent-soft);
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
}

/* ---------- Phase 3: mockup-aligned layout ---------- */

body.login-mode {
  padding-top: 0;
  padding-bottom: 0;
}

/*
 * Legacy in-page page header styles.
 * pageShell() no longer emits .page-header (title/back live in #shell-header).
 * Kept so any remaining hand-built markup or older screens still look correct.
 */
.page-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.page-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  min-height: var(--harmony-touch-min);
  font-size: 1.5rem;
  line-height: 1;
  color: var(--harmony-text);
  text-decoration: none;
  margin: -0.25rem 0;
}

.page-header .page-title {
  margin-bottom: 0;
}

.state-block {
  text-align: center;
  padding: 2.5rem 1rem;
}

.state-error {
  text-align: left;
  background: var(--harmony-surface);
  border: 1px solid var(--harmony-border);
  border-radius: var(--harmony-radius);
  padding: 1rem 1.15rem;
}

/* Login */
.login-wrap {
  min-height: calc(100dvh - 2rem);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 0;
}

.login-card {
  width: 100%;
  max-width: 400px;
}

.login-version {
  margin-top: 0.85rem;
  font-size: 0.72rem;
  color: var(--harmony-text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  opacity: 0.9;
}

/* Logo left + title/subtitle inline to the right */
.login-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
  min-width: 0;
}

.login-header-text {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
}

.login-title {
  font-size: 1.35rem;
  line-height: 1.25;
  margin-bottom: 0.15rem;
}

.login-subtitle {
  line-height: 1.35;
  word-break: break-word;
}

.login-mark {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  margin: 0;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  box-shadow: 0 4px 12px rgba(211, 57, 42, 0.35);
}

.login-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.btn-harmony {
  background: var(--harmony-brand);
  border: 1px solid var(--harmony-brand);
  color: #fff;
  font-weight: 600;
  min-height: var(--harmony-touch-min);
  border-radius: 0.5rem;
}

.btn-harmony:hover,
.btn-harmony:focus {
  background: var(--harmony-brand-pressed);
  border-color: var(--harmony-brand-pressed);
  color: #fff;
}

.btn-outline-harmony {
  background: transparent;
  border: 1px solid var(--harmony-border-strong);
  color: var(--harmony-text);
  font-weight: 600;
  min-height: var(--harmony-touch-min);
  border-radius: 0.5rem;
}

.btn-outline-harmony:hover {
  background: var(--harmony-row-hover);
  color: var(--harmony-text);
}

/* Compact buttons match form-select-sm / form-control-sm height */
.btn-sm.btn-harmony,
.btn-sm.btn-outline-harmony {
  min-height: 0;
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
  border-radius: 0.375rem;
}

/* Filter bar (Go To) */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--harmony-surface);
  border: 1px solid var(--harmony-border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--harmony-card-shadow);
}

.filter-icon {
  color: var(--harmony-text-muted);
  font-size: 1.1rem;
}

.filter-input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--harmony-text);
  min-height: 40px;
  outline: none;
}

.filter-input::placeholder {
  color: var(--harmony-text-muted);
}

.filter-clear {
  border: 0;
  background: transparent;
  color: var(--harmony-text-muted);
  font-size: 1.35rem;
  line-height: 1;
  min-width: 36px;
  min-height: 36px;
}

/* Tree */
.tree-list {
  background: var(--harmony-surface);
  border: 1px solid var(--harmony-border);
  border-radius: var(--harmony-radius);
  overflow: hidden;
  box-shadow: var(--harmony-card-shadow);
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: var(--harmony-touch-min);
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--harmony-border);
  color: var(--harmony-text);
  text-decoration: none;
  background: var(--harmony-surface);
  /* Allow expand hit targets to remain tappable without clipping */
  overflow: visible;
}

.tree-row:last-child {
  border-bottom: 0;
}

.tree-row:hover,
.tree-row:active {
  background: var(--harmony-row-hover);
}

/*
 * Expand/collapse control for folder rows.
 * Visual chevron is modest; hit target is full touch min (~48px) for mobile.
 */
.tree-expand {
  --tree-expand-hit: var(--harmony-touch-min, 48px);
  box-sizing: border-box;
  border: 0;
  background: transparent;
  padding: 0;
  width: var(--tree-expand-hit);
  height: var(--tree-expand-hit);
  min-width: var(--tree-expand-hit);
  min-height: var(--tree-expand-hit);
  margin: calc((var(--harmony-touch-min, 48px) - var(--tree-expand-hit)) / 2) 0;
  /* Pull slightly so row density stays reasonable while hit area stays large */
  margin-left: -0.35rem;
  margin-right: -0.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--harmony-text-muted);
  border-radius: 0.5rem;
  flex-shrink: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  line-height: 0;
  z-index: 1;
}

.tree-expand:hover,
.tree-expand:active {
  color: var(--harmony-text);
  background: rgba(127, 127, 127, 0.16);
}

.tree-expand:focus-visible {
  outline: 2px solid var(--harmony-brand, #d3392a);
  outline-offset: 0;
  background: rgba(211, 57, 42, 0.12);
}

.tree-expand--empty {
  cursor: default;
  pointer-events: none;
  opacity: 0;
}

/*
 * Leaf rows (device / well / tank) omit a real expand control. Keep the same
 * column width so markers line up under folder icons on the parent row and with
 * nested folder rows at this depth.
 */
.tree-expand--leaf-gutter {
  cursor: default;
  pointer-events: none;
  visibility: hidden;
  /* Match .tree-expand box; no hover/focus chrome */
  background: transparent !important;
  margin-top: 0;
  margin-bottom: 0;
}

.tree-expand-chevron {
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2.5px solid currentColor;
  border-bottom: 2.5px solid currentColor;
  transform: rotate(-45deg); /* ▶ collapsed */
  transition: transform 0.12s ease;
  display: block;
  margin-left: 0.1rem;
  pointer-events: none;
}

.tree-expand[aria-expanded="true"] .tree-expand-chevron {
  transform: rotate(45deg); /* ▼ expanded */
  margin-top: -0.15rem;
  margin-left: 0;
}

.folder-icon {
  width: 1.15rem;
  height: 0.9rem;
  border: 2px solid var(--harmony-nav-icon);
  border-radius: 0.15rem 0.15rem 0.1rem 0.1rem;
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  margin-right: 0.1rem;
}

.folder-icon::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 0;
  width: 40%;
  height: 4px;
  background: var(--harmony-nav-icon);
  border-radius: 0.1rem 0.1rem 0 0;
}

.folder-icon.is-open {
  background: var(--harmony-accent-soft);
}

.tree-label {
  flex: 1;
  color: var(--harmony-text);
  text-decoration: none;
  font-weight: 600;
  min-width: 0;
}

.tree-chevron {
  color: var(--harmony-text-muted);
  text-decoration: none;
  font-size: 1.25rem;
  padding: 0 0.25rem;
}

.tree-chevron--muted {
  opacity: 0.25;
}

.tree-group--virtual .tree-label {
  cursor: default;
}

.tree-well {
  border-left-width: 3px;
  border-left-style: solid;
}

.tree-well.rail-good {
  border-left-color: var(--harmony-rail-good);
}

.tree-well.rail-bad {
  border-left-color: var(--harmony-rail-bad);
}

.rail-neutral {
  border-left: 4px solid var(--harmony-border-strong);
}

.well-marker {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 0.1rem;
  background: var(--harmony-nav-icon);
  opacity: 0.5;
  margin-right: 0.15rem;
}

.well-marker.tank-marker {
  border-radius: 0.12rem 0.12rem 0.05rem 0.05rem;
  background: var(--harmony-brand, #d3392a);
  opacity: 0.65;
}

.tree-well-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.tree-well-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.tree-well-sub {
  font-size: 0.75rem;
  color: var(--harmony-text-muted);
}

/* Action tiles (Alarms / Memos) */
.action-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.action-tile {
  background: var(--harmony-surface);
  border: 1px solid var(--harmony-border);
  border-radius: 0.65rem;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--harmony-text);
  position: relative;
  box-shadow: var(--harmony-card-shadow);
}

.action-tile-empty {
  opacity: 0.35;
}

.action-tile-icon {
  font-size: 1.15rem;
}

.action-tile-new {
  position: absolute;
  top: 0.25rem;
  right: 0.35rem;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--harmony-brand);
}

/* KPI strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin-bottom: 1rem;
  overflow: hidden;
}

.kpi-cell {
  padding: 0.85rem 0.5rem;
  text-align: center;
  border-right: 1px solid var(--harmony-border);
}

.kpi-cell:last-child {
  border-right: 0;
}

.kpi-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--harmony-text-muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--harmony-text);
  line-height: 1.2;
}

.kpi-sub {
  font-size: 0.7rem;
}

.section-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--harmony-text-muted);
  margin: 0.5rem 0 0.5rem;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.5rem 0 0.5rem;
}

.section-heading .section-label,
.section-heading-title {
  margin: 0;
}

.section-toggle {
  border: 1px solid var(--harmony-border);
  background: var(--harmony-surface);
  color: var(--harmony-text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  min-height: 30px;
  padding: 0 0.7rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.section-toggle:hover {
  color: var(--harmony-text);
  border-color: var(--harmony-border-strong, var(--harmony-border));
}

.section-toggle[aria-expanded="true"] {
  color: var(--harmony-text);
  border-color: var(--harmony-brand, #1565c0);
}

/* Tags/Sensors: inline Hide ▲ / Show ▼ (product trends update) */
.section-toggle-inline {
  border: none;
  background: transparent;
  color: var(--harmony-text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  min-height: auto;
  padding: 0.15rem 0.25rem;
  border-radius: 0.25rem;
}

.section-toggle-inline:hover {
  color: var(--harmony-text);
  border-color: transparent;
  background: transparent;
}

.section-toggle-inline[aria-expanded="true"] {
  border-color: transparent;
  color: var(--harmony-text-muted);
}

.collapsible-section {
  margin-bottom: 1rem;
}

/* Admin move-in-hierarchy on asset pages (matches Tags / sensors section chrome) */
.asset-move-section .section-heading {
  margin-bottom: 0.65rem;
}

.asset-move-body {
  min-width: 0;
}

.asset-move-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.5rem;
}

.asset-move-controls #asset-move-parent {
  flex: 1 1 12rem;
  min-width: 0;
  max-width: 100%;
}

.asset-move-controls #asset-move-container {
  flex: 0 0 auto;
  align-self: stretch;
  white-space: nowrap;
}

@media (max-width: 575.98px) {
  .asset-move-controls #asset-move-parent {
    flex: 1 1 100%;
  }

  .asset-move-controls #asset-move-container {
    flex: 1 1 100%;
  }
}

.series-summary-section {
  margin: 0 0 1rem;
  position: relative;
  z-index: 1;
  isolation: isolate;
  clear: both;
}

.collapsible-section-body,
.series-summary-body {
  margin-top: 0.35rem;
}

.series-summary-placeholder {
  padding: 0.5rem 0;
}

/* Entity cards (group children / recents / wells / alarms)
   1 col mobile · 2 cols tablet+ · 3 cols large desktop */
.entity-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
  align-items: stretch;
}

.entity-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--harmony-surface);
  border: 1px solid var(--harmony-border);
  border-radius: var(--harmony-radius);
  padding: 0.75rem 0.85rem;
  min-height: var(--harmony-touch-min);
  height: 100%;
  min-width: 0;
  text-decoration: none;
  color: var(--harmony-text);
  box-shadow: var(--harmony-card-shadow);
  border-left-width: 4px;
  border-left-style: solid;
}

/* Alarm cards share the same multi-column list container */
.entity-list > .alarm-card {
  height: 100%;
  min-width: 0;
}

.entity-card.rail-good {
  border-left-color: var(--harmony-rail-good);
}

.entity-card.rail-bad {
  border-left-color: var(--harmony-rail-bad);
}

.entity-card.rail-neutral {
  border-left-color: var(--harmony-border-strong);
}

.entity-card-main {
  flex: 1;
  min-width: 0;
}

.entity-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.entity-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.25rem;
  font-size: 0.78rem;
  color: var(--harmony-text);
}

.metric-k {
  color: var(--harmony-text-muted);
  font-weight: 600;
  margin-right: 0.2rem;
}

.entity-action {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--harmony-nav-icon);
  white-space: nowrap;
}

/* Well asset card — mockup: name + View Well, oil/gas/water row */
.asset-card {
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  min-height: 0;
}

.asset-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.asset-card-name {
  min-width: 0;
  line-height: 1.25;
}

.asset-card-action {
  flex-shrink: 0;
  color: var(--harmony-text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding-top: 0.1rem;
}

.asset-card:hover .asset-card-action {
  color: var(--harmony-text);
}

/* Type pill on asset cards (replaces “View Device / Group / Well”) */
.asset-card-type-pill {
  flex-shrink: 0;
  min-width: 3.25rem;
  height: 1.4rem;
  padding: 0 0.5rem;
  font-size: 0.68rem;
  align-self: flex-start;
  margin-top: 0.05rem;
}

.asset-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem 0.5rem;
}

.asset-metric {
  min-width: 0;
}

.asset-metric-label {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--harmony-text-muted);
  line-height: 1.2;
  margin-bottom: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.asset-metric-value {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.35rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--harmony-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.asset-metric-delta {
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.asset-metric-delta.is-up {
  color: #2e7d32;
}

.asset-metric-delta.is-down {
  color: #c62828;
}

.asset-metric-delta.is-flat {
  color: var(--harmony-text-muted);
}

@media (max-width: 380px) {
  .asset-metrics {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }
}

/* ----- Tank gallery (CTB mockup) ----- */
.tank-gallery {
  margin-left: -0.15rem;
  margin-right: -0.15rem;
}

.tank-gallery-scroll {
  display: flex;
  gap: 0.65rem;
  overflow-x: auto;
  padding: 0.15rem 0.15rem 0.35rem;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.tank-card {
  flex: 0 0 auto;
  width: 6.5rem;
  scroll-snap-align: start;
  background: var(--harmony-surface);
  border: 1px solid var(--harmony-border);
  border-radius: var(--harmony-radius);
  box-shadow: var(--harmony-card-shadow);
  padding: 0.55rem 0.45rem 0.5rem;
  text-align: center;
}
a.tank-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
a.tank-card-link:hover,
a.tank-card-link:focus-visible {
  border-color: rgba(211, 57, 42, 0.45);
  box-shadow: 0 0 0 1px rgba(211, 57, 42, 0.2);
  outline: none;
}
.tank-tag-count {
  margin-top: 0.2rem;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--harmony-brand, #d3392a);
}
.tank-detail-gauge .tank-card {
  width: 7.25rem;
  pointer-events: none;
}

.tank-card-name {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--harmony-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.4rem;
}

.tank-cylinder {
  width: 3.4rem;
  margin: 0 auto 0.4rem;
}

.tank-lid {
  height: 0.55rem;
  border-radius: 50%;
  background: linear-gradient(180deg, #c5cddb 0%, #9aa8bc 100%);
  border: 1px solid var(--harmony-border-strong);
  position: relative;
  z-index: 2;
  margin-bottom: -0.28rem;
}

html[data-theme="dark"] .tank-lid {
  background: linear-gradient(180deg, #484f58 0%, #30363d 100%);
}

.tank-body {
  position: relative;
  height: 3.6rem;
  border-radius: 0.15rem 0.15rem 0.35rem 0.35rem;
  border: 1px solid var(--harmony-border-strong);
  border-top: 0;
  background: var(--harmony-input-bg);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.03);
}

.tank-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  transition: height 0.25s ease;
}

.tank-fill-water {
  background: linear-gradient(180deg, #5b9fd4 0%, #3d7eb8 100%);
  z-index: 1;
}

.tank-fill-oil {
  background: linear-gradient(180deg, #7cb342 0%, #558b2f 100%);
  z-index: 2;
  border-radius: 0.1rem 0.1rem 0 0;
}

.tank-base {
  height: 0.35rem;
  margin-top: -0.08rem;
  border-radius: 0 0 0.4rem 0.4rem;
  background: var(--harmony-border);
}

.tank-fill-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--harmony-text-muted);
  font-variant-numeric: tabular-nums;
}

.tank-fill-label.is-critical {
  color: var(--harmony-danger);
  font-weight: 700;
}

.status-chip {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--harmony-accent-soft);
  color: var(--harmony-text);
}

.status-chip.status-active {
  background: rgba(46, 125, 50, 0.15);
  color: var(--harmony-success);
}

.status-chip.status-alarm,
.status-chip.status-offline {
  background: rgba(198, 40, 40, 0.12);
  color: var(--harmony-danger);
}

/* Tag table (well sensors) */
.tag-table-wrap {
  overflow-x: auto;
}

/* Group series dropdown — keep usable on mobile (was collapsing to ~chevron only) */
.tag-table .series-bucket-select,
select.series-bucket-select {
  min-width: 9.5rem;
}

@media (max-width: 575.98px) {
  .tag-table .series-bucket-select,
  select.series-bucket-select.form-select-sm {
    min-width: 10.5rem;
  }

  .tag-table td:has(> .series-bucket-select) {
    min-width: 11rem;
  }
}

.tag-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.tag-table th,
.tag-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--harmony-border);
  text-align: left;
  vertical-align: top;
}

.tag-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--harmony-text-muted);
  font-weight: 700;
  background: var(--harmony-bg);
}

.tag-name {
  font-weight: 600;
}

.tag-code {
  font-size: 0.75rem;
}

.tag-row[role="link"] {
  cursor: pointer;
}

.tag-row[role="link"]:hover {
  background: var(--harmony-bg);
}

.tag-well-link {
  color: var(--harmony-brand, #1565c0);
  font-weight: 600;
  text-decoration: none;
}

.tag-row.is-tag-hidden {
  opacity: 0.62;
}

.tag-row.is-tag-hidden .tag-name {
  text-decoration: line-through;
  text-decoration-color: var(--harmony-text-muted);
}

.tag-visibility-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  line-height: 1.2;
}

.tag-visibility-header-label {
  font-weight: inherit;
}

.tag-visibility-master {
  font-weight: 500;
}

.tag-visibility-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
  margin: 0;
  white-space: nowrap;
}

.tag-visibility-toggle .form-check-input {
  margin: 0;
  cursor: pointer;
}

.tag-hidden-chip {
  font-size: 0.7rem;
}

/* Group trend series admin (Profile + Manage containers) */
.series-buckets-list li.is-editing {
  background: rgba(211, 57, 42, 0.06);
  border-radius: 0.25rem;
}

#series-buckets-admin #sb-key[readonly] {
  opacity: 0.75;
  background: var(--harmony-input-bg, transparent);
}

.tag-well-link:hover {
  text-decoration: underline;
}

.chart-placeholder {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--harmony-bg);
  border: 1px dashed var(--harmony-border);
  border-radius: 0.5rem;
  padding: 1rem;
  text-align: center;
}

/* Segmented control */
.segmented {
  display: flex;
  background: var(--harmony-bg);
  border: 1px solid var(--harmony-border);
  border-radius: 999px;
  padding: 0.2rem;
  gap: 0.2rem;
}

.segmented-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--harmony-text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  min-height: 40px;
  border-radius: 999px;
}

.segmented-btn.is-active {
  background: var(--harmony-pill-bg);
  color: var(--harmony-pill-text);
}

/* Quick actions grid */
.actions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.action-grid-tile {
  background: var(--harmony-surface);
  border: 1px solid var(--harmony-border);
  border-radius: var(--harmony-radius);
  min-height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--harmony-text);
  box-shadow: var(--harmony-card-shadow);
}

.action-grid-tile:disabled {
  opacity: 0.85;
}

.action-grid-icon {
  font-size: 1.35rem;
  color: var(--harmony-nav-icon-active);
  line-height: 1;
}

.action-tile-icon i {
  font-size: 1.15rem;
  color: var(--harmony-nav-icon-active);
}



/* ---------- Phase 4: trends / uPlot ---------- */

.trends-panel {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.trends-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.range-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.range-pill {
  border: 1px solid var(--harmony-border);
  background: var(--harmony-bg);
  color: var(--harmony-text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  min-height: 34px;
  padding: 0 0.65rem;
  border-radius: 999px;
}

.range-pill.is-active {
  background: var(--harmony-pill-bg);
  border-color: var(--harmony-pill-bg);
  color: var(--harmony-pill-text);
}

.trends-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-chart-tool {
  border: 1px solid var(--harmony-border);
  background: var(--harmony-surface);
  color: var(--harmony-text);
  font-size: 0.75rem;
  font-weight: 600;
  min-height: 34px;
  padding: 0 0.65rem;
  border-radius: 0.45rem;
}

.trends-live.is-stale {
  color: var(--harmony-warning);
}

.sensor-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.sensor-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--harmony-border);
  background: var(--harmony-bg);
  color: var(--harmony-text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  min-height: 32px;
  padding: 0 0.55rem;
  border-radius: 999px;
}

.sensor-chip.is-on {
  color: var(--harmony-text);
  border-color: var(--chip-color, var(--harmony-brand));
  background: var(--harmony-surface);
  box-shadow: inset 0 0 0 1px var(--chip-color, var(--harmony-brand));
}

.sensor-chip-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--harmony-border-strong);
}

.sensor-chip.is-on .sensor-chip-dot {
  background: var(--chip-color, var(--harmony-brand));
}

/*
 * Fixed plot box: exact height so loading → data does not reflow the page
 * (avoids chart “pop-in”). Loading/empty states fill this box absolutely.
 */
.chart-stage {
  position: relative;
  width: 100%;
  height: var(--harmony-chart-height);
  min-height: var(--harmony-chart-height);
  max-height: var(--harmony-chart-height);
  background: var(--harmony-bg);
  border: 1px solid var(--harmony-border);
  border-radius: 0.5rem;
  overflow: hidden;
  box-sizing: border-box;
}

/* Hosts before mountGroupTrends/mountWellTrends inject the panel */
#group-trends-host,
#well-trends-host,
#device-trends-host,
#tank-trends-host {
  min-height: calc(var(--harmony-chart-height) + 4.5rem);
}

.chart-stage .uplot,
.chart-stage .u-wrap {
  font-family: var(--harmony-font);
}

/* Theme-aware uPlot chrome */
.chart-stage .u-legend {
  display: none;
}

.chart-loading,
.chart-empty {
  position: absolute;
  inset: 0;
  min-height: 0;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  box-sizing: border-box;
}

/* Spinner + caption while readings load (initial and range changes) */
.chart-loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.chart-loading .spinner-border {
  width: 2rem;
  height: 2rem;
  border-width: 0.2em;
}

.chart-loading-label {
  margin: 0;
}

/* Overlay spinner when a chart is already drawn and data is refetching */
.chart-stage.is-loading .chart-loading-overlay {
  display: flex;
}

.chart-loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 5;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--harmony-bg) 72%, transparent);
  backdrop-filter: blur(1px);
}

.chart-loading-overlay .chart-loading-inner {
  padding: 1rem 1.25rem;
  border-radius: var(--harmony-radius);
  background: color-mix(in srgb, var(--harmony-surface) 92%, transparent);
  box-shadow: var(--harmony-card-shadow);
  border: 1px solid var(--harmony-border);
}

.chart-loading-overlay .spinner-border {
  width: 2rem;
  height: 2rem;
  border-width: 0.2em;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  max-width: 100%;
  overflow: hidden;
  margin-bottom: 0.15rem;
  /* Reserve a line so legend text does not push content down after load */
  min-height: 1.5rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--harmony-text);
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-swatch {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 0.15rem;
  flex-shrink: 0;
}

.legend-item .thr {
  font-size: 0.7rem;
}

.chart-meta {
  min-height: 1.1rem;
}

/* Title left · series/bucket meta (and optional actions) top-right */
.trends-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.trends-card-title {
  flex-shrink: 0;
  padding-top: 0.1rem;
}

.trends-card-header-end {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  min-width: 0;
}

.chart-meta-top {
  text-align: right;
  margin: 0;
  line-height: 1.25;
  min-height: 1rem;
}

/* Chart controls button + popover (series, range, reset, pan) */
.trends-controls-wrap {
  position: relative;
  flex-shrink: 0;
}

.trends-pan-hint {
  margin-top: 0.4rem;
  line-height: 1.3;
  font-size: 0.7rem;
}

/* Always-visible pan bar under chart when zoomed (mobile-first) */
.chart-pan-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 0.45rem;
  padding: 0.35rem 0.25rem;
}

.chart-pan-bar[hidden] {
  display: none !important;
}

.chart-pan-bar-label {
  flex: 1 1 auto;
  text-align: center;
  min-width: 5rem;
  font-size: 0.72rem;
}

.chart-pan-btn {
  min-width: 2.5rem;
  min-height: 2.35rem;
  font-size: 1rem;
  line-height: 1;
}

.chart-stage.is-zoomed-pan .u-over {
  touch-action: none;
  cursor: grab;
}

.chart-stage.is-zoomed-pan .u-over.is-chart-panning {
  cursor: grabbing;
}

.trends-controls-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  padding: 0;
  border: 1px solid var(--harmony-border);
  border-radius: 0.5rem;
  background: var(--harmony-surface);
  color: var(--harmony-text-muted);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.trends-controls-btn:hover {
  color: var(--harmony-text);
  border-color: var(--harmony-border-strong, var(--harmony-border));
}

.trends-controls-btn.is-open {
  color: var(--harmony-brand, #1565c0);
  border-color: var(--harmony-brand, #1565c0);
  background: var(--harmony-bg);
}

.trends-controls-pop {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 40;
  min-width: min(18rem, 88vw);
  max-width: min(22rem, 92vw);
  padding: 0.75rem;
  border: 1px solid var(--harmony-border);
  border-radius: 0.65rem;
  background: var(--harmony-surface);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.trends-controls-pop[hidden] {
  display: none !important;
}

.trends-controls-pop-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.trends-controls-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--harmony-text-muted);
}

.trends-controls-pop-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding-top: 0.15rem;
  border-top: 1px solid var(--harmony-border);
}

html[data-theme="dark"] .trends-controls-btn {
  box-shadow: none;
}

html[data-theme="dark"] .trends-controls-pop {
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* Visually hidden (if Bootstrap util missing) */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Series summary — mockup KPI: title · primary+unit · avg label · avg+Δ% */
.series-summary {
  width: 100%;
}

.series-summary-strip {
  display: flex;
  align-items: stretch;
  width: 100%;
  border: 1px solid var(--harmony-border);
  border-radius: 0.75rem;
  background: var(--harmony-surface);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.series-stat {
  flex: 1 1 0;
  min-width: 0;
  max-width: 100%;
  padding: 0.95rem 0.85rem 0.85rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

.series-stat + .series-stat {
  border-left: 1px solid var(--harmony-border);
}

.series-stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--harmony-text-muted);
  margin-bottom: 0.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  width: 100%;
  flex-shrink: 0;
}

/* Mobile: earlier ellipsis on long Group Series titles (e.g. Oil Production) */
@media (max-width: 575.98px) {
  .series-stat {
    min-width: 0;
    padding-left: 0.45rem;
    padding-right: 0.45rem;
  }

  .series-stat-label {
    max-width: 100%;
    letter-spacing: 0.03em;
    font-size: 0.68rem;
  }
}

.series-stat-value {
  /* ~20% smaller than original 1.7rem mockup scale */
  font-size: 1.36rem;
  font-weight: 700;
  color: var(--harmony-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  white-space: nowrap;
  margin-bottom: 0.55rem;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.2rem;
  max-width: 100%;
  overflow: hidden;
}

.series-stat-primary-num {
  font-size: inherit;
  font-weight: inherit;
}

.series-stat-unit {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--harmony-text-muted);
  position: relative;
  top: -0.45em;
}

.series-stat-unit-sm {
  top: 0;
  font-size: 0.65rem;
  font-weight: 600;
}

.series-stat-avg-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--harmony-text-muted);
  margin-bottom: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  width: 100%;
}

/* Single bottom row: avg value+unit  then  Δ% */
.series-stat-footer-line {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  margin-top: auto;
}

.series-stat-secondary-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--harmony-text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.series-stat-delta {
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.series-stat-delta.is-up {
  color: #2e7d32;
}

.series-stat-delta.is-down {
  color: #c62828;
}

.series-stat-delta.is-flat {
  color: var(--harmony-text-muted);
}

html[data-theme="dark"] .series-summary-strip {
  background: var(--harmony-surface);
}

/* Tag table: stacked last reading date / time (UTC) */
.tag-th-datetime {
  white-space: nowrap;
  vertical-align: bottom;
}

.tag-th-datetime-main {
  display: block;
  font-weight: inherit;
}

.tag-th-datetime-tz {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-top: 0.1rem;
  text-transform: none;
}

.tag-datetime {
  line-height: 1.25;
  white-space: nowrap;
}

.tag-datetime-date {
  font-weight: 600;
  color: var(--harmony-text);
}

.tag-datetime-time {
  font-size: 0.78rem;
  color: var(--harmony-text-muted);
}

/* Standard users: keep tags table on one screen without sideways scroll */
.tag-table-wrap.tag-table-standard {
  overflow-x: hidden;
}

.tag-table-standard .tag-table {
  table-layout: fixed;
}

.tag-table-standard .tag-table th:first-child,
.tag-table-standard .tag-table td:first-child {
  width: 42%;
}

.tag-table-standard .tag-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Touch-friendlier cursor area */
.chart-stage .u-cursor-pt {
  pointer-events: none;
}

html[data-theme="dark"] .chart-stage {
  background: var(--harmony-surface);
}

/* ---------- Responsive multi-column layouts (must be AFTER base .entity-list) ---------- */

/* max-width / horizontal centering for #app is set in the shell scroll model above */

/* Optional: force single column for dense lists */
.entity-list.entity-list-stack {
  grid-template-columns: 1fr !important;
}

/* Tablet / laptop: 2 columns */
@media (min-width: 768px) {
  #app.container-fluid {
    padding-left: 1.25rem !important;
    padding-right: 1.25rem !important;
  }

  .entity-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .actions-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .action-tiles {
    max-width: 28rem;
  }

  .login-wrap {
    padding: 2rem 0;
  }

  .login-card {
    max-width: 420px;
  }
}

/* Large screens: 3 columns */
@media (min-width: 1200px) {
  #app.container-fluid {
    padding-left: 1.75rem !important;
    padding-right: 1.75rem !important;
  }

  .entity-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.85rem;
  }

  .actions-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-width: 56rem;
  }

  .chart-stage {
    min-height: 280px;
  }
}

@media (min-width: 1600px) {
  :root {
    --harmony-content-max-width: 1600px;
  }
}

/* ---------- In-app help / user manual ---------- */
.help-doc {
  max-width: 40rem;
}

.help-lead {
  color: var(--harmony-text-muted);
  font-size: 0.95rem;
}

.help-toc {
  padding: 0.75rem 1rem;
  border: 1px solid var(--harmony-border);
  border-radius: var(--harmony-radius);
  background: var(--harmony-accent-soft, rgba(127, 127, 127, 0.06));
}

.help-toc-list {
  margin: 0;
  padding-left: 1.15rem;
}

.help-toc-list a {
  color: var(--harmony-brand, #e53935);
  text-decoration: none;
  font-weight: 600;
}

.help-toc-list a:hover {
  text-decoration: underline;
}

.help-section {
  margin-top: 1.5rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--harmony-border);
}

.help-section:first-of-type {
  border-top: 0;
  margin-top: 0.5rem;
}

.help-h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 0.65rem;
  color: var(--harmony-text);
}

.help-h3 {
  font-size: 0.92rem;
  font-weight: 700;
  margin: 1rem 0 0.4rem;
  color: var(--harmony-text);
}

.help-list {
  margin: 0 0 0.5rem;
  padding-left: 1.2rem;
}

.help-list li {
  margin-bottom: 0.35rem;
}

.help-table {
  font-size: 0.875rem;
  color: var(--harmony-text);
}

.help-section-admin {
  /* same as other sections; marker for TOC */
}

/* ---------- Admin containers ---------- */
.admin-containers {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
@media (min-width: 900px) {
  .admin-containers {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(280px, 1.4fr);
    align-items: start;
  }
}
.admin-containers-tree,
.admin-containers-detail {
  min-width: 0;
}
.admin-containers-tree .card-body {
  padding: 0.75rem 0.85rem;
}
/* Compact explorer-style hierarchy tree */
.admin-tree-list {
  --tree-indent: 0.72rem;
  /* Layout column for chevron; hit target is larger (see toggle) */
  --tree-gutter: 1.35rem;
  --tree-row-h: 1.85rem;
  --tree-toggle-hit: 2.75rem; /* ≥ ~44px touch target */
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: min(70vh, 640px);
  overflow-x: hidden;
  overflow-y: auto;
  margin: 0;
  padding: 0.35rem 0; /* room for overlapping toggle hit areas */
}
.admin-tree-node {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.admin-tree-row-wrap {
  display: grid;
  grid-template-columns: var(--tree-gutter) minmax(0, 1fr);
  align-items: center;
  column-gap: 0.1rem;
  min-width: 0;
  min-height: var(--tree-row-h);
  /* Allow toggle hit area to extend outside the row box */
  overflow: visible;
  /* single indent source — no extra margin on children */
  padding-left: calc(var(--depth, 0) * var(--tree-indent));
}
.admin-tree-node[data-depth="0"] > .admin-tree-row-wrap { --depth: 0; }
.admin-tree-node[data-depth="1"] > .admin-tree-row-wrap { --depth: 1; }
.admin-tree-node[data-depth="2"] > .admin-tree-row-wrap { --depth: 2; }
.admin-tree-node[data-depth="3"] > .admin-tree-row-wrap { --depth: 3; }
.admin-tree-node[data-depth="4"] > .admin-tree-row-wrap { --depth: 4; }
.admin-tree-node[data-depth="5"] > .admin-tree-row-wrap { --depth: 5; }
.admin-tree-node[data-depth="6"] > .admin-tree-row-wrap { --depth: 6; }
.admin-tree-node[data-depth="7"] > .admin-tree-row-wrap { --depth: 7; }
.admin-tree-node[data-depth="8"] > .admin-tree-row-wrap { --depth: 8; }

.admin-tree-children {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;
}
.admin-tree-node.is-collapsed > .admin-tree-children {
  display: none;
}

/*
 * Chevron: compact layout column, ~44px real hit target via size + negative margin
 * so finger taps register without bloating every row.
 */
.admin-tree-toggle,
.admin-tree-toggle-spacer {
  box-sizing: border-box;
  width: var(--tree-toggle-hit);
  height: var(--tree-toggle-hit);
  min-width: var(--tree-toggle-hit);
  min-height: var(--tree-toggle-hit);
  /* Pull back into the gutter/row so neighbors stay dense */
  margin-left: calc((var(--tree-gutter) - var(--tree-toggle-hit)) / 2);
  margin-right: calc((var(--tree-gutter) - var(--tree-toggle-hit)) / 2);
  margin-top: calc((var(--tree-row-h) - var(--tree-toggle-hit)) / 2);
  margin-bottom: calc((var(--tree-row-h) - var(--tree-toggle-hit)) / 2);
  padding: 0;
  border: none;
  background: transparent;
  color: var(--harmony-text-muted);
  border-radius: 0.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  cursor: pointer;
  flex-shrink: 0;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.admin-tree-toggle:hover,
.admin-tree-toggle:active {
  color: var(--harmony-text);
  background: rgba(127, 127, 127, 0.18);
}
.admin-tree-toggle:focus-visible {
  outline: 2px solid var(--harmony-brand, #d3392a);
  outline-offset: 0;
  background: rgba(211, 57, 42, 0.12);
}
.admin-tree-chevron {
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2.25px solid currentColor;
  border-bottom: 2.25px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.1s ease;
  margin-top: -0.15rem;
  display: block;
  pointer-events: none;
}
.admin-tree-node.is-collapsed > .admin-tree-row-wrap > .admin-tree-toggle .admin-tree-chevron {
  transform: rotate(-45deg);
  margin-top: 0;
  margin-left: 0.06rem;
}
.admin-tree-toggle-spacer {
  cursor: default;
  pointer-events: none;
  visibility: hidden;
  background: transparent;
}

.admin-tree-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 0.3rem;
  background: transparent;
  color: var(--harmony-text);
  padding: 0.1rem 0.3rem;
  min-height: var(--tree-row-h);
  height: var(--tree-row-h);
  font: inherit;
  cursor: pointer;
}
.admin-tree-row:hover {
  background: rgba(127, 127, 127, 0.1);
}
.admin-tree-row.is-selected {
  background: rgba(211, 57, 42, 0.12);
  border-color: rgba(211, 57, 42, 0.35);
  box-shadow: inset 2px 0 0 var(--harmony-brand, #d3392a);
}

.admin-tree-row.is-container-hidden {
  opacity: 0.72;
}

.admin-tree-row.is-container-hidden .admin-tree-name {
  text-decoration: line-through;
  text-decoration-color: var(--harmony-text-muted);
}
/* Short type pill — fixed-ish width so names align */
.admin-tree-type {
  flex: 0 0 auto;
  min-width: 1.55rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: center;
  color: var(--harmony-text-muted);
  background: rgba(127, 127, 127, 0.1);
  border: 1px solid rgba(127, 127, 127, 0.16);
  border-radius: 0.25rem;
  padding: 0.05rem 0.28rem;
  line-height: 1.2;
  white-space: nowrap;
}
.admin-tree-type--well {
  color: #7eb8ff;
  background: rgba(90, 150, 230, 0.12);
  border-color: rgba(90, 150, 230, 0.28);
}
.admin-tree-type--device {
  color: #9ad4a8;
  background: rgba(80, 160, 100, 0.12);
  border-color: rgba(80, 160, 100, 0.28);
}
.admin-tree-type--tank {
  color: #e0b87a;
  background: rgba(200, 150, 60, 0.12);
  border-color: rgba(200, 150, 60, 0.28);
}
.admin-tree-type--tank_battery {
  color: #c9a0e8;
  background: rgba(150, 100, 200, 0.12);
  border-color: rgba(150, 100, 200, 0.28);
}
.admin-tree-type--group {
  color: #a8b0bc;
  background: rgba(127, 127, 127, 0.12);
  border-color: rgba(127, 127, 127, 0.22);
}
.admin-tree-name {
  font-weight: 600;
  font-size: 0.8125rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-tree-meta {
  flex: 0 0 auto;
  font-size: 0.65rem;
  color: var(--harmony-text-muted);
  white-space: nowrap;
  margin-left: auto;
  opacity: 0.85;
  max-width: 4.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-form .form-label {
  margin-bottom: 0.2rem;
}

/* Panel header row: title left, type select + Add (+ Delete) upper-right */
.admin-panel-toolbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  min-height: 2rem;
}
.admin-panel-title {
  flex: 1 1 auto;
  min-width: 0;
}
.admin-panel-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-shrink: 0;
}
.admin-add-bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.35rem;
}
.admin-add-bar .form-select {
  width: auto;
  min-width: 8.5rem;
  max-width: 12rem;
}

/* Admin container/tag pickers — wrapping lists (native <select size> truncates paths) */
.admin-picker-dialog {
  width: min(100% - 1rem, 32rem);
  max-width: 32rem;
  margin-left: auto;
  margin-right: auto;
}
@media (min-width: 768px) {
  .admin-picker-dialog {
    width: min(100% - 2rem, 40rem);
    max-width: 40rem;
  }
}
.admin-picker-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
  max-height: min(36vh, 14rem);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.35rem;
  border: 1px solid rgba(127, 127, 127, 0.28);
  border-radius: 0.4rem;
  background: rgba(0, 0, 0, 0.12);
}
.admin-picker-list--tags {
  max-height: min(28vh, 11rem);
}
.admin-picker-list.is-disabled {
  opacity: 0.65;
  pointer-events: none;
}
.admin-picker-empty {
  padding: 0.5rem 0.4rem;
}
.admin-picker-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 0.35rem;
  background: transparent;
  color: var(--harmony-text);
  padding: 0.45rem 0.55rem;
  font: inherit;
  line-height: 1.3;
  cursor: pointer;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.admin-picker-item:hover,
.admin-picker-item:focus-visible {
  background: rgba(127, 127, 127, 0.12);
  outline: none;
}
.admin-picker-item.is-selected {
  background: rgba(211, 57, 42, 0.14);
  border-color: rgba(211, 57, 42, 0.4);
  box-shadow: inset 2px 0 0 var(--harmony-brand, #d3392a);
}
.admin-picker-item-title {
  display: block;
  width: 100%;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.admin-picker-item-path {
  display: block;
  width: 100%;
  font-size: 0.75rem;
  color: var(--harmony-text-muted);
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}
@media (max-width: 575.98px) {
  .admin-picker-dialog {
    width: calc(100% - 0.75rem);
    max-width: none;
    margin: 0.35rem auto;
  }
  .admin-picker-list {
    max-height: min(32vh, 12rem);
  }
  .admin-picker-list--tags {
    max-height: min(24vh, 9.5rem);
  }
  .admin-picker-item {
    padding: 0.5rem 0.5rem;
  }
}

/* ---------- Chart data table (fullscreen) ---------- */
/* One scroll surface only: lock page/body; table body scrolls. */
body.chart-table-mode #shell-nav {
  display: none !important;
}

body.chart-table-mode #app {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* bottom inset = home indicator only (nav hidden) — set by syncShellLayoutOffsets */
  overflow: hidden; /* table body scrolls inside */
  padding-top: 0.5rem !important;
  padding-bottom: 0.5rem !important;
}

.chart-table-page {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  margin: 0;
}

.chart-table-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-shrink: 0;
  z-index: 5;
  background: var(--harmony-bg);
  padding-bottom: 0.35rem;
}

.chart-table-top-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.chart-table-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--harmony-text);
  line-height: 1.25;
}

.chart-table-range-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.45rem;
}

.chart-table-dt {
  border: 1px solid var(--harmony-border);
  background: var(--harmony-surface);
  color: var(--harmony-text);
  border-radius: 0.45rem;
  font-size: 0.78rem;
  min-height: 34px;
  padding: 0.2rem 0.4rem;
  max-width: 100%;
}

/* Duration pills span full content width (2 rows × 5 presets) */
.chart-table-presets {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.3rem;
  width: 100%;
}

.chart-table-presets .range-pill {
  width: 100%;
  min-width: 0;
  text-align: center;
  padding-left: 0.15rem;
  padding-right: 0.15rem;
}

.chart-table-top-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.chart-table-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 0.5rem;
  border: 1px solid var(--harmony-border);
  background: var(--harmony-surface);
  color: var(--harmony-text);
  text-decoration: none;
  font-size: 1.1rem;
}

.chart-table-close:hover,
.chart-table-close:focus {
  border-color: var(--harmony-border-strong);
  color: var(--harmony-brand);
}

.chart-table-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow: hidden;
}

.chart-table-meta {
  margin: 0;
  flex-shrink: 0;
}

.chart-table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--harmony-border);
  border-radius: 0.55rem;
  background: var(--harmony-surface);
  -webkit-overflow-scrolling: touch;
}

.chart-table-grid {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
}

.chart-table-grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--harmony-surface-elevated, var(--harmony-surface));
  border-bottom: 1px solid var(--harmony-border);
  /* Series headers match numeric cell alignment; time col overrides left. */
  text-align: right;
  font-weight: 700;
  padding: 0.45rem 0.45rem;
  color: var(--harmony-text);
  vertical-align: bottom;
  /* Series headers wrap so columns stay narrow; time col overrides below. */
  white-space: normal;
  line-height: 1.2;
  max-width: 5.25rem;
  min-width: 3.25rem;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  box-sizing: border-box;
}

.chart-table-grid tbody td,
.chart-table-grid tfoot td {
  padding: 0.35rem 0.45rem;
  border-bottom: 1px solid var(--harmony-border);
  white-space: nowrap;
  color: var(--harmony-text);
  background: var(--harmony-surface);
  max-width: 5.25rem;
  min-width: 3.25rem;
  overflow: hidden;
  box-sizing: border-box;
  vertical-align: middle;
}

.chart-table-grid tbody tr:nth-child(even) td {
  background: var(--harmony-bg);
}

.chart-table-grid tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  font-weight: 700;
  border-top: 1px solid var(--harmony-border-strong);
  background: var(--harmony-surface-elevated, var(--harmony-surface));
}

/* Two-line date + time keeps the first column narrow and avoids header bleed. */
.chart-table-time,
.chart-table-th-time {
  width: 6.75rem;
  min-width: 6.75rem;
  max-width: 6.75rem;
  white-space: normal;
  overflow: hidden;
}

.chart-table-th-time {
  text-align: left;
  vertical-align: bottom;
  z-index: 3; /* above series sticky headers when scrolling horizontally */
}

.chart-table-dt-date,
.chart-table-dt-time {
  display: block;
  line-height: 1.2;
  white-space: nowrap;
}

.chart-table-dt-time {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--harmony-text-muted, var(--harmony-text));
  opacity: 0.9;
}

.chart-table-col-label {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.2;
}

.chart-table-col-unit {
  display: block;
  margin-top: 0.1rem;
  font-weight: 500;
  white-space: normal;
}

.chart-table-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.chart-table-sum-label {
  font-weight: 700;
  width: 6.75rem;
  min-width: 6.75rem;
  max-width: 6.75rem;
  white-space: nowrap;
}

.chart-table-sort {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  white-space: nowrap;
  max-width: 100%;
}

/* Date/Time header: title + sort on line 1, UTC horizontal on line 2 */
.chart-table-sort-time {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  white-space: normal;
  width: 100%;
}

.chart-table-sort-main {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}

.chart-table-tz-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.15;
  white-space: nowrap;
  overflow: visible;
}

.chart-table-loading {
  padding: 1.5rem 0;
}

.trends-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.trends-toolbar-actions .btn-chart-tool {
  min-width: 34px;
}
