/* ==========================================================================
   EnMon / Posho Mill — modern UI layer, v1
   --------------------------------------------------------------------------
   Loaded LAST on every live page (via web/layout/ui_head.php), on top of the
   legacy Volgh template CSS (Bootstrap 4.3.1). It re-skins the existing
   markup/classes rather than replacing them, so no page's JS, IDs or
   Bootstrap behaviour changes.

   Specificity convention: selectors are prefixed with `:root` so they tie
   the template's `.dark-mode .x` rules (0,2,0) and win on source order.
   Colours only ever come from the tokens below; dark / transparent modes
   just swap the tokens (see bottom), so component rules are written once.

   --ui-primary / --ui-primary-hover / --ui-primary-rgb are emitted per
   request by ui_head.php from the user's colour skin (color1..5.css).
   Design notes: web/docs/ui_modernization.md
   ========================================================================== */

/* ---------- 0. Tokens ---------------------------------------------------- */
:root {
  --ui-primary: #5e2dd8;
  --ui-primary-hover: #5425ca;
  --ui-primary-rgb: 94, 45, 216;
  --ui-primary-soft: rgba(var(--ui-primary-rgb), .10);
  --ui-primary-ring: rgba(var(--ui-primary-rgb), .28);

  --ui-bg: #f5f6fa;
  --ui-surface: #ffffff;
  --ui-surface-2: #f8f9fc;          /* table heads, card headers, wells  */
  --ui-surface-hover: #f2f4f9;
  --ui-border: #e6e8ef;
  --ui-border-strong: #d5d9e3;
  --ui-text: #1f2330;
  --ui-text-2: #454b5e;
  --ui-muted: #6b7185;

  --ui-success: #12a150;  --ui-success-soft: rgba(18, 161, 80, .12);
  --ui-warning: #c27c05;  --ui-warning-soft: rgba(230, 150, 10, .14);
  --ui-danger:  #d63b3b;  --ui-danger-soft:  rgba(214, 59, 59, .12);
  --ui-info:    #1b7fcc;  --ui-info-soft:    rgba(27, 127, 204, .12);

  --ui-radius-sm: 6px;
  --ui-radius: 10px;
  --ui-radius-lg: 14px;
  --ui-shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --ui-shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --ui-shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);

  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --ui-font-mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;

  --ui-sidebar-w: 248px;
  --ui-bottom-nav-h: 60px;
}

/* ---------- 1. Base ------------------------------------------------------ */
:root body {
  font-family: var(--ui-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ui-text);
  background-color: var(--ui-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
:root h1, :root h2, :root h3, :root h4, :root h5, :root h6,
:root .h1, :root .h2, :root .h3, :root .h4, :root .h5, :root .h6 {
  font-family: var(--ui-font);
  color: var(--ui-text);
  letter-spacing: -.01em;
}
:root a { color: var(--ui-primary); }
:root a:hover { color: var(--ui-primary-hover); }
:root .text-muted { color: var(--ui-muted) !important; }
:root .text-dark { color: var(--ui-text) !important; }
:root code, :root pre, :root kbd, :root samp { font-family: var(--ui-font-mono); }
/* Telemetry is numbers: keep digits aligned in tables, counters and KPIs */
:root table, :root .number-font, :root .count, :root .kpi-value { font-variant-numeric: tabular-nums; }
:root hr { border-color: var(--ui-border); }
:root ::selection { background: rgba(var(--ui-primary-rgb), .2); }

/* ---------- 2. App shell ------------------------------------------------- */
/* 2a. Sidebar */
:root .app-sidebar {
  width: var(--ui-sidebar-w);
  background: var(--ui-surface) !important;
  border-right: 1px solid var(--ui-border);
  box-shadow: none;
  color: var(--ui-text-2);
  overflow-y: auto;            /* long admin menus must scroll on short screens */
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
@media (min-width: 768px) {
  :root .app-sidebar { padding-top: 60px; }
  :root .side-header {
    width: var(--ui-sidebar-w);
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: var(--ui-surface);
    border-bottom: 1px solid var(--ui-border);
    border-right: 1px solid var(--ui-border);
  }
  :root .app-content { margin-left: var(--ui-sidebar-w); }
  :root .footer { padding-left: calc(var(--ui-sidebar-w) + 1.25rem); }
}
/* Compact profile block: avatar + name/role on one row instead of a
   ~300px centred stack */
:root .app-sidebar__user {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--ui-border);
}
:root .app-sidebar__user .user-pro-body {
  display: grid;
  grid-template-columns: 44px 1fr;
  column-gap: 12px;
  align-items: center;
  text-align: left !important;
}
:root .app-sidebar__user .user-pic { grid-row: 1 / span 2; margin: 0; }
:root .app-sidebar__user .user-pic img,
:root .app-sidebar__user .avatar-xl {
  width: 44px; height: 44px;
  border: 1px solid var(--ui-border);
  box-shadow: none;
}
:root .app-sidebar__user .user-info { margin: 0; padding: 0; line-height: 1.3; }
:root .app-sidebar__user .user-info h6 { font-size: 14px; font-weight: 600; margin: 0 !important; }
:root .app-sidebar__user .user-info .text-sm { font-size: 12px; }
:root .sidebar-navs { padding: 8px 12px 4px; border-bottom: 1px solid var(--ui-border); }
:root .sidebar-navs .nav { justify-content: flex-start; gap: 6px; }
:root .sidebar-navs .nav-link {
  margin: 0 !important;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--ui-radius-sm);
  border: 1px solid var(--ui-border);
  background: var(--ui-surface);
  color: var(--ui-muted);
}
:root .sidebar-navs .nav-link:hover { color: var(--ui-primary); border-color: var(--ui-primary-ring); background: var(--ui-primary-soft); }

/* Menu */
:root .side-menu { padding: 4px 10px 24px; margin: 0; }
:root .side-menu h3 {
  color: var(--ui-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  opacity: 1;
  margin: 18px 10px 6px;
}
:root .side-menu__item {
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: var(--ui-radius-sm);
  color: var(--ui-text-2);
  font-size: 14px;
  font-weight: 500;
  transition: background-color .15s ease, color .15s ease;
}
:root .side-menu__item:hover,
:root .side-menu__item:focus {
  color: var(--ui-text);
  background: var(--ui-surface-hover);
}
:root .side-menu__item.active,
:root .side-menu__item.active:hover {
  color: var(--ui-primary);
  background: var(--ui-primary-soft);
  font-weight: 600;
}
:root .side-menu__item.active::before { display: none; }
/* sidemenu.js also marks the *group toggle* of the current page active;
   keep that one text-only so only the actual page gets the pill */
:root .side-menu__item.active[href="#"],
:root .side-menu__item.active[href="#"]:hover { background: transparent; color: var(--ui-text); }
:root .side-menu__item.active[href="#"] .side-menu__icon { color: var(--ui-text-2); }
:root .side-menu .side-menu__icon {
  color: var(--ui-muted);
  font-size: 16px;
  width: 20px;
  height: 20px;
  line-height: 20px;           /* legacy forces a 30px line box → 46px rows */
  margin-right: 10px;
  text-align: center;
}
:root .side-menu__label { white-space: normal; line-height: 1.35; }
:root .side-menu__item:hover .side-menu__icon { color: var(--ui-text-2); }
:root .side-menu__item.active .side-menu__icon { color: var(--ui-primary); }
:root .side-menu .angle { color: var(--ui-muted); font-size: 14px; }
:root .slide-menu { padding-left: 14px; margin: 2px 0 4px; border-left: 1px solid var(--ui-border); margin-left: 19px; }
:root .slide-menu .side-menu__item { padding: 6px 10px; font-size: 13.5px; }
:root .slide-menu .side-menu__icon { font-size: 14px; }
:root .app-sidebar__overlay { background: rgba(15, 18, 30, .45); }

/* 2b. Content column */
:root .app-content .side-app { padding: 0 28px; }
/* Page header: was its own white card eating a full band on every page —
   now a flat title row sitting on the page background */
:root .page-header {
  background: transparent !important;
  box-shadow: none !important;
  border: 0 !important;
  margin: 20px 0 16px;
  padding: 0;
  min-height: 0;
  gap: 8px 16px;
}
:root .page-title { font-size: 22px; font-weight: 650; letter-spacing: -.02em; margin-bottom: 2px; }
:root .page-header .breadcrumb {
  background: transparent; padding: 0; margin: 0;
  font-size: 13px;
}
:root .breadcrumb-item, :root .breadcrumb-item a { color: var(--ui-muted); }
:root .breadcrumb-item.active { color: var(--ui-text-2); }
:root .breadcrumb-item + .breadcrumb-item::before { color: var(--ui-border-strong); content: "/"; }
:root .page-header .nav-link.icon {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--ui-radius-sm);
  color: var(--ui-muted);
  padding: 0; margin: 0 2px;
}
:root .page-header .nav-link.icon:hover { background: var(--ui-surface); color: var(--ui-text); }
:root .page-header .profile-user { width: 34px; height: 34px; }
/* The right-hand "Notifications" off-canvas and its toggle are empty on
   every page — inert chrome, hidden rather than offered */
:root .header-settings,
:root .sidebar-right { display: none !important; }

/* 2c. Footer */
:root .footer {
  background: transparent;
  border-top: 1px solid var(--ui-border);
  color: var(--ui-muted);
  font-size: 12.5px;
  padding-top: 14px;
  padding-bottom: 14px;
}
:root .footer a { color: var(--ui-muted); }
:root #back-to-top {
  background: var(--ui-primary);
  border-radius: 50%;
  box-shadow: var(--ui-shadow-lg);
}

/* ---------- 3. Cards ----------------------------------------------------- */
:root .card {
  background-color: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-lg);
  box-shadow: var(--ui-shadow-sm);
  margin-bottom: 1.25rem;
}
:root .card-header {
  background: transparent;
  border-bottom: 1px solid var(--ui-border);
  padding: 14px 20px;
  min-height: 56px;
  flex-wrap: wrap;
  gap: 8px;
}
:root .card-header:first-child { border-radius: var(--ui-radius-lg) var(--ui-radius-lg) 0 0; }
:root .card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ui-text);
  text-transform: none;
  letter-spacing: -.005em;
}
:root .card-header .card-title { margin-bottom: 0; }
:root .card-body { padding: 18px 20px; }
:root .card-footer { background: var(--ui-surface-2); border-top: 1px solid var(--ui-border); padding: 12px 20px; }
:root .card-footer:last-child { border-radius: 0 0 var(--ui-radius-lg) var(--ui-radius-lg); }
/* Cards nested in cards (common in the legacy pages): flatten the inner
   one so it reads as a section, not a floating box */
:root .card .card { box-shadow: none; }

/* ---------- 4. Tables ---------------------------------------------------- */
:root .table { color: var(--ui-text); margin-bottom: 0; }
:root .table th, :root .table td {
  border-top-color: var(--ui-border);
  padding: 10px 12px;
  vertical-align: middle;
}
:root .table thead th,
:root .table > thead > tr > th {
  background: var(--ui-surface-2);
  color: var(--ui-muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--ui-border);
  border-top: 0;
  white-space: nowrap;
}
:root .table-sm th, :root .table-sm td { padding: 7px 10px; }
:root .table-bordered, :root .table-bordered th, :root .table-bordered td { border-color: var(--ui-border); }
:root .table-striped tbody tr:nth-of-type(odd) { background-color: var(--ui-surface-2); }
:root .table-hover tbody tr:hover,
:root .table tbody tr:hover { background-color: var(--ui-surface-hover); }
:root .table-borderless tbody tr:hover { background-color: transparent; }
:root .table-responsive,
:root .ui-table-scroll {
  border-radius: var(--ui-radius);
  -webkit-overflow-scrolling: touch;
}
/* ui-modern.js wraps any wide, unwrapped .table in .ui-table-scroll */
:root .ui-table-scroll { display: block; width: 100%; overflow-x: auto; }
:root .ui-table-scroll.is-scrollable {
  /* edge fade hints that there is more table off to the right */
  background:
    linear-gradient(to right, var(--ui-surface) 30%, rgba(255,255,255,0)) left center / 24px 100% no-repeat local,
    linear-gradient(to left, var(--ui-surface) 30%, rgba(255,255,255,0)) right center / 24px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.12), rgba(0,0,0,0)) left center / 10px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.12), rgba(0,0,0,0)) right center / 10px 100% no-repeat scroll;
}
:root .dataTables_wrapper .dataTables_filter input,
:root .dataTables_wrapper .dataTables_length select { border-radius: var(--ui-radius-sm); }

/* ---------- 5. Buttons & badges ----------------------------------------- */
:root .btn {
  border-radius: var(--ui-radius-sm);
  font-weight: 500;
  font-size: 14px;
  padding: 7px 14px;
  line-height: 1.4;
  box-shadow: none;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
:root .btn-sm { font-size: 12.5px; padding: 4px 10px; }
:root .btn-lg { font-size: 15px; padding: 10px 18px; }
:root .btn-primary {
  background-color: var(--ui-primary) !important;
  border-color: var(--ui-primary) !important;
  color: #fff !important;
}
:root .btn-primary:hover, :root .btn-primary:focus, :root .btn-primary.active, :root .btn-primary:not(:disabled):not(.disabled):active {
  background-color: var(--ui-primary-hover) !important;
  border-color: var(--ui-primary-hover) !important;
}
:root .btn-outline-primary { color: var(--ui-primary) !important; border-color: var(--ui-primary-ring) !important; background: transparent; }
:root .btn-outline-primary:hover { background: var(--ui-primary-soft) !important; }
:root .btn-light, :root .btn-default, :root .btn-secondary {
  background: var(--ui-surface) !important;
  border: 1px solid var(--ui-border-strong) !important;
  color: var(--ui-text-2) !important;
}
:root .btn-light:hover, :root .btn-default:hover, :root .btn-secondary:hover { background: var(--ui-surface-hover) !important; color: var(--ui-text) !important; }
:root .btn-group > .btn { border-radius: 0; }
:root .btn-group > .btn:first-child { border-radius: var(--ui-radius-sm) 0 0 var(--ui-radius-sm); }
:root .btn-group > .btn:last-child { border-radius: 0 var(--ui-radius-sm) var(--ui-radius-sm) 0; }
:root .btn-group > .btn:only-child { border-radius: var(--ui-radius-sm); }

:root .badge {
  border-radius: 999px;
  font-weight: 600;
  font-size: 11.5px;
  padding: .3em .7em;
  letter-spacing: .01em;
}
/* style.css sets badge colours with !important (and white text on yellow
   for .badge-warning, which is unreadable) — soft tinted badges instead */
:root .badge-primary { background: var(--ui-primary-soft) !important; color: var(--ui-primary) !important; }
:root .badge-success { background: var(--ui-success-soft) !important; color: var(--ui-success) !important; }
:root .badge-warning { background: var(--ui-warning-soft) !important; color: var(--ui-warning) !important; }
:root .badge-danger  { background: var(--ui-danger-soft) !important;  color: var(--ui-danger) !important; }
:root .badge-info    { background: var(--ui-info-soft) !important;    color: var(--ui-info) !important; }

/* ---------- 6. Forms ----------------------------------------------------- */
:root .form-control,
:root .custom-select,
:root select.form-control {
  background-color: var(--ui-surface);
  border: 1px solid var(--ui-border-strong);
  border-radius: var(--ui-radius-sm);
  color: var(--ui-text);
  font-size: 14px;
  min-height: 38px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
:root .form-control-sm { min-height: 32px; font-size: 13px; }
:root .form-control::placeholder { color: var(--ui-muted); opacity: .8; }
:root .form-control:focus,
:root .custom-select:focus {
  border-color: var(--ui-primary);
  box-shadow: 0 0 0 3px var(--ui-primary-ring);
  background-color: var(--ui-surface);
  color: var(--ui-text);
}
:root .input-group-text { background: var(--ui-surface-2); border-color: var(--ui-border-strong); color: var(--ui-muted); }
:root .input-group > .form-control:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
:root .input-group-append .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; }
:root label, :root .form-label { font-weight: 500; color: var(--ui-text-2); }
:root .custom-control-input:checked ~ .custom-control-label::before {
  background-color: var(--ui-primary); border-color: var(--ui-primary);
}
:root .custom-control-input:focus ~ .custom-control-label::before { box-shadow: 0 0 0 3px var(--ui-primary-ring); }

/* ---------- 7. Other components ----------------------------------------- */
:root .list-group-item {
  background: var(--ui-surface);
  border-color: var(--ui-border);
  color: var(--ui-text);
}
:root .list-group-item-action:hover, :root .list-group-item-action:focus { background: var(--ui-surface-hover); }
:root .list-group-item.active {
  background: var(--ui-primary-soft);
  border-color: var(--ui-border);
  color: var(--ui-text);
  box-shadow: inset 3px 0 0 var(--ui-primary);
  z-index: 1;
}
:root .list-group-item.active h5, :root .list-group-item.active .mb-1 { color: var(--ui-text); }
:root .list-group > .list-group-item:first-child { border-top-left-radius: var(--ui-radius); border-top-right-radius: var(--ui-radius); }
:root .list-group > .list-group-item:last-child { border-bottom-left-radius: var(--ui-radius); border-bottom-right-radius: var(--ui-radius); }

:root .pagination { gap: 4px; flex-wrap: wrap; }
:root .page-link {
  border-radius: var(--ui-radius-sm) !important;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface);
  color: var(--ui-text-2);
  min-width: 34px; text-align: center;
  margin-left: 0 !important;
}
:root .page-link:hover { background: var(--ui-surface-hover); color: var(--ui-text); }
:root .page-item.active .page-link { background: var(--ui-primary); border-color: var(--ui-primary); color: #fff; }

:root .dropdown-menu {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow-lg);
  padding: 6px;
}
:root .dropdown-item { border-radius: var(--ui-radius-sm); color: var(--ui-text-2); padding: 7px 10px; }
:root .dropdown-item:hover, :root .dropdown-item:focus { background: var(--ui-surface-hover); color: var(--ui-text); }
:root .dropdown-divider { border-color: var(--ui-border); }

:root .modal-content {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-lg);
  box-shadow: var(--ui-shadow-lg);
}
:root .modal-header, :root .modal-footer { border-color: var(--ui-border); }
:root .modal-backdrop.show { opacity: .45; }

:root .alert { border-radius: var(--ui-radius); border-width: 1px; }
:root .progress { background: var(--ui-surface-2); border-radius: 999px; }
:root .progress-bar { border-radius: 999px; }
:root .nav-tabs { border-bottom-color: var(--ui-border); }
:root .nav-tabs .nav-link { border-radius: var(--ui-radius-sm) var(--ui-radius-sm) 0 0; color: var(--ui-muted); }
:root .nav-tabs .nav-link.active { color: var(--ui-primary); border-color: var(--ui-border) var(--ui-border) var(--ui-surface); background: var(--ui-surface); }

/* ---------- 8. Page-specific (homepage) ---------------------------------- */
/* The homepage wraps search + KPIs + device list in one outer card (card
   inside card inside card). Flatten that outer wrapper: the search header
   becomes its own card and the body sits directly on the page. */
:root .ui-home-shell { background: transparent; border: 0; box-shadow: none; overflow: visible !important; }
:root .ui-home-shell > .card-header {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-lg);
  box-shadow: var(--ui-shadow-sm);
  margin-bottom: 1.25rem;
}
:root .ui-home-shell > .card-header .card-title { font-size: 14px; white-space: nowrap; }
:root .ui-home-shell > .card-body { padding: 0; }
/* KPI tiles */
:root .ui-kpi .card { height: calc(100% - 1.25rem); }
:root .ui-kpi .card-body { padding: 14px 16px; }
:root .ui-kpi p.mb-1 { color: var(--ui-muted); font-size: 12.5px; font-weight: 500; line-height: 1.35; min-height: 2.7em; }
:root .ui-kpi h3 { font-size: 24px; font-weight: 700; margin: 2px 0 8px; }
:root .ui-kpi .progress { height: 4px; }
/* the "no ratio" tiles use a full-width bg-light bar as a placeholder —
   render it as a neutral track so it doesn't glare white in dark mode */
:root .ui-kpi .progress-bar.bg-light { background: var(--ui-border-strong) !important; }
:root .ui-kpi .card-body > div:last-child { font-size: 11.5px; color: var(--ui-muted); }
/* Device list */
:root .device-list-item { padding: 12px 16px; }
:root .device-list-item h5 { font-size: 14.5px; font-weight: 600; margin-bottom: 2px !important; }
:root .device-list-item p { font-size: 12.5px; color: var(--ui-muted); margin: 0 !important; }
/* Device detail action buttons: a wrapping grid instead of 4 squeezed cols */
:root .device-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin: 16px 0 0 !important;
}
:root .device-actions > .btn { margin: 0 !important; max-width: none; }
:root .device-details-container { scroll-margin-top: 72px; }

/* ---------- 9. Mobile bottom navigation ---------------------------------- */
.ui-bottom-nav { display: none; }
@media (max-width: 767.98px) {
  .ui-bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 1030;
    display: flex;
    height: calc(var(--ui-bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--ui-surface);
    border-top: 1px solid var(--ui-border);
    box-shadow: 0 -4px 16px rgba(16, 24, 40, .06);
  }
  .ui-bottom-nav__item {
    flex: 1 1 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px;
    min-width: 0;
    border: 0; background: none;
    color: var(--ui-muted) !important;
    font: 500 11px/1.1 var(--ui-font);
    text-decoration: none !important;
    -webkit-tap-highlight-color: transparent;
  }
  .ui-bottom-nav__item i { font-size: 19px; line-height: 1; }
  .ui-bottom-nav__item.is-active { color: var(--ui-primary) !important; }
  .ui-bottom-nav__item:focus { outline: none; }
  .ui-bottom-nav__item:focus-visible { outline: 2px solid var(--ui-primary); outline-offset: -4px; border-radius: 10px; }
  .ui-bottom-nav__item.is-active i { transform: translateY(-1px); }
  :root body { padding-bottom: calc(var(--ui-bottom-nav-h) + env(safe-area-inset-bottom, 0px)); }
  :root #back-to-top { bottom: calc(var(--ui-bottom-nav-h) + 16px + env(safe-area-inset-bottom, 0px)) !important; }
}

/* ---------- 10. Responsive ----------------------------------------------- */
@media (max-width: 1199.98px) {
  :root .app-content .side-app { padding: 0 18px; }
}
@media (max-width: 767.98px) {
  :root body { font-size: 14.5px; }
  :root .app-content .side-app { padding: 0 12px; }
  :root .mobile-header {
    background: var(--ui-surface) !important;
    border-bottom: 1px solid var(--ui-border);
    box-shadow: none;
  }
  /* The "more" (⋮) toggler only reveals inert search/bell/mail icons */
  :root .navresponsive-toggler,
  :root .responsive-navbar { display: none !important; }
  :root .page-header { margin: 14px 0 12px; }
  :root .page-header .header-right-icons { display: none !important; }
  :root .page-title { font-size: 19px; }
  :root .card { border-radius: var(--ui-radius); margin-bottom: 12px; }
  :root .card-header { padding: 12px 14px; min-height: 0; }
  :root .card-body { padding: 14px; }
  :root .table th, :root .table td { padding: 8px 10px; }
  :root .btn { padding: 8px 14px; }             /* comfortable tap targets */
  :root .form-control { font-size: 16px; }     /* stops iOS zoom-on-focus */
  :root .footer { padding-left: 12px; padding-right: 12px; }
  :root .footer .row { gap: 4px; }
  :root .app-sidebar { width: min(84vw, 300px); left: calc(-1 * min(84vw, 300px)); box-shadow: var(--ui-shadow-lg); }
  :root .app.sidenav-toggled .app-sidebar { left: 0; }
  :root .ui-kpi h3 { font-size: 21px; }
  :root .ui-kpi p.mb-1 { min-height: 0; }
  /* device detail: the decorative icon column costs ~40px of a 390px screen */
  :root .device-details-container td.border-left-0.border-right { display: none; }
  :root .ui-home-shell > .card-header { padding: 10px 12px; }
  :root .ui-home-shell > .card-header .col { padding: 0; }
  :root .modal-dialog { margin: 12px; }
  /* sengine.css gives EVERY .input-group min-width:450px (meant for the
     homepage search) — wider than a phone, so filters spill off-card */
  :root .input-group { min-width: 0; }
  /* sidemenu.css hides section headings whenever the sidebar is "toggled" —
     right for desktop icon-only mode, wrong for the open phone drawer */
  :root .app.sidenav-toggled .side-menu h3 { display: block; }
}

/* ---------- 11. Colour modes -------------------------------------------- */
body.dark-mode {
  --ui-primary-soft: rgba(var(--ui-primary-rgb), .20);
  --ui-primary-ring: rgba(var(--ui-primary-rgb), .45);
  --ui-bg: #13141c;
  --ui-surface: #1c1e29;
  --ui-surface-2: #222533;
  --ui-surface-hover: #272a3a;
  --ui-border: rgba(255, 255, 255, .08);
  --ui-border-strong: rgba(255, 255, 255, .14);
  --ui-text: #e7e8ef;
  --ui-text-2: #c3c6d4;
  --ui-muted: #9195a8;
  --ui-success: #3ccf7d; --ui-warning: #f0b43c; --ui-danger: #f06a6a; --ui-info: #5cb3f0;
  --ui-shadow-sm: none;
  --ui-shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
body.transparent-mode {
  --ui-surface: rgba(255, 255, 255, .08);
  --ui-surface-2: rgba(255, 255, 255, .05);
  --ui-surface-hover: rgba(255, 255, 255, .12);
  --ui-border: rgba(255, 255, 255, .12);
  --ui-border-strong: rgba(255, 255, 255, .2);
  --ui-text: #fff;
  --ui-text-2: rgba(255, 255, 255, .85);
  --ui-muted: rgba(255, 255, 255, .65);
  --ui-shadow-sm: none;
}
/* transparent-mode paints its own gradient page background; keep it */
:root body.transparent-mode { background-color: transparent; }
:root body.transparent-mode .app-sidebar,
:root body.transparent-mode .side-header,
:root body.transparent-mode .ui-bottom-nav { background: rgba(20, 20, 40, .72) !important; backdrop-filter: blur(12px); }
:root body.transparent-mode .dropdown-menu,
:root body.transparent-mode .modal-content { background: #2a2a45; }
/* Bootstrap's .bg-light / .bg-white utilities stay near-white in dark mode
   (used as wells on analytics, diagnostics, summary pages) */
:root body.dark-mode .bg-light { background-color: var(--ui-surface-2) !important; }
:root body.dark-mode .bg-white { background-color: var(--ui-surface) !important; }
:root .dark-mode .ui-table-scroll.is-scrollable,
:root .transparent-mode .ui-table-scroll.is-scrollable { background: none; }

/* ---------- 12. Accessibility -------------------------------------------- */
:root :focus-visible {
  outline: 2px solid var(--ui-primary);
  outline-offset: 2px;
}
:root .btn:focus-visible, :root .form-control:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ui-primary-ring); }
@media (prefers-reduced-motion: reduce) {
  :root *, :root *::before, :root *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- 13. Print ---------------------------------------------------- */
@media print {
  .ui-bottom-nav, :root .page-header .header-right-icons, :root #back-to-top { display: none !important; }
  :root .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  :root body { background: #fff; padding-bottom: 0; }
}
