:root {
  --bg0: #0c0e10;
  --bg1: #14181c;
  --bg2: #1a2026;
  --ink: #e8eef2;
  --muted: #8b98a5;
  --line: #2a333c;
  --accent: #3d8fd1;
  --accent-dim: #2a6a9e;
  --brand: #9b1b2e;
  --brand-dim: #7a1524;
  --ok: #3ecf8e;
  --warn: #c9a227;
  --bad: #d45b5b;
  --row-alert: rgba(140, 90, 40, 0.45);
  --header-h: 56px;
  --footer-h: 36px;
  --sidebar-w: 460px;
  --tree-indent: 1.1rem;
  --font: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app-shell {
  min-height: 100%;
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--footer-h);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: grid;
  grid-template-columns: minmax(280px, 1.2fr) minmax(160px, 1fr) auto;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.header-center {
  min-width: 0;
  overflow: hidden;
}

.logo-mark {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.35rem;
  flex-shrink: 0;
  display: block;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong {
  font-family: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.brand-text span {
  font-size: 0.7rem;
  color: var(--muted);
}

.header-search {
  display: inline-flex;
  align-items: stretch;
  margin-left: 1.75rem;
  flex-shrink: 0;
  min-width: 0;
}

.header-search-field {
  display: block;
  min-width: 0;
}

.header-search input {
  width: min(240px, 30vw);
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--bg0);
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 0.3rem 0 0 0.3rem;
  padding: 0.4rem 0.6rem;
}

.header-search input:focus {
  outline: none;
  border-color: rgba(61, 143, 209, 0.7);
  box-shadow: inset 0 0 0 1px rgba(61, 143, 209, 0.35);
}

.header-search-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0 0.3rem 0.3rem 0;
  background: var(--bg0);
  color: var(--muted);
  cursor: pointer;
}

.header-search-btn:hover,
.header-search-btn:focus-visible {
  color: var(--ink);
  background: rgba(61, 143, 209, 0.14);
  outline: none;
}

.header-search-btn svg {
  width: 1rem;
  height: 1rem;
  display: block;
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breadcrumb strong {
  color: var(--ink);
  font-weight: 500;
}

.conn-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--muted);
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: var(--bg0);
  cursor: help;
}

.dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--warn);
  flex-shrink: 0;
}

.dot.ok {
  background: var(--ok);
  box-shadow: 0 0 6px rgba(62, 207, 142, 0.45);
}

.dot.warn {
  background: var(--warn);
}

.dot.bad {
  background: var(--bad);
}

.dot.idle {
  background: #6a7682;
}

.gw-cell-card {
  margin-top: 0.65rem;
}

.notif-wrap {
  position: relative;
}

.notif-btn {
  position: relative;
  width: 2.2rem;
  height: 2.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  background: var(--bg0);
  color: var(--ink);
  cursor: pointer;
}

.notif-btn:hover,
.notif-btn[aria-expanded='true'] {
  border-color: var(--accent);
  color: var(--accent);
}

.notif-btn svg {
  width: 1.1rem;
  height: 1.1rem;
}

.notif-badge {
  position: absolute;
  top: -0.35rem;
  right: -0.35rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.28rem;
  border-radius: 999px;
  background: var(--bad);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  font-family: var(--mono);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.notif-panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  width: min(360px, calc(100vw - 1.5rem));
  max-height: min(420px, 70vh);
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
  z-index: 60;
  overflow: hidden;
}

.notif-panel[hidden] {
  display: none !important;
}

.notif-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.notif-panel-head strong {
  font-size: 0.85rem;
}

.notif-list {
  overflow: auto;
  flex: 1;
}

.notif-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid rgba(42, 51, 60, 0.7);
  cursor: pointer;
  text-align: left;
  width: 100%;
  border-left: none;
  border-right: none;
  border-top: none;
  background: transparent;
  color: inherit;
  font: inherit;
}

.notif-item:hover {
  background: rgba(61, 143, 209, 0.12);
}

.notif-item.unread {
  background: rgba(140, 90, 40, 0.22);
}

.notif-item-body {
  min-width: 0;
}

.notif-item-title {
  font-size: 0.84rem;
  font-weight: 560;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notif-item-meta {
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
}

.notif-empty {
  margin: 0;
  padding: 1.25rem 0.75rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.notif-empty[hidden] {
  display: none !important;
}

.notif-panel-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  padding: 0.45rem 0.65rem 0.55rem;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.12);
}

dialog.about-dialog {
  max-width: min(640px, 94vw);
  width: 100%;
}

.about-shell {
  display: flex;
  flex-direction: column;
}

.about-shell > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem 0.65rem;
  border-bottom: 1px solid var(--line);
}

.about-shell > header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.about-body {
  padding: 1rem 1.1rem 1.15rem;
  display: grid;
  gap: 0.85rem;
}

.about-lead {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink);
}

.about-points {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.about-points li + li {
  margin-top: 0.25rem;
}

.about-collab {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--ink);
}

.about-brands {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1rem;
  padding: 0.35rem 0 0.15rem;
}

.about-brand {
  margin: 0;
  display: grid;
  gap: 0.35rem;
  justify-items: center;
  min-width: 7.5rem;
}

.about-brand-plate {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 10rem;
  height: 4.25rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0.4rem;
  background: #fff;
  border: 1px solid var(--line);
  box-sizing: border-box;
}

.about-brand-plate img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.about-brand-plate-sncf {
  background: #000;
  border-color: rgba(255, 255, 255, 0.12);
  padding: 0.35rem 0.45rem;
}

.about-brand figcaption {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.about-brand-x {
  color: var(--muted);
  font-size: 1.1rem;
  opacity: 0.7;
}

.about-legal {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 560px) {
  .about-brand-x {
    display: none;
  }
}

dialog.notif-history-dialog {
  max-width: min(560px, 94vw);
  max-height: min(86vh, 720px);
  width: 100%;
}

.notif-history-shell {
  display: flex;
  flex-direction: column;
  max-height: min(86vh, 720px);
}

.notif-history-shell > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem 0.65rem;
  border-bottom: 1px solid var(--line);
}

.notif-history-shell > header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.notif-history-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
}

.notif-history-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.notif-history-actions {
  display: flex;
  gap: 0.35rem;
}

.notif-history-list {
  flex: 1;
  overflow: auto;
  min-height: 12rem;
  max-height: min(58vh, 480px);
  padding: 0.35rem 0.5rem 0.75rem;
}

.notif-history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.55rem;
  align-items: start;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  border-bottom: 1px solid rgba(155, 184, 208, 0.12);
  padding: 0.65rem 0.45rem;
  cursor: pointer;
}

.notif-history-item:hover {
  background: rgba(61, 143, 209, 0.08);
}

.notif-history-item.unread {
  background: rgba(61, 143, 209, 0.06);
}

.notif-history-item .notif-item-title {
  font-size: 0.88rem;
}

.notif-history-kind {
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  padding-top: 0.15rem;
}

.notif-history-time {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
  margin-top: 0.2rem;
}

.user-menu-wrap {
  position: relative;
}

.user-menu-btn {
  width: 2.2rem;
  height: 2.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg0);
  color: var(--ink);
  cursor: pointer;
}

.user-menu-btn svg {
  width: 1.15rem;
  height: 1.15rem;
}

.user-menu-btn:hover,
.user-menu-btn[aria-expanded='true'] {
  border-color: var(--accent);
  color: var(--accent);
}

.user-menu-panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  width: min(240px, calc(100vw - 1.5rem));
  padding: 0.35rem;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
  z-index: 70;
}

.user-menu-panel[hidden] {
  display: none !important;
}

.user-menu-head {
  display: grid;
  gap: 0.1rem;
  padding: 0.55rem 0.65rem 0.45rem;
}

.user-menu-head strong {
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-head span {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
}

a.user-menu-item {
  text-decoration: none;
  color: inherit;
  box-sizing: border-box;
}

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.84rem;
  padding: 0.5rem 0.65rem;
  border-radius: 0.28rem;
  cursor: pointer;
}

/* display:block ci-dessus écrase l’attribut HTML hidden — forcer le masquage */
.user-menu-item[hidden],
a.user-menu-item[hidden] {
  display: none !important;
}

.user-menu-item:hover,
.user-menu-item:focus-visible {
  background: rgba(61, 143, 209, 0.16);
  outline: none;
}

.user-menu-item.danger {
  color: #f0a0a0;
}

.user-menu-sep {
  height: 1px;
  margin: 0.25rem 0.4rem;
  background: var(--line);
}

.account-body {
  grid-template-columns: 1fr 1fr;
}

dialog#accountDialog {
  max-width: min(480px, 94vw);
}

.access-body {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(220px, 1.1fr);
  gap: 0;
  min-height: 320px;
}

.access-list-wrap {
  border-right: 1px solid var(--line);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.access-list-wrap h3,
.access-editor h3 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.access-list {
  margin-top: 0.55rem;
  overflow: auto;
  flex: 1;
  display: grid;
  gap: 0.25rem;
  align-content: start;
}

.access-user {
  display: grid;
  gap: 0.1rem;
  text-align: left;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0.5rem 0.55rem;
  border-radius: 0.3rem;
  cursor: pointer;
}

.access-user:hover,
.access-user.active {
  background: rgba(61, 143, 209, 0.14);
  border-color: rgba(61, 143, 209, 0.35);
}

.access-user strong {
  font-size: 0.86rem;
}

.access-user span {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
}

.access-editor {
  padding: 0.85rem 1rem 1rem;
  display: grid;
  gap: 0.65rem;
  align-content: start;
}

.access-editor label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.access-editor input,
.access-editor select {
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 0.5rem 0.55rem;
}

.access-editor .check-row {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--ink);
}

.access-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

@media (max-width: 720px) {
  .access-body {
    grid-template-columns: 1fr;
  }
  .access-list-wrap {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 180px;
  }
}

.toast-stack {
  position: fixed;
  top: calc(var(--header-h) + 0.75rem);
  right: 0.85rem;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: min(340px, calc(100vw - 1.5rem));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: start;
  padding: 0.75rem 0.8rem;
  background: var(--bg2);
  border: 1px solid rgba(61, 143, 209, 0.45);
  border-left: 3px solid var(--accent);
  border-radius: 0.4rem;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.22s ease;
}

.toast.is-out {
  animation: toast-out 0.18s ease forwards;
}

.toast.is-bad {
  border-color: rgba(220, 80, 80, 0.5);
  border-left-color: var(--bad);
}

.toast.is-bad .toast-ico {
  color: var(--bad);
}

.toast.is-warn {
  border-color: rgba(220, 170, 60, 0.5);
  border-left-color: var(--warn);
}

.toast.is-warn .toast-ico {
  color: var(--warn);
}

.toast.is-ok {
  border-color: rgba(62, 207, 142, 0.45);
  border-left-color: var(--ok);
}

.toast.is-ok .toast-ico {
  color: var(--ok);
}

.toast-ico {
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.1rem;
  color: var(--accent);
}

.toast-body {
  min-width: 0;
}

.toast-title {
  font-size: 0.86rem;
  font-weight: 600;
}

.toast-meta {
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
}

.toast-close {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.1rem;
}

.toast-close:hover {
  color: var(--ink);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 0;
  height: calc(100vh - var(--header-h) - var(--footer-h));
}

.app-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg1);
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.sidebar-block {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-block.grow {
  flex: 1;
  min-height: 0;
}

/* Gateway + horloges collés en bas du panneau, au-dessus du footer */
.sidebar-dock {
  flex-shrink: 0;
  margin-top: auto;
  margin-left: -0.75rem;
  margin-right: -0.75rem;
  margin-bottom: -0.75rem;
  padding: 0.55rem 0.75rem 0.65rem;
  border-top: 1px solid var(--line);
  background: var(--bg1);
}

.sidebar-dock .status-card.compact {
  border: none;
  background: transparent;
  border-radius: 0;
  padding: 0;
}

.sidebar-dock .clock-sync {
  margin-top: 0.25rem;
  padding-top: 0.3rem;
}

.sidebar-block h2,
.sidebar-head h2 {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.status-card {
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--bg2);
  padding: 0.65rem 0.75rem;
}

.status-card.compact {
  padding: 0.5rem 0.65rem;
}

.status-card.inline {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.status-card-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
  font-size: 0.9rem;
}

.status-card.compact .status-card-title {
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
}

.status-card.inline .status-card-title {
  margin-bottom: 0;
}

.status-dl {
  margin: 0;
  display: grid;
  gap: 0.25rem;
  font-size: 0.78rem;
}

.status-dl.horizontal {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
}

.clock-sync {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.clock-delta.ok {
  color: var(--ok);
}

.clock-delta.warn {
  color: var(--warn);
}

.clock-delta.bad {
  color: var(--bad);
}

.status-dl div {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.35rem;
}

.status-dl.horizontal div {
  grid-template-columns: auto auto;
}

.status-dl dt {
  margin: 0;
  color: var(--muted);
}

.status-dl dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.75rem;
}

.tree {
  overflow: auto;
  flex: 1;
  padding: 0.15rem 0.1rem 0.75rem;
}

.dt-tree,
.dt-tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.dt-tree ul {
  position: relative;
  margin-left: calc(var(--tree-indent) * 0.55);
  padding-left: calc(var(--tree-indent) * 0.85);
}

.dt-tree ul::before {
  content: '';
  position: absolute;
  left: 0.35rem;
  top: 0;
  bottom: 0.55rem;
  width: 1px;
  background: var(--line);
}

.dt-node {
  position: relative;
}

.dt-node > ul > .dt-node::before {
  content: '';
  position: absolute;
  left: -0.85rem;
  top: 0.95rem;
  width: 0.7rem;
  height: 1px;
  background: var(--line);
}

.dt-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 1.85rem;
  padding: 0.15rem 0.35rem 0.15rem 0.15rem;
  border-radius: 0.25rem;
  cursor: pointer;
  user-select: none;
}

.dt-row:hover,
.dt-row.is-active {
  background: rgba(61, 143, 209, 0.14);
}

.dt-row.is-active {
  outline: 1px solid rgba(61, 143, 209, 0.35);
}

.dt-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  flex-shrink: 0;
}

.dt-meta .dot {
  display: inline-block;
  align-self: center;
}

.dt-twist {
  width: 1rem;
  height: 1rem;
  border: none;
  padding: 0;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 0.15rem;
}

.dt-twist:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
}

.dt-twist svg {
  width: 0.7rem;
  height: 0.7rem;
  transition: transform 0.12s ease;
}

.dt-node.is-open > .dt-row > .dt-twist svg {
  transform: rotate(90deg);
}

.dt-twist.is-leaf {
  visibility: hidden;
  pointer-events: none;
}

.dt-ico {
  width: 1rem;
  height: 1rem;
  display: inline-flex;
  color: #7aa0c0;
}

.dt-ico svg {
  width: 100%;
  height: 100%;
}

.dt-row.level-org .dt-ico {
  color: #9bb8d0;
}

.dt-row.level-site .dt-ico {
  color: #7aa0c0;
}

.dt-row.level-group .dt-ico {
  color: #6b93b3;
}

.dt-row.level-device .dt-ico {
  color: #8a9aaa;
}

.dt-row.level-channel .dt-ico {
  color: #6a7a8a;
}

.dt-row.level-channel .dt-name {
  font-size: 0.8rem;
  color: #c5d0da;
}

.dt-name {
  flex: 1 1 auto;
  min-width: 3.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
}

.dt-twist,
.dt-ico {
  flex-shrink: 0;
}

.dt-row.level-org .dt-name {
  font-weight: 600;
  font-size: 0.88rem;
}

.dt-count {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  white-space: nowrap;
}

.dt-batt {
  font-family: var(--mono);
  font-size: 0.68rem;
  white-space: nowrap;
  color: var(--muted);
}

.dt-age {
  font-family: var(--mono);
  font-size: 0.66rem;
  white-space: nowrap;
  color: var(--muted);
  opacity: 0.85;
}

.dt-batt.ok {
  color: var(--ok);
}

.dt-batt.warn {
  color: var(--warn);
}

.dt-batt.bad {
  color: var(--bad);
}

.dt-batt.idle {
  color: var(--muted);
  opacity: 0.9;
}

.dt-occ {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(200, 64, 64, 0.85);
  border-radius: 0.2rem;
  padding: 0.1rem 0.28rem;
  white-space: nowrap;
  max-width: none;
}

.dt-row.is-occupied {
  background: rgba(200, 64, 64, 0.1);
}

.tables-split {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.tables-split:has(#sessionListWrap:not([hidden])) {
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.9fr);
}

.session-list-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-left: 1px solid var(--line);
  border-right: 0;
  border-bottom: 0;
  border-radius: 0;
  background: var(--bg1);
  overflow: hidden;
}

.session-list-wrap[hidden] {
  display: none !important;
}

.session-list-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  flex-shrink: 0;
}

.session-list-title {
  margin: 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  line-height: 1.3;
}

.session-list-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.sessions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.sessions-table th,
.sessions-table td {
  text-align: left;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--line);
}

.sessions-table tr.is-open td {
  color: #f0a0a0;
  font-weight: 600;
}

@media (max-width: 1100px) {
  .tables-split:has(#sessionListWrap:not([hidden])) {
    grid-template-columns: 1fr;
  }

  .session-list-wrap {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 40vh;
    order: 2;
  }
}

.events tbody tr.event-row.is-session-focus {
  background: rgba(61, 143, 209, 0.14);
}

.events .event-designation {
  cursor: pointer;
}

.status-dl .dot {
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.25rem;
}

.dt-online {
  color: var(--ok);
  font-family: var(--mono);
  font-size: 0.68rem;
  white-space: nowrap;
}

.dt-eye {
  width: 1rem;
  height: 1rem;
  opacity: 0.25;
  color: var(--accent);
  display: inline-flex;
}

.dt-eye.is-on {
  opacity: 1;
}

.dt-eye svg {
  width: 100%;
  height: 100%;
}

.dt-children[hidden] {
  display: none !important;
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg0);
}

.main-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem 1.25rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg1);
}

.toolbar-title {
  min-width: 10rem;
}

.main-toolbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: end;
  margin-left: auto;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.filter-group-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.filter-group-body {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.68rem;
  color: var(--muted);
}

.filter-field span {
  padding-left: 0.1rem;
}

.filter-field input,
.toolbar-actions input {
  font: inherit;
  font-size: 0.84rem;
  color: var(--ink);
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 0.4rem 0.5rem;
  min-width: 11.5rem;
}

.filter-sep {
  color: var(--muted);
  opacity: 0.7;
  padding-top: 0.9rem;
  font-size: 0.85rem;
}

.preset-row {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  overflow: hidden;
  background: var(--bg0);
}

.preset-btn {
  border: none;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.78rem;
  padding: 0.42rem 0.65rem;
  cursor: pointer;
  white-space: nowrap;
}

.preset-btn:last-child {
  border-right: none;
}

.preset-btn:hover,
.preset-btn.is-active {
  background: rgba(61, 143, 209, 0.18);
  color: #fff;
}

.filter-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding-bottom: 0.05rem;
}

.history-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.4rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg1);
}

.history-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.history-meta strong {
  color: var(--ink);
  font-weight: 600;
}

.pager {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.pager-info {
  min-width: 4.5rem;
  text-align: center;
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--muted);
}

.pager-size {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--muted);
  margin-right: 0.35rem;
}

.pager-size select {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink);
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  padding: 0.2rem 0.3rem;
}

.pager button:disabled {
  opacity: 0.35;
  cursor: default;
}

.device-status-bar {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg1);
}

.table-panel {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.events {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.events th,
.events td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.events tbody tr.is-occupied-event .event-designation {
  color: var(--danger, #e85d4c);
}
.events tbody tr.event-row {
  cursor: pointer;
  transition: background 0.12s ease;
}

.events tbody tr.event-row:hover,
.events tbody tr.event-row:focus-visible {
  background: rgba(61, 143, 209, 0.1);
  outline: none;
}

.events tbody tr.event-row.is-selected {
  background: rgba(61, 143, 209, 0.16);
}

.events td.event-row-open {
  color: var(--muted);
  text-align: right;
  width: 2rem;
  font-size: 1.1rem;
}

.events th.col-check,
.events td.col-check {
  width: 2rem;
  padding-right: 0.25rem;
  text-align: center;
  vertical-align: middle;
}

.events td.col-check input {
  cursor: pointer;
}

.bulk-bar {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
}

.bulk-bar .bulk-check {
  gap: 0.3rem;
  margin: 0;
  font-size: 0.8rem;
}

.event-detail-actions {
  display: flex;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.65rem 1rem 0.85rem;
  border-top: 1px solid var(--line);
}

.events th {
  position: sticky;
  top: 0;
  background: var(--bg2);
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  z-index: 1;
}

.events tbody tr:hover {
  background: rgba(61, 143, 209, 0.08);
}

.events tbody tr.flash,
.events tbody tr.alert-row {
  background: var(--row-alert);
}

.events tbody tr.flash {
  animation: flash 1.2s ease;
}

@keyframes flash {
  from {
    background: rgba(61, 143, 209, 0.28);
  }
  to {
    background: var(--row-alert);
  }
}

.mono {
  font-family: var(--mono);
  font-size: 0.8rem;
}

.muted-sm {
  color: var(--muted);
  font-size: 0.75rem;
}

.ghost,
.primary {
  font: inherit;
  cursor: pointer;
  border-radius: 0.3rem;
  padding: 0.45rem 0.75rem;
}

.ghost {
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--ink);
}

.ghost:hover {
  border-color: var(--accent);
}

.ghost.tiny,
.primary.tiny {
  padding: 0.28rem 0.5rem;
  font-size: 0.75rem;
}

.primary {
  border: none;
  background: linear-gradient(145deg, var(--accent), var(--accent-dim));
  color: #fff;
  font-weight: 600;
}

.danger {
  color: #f0a0a0;
  border-color: rgba(212, 91, 91, 0.45);
}

.empty {
  margin: 0;
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

.app-footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--bg1);
  border-top: 1px solid var(--line);
}

.footer-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.footer-conn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--ink);
  padding: 0.2rem 0.55rem;
  border-radius: 0.25rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  cursor: pointer;
  font: inherit;
  max-width: min(42vw, 28rem);
}

.footer-conn:hover,
.footer-conn:focus-visible {
  background: rgba(61, 143, 209, 0.14);
  outline: none;
}

.footer-conn .dot {
  width: 0.55rem;
  height: 0.55rem;
  flex-shrink: 0;
}

.footer-conn-bit {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  cursor: help;
  border-bottom: 1px dotted rgba(155, 184, 208, 0.35);
}

.footer-conn-bit:hover {
  color: var(--ink);
}

.footer-conn-sep {
  color: var(--line);
  flex-shrink: 0;
}

.footer-conn-action {
  flex-shrink: 0;
  font-weight: 600;
  color: var(--ink);
}

.clock-sync > div {
  cursor: help;
}

/* —— Carte GPS gateway —— */
.map-dialog {
  width: 99.5vw;
  height: 97vh;
  max-width: 99.5vw;
  max-height: 97vh;
  margin: 0.75vh auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  background: var(--bg1);
  color: var(--ink);
  inset: unset;
}

.map-dialog::backdrop {
  background: rgba(0, 0, 0, 0.82);
}

.map-shell {
  display: flex;
  flex-direction: column;
  height: 97vh;
  max-height: 97vh;
  box-sizing: border-box;
  padding: 0.65rem 0.85rem 0.7rem;
  gap: 0.45rem;
}

.map-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.map-head h2 {
  margin: 0;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.4rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.map-sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.map-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.map-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.85rem;
  align-items: end;
  padding: 0.35rem 0.15rem;
}

.map-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.map-controls select {
  min-width: 9rem;
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 0.25rem;
  padding: 0.3rem 0.45rem;
  font: inherit;
  font-size: 0.85rem;
  text-transform: none;
  letter-spacing: 0;
}

.map-meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

.map-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.map-canvas {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  overflow: hidden;
  background: #101418;
}

.map-canvas.placing,
.map-canvas.placing .leaflet-container {
  cursor: crosshair !important;
}

.map-place-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0.65rem;
  margin-bottom: 0.35rem;
  border: 1px solid rgba(232, 160, 75, 0.45);
  border-radius: 0.3rem;
  background: rgba(232, 160, 75, 0.12);
  color: #f0d2a8;
  font-size: 0.82rem;
}

.map-place-banner[hidden] {
  display: none !important;
}

.map-ctx-menu {
  position: fixed !important;
  z-index: 2147483646 !important;
  min-width: 12rem;
}

.map-ctx-menu:not([hidden]) {
  display: block !important;
}

.map-equip-popup .map-popup-move {
  margin-top: 0.45rem;
  width: 100%;
  border: 1px solid rgba(232, 160, 75, 0.55);
  background: rgba(232, 160, 75, 0.18);
  color: #f3d7b0;
  border-radius: 0.25rem;
  padding: 0.35rem 0.5rem;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.map-equip-popup .map-popup-move:hover {
  background: rgba(232, 160, 75, 0.32);
}

.leaflet-div-icon.map-pin-icon {
  background: transparent !important;
  border: none !important;
}

.leaflet-marker-icon.map-pin-icon {
  pointer-events: auto !important;
}

.map-pin {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0.12rem;
  width: 76px;
  height: 48px;
  box-sizing: border-box;
  pointer-events: auto;
  cursor: context-menu;
}

.map-pin-mark {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 0.35rem;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #0b1014;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

.map-pin.gateway .map-pin-mark {
  background: #3d8fd1;
  border-radius: 50%;
}

.map-pin.equipment .map-pin-mark {
  background: #e8a04b;
}

.map-pin.equipment.approx .map-pin-mark {
  background: #c9a227;
  border-style: dashed;
}

.map-pin-label {
  max-width: 7.2rem;
  padding: 0.1rem 0.35rem;
  border-radius: 0.2rem;
  background: rgba(12, 16, 20, 0.82);
  color: #e8eef4;
  font-size: 0.68rem;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.map-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.map-hint code {
  font-family: var(--mono);
  font-size: 0.72rem;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.map-swatch {
  width: 0.85rem;
  height: 0.35rem;
  border-radius: 2px;
  display: inline-block;
}

.map-swatch.urban {
  background: #3d8fd1;
}

.map-swatch.suburb {
  background: #c9a227;
}

.map-swatch.rural {
  background: #3ecf8e;
}

/* —— SCADA voies —— */
.scada-dialog {
  width: 99.5vw;
  height: 97vh;
  max-width: 99.5vw;
  max-height: 97vh;
  margin: 0.75vh auto;
  padding: 0;
  border: 1px solid #2a3a2a;
  border-radius: 0.25rem;
  background: #0a100c;
  color: #d7e8d7;
  inset: unset;
}

.scada-dialog::backdrop {
  background: rgba(0, 0, 0, 0.82);
}

.scada-shell {
  display: flex;
  flex-direction: column;
  height: 97vh;
  max-height: 97vh;
  box-sizing: border-box;
  padding: 0.85rem 1.1rem 0.75rem;
  gap: 0.75rem;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(40, 90, 50, 0.18), transparent 55%),
    linear-gradient(180deg, #0d1510 0%, #0a100c 100%);
}

.scada-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(70, 120, 70, 0.35);
  padding-bottom: 0.65rem;
}

.scada-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.scada-brand h2 {
  margin: 0;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #c8e8c8;
}

.scada-sub {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: #7a9a7a;
}

.scada-lamp {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: #3ecf8e;
  box-shadow: 0 0 10px #3ecf8e;
  flex-shrink: 0;
}

.scada-lamp.is-alarm {
  background: #d45b5b;
  box-shadow: 0 0 12px #d45b5b;
  animation: scada-blink 1.1s ease-in-out infinite;
}

.scada-kpis {
  display: flex;
  gap: 0.75rem;
  margin-left: auto;
}

.scada-kpi {
  min-width: 7.5rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid rgba(70, 120, 70, 0.4);
  background: rgba(0, 0, 0, 0.35);
  border-radius: 0.2rem;
}

.scada-kpi-label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7a9a7a;
}

.scada-kpi-value {
  font-size: 1.15rem;
  font-family: 'Barlow Condensed', sans-serif;
  color: #e8ffe8;
}

.scada-board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow: auto;
  padding: 0.35rem 0.15rem;
}

.scada-track {
  --track-accent: #3ecf8e;
  position: relative;
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr) 11rem;
  gap: 0.75rem;
  align-items: center;
  padding: 0.55rem 0.75rem;
  border: 1px solid rgba(70, 120, 70, 0.35);
  border-left: 4px solid var(--track-accent);
  border-radius: 0.2rem;
  background: rgba(8, 16, 10, 0.85);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.scada-track:hover,
.scada-track:focus-visible {
  background: rgba(20, 40, 24, 0.95);
  outline: none;
}

.scada-track.is-busy {
  --track-accent: #d45b5b;
  border-color: rgba(180, 70, 70, 0.45);
  background: rgba(40, 12, 12, 0.55);
}

.scada-track-id {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.scada-track-id strong {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.45rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #e8ffe8;
}

.scada-track-id span {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: #7a9a7a;
}

.scada-rails {
  position: relative;
  height: 3.4rem;
  border-radius: 0.15rem;
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 18px,
      rgba(120, 140, 100, 0.22) 18px,
      rgba(120, 140, 100, 0.22) 20px
    ),
    linear-gradient(
      180deg,
      transparent 0,
      transparent 28%,
      rgba(150, 170, 130, 0.55) 28%,
      rgba(150, 170, 130, 0.55) 34%,
      transparent 34%,
      transparent 66%,
      rgba(150, 170, 130, 0.55) 66%,
      rgba(150, 170, 130, 0.55) 72%,
      transparent 72%
    ),
    #121a14;
  overflow: hidden;
}

.scada-rails::before,
.scada-rails::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: rgba(180, 200, 160, 0.35);
}

.scada-rails::before {
  top: 30%;
}

.scada-rails::after {
  top: 68%;
}

.scada-train {
  --wagon: linear-gradient(180deg, #d07070 0%, #a83838 42%, #6e1f1f 100%);
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  width: min(72%, 28rem);
  height: 76%;
  display: flex;
  align-items: stretch;
  gap: 0.18rem;
  filter: drop-shadow(0 0 10px rgba(212, 91, 91, 0.55));
}

.scada-track:not(.is-busy) .scada-train {
  display: none;
}

.scada-track.is-busy .scada-rails {
  box-shadow: inset 0 0 24px rgba(180, 50, 50, 0.25);
}

.scada-wagon {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  background: var(--wagon);
  border: 1px solid #ffb0b0;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.05;
}

.scada-wagon::before {
  content: '';
  position: absolute;
  left: 10%;
  top: 18%;
  bottom: 28%;
  width: 14%;
  border-radius: 0.12rem;
  background: rgba(255, 220, 180, 0.22);
  border: 1px solid rgba(255, 230, 200, 0.25);
}

.scada-wagon::after {
  content: '';
  position: absolute;
  right: 12%;
  top: 18%;
  bottom: 28%;
  width: 14%;
  border-radius: 0.12rem;
  background: rgba(255, 220, 180, 0.16);
  border: 1px solid rgba(255, 230, 200, 0.2);
}

.scada-wagon.is-loco {
  flex: 1.15 1 0;
  border-radius: 1.1rem 0.28rem 0.28rem 0.35rem;
  padding-left: 0.35rem;
}

.scada-wagon.is-loco::before {
  left: 22%;
  width: 18%;
  top: 22%;
  bottom: 34%;
  background: rgba(120, 200, 255, 0.28);
}

.scada-wagon.is-loco::after {
  right: 10%;
  width: 28%;
  height: 0.35rem;
  top: auto;
  bottom: 18%;
  background: #f0c040;
  border: none;
  border-radius: 0.1rem;
  box-shadow: 0 0 8px rgba(240, 192, 64, 0.7);
}

.scada-wagon.is-mid {
  border-radius: 0.28rem;
}

.scada-wagon.is-tail {
  flex: 1.05 1 0;
  border-radius: 0.28rem 1.1rem 0.35rem 0.28rem;
}

.scada-wagon-label {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-size: clamp(0.7rem, 1.4vw, 0.92rem);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.scada-wagon-label small {
  font-size: 0.58em;
  letter-spacing: 0.14em;
  opacity: 0.92;
}

.scada-coupler {
  flex: 0 0 0.28rem;
  align-self: center;
  height: 28%;
  background: linear-gradient(180deg, #8a9098, #3a4048);
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.scada-status {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: flex-end;
}

.scada-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 0.15rem;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.scada-badge .dot {
  width: 0.55rem;
  height: 0.55rem;
}

.scada-badge.is-free {
  color: #0a100c;
  background: #3ecf8e;
}

.scada-badge.is-busy {
  color: #fff;
  background: #d45b5b;
  animation: scada-blink 1.4s ease-in-out infinite;
}

.scada-dur {
  font-family: var(--mono);
  font-size: 0.92rem;
  color: #e8ffe8;
}

.scada-meta {
  font-size: 0.72rem;
  color: #7a9a7a;
}

.scada-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  padding-top: 0.45rem;
  border-top: 1px solid rgba(70, 120, 70, 0.35);
  font-size: 0.78rem;
  color: #8aaa8a;
}

.scada-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.scada-swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 2px;
  display: inline-block;
}

.scada-swatch.free {
  background: #3ecf8e;
}

.scada-swatch.busy {
  background: #d45b5b;
}

.scada-swatch.pulse {
  background: #c9a227;
  animation: scada-blink 1.2s ease-in-out infinite;
}

.scada-hint {
  margin-left: auto;
  color: #6a8a6a;
  font-family: var(--mono);
  font-size: 0.7rem;
}

@keyframes scada-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

@media (max-width: 820px) {
  .scada-track {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .scada-status {
    align-items: flex-start;
    text-align: left;
  }

  .scada-hint {
    margin-left: 0;
  }
}

.charts-dialog {
  width: 99.5vw;
  height: 97vh;
  max-width: 99.5vw;
  max-height: 97vh;
  margin: 0.75vh auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  background: var(--bg1);
  color: var(--text);
  inset: unset;
}

.charts-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.charts-shell {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem 1rem 0.9rem;
  height: 97vh;
  max-height: 97vh;
  box-sizing: border-box;
  overflow: hidden;
}

.charts-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.charts-head h2 {
  margin: 0;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.45rem;
  font-weight: 700;
}

.charts-sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.charts-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
}

.charts-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.charts-toolbar select,
.charts-toolbar input[type='month'] {
  min-width: 11rem;
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 0.35rem;
  padding: 0.35rem 0.5rem;
  font: inherit;
}

.charts-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}

.charts-stat {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 0.4rem;
  padding: 0.55rem 0.65rem;
}

.charts-stat .k {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.charts-stat .v {
  font-family: var(--mono);
  font-size: 0.95rem;
  margin-top: 0.15rem;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 0.85rem;
  flex: 1 1 auto;
  min-height: 0;
}

@media (max-width: 860px) {
  .charts-grid {
    grid-template-columns: 1fr;
    overflow: auto;
  }
}

.charts-panel {
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.charts-panel h3 {
  margin: 0 0 0.65rem;
  font-size: 0.92rem;
  font-weight: 600;
  flex: 0 0 auto;
}

.charts-canvas-wrap {
  flex: 1 1 auto;
  min-height: 320px;
  position: relative;
}

.charts-canvas-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.charts-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.9rem;
  margin-top: 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.charts-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.charts-swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  display: inline-block;
}

.ctx-menu {
  position: fixed;
  z-index: 80;
  min-width: 11.5rem;
  padding: 0.3rem;
  margin: 0;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.ctx-menu[hidden] {
  display: none !important;
}

.ctx-menu button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.55rem;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  padding: 0.45rem 0.55rem;
  border-radius: 0.25rem;
  cursor: pointer;
}

.ctx-menu button:hover,
.ctx-menu button:focus-visible {
  background: rgba(61, 143, 209, 0.18);
  outline: none;
}

.ctx-menu button.danger {
  color: #f0a0a0;
}

.ctx-menu .ctx-sep {
  height: 1px;
  margin: 0.25rem 0.35rem;
  background: var(--line);
}

.ctx-menu .ctx-label {
  padding: 0.35rem 0.55rem 0.2rem;
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: var(--bg1);
  color: var(--ink);
  padding: 0;
  max-width: min(640px, 92vw);
  width: 100%;
}

dialog.ui-dialog {
  max-width: min(440px, 94vw);
  z-index: 80;
}

.ui-dialog-shell {
  display: flex;
  flex-direction: column;
}

.ui-dialog-body {
  padding: 0.85rem 1rem 0.35rem;
}

.ui-dialog-message {
  margin: 0 0 0.75rem;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.ui-dialog-input-wrap {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.ui-dialog-input-wrap input {
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 0.5rem 0.6rem;
}

.ui-dialog-actions {
  padding: 0.65rem 1rem 0.9rem;
}

dialog#settingsDialog {
  max-width: min(920px, 96vw);
  max-height: min(92vh, 900px);
}

.settings-shell {
  min-height: 480px;
  max-height: min(88vh, 860px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.settings-layout {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  min-height: 420px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  border-right: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.15);
}

.settings-nav-btn {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.86rem;
  padding: 0.55rem 0.65rem;
  border-radius: 0.3rem;
  cursor: pointer;
}

.settings-nav-btn:hover,
.settings-nav-btn.active {
  color: var(--ink);
  background: rgba(61, 143, 209, 0.14);
  border-color: rgba(61, 143, 209, 0.3);
}

.settings-panels {
  padding: 0.85rem 1rem 1rem;
  overflow: auto;
}

.settings-panel {
  display: none;
  gap: 0.65rem;
}

.settings-panel.active {
  display: grid;
  align-content: start;
}

.settings-panel h3 {
  margin: 0;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.settings-help {
  margin: 0 0 0.35rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.settings-help.muted-help {
  margin-top: -0.15rem;
  margin-bottom: 0.65rem;
}

.diag-launch {
  margin-top: 0.45rem;
  width: 100%;
}

.diag-summary {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.5rem 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  background: var(--bg0);
}

.diag-summary strong {
  font-weight: 600;
  line-height: 1.35;
}

.diag-list {
  display: grid;
  gap: 0.45rem;
  max-height: min(48vh, 420px);
  overflow: auto;
  margin-bottom: 0.5rem;
}

.diag-item {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: rgba(0, 0, 0, 0.12);
}

.diag-item.ok {
  border-color: rgba(72, 187, 120, 0.35);
}

.diag-item.warn {
  border-color: rgba(214, 158, 46, 0.45);
}

.diag-item.bad {
  border-color: rgba(220, 80, 80, 0.45);
}

.diag-item-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.diag-item-head strong {
  flex: 1;
  font-size: 0.88rem;
}

.diag-status {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.diag-detail {
  margin: 0.3rem 0 0;
  font-size: 0.82rem;
  color: var(--ink);
}

.diag-hint {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.settings-sub {
  margin: 1rem 0 0.45rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.gw-status-card {
  margin: 0.55rem 0 0.9rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--bg0);
}

.gw-status-head {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}

.gw-status-head .muted-sm {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--muted);
}

.gw-telemetry-dl {
  gap: 0.35rem 0.85rem;
}

.gw-telemetry-dl div {
  min-width: 10.5rem;
}

.gw-quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.readonly-grid input {
  opacity: 0.85;
  cursor: default;
}

.settings-panel textarea {
  font: inherit;
  font-size: 0.84rem;
  color: var(--ink);
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 0.45rem 0.55rem;
  width: 100%;
  resize: vertical;
  min-height: 4rem;
  box-sizing: border-box;
}

.settings-panel label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.settings-panel input:not([type='checkbox']),
.settings-panel select {
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 0.5rem 0.55rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.settings-grid .full {
  grid-column: 1 / -1;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  margin-top: 0.4rem;
}

.ok-inline {
  margin: 0;
  color: #9fe7c2;
  font-size: 0.84rem;
}

@media (max-width: 720px) {
  .settings-layout {
    grid-template-columns: 1fr;
  }
  .settings-nav {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.detail-form header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}

.detail-form h2 {
  margin: 0;
  font-size: 1rem;
}

.detail-form pre {
  margin: 0;
  padding: 1rem;
  max-height: 60vh;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

dialog.event-detail-dialog {
  max-width: min(560px, 94vw);
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: var(--bg1);
  color: var(--ink);
}

.event-detail-shell {
  display: flex;
  flex-direction: column;
  max-height: min(86vh, 720px);
}

.detail-sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.event-detail-body {
  padding: 0.85rem 1rem 1rem;
  overflow: auto;
}

.event-detail-body .status-dl {
  display: grid;
  gap: 0.45rem 1rem;
  margin: 0 0 0.85rem;
}

.event-detail-body .status-dl > div {
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr);
  gap: 0.35rem 0.75rem;
  align-items: baseline;
}

.event-detail-body .status-dl dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.event-detail-body .status-dl dd {
  margin: 0;
  font-size: 0.9rem;
  word-break: break-word;
  white-space: normal;
}

.payload-details {
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  background: var(--bg0);
  overflow: hidden;
}

.payload-details summary {
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
  user-select: none;
}

.payload-details pre {
  max-height: 36vh;
  border-top: 1px solid var(--line);
  margin: 0;
  padding: 0.75rem;
}

.edit-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 1rem;
}

.edit-body label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.edit-body label.full {
  grid-column: 1 / -1;
}

.edit-body input,
.edit-body textarea {
  font: inherit;
  font-size: 0.92rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  padding: 0.5rem 0.6rem;
}

.edit-foot {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
}

.edit-form .err {
  grid-column: 1 / -1;
  margin: 0;
  padding: 0.55rem 0.7rem;
  border-radius: 0.3rem;
  background: rgba(212, 91, 91, 0.15);
  color: #f0a0a0;
  font-size: 0.85rem;
  text-transform: none;
  letter-spacing: 0;
}

/* Login page reuse */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: radial-gradient(ellipse 70% 50% at 20% -10%, #1a3040 0%, transparent 55%), var(--bg0);
}

.login-box {
  width: min(380px, 100%);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(20, 24, 28, 0.92);
  padding: 1.5rem;
}

.events button {
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  padding: 0.2rem 0.45rem;
}

.events button:hover {
  color: var(--ink);
  border-color: var(--accent);
}

@media (max-width: 960px) {
  .app-header {
    grid-template-columns: 1fr;
    height: auto;
    padding: 0.65rem 0.85rem;
    gap: 0.5rem;
  }

  .app-body {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 120px);
  }

  .app-sidebar {
    max-height: 42vh;
  }

  .edit-body {
    grid-template-columns: 1fr;
  }
}
