/* ------------------------------------------------------------------
   Global Styles
------------------------------------------------------------------ */
:root {
  --navy-900: #0b1220;
  --navy-800: #0f172a;
  --navy-700: #111827;
  --stone-100: #e2e8f0;
  --stone-300: #cbd5e1;
  --stone-400: #94a3b8;
  --brand-500: #3b82f6;
  --brand-400: #60a5fa;
  --mint-400: #22d3ee;
  --card-800: rgba(255,255,255,0.04);
  --card-700: rgba(255,255,255,0.08);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: system-ui, Arial, sans-serif;
  background: #f5f7fa;
  color: #222;
}
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 0.5rem; font-weight: 600; }
button, .btn { cursor: pointer; font: inherit; margin-left: 20px; padding: 0.45rem 1rem; border: 1px solid #1e293b; border-radius: 6px; background: #1e293b; color: #fff; transition: background 0.2s, box-shadow 0.2s, transform 0.1s; display: inline-block; text-decoration: none; }
button:hover, .btn:hover { background: #0f172a; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
button:active, .btn:active { background: #0b1220; transform: translateY(1px); box-shadow: inset 0 2px 6px rgba(0,0,0,0.45); }
button.is-pressed, .btn.is-pressed { transform: translateY(1px); box-shadow: inset 0 2px 6px rgba(0,0,0,0.45); filter: brightness(0.92); }
button:disabled, .btn:disabled { cursor: not-allowed; opacity: 0.55; box-shadow: none; }
button:disabled:hover, .btn:disabled:hover { background: #1e293b; }

body.edit-mode button:active,
body.edit-mode .btn:active,
body.edit-mode button.is-pressed,
body.edit-mode .btn.is-pressed {
  transform: none;
  box-shadow: none;
  filter: none;
}

/* ------------------------------------------------------------------
   Header / Top Bar
------------------------------------------------------------------ */
header { background: linear-gradient(90deg, #0f172a 0%, #1e293b 100%); color: #fff; padding: 1rem 1.5rem; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 6px rgba(0,0,0,0.25); position: sticky; top: 0; z-index: 400; }
header h1 { font-size: 1.25rem; letter-spacing: .3px; }
header .header-actions { display: flex; align-items: center; gap: 0.75rem; }
header .header-actions .btn { margin-left: 0; }
.avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
}
/* Login button inside header */
header .login-btn { border: none; background: #3b82f6; color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.15); margin-left: 10px;}
header .login-btn:hover { background: #2563eb; }
header .login-btn:active { background: #1d4ed8; }

.edit-layout-btn {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  margin: 0;
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.18);
  color: #e5e7eb;
  box-shadow: none;
  z-index: 200; /* keep above canvas/grid */
}

.edit-layout-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.edit-layout-btn:active {
  background: rgba(255, 255, 255, 0.16);
}

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  background: #fff;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
  padding: 0.35rem 0;
  z-index: 200;
}

.dropdown-item {
  display: block;
  padding: 0.6rem 0.9rem;
  color: inherit;
  font-weight: 600;
  margin: 0;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
}

.dropdown-item:hover {
  background: #f1f5f9;
  text-decoration: none;
}

/* ------------------------------------------------------------------
   edit warning
   This is shown when the user is in edit mode
------------------------------------------------------------------ */
#editWarning {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #fff3cd;
  color: #856404;
  padding: 0.75rem 1.25rem;
  border: 1px solid #ffeeba;
  border-radius: 6px;
  font-weight: bold;
  text-align: center;
  z-index: 150;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

/* ------------------------------------------------------------------
   Layout Containers
------------------------------------------------------------------ */
main { padding: 1.5rem; }
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Responsive grid for device cards */
.device-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.area-device-status {
  position: absolute;
  right: 0.9rem;
  bottom: 0.9rem;
  z-index: 4;
  max-width: min(70%, 640px);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: rgba(255, 255, 255, 0.93);
  color: #334155;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.35;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.2);
  pointer-events: none;
}

.area-device-status.ok {
  color: #166534;
  border-color: #86efac;
}

.area-device-status.alert {
  color: #b91c1c;
  border-color: #fecaca;
}

.area-device-status.empty {
  color: #475569;
}

#deviceContainer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  transform-origin: 0 0;
}

/* ------------------------------------------------------------------
   Device Card Component
------------------------------------------------------------------ */
.device-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.04); padding: 1rem 1.25rem; display: flex; flex-direction: column; justify-content: space-between; transition: transform 0.15s, box-shadow 0.15s; color: #0f172a; }
.device-card:hover { /*transform: translateY(-2px); */box-shadow: 0 4px 8px rgba(0,0,0,0.06); }
.device-title { font-size: 1.1rem; margin-bottom: 0.5rem; color: #0f172a; }
.device-lifecycle { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.45rem; }
.device-lifecycle-pill {
  align-self: flex-start;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.device-lifecycle-pill.online { background: #dcfce7; color: #166534; }
.device-lifecycle-pill.offline { background: #fee2e2; color: #991b1b; }
.device-lifecycle-pill.never-connected { background: #e2e8f0; color: #334155; }
.device-last-seen { font-size: 0.75rem; color: #475569; font-weight: 500; }
.device-card.device-online { border-color: #22c55e; }
.device-card.device-offline { border-color: #ef4444; }
.device-card.device-never-connected { border-color: #94a3b8; }
.level-value, .pump-state { font-weight: 500; color: #0f172a; }
.pump-state { text-transform: capitalize; }
.level-value.telemetry-stale,
.pump-state.telemetry-stale {
  color: #b45309;
}
.level-value.telemetry-no-data,
.pump-state.telemetry-no-data {
  color: #64748b;
  font-style: italic;
}
.device-card.editing { border: 2px dashed #2563eb; cursor: move; }
.device-card.control-disabled { border-color: #f59e0b; }
.device-card .device-control-status {
  margin: 0.35rem 0 0;
  color: #92400e;
  font-size: 0.78rem;
  font-weight: 600;
}
.device-card .device-control-status.command-feedback-pending {
  color: #1d4ed8;
}
.device-card .device-control-status.command-feedback-accepted {
  color: #047857;
}
.device-card .device-control-status.command-feedback-rejected {
  color: #b91c1c;
}

.device-card.selected {
  outline: 2px solid #1e293b;
  outline-offset: 2px;
}

/* Buttons inside device card */
.device-card .start-btn,
.device-card .stop-btn {
  width: 80px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  margin-top: 0.5rem;
  margin-right: 0.5rem;
  position: relative;
  overflow: hidden;
}

.device-card .start-btn {
  background: #10b981;
  border-color: #10b981;
  color: #fff;
}

.device-card .start-btn:hover {
  background: #059669;
}

.device-card .start-btn:active {
  background: #047857;
}

.device-card .stop-btn {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

.device-card .stop-btn:hover {
  background: #dc2626;
}

.device-card .stop-btn:active {
  background: #b91c1c;
}

.device-card .graph-btn {
  background: #fff;
  border-color: #cfd8e3;
  color: #0f172a;
}

.device-card .graph-btn:hover {
  background: #f3f4f6;
}

.device-card .graph-btn:active {
  background: #e5e7eb;
}


/* ------------------------------------------------------------------
   Forms (login page)
------------------------------------------------------------------ */
form { display: flex; flex-direction: column; gap: 0.75rem; max-width: 320px; margin: 2rem auto; background: #fff; padding: 1.5rem 2rem; border: 1px solid #e2e8f0; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.04); }
label { font-size: 0.9rem; color: #374151; }
input, select { padding: 0.45rem 0.6rem; border: 1px solid #cbd5e1; border-radius: 6px; font: inherit; }
.error { color: #dc2626; margin-top: 0.5rem; font-size: 0.85rem; min-height: 18px; }

/* ------------------------------------------------------------------
   Utility classes
------------------------------------------------------------------ */
.text-center { text-align: center; }
.mt-1 { margin-top: 0.25rem; }

/* ------------------------------------------------------------------
   Chart modal for device history
------------------------------------------------------------------ */
.modal.hidden { display: none; }
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center;
  z-index: 500;
}
.modal-content {
  background: white; padding: 20px; border-radius: 8px;
  position: relative;
  z-index: 501;
}

/* ------------------------------------------------------------------
   Device wizard modal
------------------------------------------------------------------ */
.wizard-modal {
  width: min(1200px, 96vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.indicator-modal {
  width: min(520px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: hidden;
}

.progress-modal {
  width: min(560px, 92vw);
  --progress-input-height: 2.4rem;
}

.text-modal {
  width: min(520px, 92vw);
}

.button-modal {
  width: min(600px, 92vw);
}

.button-state {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.5rem;
  background: #f8fafc;
  display: grid;
  gap: 0.35rem;
}

.indicator-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.indicator-modal-body {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex: 1;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.indicator-modal-body input,
.indicator-modal-body select,
.indicator-modal-body textarea {
  width: 100%;
}

.indicator-modal-body input[type="checkbox"],
.indicator-modal-body input[type="radio"] {
  width: auto;
}

.command-confirm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.2rem 0 0;
  font-size: 0.92rem;
  color: #334155;
}

.command-confirm-row input[type="checkbox"] {
  width: 1.15rem !important;
  height: 1.15rem !important;
  accent-color: #2563eb;
  flex: 0 0 auto;
}

.command-confirm-title {
  color: #0b1220;
  font-weight: 700;
}

.pump-speed-fields {
  margin-top: 0.35rem;
  display: grid;
  gap: 0.45rem;
}

.pump-speed-fields.hidden {
  display: none;
}

.indicator-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.indicator-color-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.indicator-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.indicator-tag-list {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  max-height: 180px;
  overflow-y: auto;
  padding: 0.4rem;
  display: grid;
  gap: 0.35rem;
}

.indicator-tag-item {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  text-align: left;
  cursor: pointer;
  font: inherit;
  margin-left: 0;
  width: 100%;
}

.indicator-tag-item:hover {
  background: #e2e8f0;
}

.indicator-tag-item.active {
  background: #1e293b;
  border-color: #1e293b;
  color: #fff;
}

.indicator-tag-empty {
  font-size: 0.85rem;
  color: #64748b;
  padding: 0.35rem;
}

.indicator-error {
  margin-top: 0.25rem;
}

.progress-setpoints {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.progress-setpoint-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  align-items: center;
}

.progress-setpoint-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
}

.progress-setpoint-row input[type="number"] {
  width: 100%;
}

.progress-modal input,
.progress-modal select {
  min-height: var(--progress-input-height);
  color: #0f172a;
}

.wizard-modal .btn,
.indicator-modal .btn {
  background: #1e293b;
  border-color: #1e293b;
  color: #fff;
  box-shadow: none;
}

.wizard-modal .btn.primary,
.indicator-modal .btn.primary {
  background: #1e293b;
  border-color: #1e293b;
  color: #fff;
}

#wizardBack,
#wizardSave,
#addPointBtn,
#importCsvBtn {
  background: #1e293b;
  border-color: #1e293b;
  color: #fff;
  box-shadow: none;
}

.wizard-modal .btn:hover,
.indicator-modal .btn:hover {
  background: #0f172a;
}

.wizard-modal .btn:active,
.indicator-modal .btn:active {
  background: #0b1220;
}

.wizard-modal .btn:disabled,
.indicator-modal .btn:disabled {
  opacity: 0.6;
}

.wizard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.wizard-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.wizard-step-indicator {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: #e2e8f0;
  color: #0f172a;
  font-weight: 600;
  font-size: 0.85rem;
}

.wizard-step-indicator.active {
  background: #2563eb;
  color: #fff;
}

.wizard-body {
  overflow-y: auto;
  padding-right: 0.35rem;
}

.wizard-step {
  display: none;
}

.wizard-step.active {
  display: block;
}

.wizard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem 1rem;
}

.wizard-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.wizard-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.wizard-toggle .btn {
  margin-left: 0;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
}

.wizard-toggle .btn.active {
  background: #1e293b;
  border-color: #1e293b;
  color: #fff;
}

.wizard-grid input,
.wizard-grid select,
.wizard-stack input,
.wizard-stack select {
  width: 100%;
}

.driver-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

.driver-option {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  cursor: pointer;
}

.driver-option span { font-weight: 600; }
.driver-option small { color: #475569; }

.wizard-note {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: #64748b;
}

.driver-config.hidden { display: none; }

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

.csv-import {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.points-table-wrap {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  max-height: 320px;
  overflow-x: auto;
  overflow-y: auto;
}

.points-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.points-table th,
.points-table td {
  border-bottom: 1px solid #e2e8f0;
  padding: 0.4rem 0.5rem;
  text-align: left;
  white-space: nowrap;
}

.points-table th {
  position: sticky;
  top: 0;
  background: #1e293b;
  color: #fff;
  border-bottom-color: #0f172a;
  z-index: 1;
}

.points-table input[type="text"],
.points-table input[type="number"],
.points-table select {
  width: auto;
  min-width: 6ch;
}

.points-table .btn {
  margin-left: 0;
  padding: 0.3rem 0.6rem;
}

.points-table .point-bit-col {
  min-width: 10ch;
}

.points-table .point-bit-warning {
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: #b45309;
  line-height: 1.2;
}

.points-table .point-bit.invalid {
  border-color: #dc2626;
}

.wizard-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.wizard-actions {
  display: flex;
  gap: 0.5rem;
}

.wizard-error {
  color: #dc2626;
  font-size: 0.85rem;
  min-height: 1rem;
}

.btn.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.btn.primary:hover {
  background: #1d4ed8;
}

/* ------------------------------------------------------------------
   Footer
------------------------------------------------------------------ */
.app-footer {
  margin-top: 2rem;
  background: linear-gradient(90deg, #0f172a 0%, #1e293b 100%);
  color: #e2e8f0;
  padding: 1rem 1.5rem;
  text-align: center;
  font-weight: 600;
  letter-spacing: .2px;
}

/* ------------------------------------------------------------------
   Left side Sidebar
------------------------------------------------------------------ */
.sidebar {
  width: 240px;
  height: calc(100vh - 64px); /* subtract header height */
  top: 64px;                  /* push down below header */
  left: 0;
  position: fixed;
  background: #f1f5f9;
  border-right: 1px solid #cbd5e1;
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease;
  z-index: 50;
}

.sidebar-header {
  height: 54px;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  padding: 6px 0.75rem;
  justify-content: space-between;
  border-bottom: 1px solid #cbd5e1;
  font-weight: bold;
}

.sidebar-content {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem;
}

.sidebar.collapsed {
  width: 48px;
  overflow: hidden;
  background: transparent;
  border-right: none;
}

.sidebar.collapsed .sidebar-header span {
  display: none;
}

.sidebar.collapsed .sidebar-header {
  padding: 0;
  border-bottom: none;
  justify-content: center;
  background: transparent;
}

.sidebar.collapsed .sidebar-content {
  display: none;
}

.sidebar.collapsed #sidebarLabel {
  display: none; /* hide the text label */
}

#sidebarToggle {
  background: none;
  border: solid 1px #cbd5e1;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
  margin-right: 0;
  margin-left: 0;
  background: #e2e8f0;
  margin-top: 3px;
}

#sidebarToggle:hover {
  background: #e5e7eb;
}

/* ------------------------------------------------------------------
   Right side toolbox Sidebar
------------------------------------------------------------------ */
.edit-sidebar {
  position: absolute;
  top: 80px; /* below header */
  bottom: 20px;
  right: 20px;
  width: 300px;
  background: #fff;
  border: 1px solid #ddd;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 0 8px rgba(0,0,0,0.1);
  z-index: 99;
  overflow-y: auto;
}
.hidden {
  display: none;
}

/* ------------------------------------------------------------------
   Toolbox layout
------------------------------------------------------------------ */
.edit-sidebar .tool-group {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid #e2e8f0;
}

.edit-sidebar .tool-label {
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: #1f2937;
}

.tool-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
}

.tool-btn {
  width: 100%;
  text-align: center;
  padding: 0.35rem 0.4rem;
}

.color-picker-row {
  display: flex;
  align-items: center;
  border: 1px solid rgba(15, 23, 42, 0.08);
  gap: 0.5rem;
}

input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(15, 23, 42, 0.15);
  border-radius: 6px;
  padding: 1px;
  background: transparent;
  width: 36px;
  height: 32px;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 4px;
}

.recent-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.recent-color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(15, 23, 42, 0.15);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.recent-color-swatch.selected {
  outline: 1px solid #2563eb;
}

.btn.danger {
  border-color: #ef4444;
  color: #b91c1c;
}

.btn.danger:hover {
  background: #fef2f2;
}

.tool-hint {
  font-size: 0.85rem;
  color: #475569;
  margin-top: 0.6rem;
}

.input-sm {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font: inherit;
  text-align: center;
}

.pipe-width-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  column-gap: 0.2rem;
  align-items: center;
}

/* Hide default number spinners for pipe width input */
#pipeWidthInput::-webkit-inner-spin-button,
#pipeWidthInput::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#pipeWidthInput {
  -moz-appearance: textfield;
}

.pipe-width-btn {
  padding: 0.35rem 0.65rem;
  min-width: 36px;
}

.grid-size-btn {
  padding: 0.3rem 0.6rem;
  min-width: 44px;
}

.grid-size-btn.active {
  background: #1e293b;
  color: #fff;
  border-color: #1e293b;
}

.order-row {
  display: flex;
  gap: 0.5rem;
}

.order-row .btn {
  flex: 1;
  text-align: center;
}

.view-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  align-items: center;
}

.zoom-readout {
  text-align: center;
  font-weight: 600;
  color: #fff;
}

.view-row-secondary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.35rem;
  align-items: center;
}

/* ------------------------------------------------------------------
   Diagram shapes (pipes + elbows)
------------------------------------------------------------------ */
.diagram-shape {
  position: absolute;
  min-width: 4px;
  min-height: 4px;
  cursor: move;
  transform-origin: center;
  box-sizing: border-box;
  border: none;
  outline: 1px dashed transparent;
  background: transparent;
}

.diagram-shape.selected {
  outline-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.diagram-shape.dragging,
.diagram-shape.resizing {
  opacity: 0.92;
}

.diagram-shape svg {
  width: 100%;
  height: 100%;
  pointer-events: none;
  shape-rendering: crispEdges;
}

.diagram-shape.indicator {
  border-radius: 50%;
  border: 2px solid rgba(15, 23, 42, 0.6);
  background: transparent;
  display: grid;
  place-items: center;
}

.diagram-shape.indicator .indicator-dot {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  transition: background 0.2s ease;
}

.diagram-shape.pump {
  min-width: 64px;
  min-height: 64px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  position: relative;
}

.diagram-shape.pump .pump-icon {
  width: 100%;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.diagram-shape.pump .pump-icon svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.2));
}

.diagram-shape.pump .pump-speed {
  font-size: 0.75rem;
  font-weight: 600;
  color: #0f172a;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  position: absolute;
  left: var(--pump-center-x, 50%);
  top: var(--pump-center-y, 58%);
  transform: translate(-50%, -50%);
}

.diagram-shape.pump .pump-speed.telemetry-stale {
  color: #b45309;
}

.diagram-shape.pump .pump-speed.telemetry-no-data {
  color: #64748b;
  font-style: italic;
}

.diagram-shape.pump .pump-speed.hidden {
  display: none;
}

.diagram-shape.numeric {
  min-width: 120px;
  min-height: 56px;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.2rem;
}

.diagram-shape.numeric .numeric-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
}

.diagram-shape.numeric .numeric-readout {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.1;
}

.diagram-shape.numeric.telemetry-stale .numeric-value {
  color: #b45309;
}

.diagram-shape.numeric.telemetry-no-data .numeric-value {
  color: #64748b;
  font-style: italic;
}

.diagram-shape.numeric .numeric-unit {
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
}

.diagram-shape.progress {
  min-width: 24px;
  min-height: 80px;
}

.diagram-shape.progress.telemetry-stale::after,
.diagram-shape.progress.telemetry-no-data::after {
  content: attr(data-telemetry-status-label);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: lowercase;
  letter-spacing: 0.02em;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
}

.diagram-shape.progress.telemetry-stale::after {
  color: #b45309;
}

.diagram-shape.progress.telemetry-no-data::after {
  color: #64748b;
}

.diagram-shape.text {
  min-width: 80px;
  min-height: 28px;
  padding: 0.2rem 0.35rem;
  cursor: move;
}

.diagram-shape.onoff-button {
  min-width: 96px;
  min-height: 36px;
  padding: 0.35rem 0.6rem;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  line-height: 1.1;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
  transition: transform 0.1s, box-shadow 0.12s, filter 0.12s;
}

.diagram-shape.valve-onoff,
.diagram-shape.valve-analog {
  min-width: 32px;
  min-height: 32px;
}

.diagram-shape.onoff-button .onoff-label {
  text-align: center;
  pointer-events: none;
}

.diagram-shape.onoff-button:active,
.diagram-shape.onoff-button.is-pressed {
  transform: translateY(1px);
  box-shadow: inset 0 3px 10px rgba(15, 23, 42, 0.35);
  filter: brightness(0.92);
}

.diagram-shape.onoff-button.command-disabled {
  filter: grayscale(0.35);
  opacity: 0.7;
  cursor: not-allowed;
}

.command-source-pending::after,
.command-source-accepted::after,
.command-source-rejected::after {
  content: attr(data-command-status-label);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 0.25rem;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.1;
  color: #fff;
  pointer-events: none;
  border-radius: inherit;
  z-index: 3;
}

.command-source-pending::after {
  background: rgba(29, 78, 216, 0.78);
}

.command-source-accepted::after {
  background: rgba(4, 120, 87, 0.76);
}

.command-source-rejected::after {
  background: rgba(185, 28, 28, 0.8);
}

.diagram-shape.onoff-button.command-pending {
  animation: onoff-command-pending 0.8s ease-in-out infinite alternate;
  cursor: progress;
}

.diagram-shape.onoff-button.command-accepted {
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.55), 0 2px 6px rgba(15, 23, 42, 0.12);
}

.diagram-shape.onoff-button.command-rejected {
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.6), 0 2px 6px rgba(15, 23, 42, 0.12);
}

@keyframes onoff-command-pending {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.1);
  }
}

body.edit-mode .diagram-shape.onoff-button:active,
body.edit-mode .diagram-shape.onoff-button.is-pressed {
  transform: none;
  box-shadow: none;
  filter: none;
}

.diagram-shape.text .text-content {
  width: 100%;
  height: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.2;
}

.diagram-shape.indicator .resize-handle {
  right: -6px;
  top: 50%;
  bottom: auto;
  transform: translate(50%, -50%);
  cursor: ew-resize;
}

.diagram-shape .resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  right: -3px;
  bottom: -3px;
  background: #1e293b;
  border: 1px solid #fff;
  border-radius: 50%;
  cursor: nwse-resize;
  box-shadow: 0 0 0 1px #1e293b;
}

#deviceContainer.grid-enabled {
  --grid-size: 20px;
}

#deviceContainer.grid-enabled::before {
  content: '';
  position: absolute;
  inset: 0;
  background-size: var(--grid-size) var(--grid-size);
  background-repeat: repeat;
  background-position: 0 0;
  background-image:
    linear-gradient(to right, rgba(31,41,55,0.35) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(31,41,55,0.35) 1px, transparent 1px);
  pointer-events: none;
  z-index: 0;
}

.device-card,
.diagram-shape {
  z-index: 1;
}

/* ------------------------------------------------------------------
   Landing page
------------------------------------------------------------------ */
body.landing {
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.12), transparent 35%), radial-gradient(circle at 90% 10%, rgba(34, 211, 238, 0.16), transparent 32%), var(--navy-900);
  color: var(--stone-100);
  overflow: auto;
}

body.landing a {
  color: var(--stone-100);
}

body.landing main {
  flex: initial;
  display: block;
  padding: 0;
  overflow: visible;
}

.landing-header {
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #1f2937, #0ea5e9);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.3px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.brand-text span {
  display: block;
  font-weight: 700;
  color: #fff;
}

.brand-text small {
  color: var(--stone-400);
  letter-spacing: 0.3px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.nav-links a {
  padding: 0.4rem 0.65rem;
  border-radius: 10px;
  color: var(--stone-300);
  font-weight: 600;
}

.nav-links a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  text-decoration: none;
}

.landing-main {
  display: flex;
  flex-direction: column;
  gap: 5rem;
  padding: 3rem 0 4rem;
}

.section-shell {
  width: min(1200px, 92vw);
  margin: 0 auto;
}

.hero {
  position: relative;
  padding: 2rem 0 1rem;
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 60% 10%, rgba(96, 165, 250, 0.25), transparent 38%), radial-gradient(circle at 10% 50%, rgba(34, 211, 238, 0.18), transparent 35%);
  opacity: 0.65;
}

.hero-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  gap: 2.5rem;
}

.hero-content h1 {
  font-size: clamp(2rem, 3vw, 2.9rem);
  margin: 0 0 1rem;
  line-height: 1.2;
  color: #fff;
}

.hero-content .lede {
  margin: 0 0 1.25rem;
  color: var(--stone-300);
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.btn.cta-btn {
  margin-left: 0;
  background: linear-gradient(120deg, #2563eb, #22d3ee);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.35);
}

.btn.cta-btn:hover {
  background: linear-gradient(120deg, #1d4ed8, #06b6d4);
  text-decoration: none;
}

.btn.ghost-btn {
  margin-left: 0;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  color: #e5e7eb;
}

.btn.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--stone-400);
  font-weight: 700;
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
}

.hero-highlights {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: #e5e7eb;
  font-weight: 700;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.metric {
  background: var(--card-800);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25);
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: #fff;
}

.metric-label {
  color: var(--stone-400);
  font-weight: 700;
}

.hero-visual {
  display: grid;
  gap: 1rem;
}

.photo-card {
  margin: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.35);
}

.photo-card img {
  width: 100%;
  height: 260px;
  object-fit: cover;
  display: block;
}

.photo-card figcaption {
  padding: 0.9rem 1rem;
  color: var(--stone-300);
  font-weight: 600;
}

.status-card {
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 1rem 1.2rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.status-header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: #fff;
  font-weight: 800;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  background: #22c55e;
  box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.15);
}

.status-rows {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.status-row {
  display: flex;
  justify-content: space-between;
  color: var(--stone-300);
  font-weight: 600;
}

.status-value {
  color: #fff;
  font-weight: 700;
}

.status-value.warning { color: #f59e0b; }
.status-value.muted { color: var(--stone-400); }

.section-header h2 {
  margin: 0.35rem 0;
  color: #fff;
  font-size: clamp(1.8rem, 2.8vw, 2.35rem);
}

.section-header .lede {
  max-width: 820px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.stat-card {
  background: var(--card-800);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
}

.stat-value {
  font-size: 1.05rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 0.35rem;
}

.stat-label {
  color: var(--stone-400);
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.stat-desc {
  margin: 0;
  color: var(--stone-300);
  line-height: 1.5;
}

.feature-section {
  padding-top: 0.5rem;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}

.feature-card {
  background: var(--card-800);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 1.25rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
}

.feature-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.28), rgba(34, 211, 238, 0.28));
  color: #e0f2fe;
  display: grid;
  place-items: center;
}

.feature-icon svg {
  width: 24px;
  height: 24px;
}

.feature-card h3 {
  margin: 0.2rem 0;
  color: #fff;
}

.feature-card p {
  margin: 0;
  color: var(--stone-300);
  line-height: 1.5;
}

.feature-list {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
  color: var(--stone-300);
  display: grid;
  gap: 0.35rem;
  line-height: 1.45;
}

.feature-list li {
  margin: 0;
}

.hardware-section {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.05));
  padding: 0.5rem 0;
}

.hardware-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2rem;
  align-items: center;
  padding: 2.5rem 0;
}

.hardware-text {
  display: grid;
  gap: 0.75rem;
}

.hardware-text h2 {
  margin: 0;
  color: #fff;
}

.photo-frame {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0.6rem;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}

.photo-frame img {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  object-fit: cover;
  display: block;
}

.cta-panel {
  padding: 0 0 2rem;
}

.cta-shell {
  background: linear-gradient(120deg, rgba(59, 130, 246, 0.16), rgba(34, 211, 238, 0.16));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

.cta-shell h3 {
  margin: 0.2rem 0;
  color: #fff;
}

.cta-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

@media (max-width: 960px) {
  .hero-grid,
  .hardware-grid {
    grid-template-columns: 1fr;
  }

  .nav-links {
    display: none;
  }

  .cta-shell {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .landing-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero {
    padding-top: 1rem;
  }

  .hero-actions {
    width: 100%;
  }

  .cta-shell {
    padding: 1.25rem;
  }
}

/* ------------------------------------------------------------------
   App shell (dashboard, admin, etc.)
------------------------------------------------------------------ */
body.app-shell {
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 15% 20%, rgba(59, 130, 246, 0.18), transparent 32%), radial-gradient(circle at 85% 10%, rgba(34, 211, 238, 0.16), transparent 32%), var(--navy-900);
  color: var(--stone-100);
  min-height: 100vh;
}

body.app-shell a { color: var(--stone-100); }

body.app-shell.report-page {
  overflow-y: auto;
  overflow-x: hidden;
}

body.app-shell.report-page .page-main {
  min-height: calc(100vh - 76px);
  overflow: visible;
}

.app-header {
  background: rgba(11, 18, 32, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.app-header .brand {
  flex-shrink: 0;
}

.app-header .header-title h1 {
  margin: 0;
  color: #fff;
}

.app-header .header-title p {
  margin: 0;
  color: var(--stone-400);
}

.app-header .header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto; /* push actions to the far right */
}

.app-header .header-actions .btn {
  margin-left: 0;
}

.app-shell .btn:not(.start-btn):not(.stop-btn) {
  background: #1e293b;
  border-color: #1e293b;
  color: #fff;
}

.app-shell .btn:not(.start-btn):not(.stop-btn):hover {
  background: #0f172a;
}
.app-shell .btn.edit-layout-btn:not(.start-btn):not(.stop-btn) {
  background-color: #0f172a;
  background-image: none;
  border-color: rgba(255, 255, 255, 0.14);
  color: #e5e7eb;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.45);
}

.app-shell #wizardClose,
.app-shell #wizardNext {
  background-color: #0f172a;
  background-image: none;
  border-color: rgba(255, 255, 255, 0.14);
  color: #e5e7eb;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.45);
}

.app-shell .btn.edit-layout-btn:not(.start-btn):not(.stop-btn):hover {
  background-color: #1e293b;
}

.app-shell #wizardClose:hover,
.app-shell #wizardNext:hover {
  background-color: #1e293b;
}

.app-shell .btn.edit-layout-btn:not(.start-btn):not(.stop-btn):active {
  background-color: #0b1220;
}

.app-shell #wizardClose:active,
.app-shell #wizardNext:active {
  background-color: #0b1220;
}

.app-shell .login-btn {
  background: linear-gradient(120deg, #2563eb, #22d3ee);
  border: none;
  color: #fff;
  box-shadow: 0 10px 25px rgba(37, 99, 235, 0.35);
}

.page-main {
  margin-left: 240px;
  padding: 0.75rem 1rem 1.25rem;
  position: relative;
  min-height: calc(100vh - 76px);
  transition: margin-left 0.25s ease;
  display: flex;
}

#mainContent.page-main {
  padding: 0;
}

.page-shell {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 120px);
  gap: 0.75rem;
  position: relative;
}

#mainContent .page-shell {
  gap: 0;
}

.system-alarm-banner {
  background: rgba(185, 28, 28, 0.92);
  border: 1px solid rgba(248, 113, 113, 0.8);
  color: #fee2e2;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin: 0.75rem 1rem 0.5rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.system-alarm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.system-alarm-title {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.8rem;
}

.system-alarm-toggle {
  margin-left: 0;
  padding: 0.25rem 0.7rem;
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
  box-shadow: none;
}

.system-alarm-toggle:hover {
  background: rgba(255, 255, 255, 0.28);
}

.system-alarm-collapsed {
  margin-top: 0.5rem;
  font-weight: 600;
}

.system-alarm-list {
  margin: 0.4rem 0 0;
  padding-left: 1.25rem;
}

.system-alarm-list li {
  margin-bottom: 0.25rem;
}

.system-alarm-banner.collapsed {
  padding: 0.6rem 0.9rem;
}

.system-alarm-banner.collapsed .system-alarm-title,
.system-alarm-banner.collapsed .system-alarm-list {
  display: none;
}

.system-alarm-banner.collapsed .system-alarm-header {
  justify-content: flex-end;
}

.system-alarm-banner.collapsed .system-alarm-collapsed {
  display: block;
  margin-top: 0.35rem;
}

.site-alarm-banner {
  background: rgba(127, 29, 29, 0.9);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fee2e2;
  border-radius: 12px;
  padding: 0.65rem 0.9rem;
  margin: 0 1rem 0.5rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
  position: relative;
  z-index: 320;
  pointer-events: auto;
  cursor: pointer;
}

.site-alarm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.site-alarm-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-alarm-toggle {
  margin-left: 0;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.34);
  box-shadow: none;
}

.site-alarm-toggle:hover {
  background: rgba(255, 255, 255, 0.24);
}

.site-alarm-ack-btn {
  margin-left: 0;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
}

.site-alarm-collapsed {
  margin-top: 0.35rem;
  font-weight: 600;
}

.site-alarm-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.site-alarm-count {
  min-width: 2rem;
  padding: 0.15rem 0.45rem;
  text-align: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
}

.site-alarm-list {
  margin: 0.45rem 0 0;
  padding-left: 1.2rem;
  max-height: calc(4 * 1.5rem);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.2rem;
}

.site-alarm-list li {
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25rem;
}

.site-alarm-banner.collapsed {
  padding: 0.55rem 0.85rem;
}

.site-alarm-banner.collapsed .site-alarm-list {
  display: none;
}

.site-alarm-banner.collapsed .site-alarm-collapsed {
  display: block;
}

.site-alarm-banner.all-acknowledged {
  background: rgba(161, 98, 7, 0.92);
  border-color: rgba(250, 204, 21, 0.55);
  color: #fef9c3;
}

.site-alarm-banner.all-acknowledged .site-alarm-count {
  background: rgba(254, 249, 195, 0.26);
  color: #fefce8;
}

.active-alarms-modal {
  width: min(980px, 94vw);
}

.active-alarms-modal .indicator-modal-header h2 {
  color: #0f172a;
}

.active-alarms-modal .eyebrow {
  color: #475569;
}

.active-alarms-modal .help-text {
  color: #334155;
}

.active-alarms-table-wrap {
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 10px;
  max-height: 52vh;
  overflow: auto;
  background: #fff;
}

.alarm-table {
  min-width: 760px;
}

.active-alarms-modal .reports-table th {
  color: #334155;
  border-bottom-color: #e2e8f0;
  background: #f8fafc;
}

.active-alarms-modal .reports-table td {
  color: #0f172a;
  border-bottom-color: #e2e8f0;
}

.page-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0 1.25rem;
}

.page-hero h2 {
  margin: 0.25rem 0;
  color: #fff;
}

.badge-row {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.pill.muted {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--stone-300);
}

.content-band {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0 1rem 1rem;
  box-shadow: none;
  flex: 1;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
  pointer-events: none;
}

#mainContent .system-alarm-banner.hidden + .content-band {
  padding-top: 0.75rem;
}

#mainContent .site-alarm-banner.hidden + .content-band {
  padding-top: 0.75rem;
}

#mainContent .system-alarm-banner.hidden + .site-alarm-banner.hidden + .content-band {
  padding-top: 0.75rem;
}

.app-shell .sidebar {
  background: rgba(15, 23, 42, 0.95);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  box-shadow: 8px 0 30px rgba(0, 0, 0, 0.35);
}

.app-shell .sidebar-header {
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
}

.app-shell #sidebar button {
  background: rgba(255, 255, 255, 0.04);
  color: #e5e7eb;
  border-color: rgba(255, 255, 255, 0.12);
}

.app-shell #sidebar button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.app-shell #sidebar h2 {
  color: #fff;
}

.app-shell #sidebarToggle {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #e2e8f0;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}

.app-shell #sidebarToggle:hover {
  background: #f8fafc;
}

.app-shell .dropdown-menu {
  background: #0f172a;
  color: #e5e7eb;
  border-color: rgba(255, 255, 255, 0.14);
}

.app-shell .dropdown-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.app-shell #deviceViewport {
  position: absolute;
  inset: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  min-height: 100%;
  height: 100%;
  flex: 1;
  z-index: 0;
  pointer-events: auto;
}

.app-shell #deviceContainer {
  padding: 0;
  min-height: 100%;
}

.app-shell #systemAlarmBanner,
.app-shell #editWarning,
.app-shell .hero-actions {
  position: relative;
  z-index: 2;
  pointer-events: auto;
}

.app-shell .edit-sidebar {
  background: rgba(15, 23, 42, 0.96);
  border-color: rgba(255, 255, 255, 0.08);
  color: #e5e7eb;
}

.app-shell .edit-sidebar .tool-label {
  color: #e5e7eb;
}

.surface-card {
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.form-stack {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.form-stack form {
  margin: 0;
  max-width: none;
}

.admin-action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  grid-column: 1 / -1;
}

.admin-action-btn {
  margin-left: 0;
}

.admin-privileges {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 0.7rem;
  margin: 0;
}

.admin-privileges legend {
  color: #e5e7eb;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 0.25rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.15rem 0;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.site-checklist {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 0.6rem;
  min-height: 80px;
  display: grid;
  gap: 0.3rem;
}

.audit-log-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.6rem;
}

.audit-log-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.audit-log-table-wrap {
  margin-top: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  overflow: auto;
  max-height: 420px;
}

.audit-log-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.audit-log-table th,
.audit-log-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-align: left;
  vertical-align: top;
}

.audit-log-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(15, 23, 42, 0.98);
  color: #e5e7eb;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.audit-metadata-cell {
  max-width: 520px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.76rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-hero .edit-layout-btn {
  position: static;
  margin: 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.app-shell form {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: #e5e7eb;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

.app-shell form label {
  color: #e5e7eb;
}

.app-shell form input {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #e5e7eb;
}

.app-shell form button {
  background: linear-gradient(120deg, #2563eb, #22d3ee);
  border: none;
  color: #fff;
  font-weight: 700;
}

.app-shell .app-footer {
  margin: 2rem auto 0;
  width: min(1180px, 94vw);
  border-radius: 12px;
}

/* ------------------------------------------------------------------
   Report builder + reports list
------------------------------------------------------------------ */
.report-builder-card {
  padding: 1.5rem;
}

.app-shell .report-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin: 0;
  max-width: none;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.report-section {
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 1rem 1.2rem;
  display: grid;
  gap: 0.75rem;
}

.report-section h3 {
  margin: 0;
  font-size: 1rem;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem 1rem;
}

.report-grid .field {
  display: grid;
  gap: 0.35rem;
}

.help-text {
  font-size: 0.85rem;
  color: var(--stone-400);
}

.tag-list {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.4);
  padding: 0.5rem;
  max-height: 240px;
  overflow-y: auto;
  display: grid;
  gap: 0.4rem;
}

.tag-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 42, 0.6);
}

.tag-item input {
  margin: 0;
}

.analysis-table {
  display: grid;
  gap: 0.5rem;
}

.analysis-header,
.analysis-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.4fr) minmax(140px, 1fr) minmax(140px, 1fr);
  gap: 0.6rem;
  align-items: center;
}

.analysis-header {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--stone-400);
}

.analysis-row {
  padding: 0.4rem 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
}

.analysis-row:last-child {
  border-bottom: none;
}

.analysis-row select {
  width: 100%;
}

.report-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.report-error {
  color: #fca5a5;
  font-size: 0.9rem;
  min-height: 1.2rem;
}

.cost-panel {
  position: sticky;
  bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.4);
  z-index: 5;
}

.cost-metric {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.cost-metric span {
  color: var(--stone-400);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.cost-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
}

.reports-table-wrap {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.55);
  overflow: auto;
}

.reports-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.reports-table th,
.reports-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}

.reports-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--stone-300);
}

.reports-table td {
  color: var(--stone-100);
}

.reports-table .btn {
  margin-left: 0;
  padding: 0.3rem 0.7rem;
}

@media (max-width: 720px) {
  .analysis-header,
  .analysis-row {
    grid-template-columns: 1fr;
  }
  .cost-panel {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ------------------------------------------------------------------
   Alarm builder
------------------------------------------------------------------- */
.alarm-builder-shell {
  display: grid;
  gap: 0.85rem;
}

.alarm-builder-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.alarm-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.alarm-filter-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.alarm-filter-row label {
  display: grid;
  gap: 0.25rem;
  min-width: 180px;
}

.alarm-table-wrap {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.55);
  overflow: auto;
  max-height: 58vh;
}

.alarm-state-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.74rem;
  white-space: nowrap;
}

.alarm-state-pill.is-active {
  background: rgba(248, 113, 113, 0.22);
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.45);
}

.alarm-state-pill.is-active-ack {
  background: rgba(251, 191, 36, 0.22);
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.45);
}

.alarm-state-pill.is-latched {
  background: rgba(251, 191, 36, 0.16);
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.35);
}

.alarm-state-pill.is-idle {
  background: rgba(148, 163, 184, 0.2);
  color: #cbd5e1;
  border-color: rgba(148, 163, 184, 0.35);
}

.alarm-history-modal {
  width: min(1040px, 92vw);
  max-width: min(2160px, 92vw);
}

.alarm-history-modal .indicator-modal-header h2 {
  color: #0f172a;
}

.alarm-history-modal .indicator-modal-body {
  color: #0f172a;
}

.alarm-history-modal .help-text {
  color: #334155;
}

.alarm-history-modal .reports-table th {
  color: #334155;
  border-bottom-color: #e2e8f0;
  background: #f8fafc;
}

.alarm-history-modal .reports-table td {
  color: #0f172a;
  border-bottom-color: #e2e8f0;
}

.alarm-history-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.alarm-history-controls label {
  display: grid;
  gap: 0.2rem;
  min-width: 190px;
}

.alarm-comparator-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(160px, 2fr);
  gap: 0.5rem;
}

.alarm-inline-field {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.alarm-inline-field span {
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
}

.alarm-inline-field select,
.alarm-inline-field input {
  width: 100%;
}

.alarm-bool-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.alarm-bool-row label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.alarm-form-grid {
  display: grid;
  gap: 0.65rem;
}

.alarm-form-grid .field {
  display: grid;
  gap: 0.25rem;
}

.alarm-form-grid .field.hidden {
  display: none;
}

.alarm-modal-title {
  color: #0f172a;
}

.alarm-enabled-field {
  margin-bottom: 0.35rem;
  padding-bottom: 0.2rem;
}

.alarm-enabled-label {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: #111827;
}

.alarm-enabled-label input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  accent-color: #2563eb;
  flex: 0 0 auto;
}

@media (max-width: 720px) {
  .alarm-filter-row label {
    min-width: 100%;
  }
  .alarm-history-controls label {
    min-width: 100%;
  }
  .alarm-comparator-row {
    grid-template-columns: 1fr;
  }
}
