/* ==========================================================================
   Design tokens (Element Plus variables overridden; shades = EP mixing rule)
   ========================================================================== */
:root {
  --el-color-primary: #2563eb;
  --el-color-primary-light-3: #6692f1;
  --el-color-primary-light-5: #92b1f5;
  --el-color-primary-light-7: #bed0f9;
  --el-color-primary-light-8: #d3e0fb;
  --el-color-primary-light-9: #e9effd;
  --el-color-primary-dark-2: #1e4fbc;

  --el-font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --el-font-size-extra-small: 13px;
  --el-font-size-small: 13px;
  --el-font-size-base: 14px;
  --el-font-size-medium: 16px;
  --el-font-size-large: 18px;
  --el-border-radius-base: 8px;
  --el-border-radius-small: 6px;
  --el-bg-color-page: #f4f6fa;
  --el-border-color-light: #e5e7eb;
  --el-border-color-lighter: #eef0f4;
  --el-fill-color-light: #f6f8fb;
  --el-text-color-primary: #111827;
  --el-text-color-regular: #374151;
  --el-text-color-secondary: #646b78;
  /* Select placeholders double as the current filter ("Tất cả thiết bị"), so they must stay readable. */
  --el-text-color-placeholder: #6b7280;

  --app-font-mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  /* Type scale: nothing renders below --fs-xs. */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 16px;
  --fs-lg: 18px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --app-radius-card: 12px;
  --app-header-h: 56px;
  --app-side-bg: #ffffff;
  --app-side-border: #e5e7eb;
  --app-side-text: #475569;
  --app-side-text-strong: #0f172a;
  --app-side-muted: #94a3b8;
  --app-side-hover: #f1f5f9;
  --app-side-active: #e9effd;
  --app-side-active-text: #1d4ed8;
  --app-focus-ring: 0 0 0 3px rgba(37, 99, 235, .35);
  --app-ease: cubic-bezier(.2, 0, 0, 1);
}

html.dark {
  --el-color-primary-light-3: #204baa;
  --el-color-primary-light-5: #1d3c80;
  --el-color-primary-light-7: #192c55;
  --el-color-primary-light-8: #17243f;
  --el-color-primary-light-9: #161a28;
  --el-color-primary-dark-2: #5182ef;

  --el-bg-color: #111827;
  --el-bg-color-overlay: #1a2233;
  --el-bg-color-page: #0b1120;
  --el-border-color: #334155;
  --el-border-color-light: #263142;
  --el-border-color-lighter: #1f2937;
  --el-border-color-extra-light: #1a2230;
  --el-fill-color: #1e293b;
  --el-fill-color-light: #172033;
  --el-fill-color-lighter: #141c2c;
  --el-fill-color-blank: #111827;
  --el-text-color-primary: #e5e7eb;
  --el-text-color-regular: #cbd5e1;
  --el-text-color-secondary: #94a3b8;
  --el-mask-color: rgba(2, 6, 23, .7);

  --app-side-bg: #0f172a;
  --app-side-border: #1e293b;
  --app-side-text: #cbd5e1;
  --app-side-text-strong: #f8fafc;
  --app-side-muted: #64748b;
  --app-side-hover: rgba(148, 163, 184, .12);
  --app-side-active: rgba(37, 99, 235, .24);
  --app-side-active-text: #ffffff;
}

/* ==========================================================================
   Base
   ========================================================================== */
[v-cloak] { display: none; }
html, body, #app { height: 100%; margin: 0; }
body {
  font-family: var(--el-font-family);
  font-size: var(--fs-base);
  line-height: 1.55;
  background: var(--el-bg-color-page);
  color: var(--el-text-color-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--el-color-primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

:focus-visible { outline: none; box-shadow: var(--app-focus-ring); border-radius: 6px; }
input:focus-visible, textarea:focus-visible, .el-input__inner:focus-visible, .el-textarea__inner:focus-visible {
  box-shadow: none; border-radius: 0;
}
.el-textarea__inner:focus-visible { box-shadow: 0 0 0 1px var(--el-color-primary) inset; border-radius: var(--el-border-radius-base); }
.el-button:focus-visible, .el-menu-item:focus-visible, .el-tabs__item:focus-visible {
  outline: none; box-shadow: var(--app-focus-ring);
}

.mono, pre.json, .code-input textarea { font-family: var(--app-font-mono); font-size: var(--fs-sm); }
.num, .el-table, .stat-card .value, .el-statistic__content, .el-pagination { font-variant-numeric: tabular-nums; }
.muted { color: var(--el-text-color-secondary); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ==========================================================================
   App shell
   ========================================================================== */
.layout { height: 100vh; }

.aside {
  background: var(--app-side-bg);
  border-right: 1px solid var(--app-side-border);
  transition: width .2s var(--app-ease);
  overflow-x: hidden;
  display: flex; flex-direction: column;
}
.brand {
  height: var(--app-header-h); flex: none;
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  font-weight: 700; font-size: var(--fs-md); letter-spacing: .2px; color: var(--app-side-text-strong);
  border-bottom: 1px solid var(--app-side-border); white-space: nowrap;
}
.brand-logo {
  width: 50px; height: 50px; flex: none; display: block;
  object-fit: contain; user-select: none; -webkit-user-drag: none;
  filter: drop-shadow(0 1px 1px rgba(15, 23, 42, .25));
}
.aside.collapsed .brand { padding: 0 7px; }
.brand-sub { display: block; font-size: var(--fs-xs); font-weight: 500; color: var(--app-side-muted); letter-spacing: 0; }

.side-menu {
  --el-menu-bg-color: transparent;
  --el-menu-text-color: var(--app-side-text);
  --el-menu-hover-text-color: var(--app-side-text-strong);
  --el-menu-hover-bg-color: var(--app-side-hover);
  --el-menu-active-color: var(--app-side-active-text);
  --el-menu-item-height: 42px;
  --el-menu-base-level-padding: 18px;
  border-right: none; flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 0 12px;
}
.side-menu .el-menu-item-group__title {
  padding: 14px 0 6px 20px !important;
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--app-side-muted);
}
.side-menu.el-menu--collapse .el-menu-item-group__title {
  padding: 0 !important; height: 1px; margin: 8px 16px; overflow: hidden; background: var(--app-side-border);
}
.side-menu.el-menu--collapse .el-menu-item-group:first-child .el-menu-item-group__title { visibility: hidden; margin: 2px 16px; }
.side-menu .el-menu-item {
  margin: 2px 8px; border-radius: 8px; height: var(--el-menu-item-height); line-height: var(--el-menu-item-height);
  transition: background-color .15s var(--app-ease), color .15s var(--app-ease);
}
.side-menu .el-menu-item { font-size: var(--fs-base); }
.side-menu .el-menu-item .el-icon { font-size: 18px; }
.side-menu .el-menu-item.is-active { background: var(--app-side-active); font-weight: 600; }
.side-menu .el-menu-item.is-active::before {
  content: ""; position: absolute; left: -8px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--el-color-primary);
}
.side-menu.el-menu--collapse { width: 64px; }
.side-menu.el-menu--collapse .el-menu-item { margin: 2px 8px; padding: 0 !important; justify-content: center; }
.side-menu.el-menu--collapse .el-menu-item .el-icon { margin: 0; }
.side-menu.el-menu--collapse .el-menu-tooltip__trigger { padding: 0 !important; justify-content: center; width: 100%; }

.menu-drawer .el-drawer { background: var(--app-side-bg); }
.menu-drawer .el-drawer__body { padding: 0; display: flex; flex-direction: column; }
.drawer-link {
  display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 0 8px 12px; padding: 0 12px 0 18px; border-radius: 8px;
  color: var(--app-side-text); font-size: var(--fs-base);
}
.drawer-link:hover { background: var(--app-side-hover); color: var(--app-side-text-strong); text-decoration: none; }
.drawer-link .el-icon { font-size: 18px; }
.drawer-link-note { margin-left: auto; font-size: var(--fs-xs); color: var(--app-side-muted); }

.header {
  height: var(--app-header-h); display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--el-bg-color); border-bottom: 1px solid var(--el-border-color-light); padding: 0 16px;
}
.header-left, .header-right { display: flex; align-items: center; gap: 10px; }
.header-left { min-width: 0; }
.header-right .el-button + .el-button { margin-left: 0; }
.crumb { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.page-title { font-size: var(--fs-lg); font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn.el-button { width: 36px; height: 36px; padding: 0; border-radius: 8px; }
.icon-btn .el-icon { font-size: 18px; }
.text-btn.el-button { padding: 0 12px; border-radius: 8px; }
.text-btn > span { display: inline-flex; align-items: center; gap: 6px; }
.text-btn .el-icon { font-size: 16px; }
.header .text-btn.el-button { height: 36px; color: var(--el-text-color-regular); text-decoration: none; }

/* Dot only; the state text is in the tooltip and for screen readers. */
.live-pill {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--el-color-danger); flex: none; }
.live-pill.on .live-dot { background: var(--el-color-success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--el-color-success) 25%, transparent); }

.user-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 8px 0 4px; border-radius: 8px;
  cursor: pointer; color: var(--el-text-color-regular); border: none; background: none; font: inherit;
}
.user-chip:hover { background: var(--el-fill-color-light); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--el-color-primary-light-9); color: var(--el-color-primary); font-weight: 700; font-size: var(--fs-sm); text-transform: uppercase;
}

.main { padding: 20px; overflow: auto; }

/* ==========================================================================
   Surfaces & components
   ========================================================================== */
.el-card { border-radius: var(--app-radius-card); border-color: var(--el-border-color-light); }
.el-card.is-always-shadow, .el-card.is-hover-shadow:hover { box-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .06); }
.el-card__header { padding: 14px 18px; font-weight: 600; font-size: var(--fs-md); border-bottom-color: var(--el-border-color-lighter); }
.el-card__body { padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.head-actions { display: inline-flex; align-items: center; gap: 8px; margin: -5px 0; }
.head-actions .el-button { margin: 0; }
.head-actions .el-badge { display: inline-flex; }

.el-table {
  --el-table-header-bg-color: var(--el-fill-color-light);
  --el-table-header-text-color: var(--el-text-color-secondary);
  --el-table-row-hover-bg-color: var(--el-fill-color-light);
  --el-table-border-color: var(--el-border-color-light);
  --el-table-tr-bg-color: var(--el-bg-color);
  --el-table-bg-color: var(--el-bg-color);
  border: 1px solid var(--el-table-border-color);
  border-radius: 10px;
}
.el-table, .el-table--small, .el-table--large { font-size: var(--fs-base); color: var(--el-text-color-regular); }
/* EP draws its own bottom line under the last row; the outer border replaces it. */
.el-table__inner-wrapper::before { display: none; }
.el-table tr:last-child > td.el-table__cell { border-bottom: none; }
/* Full grid: vertical rules between columns; the outer border closes the right edge. */
.el-table:not(.el-table--border) .el-table__cell { border-right: 1px solid var(--el-table-border-color); }
.el-table:not(.el-table--border) .el-table__cell:last-child,
.el-table:not(.el-table--border) .el-table__cell.gutter { border-right: none; }
.el-table th.el-table__cell {
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
  padding: 10px 0; border-bottom: 1px solid var(--el-border-color-light);
}
.el-table td.el-table__cell { padding: 11px 0; vertical-align: middle; }
.el-table--small th.el-table__cell { padding: 8px 0; }
.el-table--small td.el-table__cell { padding: 9px 0; }
.el-table .cell { white-space: nowrap; padding: 0 12px; line-height: 1.5; }
.el-table th.el-table__cell:first-child .cell, .el-table td.el-table__cell:first-child .cell { padding-left: 16px; }
.el-table th.el-table__cell:last-child .cell, .el-table td.el-table__cell:last-child .cell { padding-right: 16px; }
.el-table .el-table-column--selection .cell { padding: 0 8px 0 14px !important; }
.el-table td.el-table__cell .el-tag + .el-tag { margin-left: 4px; }
.el-table__empty-text { padding: 24px 0; color: var(--el-text-color-secondary); line-height: 1.5; }
.el-card .el-table { margin: 0; }
.el-table td.num, .el-table th.num { font-variant-numeric: tabular-nums; }
.el-table td.strong .cell { font-weight: 650; color: var(--el-text-color-primary); }
.el-checkbox__inner { border-radius: 3px; }
.el-input-group__prepend, .el-input-group__append { color: var(--el-text-color-secondary); }
.channel-cell { display: inline-flex; align-items: center; gap: 6px; }
.row-actions { display: inline-flex; gap: 8px; }
.row-actions .el-button { margin: 0; width: 32px; height: 32px; padding: 0; border-radius: 8px; }
.row-actions .el-button .el-icon { font-size: 15px; }
.row-actions .el-button:not(.el-button--danger) { --el-button-bg-color: var(--el-bg-color); --el-button-hover-text-color: var(--el-color-primary); --el-button-hover-border-color: var(--el-color-primary-light-5); --el-button-hover-bg-color: var(--el-color-primary-light-9); }
.clickable-row { cursor: pointer; }

.el-tag--small { font-size: var(--fs-xs); }
/* EP hardcodes 12px for size="small"; lift controls to the scale's secondary step. */
.el-button--small, .el-input--small, .el-select--small, .el-radio-button--small .el-radio-button__inner,
.el-checkbox--small .el-checkbox__label, .el-pagination--small, .el-date-editor--small .el-range-input { font-size: var(--fs-sm); }
.el-descriptions--small, .el-descriptions--small .el-descriptions__cell,
.el-descriptions--small .el-descriptions__label, .el-descriptions--small .el-descriptions__content { font-size: var(--fs-base); }
.el-tabs__item { font-size: var(--fs-base); }
.el-form-item__label { font-size: var(--fs-base); }
.el-dialog__title, .el-drawer__title { font-size: var(--fs-lg); }
.el-dialog { border-radius: 14px; max-width: calc(100vw - 24px); }
.el-dialog__title { font-weight: 650; }
.el-drawer__title { font-weight: 650; color: var(--el-text-color-primary); }
.el-descriptions { overflow-x: auto; }
.el-descriptions__content { word-break: break-word; }
.el-descriptions__label.el-descriptions__cell { color: var(--el-text-color-secondary); font-weight: 500; }
.el-tabs__item { font-weight: 500; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar .el-button + .el-button { margin-left: 0; }
.range-picker.el-date-editor.el-input__wrapper { width: 340px; flex: none; }
.range-picker .el-range-input { font-variant-numeric: tabular-nums; }
.tool-icon.el-button { width: 32px; height: 32px; padding: 0; border-radius: 8px; }
.tool-icon .el-icon { font-size: 16px; }
.tool-icon.is-loading .el-icon { margin: 0; }
.toolbar .el-badge { display: inline-flex; }
.scroll-dialog .el-dialog__body { max-height: calc(88vh - 70px); overflow: auto; }

.mode-pill {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; cursor: help;
  color: color-mix(in srgb, var(--tone) 70%, var(--el-text-color-primary));
  background: color-mix(in srgb, var(--tone) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--tone) 25%, transparent);
}
.mode-pill.ok { --tone: var(--el-color-success); }
.mode-pill.warn { --tone: var(--el-color-warning); }
.mode-pill .el-icon { font-size: 16px; }

pre.json {
  margin: 0; padding: 12px 14px; background: var(--el-fill-color-light); border: 1px solid var(--el-border-color-lighter);
  border-radius: 8px; white-space: pre-wrap; word-break: break-all; max-height: 520px; overflow: auto; line-height: 1.55;
}

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat-grid > div { display: flex; min-width: 0; }
.stat-grid .stat-card { flex: 1; }
@media (max-width: 1280px) { .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.stat-card .el-card__body { padding: 16px 18px; }
.stat-card .label { color: var(--el-text-color-secondary); font-size: var(--fs-base); font-weight: 500; }
.stat-card .value { font-size: 28px; font-weight: 700; line-height: 1.2; margin-top: 6px; letter-spacing: -.3px; }
.stat-card .sub { color: var(--el-text-color-secondary); font-size: var(--fs-sm); margin-top: 4px; }
.stat-icon {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; font-size: 20px;
  color: var(--tone, var(--el-color-primary));
  background: color-mix(in srgb, var(--tone, var(--el-color-primary)) 12%, transparent);
}

/* Device detail */
.detail-head {
  --tone: var(--el-color-info);
  --tone-text: var(--app-info-text);
  margin-bottom: 12px; background: var(--el-bg-color); border: 1px solid var(--el-border-color-light);
  border-radius: var(--app-radius-card); overflow: hidden;
}
.detail-head.is-ok { --tone: var(--el-color-success); --tone-text: var(--app-ok-text); }
.detail-head.is-bad { --tone: var(--el-color-danger); --tone-text: var(--app-bad-text); }
.dh-top { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.detail-title { min-width: 0; flex: 1; }
.detail-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: var(--fs-xl); font-weight: 650; line-height: 1.3; }
.dh-status {
  display: flex; align-items: center; gap: 7px; margin-top: 2px; font-size: var(--fs-sm); font-weight: 500;
  color: var(--tone-text);
}
.dh-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--tone); flex: none; }
.detail-head.is-ok .dh-status::before { box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 20%, transparent); }
.detail-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.detail-actions .el-button + .el-button { margin-left: 0; }
.dh-labeled { display: flex; align-items: center; gap: 8px; }
.dh-group { display: inline-flex; border: 1px solid var(--el-border-color); border-radius: 9px; overflow: hidden; }
.dh-group .icon-btn.el-button { border: none; border-radius: 0; }
.dh-group > * + * { border-left: 1px solid var(--el-border-color); }
.dh-kv { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; margin: 0; border-top: 1px solid var(--el-border-color-lighter); }
.dh-kv > div { min-width: 0; padding: 8px 16px; border-right: 1px solid var(--el-border-color-lighter); }
.dh-kv > div:last-child { border-right: none; }
.dh-kv dt { font-size: var(--fs-xs); color: var(--el-text-color-secondary); text-transform: uppercase; letter-spacing: .04em; }
.dh-kv dd {
  display: flex; align-items: center; gap: 4px; margin: 2px 0 0; min-height: 22px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dh-kv dd .mono { overflow: hidden; text-overflow: ellipsis; }
.dh-copy.el-button { height: 22px; padding: 0 4px; color: var(--el-text-color-secondary); }
.el-dropdown-menu__item.danger-item { color: var(--el-color-danger); }
.el-dropdown-menu__item.danger-item:not(.is-disabled):hover,
.el-dropdown-menu__item.danger-item:not(.is-disabled):focus {
  color: var(--el-color-danger); background: var(--el-color-danger-light-9);
}

/* Device detail grid: meters lead on the left, device info sits beside them */
.dd-grid {
  display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas: "meter info"; align-items: start;
}
.dd-meters { grid-area: meter; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.dd-info { grid-area: info; min-width: 0; }
.dd-card {
  background: var(--el-bg-color); border: 1px solid var(--el-border-color-light);
  border-radius: var(--app-radius-card); overflow: hidden;
}
.dd-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; border-bottom: 1px solid var(--el-border-color-lighter); font-weight: 600;
}

/* EMR meter: the whole card takes the pump state colour */
.meter {
  --tone: var(--el-color-primary);
  --tone-text: var(--app-pri-text);
  border-radius: 14px; overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--tone) 35%, transparent);
  background: var(--el-bg-color);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px -14px color-mix(in srgb, var(--tone) 50%, transparent);
}
.meter.filling { --tone: var(--el-color-success); --tone-text: var(--app-ok-text); }
.meter.eot { --tone: var(--el-color-warning); --tone-text: var(--app-warn-text); }
.meter.offline { --tone: var(--el-color-danger); --tone-text: var(--app-bad-text); }
.meter.stale { --tone: var(--el-color-info); --tone-text: var(--app-info-text); }
.meter-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px;
  background: color-mix(in srgb, var(--tone) 9%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--tone) 18%, transparent);
}
.meter-ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; background: var(--tone); flex: none; }
.meter-ico .el-icon { font-size: 18px; }
.meter-title { font-weight: 650; font-size: var(--fs-md); }
.meter-pump { color: var(--el-text-color-secondary); font-size: var(--fs-sm); }
.meter-state {
  margin-left: auto; display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 12px;
  border-radius: 999px; font-weight: 600; font-size: var(--fs-sm); white-space: nowrap;
  color: var(--tone-text); background: color-mix(in srgb, var(--tone) 14%, var(--el-bg-color));
  border: 1px solid color-mix(in srgb, var(--tone) 40%, transparent);
}
.meter-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.meter.filling .meter-dot { animation: meter-pulse 1.3s ease-out infinite; }
@keyframes meter-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 60%, transparent); }
  100% { box-shadow: 0 0 0 9px color-mix(in srgb, currentColor 0%, transparent); }
}
/* The EMR is drawn as the physical unit: dark housing, LEDs, a grey-green 7-segment LCD and keypad. */
.meter-stage {
  display: flex; flex-direction: column; justify-content: center; padding: 14px;
  background: radial-gradient(120% 90% at 50% 0%, var(--el-bg-color), var(--el-fill-color-light));
}
.emr-unit {
  box-sizing: border-box; width: 100%; border-radius: 18px; padding: 14px 16px 16px;
  background: linear-gradient(180deg, #3b4250 0%, #262b35 55%, #1d2129 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), inset 0 -2px 0 rgba(0, 0, 0, .4), 0 10px 26px -10px rgba(15, 23, 42, .55);
}
.emr-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; padding: 0 4px; }
.emr-brand { white-space: nowrap; font-weight: 800; letter-spacing: .14em; font-size: 12px; color: #cbd5e1; }
.emr-brand small { font-size: 11px; font-weight: 600; letter-spacing: .06em; color: #a3b1c6; }
.emr-leds { margin-left: auto; display: flex; gap: 14px; }
.emr-led { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em; color: #a3b1c6; }
.emr-led i { width: 9px; height: 9px; border-radius: 50%; background: #3f4654; box-shadow: inset 0 1px 1px rgba(0, 0, 0, .6); }
.emr-led.g.on i { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.emr-led.a.on i { background: #fbbf24; box-shadow: 0 0 6px #fbbf24; }
.emr-led.r.on i { background: #f87171; box-shadow: 0 0 6px #f87171; }
.emr-led.blink i { animation: emr-blink 1s steps(2, start) infinite; }
@keyframes emr-blink { to { visibility: hidden; } }
.emr-lcd {
  --seg-on: #1d2a1a; --lcd-dim: rgba(29, 42, 26, .5); --lcd-label: rgba(29, 42, 26, .8);
  box-sizing: border-box; position: relative; container-type: inline-size; border-radius: 10px; padding: 12px 16px; overflow: hidden;
  border: 3px solid #11141a; color: var(--seg-on);
  background: linear-gradient(180deg, #c5d1b8, #b3c1a4); box-shadow: inset 0 2px 10px rgba(0, 0, 0, .35);
}
.emr-lcd::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(160deg, rgba(255, 255, 255, .18) 0%, rgba(255, 255, 255, 0) 40%);
}
.meter.offline .emr-lcd { background: linear-gradient(180deg, #a9b29f, #9aa391); }
.meter.offline .emr-content { visibility: hidden; }
.meter.stale .emr-lcd { filter: grayscale(1) opacity(.7); }
.emr-ann { display: flex; gap: 12px; font-size: 11px; font-weight: 700; letter-spacing: .1em; color: var(--lcd-dim); }
.emr-ann .on { color: var(--seg-on); }
.emr-ann .right { margin-left: auto; }
.emr-main { display: flex; align-items: flex-end; justify-content: flex-end; gap: 10px; margin: 6px 0 4px; }
.emr-main-unit { font-size: clamp(16px, 4.5cqw, 28px); font-weight: 800; line-height: 1; padding-bottom: .2em; }
.seg { display: inline-flex; align-items: flex-end; gap: .07em; line-height: 0; }
.seg svg { height: 1em; width: .62em; fill: currentColor; }
.seg-main { font-size: clamp(48px, 17cqw, 150px); }
.emr-sub {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 6px 0 0; padding-top: 8px;
  border-top: 1px dashed var(--lcd-dim);
}
.emr-sub > div { min-width: 0; }
.emr-sub dt { font-size: 11px; font-weight: 700; letter-spacing: .1em; color: var(--lcd-label); }
.emr-sub dd { margin: 4px 0 0; font-size: clamp(16px, 4cqw, 30px); overflow: hidden; }
.emr-msg { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; }
.emr-msg b { font-size: 22px; letter-spacing: .12em; color: #5a1d1d; }
.emr-msg span { font-size: 12px; color: #4b5563; }
.emr-keys { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.emr-key {
  height: 26px; min-width: 52px; padding: 0 10px; border-radius: 7px; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; color: #cbd5e1;
  background: linear-gradient(180deg, #4b5463, #343a46); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15), 0 2px 0 #12151b;
}
.emr-key.green { background: linear-gradient(180deg, #15803d, #14532d); color: #dcfce7; }
.emr-key.red { background: linear-gradient(180deg, #b91c1c, #7f1d1d); color: #fee2e2; }

.info-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 14px; margin: 0; padding: 10px 16px 12px; }
.info-grid > div { min-width: 0; }
.info-grid .wide { grid-column: span 2; }
.info-grid dt { font-size: var(--fs-xs); color: var(--el-text-color-secondary); margin-bottom: 2px; }
.info-grid dt, .info-grid dd { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info-grid dd { margin: 0; font-weight: 500; }
.dd-card-head .head-icon.el-button { width: 28px; height: 28px; margin: -4px 0; }

@media (min-width: 1400px) { .dd-grid { grid-template-columns: minmax(0, 1fr) 380px; } }
@media (min-width: 1680px) {
  .dd-grid { grid-template-columns: minmax(0, 1fr) 440px; gap: 18px; }
  .detail-name { font-size: var(--fs-2xl); }
  .meter-head { padding: 16px 24px; }
  .meter-title { font-size: 19px; }
  .meter-ico { width: 36px; height: 36px; }
  .meter-state { height: 34px; font-size: 15px; padding: 0 16px; }
  .dd-card-head { padding: 12px 20px; font-size: var(--fs-md); }
  .info-grid { padding: 12px 20px 14px; }
}
@media (min-width: 2200px) {
  .dd-grid { grid-template-columns: minmax(0, 1fr) 560px; gap: 24px; }
  .detail-name { font-size: 28px; }
  .meter-head { padding: 20px 30px; }
  .meter-title { font-size: 22px; }
  .meter-ico { width: 42px; height: 42px; }
  .meter-ico .el-icon { font-size: 24px; }
  .meter-state { height: 40px; font-size: 17px; padding: 0 20px; }
  .emr-unit { padding: 18px 22px 22px; }
  .dd-card-head { padding: 14px 26px; font-size: var(--fs-lg); }
  .info-grid { padding: 14px 26px 16px; gap: 12px 20px; }
  .info-grid dd { font-size: var(--fs-md); }
}
@media (max-width: 1200px) {
  .dd-grid { grid-template-columns: minmax(0, 1fr) 300px; }
}
/* Tablet portrait and below: one column */
@media (max-width: 900px) {
  .dd-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "meter" "info"; }
  .info-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dh-kv { grid-template-columns: 1fr 1fr; }
  .dh-kv > div:nth-child(2) { border-right: none; }
  .dh-kv > div:nth-child(-n + 2) { border-bottom: 1px solid var(--el-border-color-lighter); }
}
@media (max-width: 600px) {
  .el-checkbox { height: auto; min-height: 32px; white-space: normal; }
  .el-checkbox__label { line-height: 1.4; }
  .dh-top { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .detail-title { order: 3; flex-basis: 100%; }
  .detail-actions { display: contents; }
  .dh-labeled { order: 1; margin-left: auto; }
  .dh-group { order: 1; }
  .dh-kv { grid-template-columns: 1fr; }
  .dh-kv > div { border-right: none; border-bottom: 1px solid var(--el-border-color-lighter); padding: 7px 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  .dh-kv > div:last-child { border-bottom: none; }
  .dh-kv dd { margin: 0; }
  .detail-name { font-size: var(--fs-lg); }
  .meter-head { padding: 10px 14px; flex-wrap: wrap; }
  .meter-state { height: 26px; font-size: var(--fs-xs); }
  .meter-stage { padding: 12px; }
  .emr-unit { padding: 10px; border-radius: 14px; }
  .emr-leds { gap: 8px; }
  .emr-led { gap: 4px; letter-spacing: .04em; }
  .emr-lcd { padding: 10px 12px; }
  .emr-sub { grid-template-columns: 1fr 1fr; }
  .emr-sub > div:last-child { grid-column: 1 / -1; }
  .emr-key { min-width: 0; flex: 1; }
  .info-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px 14px; gap: 12px; }
}

/* Event list */
.event-list { max-height: 420px; overflow: auto; }
.event-row { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--el-border-color-lighter); font-size: var(--fs-base); }
.event-row .time { color: var(--el-text-color-secondary); font-family: var(--app-font-mono); font-size: var(--fs-sm); flex: none; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }

/* ==========================================================================
   Login
   ========================================================================== */
.login-wrap {
  --login-bg: #eef2f7; --login-glow: rgba(37, 99, 235, .14); --login-glow-2: rgba(14, 165, 233, .08);
  --login-grid: rgba(15, 23, 42, .06); --login-grid-opacity: .6; --login-foot: #64748b;
  --login-shadow: 0 24px 60px -24px rgba(15, 23, 42, .25), 0 0 0 1px rgba(15, 23, 42, .06);
  position: relative; overflow: hidden; min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(60% 45% at 50% 0%, var(--login-glow), transparent 70%),
    radial-gradient(50% 40% at 50% 100%, var(--login-glow-2), transparent 70%),
    var(--login-bg);
}
html.dark .login-wrap {
  --login-bg: #05080f; --login-glow: rgba(37, 99, 235, .2); --login-glow-2: rgba(14, 165, 233, .07);
  --login-grid: rgba(148, 163, 184, .1); --login-grid-opacity: .18; --login-foot: #94a3b8;
  --login-shadow: 0 40px 80px -30px rgba(0, 0, 0, .6), 0 0 0 1px rgba(255, 255, 255, .06);
}
.login-wrap::before {
  content: ""; position: absolute; inset: 0; opacity: var(--login-grid-opacity); pointer-events: none;
  background-image:
    linear-gradient(var(--login-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--login-grid) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(60% 60% at 50% 40%, #000, transparent);
}
.login-box { position: relative; width: 100%; max-width: 420px; }
.login-card { padding: 18px 32px 26px; border-radius: 20px; background: var(--el-bg-color-overlay); box-shadow: var(--login-shadow); }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 4px; text-align: center; }
.login-logo { width: 64px; height: 52px; object-fit: contain; user-select: none; -webkit-user-drag: none; filter: drop-shadow(0 4px 10px rgba(37, 99, 235, .35)); }
.login-card h1 { margin: 0 0 6px; text-align: center; font-size: 20px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.login-card .lead { margin: 0 0 22px; text-align: center; color: var(--el-text-color-secondary); }
.login-card .el-form-item__label { font-weight: 600; }
.login-card .el-input { --el-input-height: 44px; --el-input-border-radius: 10px; }
.login-card .el-input__wrapper.is-focus { box-shadow: 0 0 0 1px var(--el-color-primary) inset, 0 0 0 3px rgba(37, 99, 235, .18); }
.login-error { margin-bottom: 16px; border-radius: 10px; }
.login-submit { width: 100%; height: 44px; margin-top: 4px; border-radius: 10px; font-weight: 600; box-shadow: 0 6px 16px -6px rgba(37, 99, 235, .6); }
.caps-hint { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--app-warn-text); margin-top: 6px; }
.login-foot { margin-top: 18px; display: flex; justify-content: center; gap: 18px; font-size: var(--fs-sm); color: var(--login-foot); }
.login-live { display: inline-flex; align-items: center; gap: 6px; }
.login-live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }

@media (max-width: 600px) {
  .login-wrap { padding: 16px; }
  .login-card { padding: 16px 20px 22px; }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (min-width: 1920px) {
  .main { padding: 24px 28px; }
}

@media (max-width: 1199px) {
  .stat-card .value { font-size: var(--fs-2xl); }
  .main { padding: 16px; }
}
@media (min-width: 768px) and (max-width: 1199px) {
  .el-drawer.rtl { width: 80% !important; }
}

@media (max-width: 767px) {
  .header { padding: 0 8px; gap: 6px; }
  .header-left, .header-right { gap: 4px; }
  .page-title { font-size: var(--fs-md); }
  .main { padding: 12px; }

  .toolbar { gap: 6px; }
  .toolbar .spacer { display: none; }
  .toolbar > .el-input, .toolbar > .el-select, .toolbar > .el-autocomplete {
    width: auto !important; flex: 1 1 calc(50% - 6px); min-width: 0;
  }
  .toolbar > .el-date-editor { width: 100% !important; flex: 1 1 100%; }
  .toolbar > .el-date-editor.half-picker { flex: 1 1 calc(50% - 6px); min-width: 0; }
  .toolbar > .el-radio-group { flex: 1 1 100%; }

  .el-drawer.rtl { width: 100% !important; }
  .el-pagination { flex-wrap: wrap; justify-content: center; row-gap: 6px; }

  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat-card .value { font-size: 20px; }
  .stat-card .el-card__body { padding: 12px 14px; }
  .stat-icon { width: 32px; height: 32px; font-size: 16px; border-radius: 8px; }
  .el-card__body { padding: 12px; }
  .el-card__header { padding: 10px 12px; }

  .el-dialog { --el-dialog-margin-top: 4vh; width: calc(100vw - 16px) !important; max-width: none; }
  .el-dialog__body { padding: 12px 14px; }
  .el-message-box { max-width: calc(100vw - 24px); }

  /* Forms: labels above inputs instead of a fixed-width left column. */
  .el-form-item { flex-direction: column; align-items: stretch; }
  .el-form-item__label { width: auto !important; justify-content: flex-start; line-height: 22px; margin-bottom: 4px; }
  .el-form-item__content { margin-left: 0 !important; }
  .el-form--inline .el-form-item { margin-right: 0; width: 100%; }

  .el-tabs__item { padding: 0 10px; }
  .event-list { max-height: 320px; }
  pre.json { max-height: 360px; }
}
