/* ==========================================================================
   ALAM IOT ENTERPRISES - SCADA INDUSTRIAL SUITE
   Ultra-Modern, Clean & High-Performance Industrial Light Theme Design System
   ========================================================================== */

:root {
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 80px;
  --topbar-h: 64px;
  --footer-h: 42px;

  /* ---- Core Light Palette ---- */
  --bg-body: #f5f7f6;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #eef4f3;
  --bg-card-subtle: #fbfcfc;

  --border-color: #dfe7e8;
  --border-subtle: #eef3f2;
  --border-strong: #cbd8da;
  --border-focus: #087f82;
  --border: var(--border-color);
  --text-primary: #101b23;

  /* ---- Brand & Industrial Accents ---- */
  --primary-blue: #087f82;
  --primary-blue-hover: #066467;
  --primary-blue-light: #e2f2f1;
  --primary-glow: rgba(8, 127, 130, 0.15);
  --scrim: rgba(11, 28, 45, 0.56);

  --accent-emerald: #20865d;
  --accent-emerald-light: #e6f4ed;
  --accent-amber: #a86b14;
  --accent-amber-light: #fff2dc;
  --accent-rose: #bf4b4b;
  --accent-rose-light: #fbe8e8;
  --accent-indigo: #4f46e5;
  --accent-indigo-light: #e0e7ff;

  /* ---- Typography Hierarchy ---- */
  --text-main: #101b23;
  --text-body: #172731;
  --text-muted: #697b88;
  --text-light: #8b9aa4;

  /* ---- Shadows & Glass ---- */
  --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
  --shadow-dropdown: 0 12px 28px rgba(15, 23, 42, 0.12), 0 4px 10px rgba(15, 23, 42, 0.06);

  --radius-sm: 7px;
  --radius-md: 10px;
  --radius-lg: 10px;
  --radius-xl: 12px;
}

/* ---------- Global Reset & Body ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------- Layout Structure ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
  background-color: var(--bg-body);
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  margin-left: var(--sidebar-w);
  transition: margin-left 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  background-color: var(--bg-body);
}

.app-shell.sidebar-collapsed .app-main {
  margin-left: var(--sidebar-w-collapsed);
}

.app-content {
  flex: 1;
  padding: 24px 32px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

.app-footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
}

/* ---------- Cards & Glassmorphism ---------- */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.glass-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* ---------- Typography & Page Headers ---------- */
.page-header {
  margin-bottom: 24px;
}

.page-header-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.badge-accent {
  background: var(--primary-blue-light);
  color: var(--primary-blue);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
}

/* ---------- Sidebar Navigation ---------- */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1), transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.02);
}

.sidebar.collapsed {
  width: var(--sidebar-w-collapsed);
}

.sidebar-brand {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  justify-content: center;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.brand-mark, .sidebar-brand .brand-logo {
  width: 64px;
  height: 48px;
  object-fit: contain;
  border: 0;
  background: transparent;
  box-shadow: none;
  mix-blend-mode: multiply;
  flex-shrink: 0;
}

.sidebar-brand .brand-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: left center;
}

.sidebar-brand .brand-logo-frame {
  width: 74px;
  height: 52px;
  flex: 0 0 74px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 10px;
}

.sidebar-brand .brand-text {
  margin-left: 0;
}

.login-brand-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: left center;
  background: transparent;
  border: 0;
  box-shadow: none;
  display: block;
  mix-blend-mode: multiply;
}

.login-brand-frame {
  width: 112px;
  height: 80px;
  flex: 0 0 112px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 10px;
}

html[data-theme="dark"] .brand-logo,
body.dark-theme .brand-logo,
html[data-theme="dark"] .login-brand-logo,
body.dark-theme .login-brand-logo {
  filter: invert(1);
  mix-blend-mode: screen;
}

.brand-text {
  margin-left: 6px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

.brand-title {
  font-weight: 800;
  font-size: 13.5px;
  color: var(--text-main);
  letter-spacing: 0.3px;
  line-height: 1.25;
  white-space: nowrap;
}

.brand-sub {
  font-size: 9.5px;
  color: var(--primary-blue);
  font-weight: 700;
  letter-spacing: 0.6px;
  white-space: nowrap;
}

.sidebar.collapsed .brand-text { display: none; }

.sidebar-nav {
  flex: 1;
  min-height: 0;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  /* Keep the navigation scrollable when groups expand without showing a
     second bright scrollbar that visually cuts through the sidebar. */
  scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar { width: 0; height: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--text-body);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--bg-card-hover);
  color: var(--primary-blue);
}

.nav-item.active {
  background: var(--primary-blue-light);
  color: var(--primary-blue);
  font-weight: 600;
}

.nav-icon {
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
}
.nav-icon svg {
  width: 21px;
  height: 21px;
}

.nav-group-children {
  margin-left: 14px;
  border-left: 1px solid var(--border-color);
  padding-left: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-child { padding: 8px 10px; font-size: 13.5px; }

.nav-caret {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.nav-item.group-open .nav-caret { transform: rotate(90deg); }

.nav-group-title { width: 100%; text-align: left; line-height: inherit; font-weight: 600; cursor: pointer; }

.sidebar.collapsed .nav-label { display: none; }

.sidebar-footer-slot {
  flex-shrink: 0;
  padding: 12px 10px;
  border-top: 1px solid var(--border-color);
}

.nav-item.logout {
  color: var(--accent-rose);
}
.nav-item.logout:hover {
  background: var(--accent-rose-light);
}

/* ---------- TopBar Header ---------- */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-xs);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.icon-btn {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 10px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all 0.15s ease;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

.search-box-wrapper {
  position: relative;
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 7px 16px;
  gap: 8px;
  width: 300px;
  transition: all 0.2s ease;
}

.search-box:focus-within {
  width: 360px;
  background: var(--bg-card);
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  color: var(--text-main);
  font-size: 13.5px;
  width: 100%;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

/* Global Search Dropdown */
.search-dropdown-menu {
  position: absolute;
  top: 44px;
  left: 0;
  width: 380px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-dropdown);
  padding: 10px;
  z-index: 200;
}

.search-category-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 10px;
}

.search-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  transition: background 0.15s ease;
  cursor: pointer;
}

.search-result-row:hover {
  background: var(--primary-blue-light);
  color: var(--primary-blue);
}



.topbar-clock {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

/* Notifications Drawer Dropdown */
.notifications-wrapper {
  position: relative;
  outline: none;
}

.bell-btn {
  position: relative;
}

.notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent-rose);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  border: 2px solid #fff;
}

.alerts-dropdown {
  position: absolute;
  top: 46px;
  right: 0;
  width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-dropdown);
  z-index: 200;
  overflow: hidden;
}

.dropdown-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13.5px;
}

.view-all-link {
  color: var(--primary-blue);
  font-weight: 600;
  font-size: 12.5px;
}

.dropdown-body {
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
}

.dropdown-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.alert-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 6px;
  background: var(--bg-card-subtle);
  border-left: 3px solid var(--text-muted);
  transition: background 0.15s ease;
}

.alert-item.critical {
  border-left-color: var(--accent-rose);
  background: var(--accent-rose-light);
}

.alert-item.warning {
  border-left-color: var(--accent-amber);
  background: var(--accent-amber-light);
}

.alert-item-header {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  margin-bottom: 4px;
}

.alert-msg {
  font-size: 12.5px;
  color: var(--text-main);
  font-weight: 500;
}

/* User Menu Dropdown */
.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px 5px 6px;
  border-radius: var(--radius-md);
  cursor: pointer;
  position: relative;
  outline: none;
  transition: background 0.15s ease;
}

.user-menu:hover {
  background: var(--bg-card-hover);
}

.user-menu-trigger { display: flex; align-items: center; gap: 10px; color: inherit; text-align: left; border-radius: var(--radius-sm); }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-blue);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-xs);
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.user-role-badge {
  font-size: 11px;
  color: var(--primary-blue);
  font-weight: 600;
}

.chevron {
  font-size: 10px;
  color: var(--text-muted);
}

.user-dropdown {
  position: absolute;
  top: 48px;
  right: 0;
  width: 220px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-dropdown);
  padding: 8px 0;
  z-index: 200;
}

.user-dropdown-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.user-dropdown-email {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-color);
  margin: 6px 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  font-size: 13px;
  color: var(--text-body);
  transition: all 0.15s ease;
}

.dropdown-item:hover {
  background: var(--bg-card-hover);
  color: var(--primary-blue);
}

.dropdown-item.logout {
  color: var(--accent-rose);
}
.dropdown-item.logout:hover {
  background: var(--accent-rose-light);
}

/* ==========================================================================
   LIVE MONITORING & FLOWMETER CARDS
   ========================================================================== */
.conn-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online { background-color: var(--accent-emerald); }
.status-dot.offline { background-color: var(--accent-rose); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
}

.status-pill.online {
  background: var(--accent-emerald-light);
  color: var(--accent-emerald);
}

.status-pill.offline {
  background: var(--accent-rose-light);
  color: var(--accent-rose);
}

.gw-device-card .status-pill {
  flex: 0 0 auto;
  width: max-content;
  min-width: max-content;
  flex-wrap: nowrap;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.gw-device-card .status-pill-label {
  flex: 0 0 auto;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

.gw-device-card .sensor-row-layout {
  flex-wrap: wrap;
  gap: 0.75rem;
}

.gw-device-card .sensor-row-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 850px) {
  .gw-device-card .sensor-row-actions {
    flex: 1 1 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
}

.meter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

@media (max-width: 1100px) {
  .meter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .meter-grid {
    grid-template-columns: 1fr;
  }
}

.meter-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 11px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  position: relative;
  overflow: hidden;
}

.meter-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary-blue), #38bdf8);
}

.meter-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}

.meter-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.meter-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

.meter-reading {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meter-value {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--primary-blue);
  font-feature-settings: 'tnum';
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.meter-unit {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.meter-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
  color: var(--text-muted);
}

.meter-reading.secondary {
  padding-top: 6px;
  border-top: 1px dashed var(--border-color);
}

.meter-value-sm {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  font-feature-settings: 'tnum';
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.btn-report {
  margin-top: 2px;
  padding: 8px 14px;
  background: var(--bg-card-subtle);
  color: var(--text-body);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
  width: 100%;
}

.btn-report:hover {
  background: var(--primary-blue-light);
  color: var(--primary-blue);
  border-color: rgba(2, 132, 199, 0.3);
}

/* ==========================================================================
   TABLES & DATA GRIDS
   ========================================================================== */
.table-card {
  padding: 20px;
  overflow: hidden;
}

.table-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 12px;
}

.table-card-header h3, .table-card-header h4 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.scada-table, .data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13.5px;
}

.scada-table thead, .data-table thead {
  background: var(--bg-card-subtle);
  border-bottom: 1px solid var(--border-color);
}

.scada-table th, .data-table th {
  padding: 13px 18px;
  font-weight: 700;
  color: var(--text-body);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.scada-table td, .data-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

.scada-table tbody tr:hover, .data-table tbody tr:hover {
  background: var(--bg-card-subtle);
}

.scada-table tbody tr:last-child td, .data-table tbody tr:last-child td {
  border-bottom: none;
}

.font-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.text-cyan { color: var(--primary-blue) !important; }
.text-green { color: var(--accent-emerald) !important; }
.text-warning { color: var(--accent-amber) !important; }
.text-danger { color: var(--accent-rose) !important; }
.text-red { color: var(--accent-rose) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-center { text-align: center; }

/* Action Buttons & Icons */
.action-btn-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon-action {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-card-hover);
  border: 1px solid var(--border-color);
  transition: all 0.15s ease;
  font-size: 14px;
}

.btn-icon-action:hover {
  background: var(--border-color);
}

.btn-icon-action.delete:hover {
  background: var(--accent-rose-light);
  border-color: rgba(220, 38, 38, 0.3);
}

.btn-sm-report {
  padding: 6px 14px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-body);
  transition: all 0.15s ease;
}

.btn-sm-report:hover {
  background: var(--primary-blue-light);
  color: var(--primary-blue);
}

.btn-sm-action-ack {
  padding: 6px 12px;
  background: var(--primary-blue);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 600;
  transition: background 0.15s ease;
}
.btn-sm-action-ack:hover {
  background: var(--primary-blue-hover);
}

.btn-sm-action-ota {
  padding: 6px 14px;
  background: var(--accent-emerald);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  font-weight: 600;
  transition: background 0.15s ease;
}
.btn-sm-action-ota:hover {
  background: #047857;
}

/* Primary Button */
.btn-primary-scada {
  background: var(--primary-blue);
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.btn-primary-scada:hover {
  background: var(--primary-blue-hover);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
  transform: translateY(-1px);
}

.btn-secondary-scada {
  background: var(--bg-card-hover);
  color: var(--text-body);
  border: 1px solid var(--border-color);
  font-weight: 600;
  font-size: 13.5px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  transition: all 0.15s ease;
}

.btn-secondary-scada:hover {
  background: var(--border-color);
}

/* ==========================================================================
   TAB SWITCHER & FILTER CHIPS
   ========================================================================== */
.tab-switcher {
  display: flex;
  background: var(--bg-card-hover);
  padding: 4px;
  border-radius: var(--radius-md);
  gap: 4px;
  border: 1px solid var(--border-color);
}

.tab-btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab-btn:hover {
  color: var(--text-main);
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--primary-blue);
  box-shadow: var(--shadow-xs);
}

.tab-counter {
  background: var(--primary-blue-light);
  color: var(--primary-blue);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 12px;
}

.filter-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.chip {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-body);
  transition: all 0.15s ease;
}

.chip:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
}

.chip.active {
  background: var(--primary-blue-light);
  border-color: var(--primary-blue);
  color: var(--primary-blue);
}

.latency-pill {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card-subtle);
  padding: 4px 12px;
  border-radius: 16px;
  border: 1px solid var(--border-color);
}

/* ==========================================================================
   CHARTS & CANVAS
   ========================================================================== */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
  gap: 24px;
}

.chart-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.chart-title-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-title-box h4 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.chart-badge {
  font-family: monospace;
  font-size: 11.5px;
  background: var(--bg-card-subtle);
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--text-muted);
}

.chart-canvas-container {
  width: 100%;
  height: 200px;
  position: relative;
}

.scada-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ==========================================================================
   STORAGE TANKS
   ========================================================================== */
.tanks-overview-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.overview-stat {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.overview-stat span {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.overview-stat strong {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-main);
}

.tanks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 24px;
}

.tank-card {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tank-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.tank-code {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--primary-blue);
  letter-spacing: 0.6px;
}

.tank-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 2px;
}

.tank-status-pill {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}
.tank-status-pill.filling { background: #e0f2fe; color: #0369a1; }
.tank-status-pill.normal { background: #d1fae5; color: #047857; }
.tank-status-pill.draining { background: #fef3c7; color: #b45309; }

.tank-body {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 20px;
  align-items: center;
}

.tank-visual-cylinder {
  height: 180px;
  background: var(--bg-card-hover);
  border: 2px solid var(--border-strong);
  border-radius: 24px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.06);
}

.tank-liquid-wave {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
  transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.tank-scale-ticks {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 9px;
  font-weight: 700;
  color: #64748b;
  pointer-events: none;
}

.tank-level-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tank-percentage-large {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.85);
  padding: 2px 8px;
  border-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.tank-specs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.spec-row {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-muted);
}

.spec-row strong {
  color: var(--text-main);
  font-weight: 600;
}

.spec-divider {
  height: 1px;
  background: var(--border-color);
  margin: 4px 0;
}

.flow-badge {
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}

.flow-badge.inlet { background: #e0f2fe; color: #0284c7; }
.flow-badge.outlet { background: #fef3c7; color: #d97706; }

/* ==========================================================================
   TREND COMPARISON
   ========================================================================== */
.comparison-wrapper {
  padding: 24px;
}

.comparison-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.comparison-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.comparison-metrics-banner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.comp-stat-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.comp-stat-card span {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.comp-stat-card h4 {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-main);
}

.badge-positive {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent-emerald);
  background: var(--accent-emerald-light);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  width: fit-content;
}

.comparison-chart-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  position: relative;
}

.comparison-canvas {
  width: 100%;
  height: 320px;
  display: block;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 16px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-body);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-box {
  width: 16px;
  height: 4px;
  border-radius: 2px;
}

.legend-box.current { background: var(--primary-blue); }
.legend-box.previous { background: #94a3b8; border-top: 1px dashed #94a3b8; }

/* ==========================================================================
   ALERTS & INCIDENTS
   ========================================================================== */
.summary-metrics-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.stat-value {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-main);
}

.alert-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.alert-badge.critical { background: var(--accent-rose-light); color: var(--accent-rose); }
.alert-badge.warning { background: var(--accent-amber-light); color: var(--accent-amber); }
.alert-badge.info { background: var(--primary-blue-light); color: var(--primary-blue); }

.alert-row-active {
  background: var(--accent-rose-light) !important;
}

.badge-resolved {
  color: var(--accent-emerald);
  font-size: 12px;
  font-weight: 600;
}

.badge-unresolved {
  color: var(--accent-rose);
  font-size: 12px;
  font-weight: 700;
}

/* ==========================================================================
   MULTI-SITE FLEET
   ========================================================================== */
.site-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 24px;
}

.site-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  cursor: pointer;
}

.site-card.active-site-card {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 2px var(--primary-blue), var(--shadow-md);
}

.site-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.site-code-badge {
  font-size: 11px;
  font-weight: 800;
  color: var(--primary-blue);
  background: var(--primary-blue-light);
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.site-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 4px 0 2px;
}

.site-loc {
  font-size: 12.5px;
  color: var(--text-muted);
}

.site-desc {
  font-size: 13px;
  color: var(--text-body);
  line-height: 1.4;
}

.site-metrics-mini {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--bg-card-subtle);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.mini-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mini-stat span {
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.mini-stat strong {
  font-size: 13px;
  font-weight: 700;
}

.site-card-footer {
  display: flex;
  justify-content: flex-end;
}

.view-telemetry-btn {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--primary-blue);
}

/* ==========================================================================
   FIRMWARE OTA
   ========================================================================== */
.ota-intro-banner {
  background: var(--bg-card);
  border-left: 4px solid var(--primary-blue);
  padding: 18px 24px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.ota-intro-banner h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.ota-intro-banner p {
  font-size: 13.5px;
  color: var(--text-body);
  line-height: 1.5;
}

.ota-progress-banner {
  padding: 20px 24px;
  margin-bottom: 24px;
  border-color: var(--primary-blue);
  background: var(--primary-blue-light);
}

.ota-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.progress-bar-track {
  height: 10px;
  background: var(--bg-card-subtle);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(2, 132, 199, 0.2);
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-blue), #38bdf8);
  border-radius: 10px;
  transition: width 0.3s ease;
}

.ota-step-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  font-weight: 500;
}

.version-tag {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 12px;
  color: var(--text-main);
}

.checksum-code {
  font-family: monospace;
  font-size: 11.5px;
  color: var(--text-muted);
}

.code-snippet-box {
  background: var(--code-bg, #172832);
  color: var(--code-fg, #e5f2f2);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
}

/* ==========================================================================
   MODALS & FORMS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 35px -5px rgba(0, 0, 0, 0.4);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-slide 0.18s ease-out;
}

@keyframes modal-slide {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-close {
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1 1 auto;
  max-height: calc(90vh - 140px);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: var(--bg-card-subtle);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-group label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-body);
}

.form-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.custom-input, .custom-select {
  padding: 9px 13px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 13.5px;
  transition: all 0.15s ease;
  outline: none;
  width: 100%;
}

.custom-input:focus, .custom-select:focus {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}

/* Password Input with Show/Hide Toggle */
.password-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.password-input-wrapper input {
  padding-right: 42px;
}

.btn-eye-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.btn-eye-toggle:hover {
  color: var(--text-main);
}

/* Toast Notifications */
.scada-toast {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  width: min(580px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 12px 28px -8px rgba(15, 23, 42, 0.35);
}

/* Inline alert shown inside modal cards (visible above the overlay backdrop) */
.modal-alert {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
  margin: 0 0 14px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.modal-alert.success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.modal-alert.error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.modal-alert.warning {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

/* Newly added sensor row flash in the expanded device card */
@keyframes sensor-flash {
  0% { background: rgba(16, 185, 129, 0.28); }
  100% { background: transparent; }
}

.sensor-row-highlight {
  animation: sensor-flash 2.5s ease-out;
  border-radius: 6px;
}

.scada-toast.success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.scada-toast.error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.toast-close {
  color: inherit;
  font-size: 15px;
  cursor: pointer;
  padding: 2px 6px;
}

/* ==========================================================================
   USERS, ROLES & SETTINGS
   ========================================================================== */
.user-role-badge {
  background: var(--bg-card-subtle);
  color: var(--primary-blue);
  font-weight: 700;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  display: inline-block;
}

.badge-lock {
  color: var(--accent-rose);
  font-size: 11.5px;
  font-weight: 700;
}

.role-permission-box {
  padding: 18px;
  margin-bottom: 16px;
}

.role-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.perm-category-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-body);
  cursor: pointer;
}

.checkbox-label.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.card-header-icon {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-color);
}

.card-header-icon .icon {
  font-size: 24px;
}

.card-header-icon h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.health-checklist {
  padding: 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.health-item {
  display: flex;
  align-items: center;
  gap: 14px;
}

.health-icon.ok {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-emerald-light);
  color: var(--accent-emerald);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}

.health-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.health-info strong {
  font-size: 13.5px;
  color: var(--text-main);
}

.health-info span {
  font-size: 12px;
  color: var(--text-muted);
}

.offline-sim-box {
  padding: 18px 22px;
  background: var(--bg-card-subtle);
  border-radius: var(--radius-md);
  margin: 16px;
  border: 1px solid var(--border-color);
}

.sim-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  margin-bottom: 14px;
}

.sim-btn-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.security-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  padding: 20px;
}

.sec-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sec-card h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.sec-card p {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
  flex: 1;
}

/* ==========================================================================
   REPORTS & ANALYTICS BUILDER
   ========================================================================== */
.report-builder-card {
  padding: 24px;
}

.builder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.report-controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  align-items: flex-end;
}

.preset-chips-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.preset-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.report-results-pane {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.btn-report-action {
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-report-action.pdf {
  background: var(--accent-rose);
  color: #fff;
}
.btn-report-action.pdf:hover {
  background: #b91c1c;
}

.btn-report-action.excel {
  background: var(--accent-emerald);
  color: #fff;
}
.btn-report-action.excel:hover {
  background: #047857;
}

/* ==========================================================================
   LOGIN SCREEN (Clean Light Theme)
   ========================================================================== */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
  padding: 20px;
  position: relative;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  padding: 40px 32px;
  z-index: 10;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 28px;
  transform: translateX(-6px);
}

.login-brand-lockup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.login-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  white-space: nowrap;
}

.login-brand-title {
  color: var(--text-main);
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.3px;
  line-height: 1.2;
}

.login-brand-sub {
  color: var(--text-main);
  width: max-content;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.8px;
}

.login-brand h2 {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.login-brand p {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary-blue);
  letter-spacing: 0.9px;
  margin-top: 5px;
}

.login-error-banner {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-body);
  cursor: pointer;
}

.btn-login {
  padding: 12px;
  background: var(--primary-blue);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  border-radius: var(--radius-md);
  transition: all 0.15s ease;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
  margin-top: 6px;
}

.btn-login:hover {
  background: var(--primary-blue-hover);
  transform: translateY(-1px);
}

/* ==========================================================================
   MOBILE & RESPONSIVE BREAKPOINTS
   ========================================================================== */
.sidebar-mobile-toggle, .sidebar-mobile-close, .sidebar-backdrop { display: none; }

/* Keep every icon on the same centerline, including nested routes and branding. */
@media (min-width: 769px) {
  .sidebar.collapsed .sidebar-brand { padding: 0; justify-content: center; gap: 0; }
  .sidebar.collapsed .sidebar-brand .brand-logo-frame { width: 72px; flex-basis: 72px; }
  .sidebar.collapsed .nav-item { justify-content: center; padding: 10px 0; gap: 0; }
  .sidebar.collapsed .nav-caret { display: none; }
  .sidebar.collapsed .nav-group-children { margin-left: 0; padding-left: 0; border-left: 0; }
  .sidebar.collapsed .nav-group-children .nav-item { border-radius: var(--radius-sm); }
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 3px;
}
.sidebar .nav-item:focus-visible { outline-offset: -2px; }
.nav-icon { flex-shrink: 0; }
.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.page-title { line-height: 1.25; }
.app-footer { flex-shrink: 0; padding: 8px 16px; min-height: var(--footer-h); height: auto; text-align: center; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 1300; padding: 10px 16px; background: var(--bg-surface); color: var(--primary-blue); border-radius: var(--radius-sm); transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }
.topbar-left { min-width: 0; }
.topbar-right { flex-shrink: 0; }
.search-box, .search-box:focus-within { width: clamp(160px, 24vw, 300px); }

@media (max-width: 1024px) {
  .topbar-clock { display: none; }
  .topbar .user-info { display: none; }
  .app-content {
    padding: 20px 16px;
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .chart-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar, .sidebar.collapsed {
    width: min(var(--sidebar-w), calc(100vw - 32px));
    transform: translateX(-100%);
    visibility: hidden;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    visibility: visible;
  }
  .sidebar.collapsed .brand-text { display: flex; }
  .sidebar.collapsed .nav-label { display: inline; }
  .sidebar-desktop-toggle { display: none; }
  .sidebar-mobile-toggle, .sidebar-mobile-close { display: inline-flex; }
  .sidebar-mobile-close { margin-left: auto; padding: 4px 8px; }
  .sidebar-brand { padding: 0 10px; gap: 6px; }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 99;
  }
  .app-main {
    margin-left: 0 !important;
  }
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }
  .topbar-left { flex: 1; gap: 8px; }
  .topbar-right { gap: 6px; }
  .search-box-wrapper { flex: 1; min-width: 0; }
  .search-box, .search-box:focus-within { width: 100%; padding: 7px 10px; }
  .search-box input { min-width: 0; }
  .search-dropdown-menu, .alerts-dropdown { position: fixed; top: calc(var(--topbar-h) + 4px); left: 12px; right: 12px; width: auto; max-height: calc(100dvh - var(--topbar-h) - 24px); }
  .topbar .user-menu { padding: 4px; gap: 4px; }
  .topbar .chevron { display: none; }
  .topbar-clock {
    display: none;
  }
  .form-grid-2 {
    grid-template-columns: 1fr;
  }
  .tank-body {
    grid-template-columns: 1fr;
  }
  .tank-visual-cylinder {
    max-width: 160px;
    margin: 0 auto;
  }
}

/* ---- Device Card Status Animation ---- */
.device-card { transition: box-shadow .3s ease, transform .2s ease; }
.device-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.status-ring { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.pulse-green { background: var(--accent-emerald); box-shadow: 0 0 8px var(--accent-emerald); animation: pulseGreen 2s infinite; }
.pulse-amber { background: var(--accent-amber); box-shadow: 0 0 8px var(--accent-amber); animation: pulseAmber 2s infinite; }
.pulse-red { background: var(--accent-rose); box-shadow: 0 0 8px var(--accent-rose); animation: pulseRed 2s infinite; }
@keyframes pulseGreen { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }
@keyframes pulseAmber { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }
@keyframes pulseRed { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.2rem; }

/* ----------------------------------------------------
   ANIMATED DEVICE CARDS (NODE-RED / DASHBOARD STYLE)
---------------------------------------------------- */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    cursor: pointer;
    overflow: hidden;
}

.device-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.card-top {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.card-top h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    flex-grow: 1;
}

.card-top code {
    background: var(--bg-card-subtle);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Pulse Glows */
.status-ring {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.pulse-green {
    background-color: var(--accent-emerald);
    box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.7);
    animation: pulse-emerald 2s infinite;
}

.pulse-amber {
    background-color: var(--accent-amber);
    box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.7);
    animation: pulse-amber 2s infinite;
}

.pulse-red {
    background-color: var(--accent-rose);
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7);
    animation: pulse-rose 2s infinite;
}

@keyframes pulse-emerald {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(5, 150, 105, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

@keyframes pulse-amber {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(217, 119, 6, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(217, 119, 6, 0); }
}

@keyframes pulse-rose {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.card-body {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-body);
    margin-bottom: 1rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed var(--border-subtle);
    padding-bottom: 4px;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    background: var(--bg-card-subtle);
    color: var(--text-muted);
}

.btn-small {
    background: var(--primary-blue-light);
    color: var(--primary-blue);
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-small:hover {
    background: var(--primary-blue);
    color: #fff;
}

/* ==========================================================================
   LIVE MONITORING - dimmed subtitle + per-sensor connection line
   ========================================================================== */
.page-subtitle-soft {
  color: var(--text-light);
  font-weight: 400;
}

.meter-conn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-subtle);
}

.meter-conn-pill {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.meter-conn-pill.online { background-color: var(--accent-emerald); }
.meter-conn-pill.offline { background-color: var(--accent-rose); }

.meter-conn-line {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.25;
}

.meter-conn-seen {
  font-size: 0.7rem;
  color: var(--text-light);
  line-height: 1.4;
}

/* ==========================================================================
   KPI BAND (Charts + Summary) - real live values only
   ========================================================================== */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.kpi-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
}

/* ==========================================================================
   ALERT INCIDENT TOAST (top-right, fired via SignalR ReceiveAlertIncident)
   ========================================================================== */
.alert-toast-stack {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  right: 20px;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 40px));
}

.alert-toast {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-amber);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-dropdown);
  padding: 12px 14px;
  animation: alert-toast-in 0.25s ease-out;
}

.alert-toast.info { border-left-color: var(--primary-blue); }
.alert-toast.warning { border-left-color: var(--accent-amber); }
.alert-toast.critical { border-left-color: var(--accent-rose); }

.alert-toast-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.alert-toast-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-amber);
  flex-shrink: 0;
  animation: pulse-amber 1.4s infinite;
}

.alert-toast.critical .alert-toast-dot { background: var(--accent-rose); animation: pulse-rose 1.4s infinite; }
.alert-toast.info .alert-toast-dot { background: var(--primary-blue); }

.alert-toast-msg {
  font-size: 12.5px;
  color: var(--text-body);
  margin-top: 4px;
}

.alert-toast-time {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
  font-family: ui-monospace, monospace;
}

@keyframes alert-toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ==========================================================================
   CHARTS - time axis window chips
   ========================================================================== */
.signal-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.signal-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.signal-hint {
  font-size: 12px;
  color: var(--text-light);
  margin-left: 4px;
}

/* ==========================================================================
   CHARTS - live level band chips (LOW / MEDIUM / HIGH per unit)
   ========================================================================== */
.level-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.level-chip.low {
  background: var(--accent-emerald-light);
  color: var(--accent-emerald);
}

.level-chip.medium {
  background: var(--accent-amber-light);
  color: var(--accent-amber);
}

.level-chip.high {
  background: var(--accent-rose-light);
  color: var(--accent-rose);
}

.level-chip.off {
  background: var(--bg-card-hover);
  color: var(--text-muted);
}

/* ==========================================================================
   LOGIN - formal SVG icon sizing
   ========================================================================== */
.eye-icon {
  width: 18px;
  height: 18px;
  display: block;
}

.login-error-banner .error-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ==========================================================================
   STORAGE TANKS (real-telemetry AQUA-style liquid tank cards, light theme)
   ========================================================================== */
.tk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px;
}

.tk-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.tk-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.tk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.tk-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--text-main);
}

.tk-body {
  padding: 14px 14px 10px;
  background: color-mix(in srgb, var(--bg-card-subtle) 78%, #0f2732 22%);
}

.tk-svg-wrap {
  position: relative;
  min-width: 0;
  border: 1px solid color-mix(in srgb, var(--border-strong) 70%, #275366 30%);
  border-radius: 10px;
  padding: 4px;
  background: radial-gradient(circle at 50% 18%, color-mix(in srgb, var(--bg-card-hover) 76%, #315568 24%), var(--bg-card-subtle));
}

.tk-svg {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
}

.tk-scale-line { stroke: var(--text-light); stroke-width: 1; opacity: .65; }
.tk-scale-text { fill: var(--text-muted); font-size: 8px; font-weight: 600; }
.tk-shadow { fill: #07141b; opacity: .38; }
.tk-vessel { stroke: #5d7887; stroke-width: 2.5; }
.tk-vessel-line { fill: none; stroke: #7595a4; stroke-width: 2; opacity: .82; }
.tk-cap { fill: none; stroke: #7696a5; stroke-width: 1.6; opacity: .85; }
.tk-vessel-detail { fill: none; stroke: #6b8a99; stroke-width: 1.5; }
.tk-sensor { fill: #182630; stroke: #9bc1cf; stroke-width: 1.5; }

.tk-read {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.tk-pct {
  grid-column: 1 / -1;
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary-blue);
  font-feature-settings: 'tnum';
  font-variant-numeric: tabular-nums;
  text-align: center;
  line-height: 1;
  padding: 2px 0 6px;
}

.tk-pct.muted {
  color: var(--text-light);
}

.tk-pct-unit {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
}

.tk-stat {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 7px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.tk-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.tk-stat-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  font-feature-settings: 'tnum';
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tk-conn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding: 8px 16px 12px;
  border-top: 1px dashed var(--border-subtle);
}

.tk-conn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tk-conn-dot.online { background-color: var(--accent-emerald); }
.tk-conn-dot.offline { background-color: var(--accent-rose); }

.tk-conn-line {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.25;
}

.tk-conn-seen {
  font-size: 0.7rem;
  color: var(--text-light);
  line-height: 1.4;
}

@media (max-width: 560px) {
  .tk-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .tk-header { padding: 11px 12px; }
  .tk-body { padding: 10px 10px 8px; }
  .tk-read { gap: 6px; }
  .tk-stat { padding: 6px 8px; }
  .tk-stat-value { font-size: .86rem; }
  .tk-conn { padding-left: 12px; padding-right: 12px; }
}

/* "Storage Tank asset" toggle inside the Configure & Add / Edit modals */
.tank-toggle-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.6rem;
  padding: 0.55rem 0.7rem;
  border: 1px dashed var(--primary-blue);
  border-radius: 6px;
  background: #f0f9ff;
}

.tank-toggle-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.87rem;
}

.tank-toggle-hint {
  color: var(--text-muted);
  font-size: 0.74rem;
  margin-top: 1px;
}

.tank-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--control-accent);
  flex-shrink: 0;
  cursor: pointer;
}

/* ==========================================================================
   PLANT ENERGY DASHBOARD (/energy) - arc-gauge category cards, real telemetry
   ========================================================================== */
.eg-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.eg-muted {
  font-size: 11px;
  color: var(--text-muted);
}

.eg-warn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  margin-bottom: 16px;
  border: 1px solid var(--accent-amber);
  border-radius: 7px;
  background: #fefce8;
  color: #854d0e;
  font-size: 12px;
}
.eg-warn svg { flex-shrink: 0; color: #ca8a04; }

.eg-clock {
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text-main);
  font-weight: 600;
}

.dash-section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--primary-blue);
  margin: 22px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dash-gateways {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 6px;
}

.dash-gw {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.dash-gw-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.dash-gw-name {
  font-weight: 650;
  color: var(--text-main);
  font-size: 0.95rem;
}

.dash-gw-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.dash-gw-seen {
  font-size: 10.5px;
  color: var(--text-light);
}

.dash-alerts {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dash-alert {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-amber);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.dash-alert:has(.sev-pill.critical) { border-left-color: var(--accent-rose); }
.dash-alert:has(.sev-pill.info) { border-left-color: var(--primary-blue); }

.dash-alert-left {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.sev-pill {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  margin-top: 1px;
}
.sev-pill.warning { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.sev-pill.critical { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.sev-pill.info { background: #e0f2fe; color: #075985; border-color: #bae6fd; }

.dash-alert-msg {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
}
.dash-alert-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.dash-alert-right {
  flex-shrink: 0;
}

/* ---------- Plant Energy dash (TREND child, category-wise reference design) ---------- */
.pe-dash { --pe-edge:#cbd5e0; --pe-muted:#5d6f80; --pe-navy:#1f4e79; --pe-navy2:#2d6ba1; --pe-blue2:#5fb3d9; --pe-inset:#eef4fb; }
.pe-topbar { background: linear-gradient(180deg, #2d6ba1, #16345a); border-bottom: 2px solid #0f2a4a; color: #fff; border-radius: var(--radius-md) var(--radius-md) 0 0; }
.pe-topbar-in { max-width: 1500px; margin: auto; padding: 14px 26px; display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.pe-title { text-align: center; flex: 1; min-width: 220px; }
.pe-t1 { font-size: 11px; letter-spacing: 3px; opacity: .85; text-transform: uppercase; }
.pe-t2 { font-size: 17px; font-weight: 650; letter-spacing: .6px; margin-top: 2px; }
.pe-brand { display: flex; align-items: center; gap: 10px; font-size: 12px; letter-spacing: 2px; opacity: .9; }
.pe-badge { width: 30px; height: 30px; border: 1.5px solid #ffffff88; border-radius: 7px; display: grid; place-items: center; }
.pe-actions { display: flex; gap: 8px; align-items: center; }
.pe-actions button { background: #ffffff1f; border-color: #ffffff40; color: #fff; border-radius: 6px; padding: 8px 12px; cursor: pointer; font-size: 12px; }
.pe-actions button:hover { background: #ffffff2e; }
.pe-actions button:disabled { opacity: .6; cursor: default; }
.pe-wrap { background: var(--bg-card); border: 1px solid var(--border-color); border-top: 0; border-radius: 0 0 var(--radius-md) var(--radius-md); padding: 24px 26px 40px; }
.pe-load { padding: 2.5rem; text-align: center; color: var(--text-muted); }
.pe-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.pe-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.pe-kpi { background: var(--bg-card-subtle); border: 1px solid var(--border-color); border-radius: 9px; padding: 14px 16px; }
.pe-kpi small { display: block; color: var(--text-muted); font-size: 10.5px; letter-spacing: 1.1px; text-transform: uppercase; }
.pe-kpi b { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; display: block; margin-top: 5px; letter-spacing: -.4px; color: var(--primary-blue); }
.pe-kpi b span { font-size: 12px; font-weight: 400; color: var(--text-muted); margin-left: 5px; }
.pe-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.pe-group { background: var(--bg-surface); border: 2px solid var(--primary-blue); border-radius: 9px; overflow: hidden; box-shadow: 0 2px 10px rgba(2, 132, 199, 0.12); display: flex; flex-direction: column; }
.pe-g-head { background: linear-gradient(180deg, var(--pe-navy2), var(--pe-navy)); color: #fff; padding: 10px 16px; text-align: center; font-size: 14px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; display: flex; align-items: center; justify-content: center; gap: 10px; }
.pe-tag { font-size: 10px; letter-spacing: 1px; opacity: .9; font-weight: 600; }
.pe-g-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0; flex: 1; }
.pe-half { padding: 12px 14px 14px; border-right: 1px solid var(--pe-edge); display: flex; flex-direction: column; }
.pe-half:last-child { border-right: 0; }
.pe-half h3 { margin: 0 0 4px; font-size: 11px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; color: var(--pe-navy); text-align: center; }
.pe-gauge { display: grid; place-items: center; padding: 2px 0 0; }
.pe-gauge svg { width: 100%; max-width: 215px; height: auto; }
.pe-gauge.offline { filter: grayscale(1); opacity: .65; }
.pe-arc-bg { fill: none; stroke: #c6d6ea; stroke-width: 13; stroke-linecap: butt; }
.pe-arc-fill { fill: none; stroke-width: 13; stroke-linecap: butt; filter: drop-shadow(0 1px 2px rgba(31, 78, 121, 0.35)); transition: stroke-dashoffset .9s cubic-bezier(.4, 0, .2, 1); }
.pe-tick-lb { fill: var(--pe-muted); font-size: 8.6px; font-weight: 700; }
.pe-g-val { fill: #16345a; font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pe-rows { border-top: 1px dashed var(--pe-edge); margin-top: 8px; }
.pe-row { display: flex; justify-content: space-between; gap: 8px; padding: 6px 2px; border-bottom: 1px solid var(--pe-edge); font-size: 11px; align-items: baseline; }
.pe-row:last-child { border-bottom: 0; }
.pe-row .lbl { color: var(--pe-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pe-row .val { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; color: var(--text-main); }
.pe-row .val.unit { font-weight: 400; color: var(--pe-muted); font-size: 10px; }
.pe-empty { color: var(--pe-muted); font-size: 11px; padding: 12px 0; text-align: center; }
.pe-foot { margin-top: auto; padding: 9px 14px; display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; color: var(--pe-muted); font-size: 10.5px; border-top: 1px solid var(--border-color); }
.pe-footline { margin-top: 22px; display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; color: var(--pe-muted); font-size: 10.5px; }
.pe-note { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; border-radius: 8px; padding: 10px 14px; font-size: 12px; margin-bottom: 14px; }
.pe-empty-state { padding: 3rem; text-align: center; color: var(--text-muted); font-size: 0.9rem; }
@media (max-width: 1080px) { .pe-kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 820px) { .pe-groups { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .pe-wrap { padding: 16px 14px 30px; } .pe-g-body { grid-template-columns: 1fr; } .pe-half { border-right: 0; border-bottom: 1px solid var(--pe-edge); } .pe-half:last-child { border-bottom: 0; } .pe-g-head { font-size: 12px; letter-spacing: 1px; } .pe-topbar-in { padding: 12px 14px; } }

.eg-groups {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.eg-group {
  background: var(--bg-surface);
  border: 2px solid var(--primary-blue);
  border-radius: 9px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.08);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.eg-group:hover {
  box-shadow: 0 6px 18px rgba(2, 132, 199, 0.16);
  transform: translateY(-2px);
}

.eg-head {
  background: linear-gradient(180deg, #075985, #0369a1);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.eg-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.eg-title svg { color: #7cc6e8; flex-shrink: 0; }

.eg-headright {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.eg-tag {
  font-size: 10px;
  letter-spacing: 1px;
  opacity: 0.95;
  font-weight: 600;
  background: #ffffff2e;
  border: 1px solid #ffffff55;
  border-radius: 5px;
  padding: 2px 7px;
}

.eg-head .status-pill {
  background: #ffffff2e;
  border-color: #ffffff55;
  color: #fff;
  font-size: 10px;
}
.eg-head .status-pill.online { background: #16a34a55; border-color: #86efacbb; }
.eg-head .status-pill.offline { background: var(--accent-rose-light); border-color: var(--accent-rose); color: var(--accent-rose); }

.eg-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  flex: 1;
}

.eg-half {
  padding: 12px 14px 14px;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}
.eg-half:last-child { border-right: 0; }
.eg-half.empty { justify-content: center; }

.eg-half-title {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--primary-blue);
  text-align: center;
}

.eg-gauge {
  display: grid;
  place-items: center;
  padding: 2px 0 0;
  position: relative;
}
.eg-gauge svg { width: 100%; max-width: 215px; height: auto; }

.eg-gauge.offline svg { filter: grayscale(0.7); opacity: 0.55; }
.eg-gauge.offline .eg-g-val { fill: var(--text-light); }

.eg-arc-bg {
  fill: none;
  stroke: #c3d2e3;
  stroke-width: 13;
  stroke-linecap: butt;
}
.eg-arc-fill {
  fill: none;
  stroke-width: 13;
  stroke-linecap: butt;
  filter: drop-shadow(0 1px 2px rgba(2, 68, 128, 0.35));
  transition: stroke-dashoffset 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.eg-tick-lb {
  fill: var(--text-muted);
  font-size: 8.6px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.eg-g-val {
  fill: #1e3a5f;
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.eg-rows {
  border-top: 1px dashed var(--border-color);
  margin-top: 10px;
  padding-top: 4px;
}
.eg-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--border-color);
  font-size: 11px;
  align-items: baseline;
}
.eg-row:last-child { border-bottom: 0; }
.eg-row .lbl { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eg-row .val { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.eg-row .val.unit { font-weight: 400; color: var(--text-muted); font-size: 10px; }

.eg-empty {
  color: var(--text-light);
  font-size: 12px;
  text-align: center;
  padding: 24px 0;
}

.eg-foot {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
  border-top: 1px dashed var(--border-color);
  font-size: 11px;
}
.eg-foot-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.eg-foot-dot.online { background-color: var(--accent-emerald); box-shadow: 0 0 0 3px #22c55e26; }
.eg-foot-dot.offline { background-color: var(--accent-rose); }

.eg-conn-line { font-weight: 600; color: var(--text-main); }
.eg-conn-seen { color: var(--text-muted); margin-top: 1px; }

@media (max-width: 1080px) {
  .eg-groups { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .eg-body { grid-template-columns: 1fr; }
  .eg-half { border-right: 0; border-bottom: 1px solid var(--border-color); }
  .eg-half:last-child { border-bottom: 0; }
  .eg-head { font-size: 12px; }
}

/* ---------- Theme toggle button (top bar) ---------- */
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color 0.15s ease, background 0.15s ease, transform 0.2s ease;
}
.theme-toggle:hover { background: var(--bg-card-hover); color: var(--text-main); }
.theme-toggle:active { transform: scale(0.92); }
.theme-toggle svg { width: 18px; height: 18px; }

/* ---------- Alert Row Styling ---------- */
.alert-row-active {
  background: rgba(239, 68, 68, 0.04) !important;
}

html[data-theme="dark"] .alert-row-active,
body.dark-theme .alert-row-active {
  background: rgba(239, 68, 68, 0.12) !important;
}

/* ---------- Table Pagination Bar ---------- */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  flex-wrap: wrap;
  gap: 12px;
}

.pagination-info {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pg-btn {
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 12.5px;
  font-weight: 600;
  transition: all 0.15s ease;
  cursor: pointer;
}

.pg-btn:hover:not(:disabled) {
  background: var(--primary-blue-light);
  color: var(--primary-blue);
  border-color: var(--primary-blue);
}

.pg-btn.active {
  background: var(--primary-blue);
  color: #ffffff;
  border-color: var(--primary-blue);
}

.pg-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.audit-log-pagination { padding: 16px 18px; }
.audit-log-pagination .pagination-controls {
  max-width: 100%;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 2px;
}
.audit-log-pagination .pg-btn {
  min-width: 40px;
  min-height: 40px;
  flex: 0 0 auto;
  padding: 6px 10px;
  white-space: nowrap;
}
.audit-log-pagination .pg-ellipsis {
  padding: 0 3px;
  color: var(--text-muted);
}

/* ============================================================================
   Unified soft-slate / teal theme
   Keep the existing component selectors above for application compatibility;
   this is the single final token and state layer used by every surface.
   ============================================================================ */
:root {
  color-scheme: light;
  --bg-body: #edf3f4;
  --bg-surface: #f8fbfb;
  --bg-card: #ffffff;
  --bg-card-hover: #e8f1f1;
  --bg-card-subtle: #f2f7f7;
  --border-color: #d3e0e2;
  --border-subtle: #e3ecee;
  --border-strong: #afc3c6;
  --border-focus: #0b7275;
  --text-primary: #172832;
  --text-main: #172832;
  --text-body: #2d414b;
  --text-muted: #5b7079;
  --text-light: #70848c;
  --primary-blue: #0b7275;
  --primary-blue-hover: #075a5d;
  --primary-action: #0b7275;
  --primary-action-hover: #075a5d;
  --control-accent: #0b7275;
  --primary-blue-light: #dcefee;
  --primary-glow: rgba(11, 114, 117, .2);
  --accent-emerald: #16734d;
  --accent-emerald-light: #e3f2ea;
  --accent-amber: #8b5b12;
  --accent-amber-light: #fff1d7;
  --accent-rose: #a33d45;
  --accent-rose-light: #fbe7e8;
  --accent-indigo: #4d5fb8;
  --accent-indigo-light: #e7eafd;
  --scrim: rgba(18, 35, 43, .58);
  --code-bg: #172832;
  --code-fg: #e5f2f2;
  --dashboard-header: #285d66;
  --dashboard-header-deep: #1b414a;
  --shadow-xs: 0 1px 2px rgba(23, 40, 50, .05);
  --shadow-sm: 0 2px 7px rgba(23, 40, 50, .08);
  --shadow-md: 0 6px 16px rgba(23, 40, 50, .1);
  --shadow-lg: 0 12px 26px rgba(23, 40, 50, .13);
  --shadow-dropdown: 0 14px 30px rgba(23, 40, 50, .16);
}

html[data-theme="dark"], body.dark-theme {
  color-scheme: dark;
  --bg-body: #101d24;
  --bg-surface: #15272f;
  --bg-card: #192f38;
  --bg-card-hover: #21404a;
  --bg-card-subtle: #1b353e;
  --border-color: #304b54;
  --border-subtle: #263f48;
  --border-strong: #4a6870;
  --border-focus: #7bd7d0;
  --text-primary: #eef8f8;
  --text-main: #eef8f8;
  --text-body: #d0e2e3;
  --text-muted: #a8bec2;
  --text-light: #8ba5aa;
  --primary-blue: #7bd7d0;
  --primary-blue-hover: #a1e6e1;
  --primary-action: #236f72;
  --primary-action-hover: #1b5a5d;
  --control-accent: #7bd7d0;
  --primary-blue-light: #204a4d;
  --primary-glow: rgba(123, 215, 208, .24);
  --accent-emerald: #6ed29e;
  --accent-emerald-light: #1d4436;
  --accent-amber: #f0c36d;
  --accent-amber-light: #49391f;
  --accent-rose: #ff9298;
  --accent-rose-light: #4c292f;
  --accent-indigo: #a3afff;
  --accent-indigo-light: #292d5d;
  --scrim: rgba(0, 0, 0, .7);
  --code-bg: #0d1a21;
  --code-fg: #d9eeee;
  --dashboard-header: #245964;
  --dashboard-header-deep: #173d47;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .25);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .28);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .32);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, .36);
  --shadow-dropdown: 0 16px 34px rgba(0, 0, 0, .46);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;
    --bg-body: #101d24;
    --bg-surface: #15272f;
    --bg-card: #192f38;
    --bg-card-hover: #21404a;
    --bg-card-subtle: #1b353e;
    --border-color: #304b54;
    --border-subtle: #263f48;
    --border-strong: #4a6870;
    --border-focus: #7bd7d0;
    --text-primary: #eef8f8;
    --text-main: #eef8f8;
    --text-body: #d0e2e3;
    --text-muted: #a8bec2;
    --text-light: #8ba5aa;
    --primary-blue: #7bd7d0;
    --primary-blue-hover: #a1e6e1;
    --primary-action: #236f72;
    --primary-action-hover: #1b5a5d;
    --control-accent: #7bd7d0;
    --primary-blue-light: #204a4d;
    --primary-glow: rgba(123, 215, 208, .24);
    --accent-emerald: #6ed29e;
    --accent-emerald-light: #1d4436;
    --accent-amber: #f0c36d;
    --accent-amber-light: #49391f;
    --accent-rose: #ff9298;
    --accent-rose-light: #4c292f;
  }
}

html, body { background: var(--bg-body); color: var(--text-main); }
body { overflow-wrap: anywhere; }
.app-shell, .app-main { background: var(--bg-body); }
.sidebar, .sidebar-brand, .topbar, .app-footer { background: var(--bg-surface); border-color: var(--border-color); }
.sidebar { box-shadow: 2px 0 10px rgba(23, 40, 50, .05); }
.sidebar .nav-item { color: var(--text-body); }
.sidebar .nav-item:hover, .sidebar .nav-item.active { color: var(--primary-blue); background: var(--primary-blue-light); }
.sidebar .nav-item.active { box-shadow: inset 3px 0 var(--primary-blue); }
.brand-title, .user-name, .page-title, .meter-name, .table-card-header h3,
.table-card-header h4, .card-header-icon h3, .modal-header h3 { color: var(--text-main); }
.view-all-link, .user-role-badge, .view-telemetry-btn { color: var(--primary-blue); }
.brand-sub { color: var(--text-main); }

/* Cards stay neutral; connectivity is communicated by its badge/dot only. */
.glass-card, .meter-card, .device-card, .stat-card, .overview-stat, .site-card,
.tk-card, .kpi-card, .dash-gw, .dash-alert, .eg-group, .pe-group,
.table-card, .chart-card, .comparison-wrapper, .report-builder-card,
.role-permission-box, .login-card, .modal-card, .infra-panel, .gateway-card,
.sensor-card, .gateway-summary, .infra-modal { background: var(--bg-card); border-color: var(--border-color); }
.device-card.online, .device-card.offline, .device-card.error { border-top-color: var(--border-color); }
.meter-card:hover, .device-card:hover, .tk-card:hover, .eg-group:hover { border-color: var(--border-strong); }
.connection-card.is-online, .connection-card.is-offline { background: var(--bg-card); }

/* Shared controls, hierarchy, validation and disabled states. */
.btn-primary-scada, .btn-sm-action-ack, .btn-login, .pg-btn.active { background: var(--primary-action); color: #fff; }
.btn-primary-scada:hover, .btn-sm-action-ack:hover, .btn-login:hover, .pg-btn.active:hover { background: var(--primary-action-hover); color: #fff; }
.btn-small:hover { background: var(--primary-action); color: #fff; }
.btn-secondary-scada, .btn-report, .btn-sm-report, .btn-icon-action, .pg-btn,
.icon-btn, .tab-switcher, .chip, .latency-pill, .version-tag { background: var(--bg-card-subtle); border-color: var(--border-strong); color: var(--text-body); }
.btn-secondary-scada:hover, .btn-report:hover, .btn-sm-report:hover, .btn-icon-action:hover,
.pg-btn:hover:not(:disabled), .chip:hover, .icon-btn:hover { background: var(--bg-card-hover); color: var(--text-main); }
.search-box, .custom-input, .custom-select { background: var(--bg-card); border-color: var(--border-strong); color: var(--text-main); }
.custom-input::placeholder, .search-box input::placeholder { color: var(--text-muted); }
.custom-input:focus, .custom-select:focus, .search-box:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--primary-glow); }
button:disabled, input:disabled, select:disabled, textarea:disabled, .disabled { opacity: .58; cursor: not-allowed; }
.custom-input:disabled, .custom-select:disabled { background: var(--bg-card-subtle); color: var(--text-muted); }
.custom-input[aria-invalid="true"], .custom-select[aria-invalid="true"], .is-invalid { border-color: var(--accent-rose); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-rose) 18%, transparent); }
.validation-message, .field-validation-error, .form-error { color: var(--accent-rose); font-size: .78rem; line-height: 1.4; }
.form-hint, .page-subtitle, .filter-label, .pagination-info { color: var(--text-muted); }
.form-group label, .checkbox-label { color: var(--text-body); overflow-wrap: anywhere; }

.scada-table thead, .data-table thead, .pagination-bar, .modal-footer,
.card-footer, .site-metrics-mini, .comp-stat-card, .sec-card, .offline-sim-box,
.pe-kpi, .table-responsive { background: var(--bg-card-subtle); }
.scada-table th, .data-table th { color: var(--text-body); border-color: var(--border-color); }
.scada-table td, .data-table td { color: var(--text-main); border-color: var(--border-color); }
.scada-table tbody tr:hover, .data-table tbody tr:hover { background: var(--bg-card-hover); }

.status-pill.online, .level-chip.low { background: var(--accent-emerald-light); color: var(--accent-emerald); }
.status-pill.offline, .level-chip.high { background: var(--accent-rose-light); color: var(--accent-rose); }
.status-dot.online, .status-ring.pulse-green, .meter-conn-pill.online, .tk-conn-dot.online, .eg-foot-dot.online { background-color: var(--accent-emerald); }
.status-dot.offline, .status-ring.pulse-red, .meter-conn-pill.offline, .tk-conn-dot.offline, .eg-foot-dot.offline { background-color: var(--accent-rose); }
.eg-head, .pe-g-head { background: linear-gradient(180deg, var(--dashboard-header), var(--dashboard-header-deep)); }
.eg-g-val, .pe-g-val { fill: var(--text-main); }
.eg-tick-lb, .pe-tick-lb { fill: var(--text-muted); }
.eg-head .status-pill.offline { background: var(--accent-rose-light); border-color: var(--accent-rose); color: var(--accent-rose); }
.tank-toggle-box { background: var(--primary-blue-light); border-color: var(--primary-blue); }
.code-snippet-box { background: var(--code-bg); color: var(--code-fg); }
.tk-body { background: var(--bg-card-subtle); }
.infrastructure-page .infra-panel, .infrastructure-page .infra-metric,
.infrastructure-page .gateway-card, .infrastructure-page .sensor-card,
.infrastructure-page .gateway-summary, .infrastructure-page .infra-modal {
  background: var(--bg-card); border-color: var(--border-color); color: var(--text-main);
}
.infrastructure-page .infra-toolbar input, .infrastructure-page .infra-toolbar select,
.infrastructure-page .offline-note, .infrastructure-page .history-table thead {
  background: var(--bg-card-subtle); color: var(--text-main); border-color: var(--border-color);
}
.infrastructure-page .infra-toolbar, .infrastructure-page .infra-panel-heading,
.infrastructure-page .sensor-group, .infrastructure-page .history-table th,
.infrastructure-page .history-table td { border-color: var(--border-color); }
.modal-alert.success, .scada-toast.success { background: var(--accent-emerald-light); color: var(--accent-emerald); border-color: var(--accent-emerald); }
.modal-alert.error, .scada-toast.error, .login-error-banner { background: var(--accent-rose-light); color: var(--accent-rose); border-color: var(--accent-rose); }
.modal-alert.warning, .pe-note, .eg-warn { background: var(--accent-amber-light); color: var(--accent-amber); border-color: var(--accent-amber); }
.alert-toast, .alert-toast.info { background: var(--bg-surface); color: var(--text-main); border-color: var(--border-color); }
.alert-toast-msg, .alert-msg { color: var(--text-body); }
.alert-toast-time, .tk-conn-seen, .meter-conn-seen, .dash-gw-seen { color: var(--text-light); }
.sev-pill.warning { background: var(--accent-amber-light); color: var(--accent-amber); border-color: var(--accent-amber); }
.sev-pill.critical { background: var(--accent-rose-light); color: var(--accent-rose); border-color: var(--accent-rose); }
.sev-pill.info { background: var(--primary-blue-light); color: var(--primary-blue); border-color: var(--primary-blue); }

/* Dialog headers and footers remain visible while only the body scrolls. */
.modal-overlay { background: var(--scrim); }
.modal-card { min-width: 0; min-height: 0; max-height: calc(100dvh - 32px); }
.modal-header, .modal-footer { flex-shrink: 0; border-color: var(--border-color); }
.modal-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.modal-header h3, .modal-footer button, .modal-footer .btn { overflow-wrap: anywhere; }

.theme-toggle { color: var(--text-muted); }
.theme-toggle:hover { background: var(--bg-card-hover); color: var(--text-main); }
:where(a, button, input, select, textarea, [tabindex]):focus-visible { outline: 2px solid var(--border-focus); outline-offset: 3px; }
.sidebar .nav-item:focus-visible { outline-offset: -2px; }

@media (max-width: 640px) {
  .modal-overlay { align-items: flex-start; padding: 12px; overflow-y: auto; }
  .modal-card { width: 100%; max-height: calc(100dvh - 24px); border-radius: var(--radius-lg); }
  .modal-header, .modal-body, .modal-footer { padding-left: 16px; padding-right: 16px; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer > * { min-width: 0; max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .pulse-green, .pulse-amber, .pulse-red, .alert-toast-dot { animation: none !important; }
}

/* Native controls use the same teal accent in both themes. The browser keeps
   its native checked mark, while color-scheme selects a contrasting mark. */
input[type="checkbox"] {
  accent-color: var(--control-accent);
}

.gateway-action-icon,
.gateway-alert-icon,
.gateway-close-icon,
.status-icon svg,
.status-indicator-icon,
.gateway-chevron,
.modal-close svg {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.14em;
}

.gateway-action-icon { flex: 0 0 auto; }
.gateway-alert-icon { flex: 0 0 auto; }
.gateway-close-icon { width: 1.1em; height: 1.1em; }
.status-icon, .status-indicator-icon,
.gateway-action-icon, .gateway-alert-icon { display: inline-flex; align-items: center; gap: .3rem; }
.modal-alert, .scada-toast { display: flex; align-items: center; gap: .3rem; }
.status-indicator-icon { width: .85em; height: .85em; fill: currentColor; stroke: none; vertical-align: -0.08em; }
.gateway-chevron { width: 1em; height: 1em; }
.toast-close .gateway-close-icon, .toast-close svg, .modal-close svg { width: 1.05em; height: 1.05em; }

/* ---------- Final responsive layout and control finish ---------- */
.summary-metrics-cards {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Keep live sensor, energy and gateway cards readable at desktop widths. */
@media (max-width: 1180px) {
  .dash-gateways, .eg-groups, .pe-groups {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1024px) {
  .kpi-strip, .summary-metrics-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .dash-gateways, .eg-groups, .pe-groups,
  .kpi-strip, .summary-metrics-cards {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Selects use the same bordered, theme-aware surface as inputs while keeping
   a visible indicator in browsers that do not draw native arrows in dark mode. */
select, .custom-select, .infra-toolbar select {
  appearance: none;
  -webkit-appearance: none;
  color-scheme: light;
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-strong);
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2.25rem;
}

option { background: var(--bg-card); color: var(--text-main); }
html[data-theme="dark"] option, body.dark-theme option { background: var(--bg-card); color: var(--text-main); }

html[data-theme="dark"] select,
html[data-theme="dark"] .custom-select,
html[data-theme="dark"] .infra-toolbar select,
body.dark-theme select,
body.dark-theme .custom-select,
body.dark-theme .infra-toolbar select {
  color-scheme: dark;
}

select:focus-visible, .custom-select:focus-visible,
.infra-toolbar select:focus-visible {
  outline-color: var(--border-focus);
}

/* The incident feed is intentionally wider than its viewport. The wrapper
   supplies the accessible horizontal scroll instead of forcing labels into
   unreadable multi-line columns. */
.alerts-incident-table, .alerts-rules-table {
  width: max-content;
  min-width: 1080px;
  table-layout: auto;
}
.alerts-incident-table th, .alerts-incident-table td,
.alerts-rules-table th, .alerts-rules-table td {
  white-space: nowrap;
}
.alerts-incident-table th:nth-child(1), .alerts-incident-table td:nth-child(1) { min-width: 100px; }
.alerts-incident-table th:nth-child(2), .alerts-incident-table td:nth-child(2) { min-width: 190px; }
.alerts-incident-table th:nth-child(3), .alerts-incident-table td:nth-child(3) { min-width: 135px; }
.alerts-incident-table th:nth-child(4), .alerts-incident-table td:nth-child(4) { min-width: 120px; }
.alerts-incident-table th:nth-child(5), .alerts-incident-table td:nth-child(5) { min-width: 260px; white-space: normal; }
.alerts-incident-table th:nth-child(6), .alerts-incident-table td:nth-child(6) { min-width: 165px; }
.alerts-incident-table th:nth-child(7), .alerts-incident-table td:nth-child(7) { min-width: 170px; }
.alerts-incident-table th:nth-child(8), .alerts-incident-table td:nth-child(8) { min-width: 150px; }
.alerts-rules-table th:nth-child(1), .alerts-rules-table td:nth-child(1) { min-width: 220px; white-space: normal; }
.alerts-rules-table th:nth-child(2), .alerts-rules-table td:nth-child(2) { min-width: 145px; }
.alerts-rules-table th:nth-child(3), .alerts-rules-table td:nth-child(3) { min-width: 135px; }
.alerts-rules-table th:nth-child(4), .alerts-rules-table td:nth-child(4) { min-width: 110px; }
.alerts-rules-table th:nth-child(5), .alerts-rules-table td:nth-child(5) { min-width: 105px; }
.alerts-rules-table th:nth-child(6), .alerts-rules-table td:nth-child(6) { min-width: 240px; }
.alerts-rules-table th:nth-child(7), .alerts-rules-table td:nth-child(7) { min-width: 125px; }
.alerts-rules-table th:nth-child(8), .alerts-rules-table td:nth-child(8) { min-width: 100px; }

/* All dialogs remain inside the viewport, including pages with legacy inline
   minimum widths. Only the body/history region scrolls. */
.modal-card {
  width: min(100%, 620px);
  min-width: 0 !important;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
}
.modal-body { min-height: 0; overflow-x: hidden; overflow-y: auto; }
.modal-header h3, .modal-body, .modal-footer { overflow-wrap: anywhere; }

/* Native focus remains visible without adding a colored surface to a whole
   connectivity card. Status color is limited to its pill/dot. */
.btn-primary-scada, .btn-secondary-scada, .btn-sm-report,
.btn-sm-action-ack, .btn-icon-action, .pg-btn, .btn-small,
.infra-filters button, .back-button {
  border: 1px solid var(--border-strong);
  color: var(--text-body);
}
.btn-primary-scada, .btn-sm-action-ack { border-color: var(--primary-action); color: #fff; }
.btn-primary-scada:hover, .btn-sm-action-ack:hover { color: #fff; }
.btn-secondary-scada:hover, .btn-sm-report:hover, .btn-icon-action:hover,
.pg-btn:hover:not(:disabled), .btn-small:hover, .infra-filters button:hover,
.back-button:hover { color: var(--text-main); }
.connection-card.is-online, .connection-card.is-offline,
.infrastructure-page .connection-card.is-online,
.infrastructure-page .connection-card.is-offline { background: var(--bg-card); }

/* SVG labels previously used fixed navy/slate values that become muddy in
   dark mode. Keep the same hierarchy but resolve through theme tokens. */
.eg-arc-bg, .pe-arc-bg { stroke: var(--border-strong); }

.eg-groups, .pe-groups {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.eg-head, .pe-g-head, .pe-topbar {
  background: linear-gradient(180deg, var(--primary-action), var(--primary-action-hover));
}
.eg-head {
  flex-wrap: nowrap;
}
.eg-title {
  min-width: 0;
}
.eg-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.eg-headright {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  white-space: nowrap;
}
.eg-head .status-pill.online {
  background: var(--accent-emerald-light);
  border-color: var(--accent-emerald);
  color: var(--accent-emerald);
}
.eg-head .status-pill.offline {
  background: var(--accent-rose-light);
  border-color: var(--accent-rose);
  color: var(--accent-rose);
}
@media (max-width: 760px) {
  .eg-groups, .pe-groups {
    grid-template-columns: minmax(0, 1fr);
  }
  .eg-head {
    gap: 6px;
  }
  .eg-headright {
    gap: 5px;
  }
}
.eg-g-val, .pe-g-val { fill: var(--text-main); }
.pe-half h3 { color: var(--primary-blue); }
.pe-row .lbl, .pe-row .val.unit, .pe-empty, .pe-tick-lb { color: var(--text-muted); }
.pe-tick-lb { fill: var(--text-muted); }
/* Instrument names and very large values must not stretch a dashboard column. */
.stat-card, .kpi-card, .meter-card, .sensor-card, .glass-card, .summary-metrics-cards > * { min-width: 0; }
.stat-value, .kpi-value, .meter-value { max-width: 100%; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.scada-table td, .scada-table th { overflow-wrap: anywhere; }
.table-responsive { max-width: 100%; overflow-x: auto; }

/* Payload-driven sensor groups: creation order is stable within each category. */
.sensor-category-heading{display:flex;align-items:center;gap:1rem;grid-column:1/-1;width:100%;min-width:0;margin:1.4rem 0 .8rem;color:var(--text-primary);font-size:1rem;font-weight:700;text-align:center}
.sensor-category-heading::before,.sensor-category-heading::after{content:"";height:1px;flex:1;background:var(--border-color,var(--border,#64748b))}
.sensor-category-heading span{overflow-wrap:anywhere;max-width:70%}
.sensor-parameter-values{display:grid;gap:.35rem;min-width:0;text-align:left}
.sensor-parameter-values>div{display:flex;gap:.8rem;justify-content:space-between;flex-wrap:wrap;min-width:0}
.sensor-parameter-values span,.sensor-parameter-values strong{overflow-wrap:anywhere;min-width:0}
.sensor-parameter-values small{font-weight:400;color:var(--text-muted)}
.sensor-empty-state{padding:2rem;text-align:center;color:var(--text-muted)}
.pe-g-head{display:flex;align-items:center;gap:.7rem;flex-wrap:wrap}
.pe-g-head>span:first-child{flex:1;min-width:0;overflow-wrap:anywhere}
.eg-body,.pe-g-body{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,210px),1fr));min-width:0}
.meter-name,.meter-label,.eg-title,.pe-half h3{overflow-wrap:anywhere;min-width:0}
@media(max-width:600px){.meter-grid,.eg-groups,.pe-groups{grid-template-columns:minmax(0,1fr)}.sensor-category-heading{gap:.5rem}}
