:root {
  color-scheme: dark;
  --bg: #12161b;
  --surface: #1e252b;
  --surface-soft: #242d34;
  --line: #33404a;
  --text: #e0e0e0;
  --muted: #9aa8b3;
  --normal: #00a3ff;
  --warning: #ffb000;
  --critical: #ff453a;
  --ok: #2ecf7a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  border-top: 3px solid var(--warning);
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(154, 168, 179, 0.14);
}

.brand-lockup {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 20px;
}

.brand-logo {
  display: block;
  width: clamp(220px, 28vw, 360px);
  height: auto;
  max-height: 88px;
  object-fit: contain;
  object-position: left center;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1 {
  font-size: clamp(1.35rem, 2.25vw, 2.35rem);
}

.eyebrow,
.section-label {
  margin: 0 0 6px;
  color: var(--normal);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.75rem, 3vw, 2.8rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.05rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.session-user {
  display: grid;
  min-width: 120px;
  gap: 2px;
  text-align: right;
}

.session-user span {
  max-width: 190px;
  overflow: hidden;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-user small {
  color: var(--normal);
  font-size: 0.64rem;
  font-weight: 800;
  text-transform: uppercase;
}

.sync-status {
  min-width: 150px;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: right;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--normal);
  background: var(--surface-soft);
  outline: none;
  transform: translateY(-1px);
}

.icon-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.icon-button.is-loading svg {
  animation: spin 0.8s linear infinite;
}

.icon-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 170px;
  margin-bottom: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-panel strong {
  display: block;
  margin-bottom: 10px;
  color: var(--normal);
  font-size: clamp(2.2rem, 5vw, 5rem);
  line-height: 1;
  text-transform: uppercase;
}

.status-panel span {
  color: var(--muted);
}

.status-panel > div:first-child {
  min-width: 0;
}

#generalDescription {
  display: block;
  overflow-wrap: anywhere;
}

.status-panel.is-warning strong {
  color: var(--warning);
}

.status-panel.is-critical strong {
  color: var(--critical);
}

.status-panel.is-offline strong {
  color: var(--muted);
}

.status-panel.is-empty strong {
  color: var(--muted);
}

.signal {
  display: grid;
  width: clamp(96px, 16vw, 170px);
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #151b20;
}

.signal span {
  position: relative;
  display: block;
  width: 44%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--normal);
  box-shadow: 0 0 44px rgba(0, 163, 255, 0.48);
}

.status-panel.is-warning .signal span::after,
.status-panel.is-critical .signal span::after {
  position: absolute;
  inset: -14px;
  border: 1px solid currentColor;
  border-radius: 50%;
  content: "";
  opacity: 0;
  animation: signal-wave 2.4s ease-out infinite;
}

.status-panel.is-warning .signal span::after {
  color: var(--warning);
}

.status-panel.is-critical .signal span::after {
  color: var(--critical);
}

.status-panel.is-warning .signal span {
  background: var(--warning);
  box-shadow: 0 0 44px rgba(255, 176, 0, 0.45);
}

.status-panel.is-critical .signal span {
  background: var(--critical);
  box-shadow: 0 0 48px rgba(255, 69, 58, 0.58);
}

.status-panel.is-offline .signal span {
  background: var(--muted);
  box-shadow: none;
}

.status-panel.is-empty .signal span {
  background: var(--muted);
  box-shadow: none;
}

.status-panel.is-new-alarm {
  animation: alarm-flash 0.8s ease-in-out 3;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel,
.device-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(30, 37, 43, 0.92);
}

.metric {
  position: relative;
  overflow: hidden;
  min-height: 126px;
  padding: 18px;
}

.metric::before {
  position: absolute;
  top: 0;
  right: 18px;
  left: 18px;
  height: 2px;
  background: var(--line);
  content: "";
}

.metric:nth-child(1)::before,
.metric:nth-child(2)::before {
  background: var(--normal);
}

.metric:nth-child(3)::before,
.metric:nth-child(4)::before {
  background: var(--warning);
}

.metric span,
.metric small,
.device-meta,
td,
.empty-state span {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 12px 0 4px;
  color: var(--text);
  font-size: 2rem;
  line-height: 1;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.82fr) minmax(520px, 1.18fr);
  gap: 18px;
  align-items: start;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 12px;
}

.panel-heading-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.device-grid {
  display: grid;
  gap: 12px;
  padding: 0 18px 18px;
}

.devices-panel,
.shelly-panel,
.charts-panel {
  margin-bottom: 18px;
}

.shelly-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  padding: 0 18px 18px;
}

.shelly-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161c22;
}

.shelly-card.is-on { border-color: var(--warning); }
.shelly-card.is-offline { opacity: .72; }
.shelly-card > header,
.shelly-card > footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.shelly-output { display: flex; align-items: center; gap: 12px; margin: 18px 0; }
.shelly-output-indicator { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); }
.shelly-card.is-on .shelly-output-indicator { background: var(--warning); box-shadow: 0 0 14px rgba(255, 176, 0, .55); }
.shelly-output div { display: grid; gap: 2px; }
.shelly-output small, .shelly-metrics dt, .shelly-card footer small { color: var(--muted); }
.shelly-output strong { color: var(--text); }
.shelly-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 16px; }
.shelly-metrics div { min-width: 0; padding: 10px; background: var(--surface); border-radius: 6px; }
.shelly-metrics dt { font-size: .72rem; }
.shelly-metrics dd { margin: 3px 0 0; overflow-wrap: anywhere; font-weight: 800; }
.shelly-error { margin: 0 0 14px; color: var(--critical); font-size: .82rem; }
.shelly-control-button { min-height: 36px; padding: 7px 12px; background: transparent; border-color: var(--warning); color: var(--warning); }

.routines-panel {
  margin-bottom: 18px;
}

.routine-title-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.readonly-badge,
.routine-state,
.routine-result {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
}

.readonly-badge {
  border-color: rgba(0, 163, 255, 0.45);
  color: var(--normal);
}

.routine-summary {
  color: var(--muted);
  font-size: 0.78rem;
}

.routine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 12px;
  padding: 0 18px 18px;
}

.routine-card {
  position: relative;
  min-width: 0;
  padding: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161c22;
}

.routine-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--muted);
  content: "";
}

.routine-card.is-active::before {
  background: var(--normal);
}

.routine-card.has-warning::before {
  background: var(--warning);
}

.routine-card.is-inactive {
  opacity: 0.72;
}

.routine-card-header,
.routine-identity,
.routine-footer {
  display: flex;
  align-items: center;
  gap: 12px;
}

.routine-card-header,
.routine-footer {
  justify-content: space-between;
}

.routine-identity {
  min-width: 0;
}

.routine-identity > div {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.routine-identity strong {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.routine-identity span,
.routine-description,
.routine-footer {
  color: var(--muted);
  font-size: 0.75rem;
}

.routine-icon {
  position: relative;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.routine-icon::before,
.routine-icon::after {
  position: absolute;
  content: "";
}

.routine-icon::before {
  top: 8px;
  left: 15px;
  width: 2px;
  height: 8px;
  background: var(--normal);
}

.routine-icon::after {
  top: 15px;
  left: 15px;
  width: 7px;
  height: 2px;
  background: var(--normal);
  transform: rotate(32deg);
  transform-origin: left center;
}

.routine-state.is-active {
  border-color: rgba(46, 207, 122, 0.45);
  color: var(--ok);
}

.routine-description {
  margin: 14px 0 0;
  line-height: 1.5;
}

.routine-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 14px 0;
}

.routine-action {
  display: inline-flex;
  max-width: 100%;
  gap: 5px;
  padding: 6px 8px;
  overflow: hidden;
  border: 1px solid rgba(224, 224, 224, 0.09);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.7rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.routine-action b {
  color: var(--text);
}

.routine-action.is-empty {
  color: var(--muted);
}

.routine-footer {
  padding-top: 12px;
  border-top: 1px solid rgba(154, 168, 179, 0.12);
}

.routine-footer strong {
  color: var(--text);
}

.routine-result.is-success {
  border-color: rgba(46, 207, 122, 0.45);
  color: var(--ok);
}

.routine-result.is-warning,
.routine-warning {
  color: var(--warning);
}

.routine-result.is-critical {
  color: var(--critical);
}

.routine-warning {
  margin: 10px 0 0;
  font-size: 0.7rem;
}

.routine-empty {
  grid-column: 1 / -1;
}

.motion-enabled .motion-reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 420ms ease, transform 420ms cubic-bezier(.2, .75, .25, 1);
}

.motion-enabled .motion-reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.motion-enabled .routine-card {
  animation: routine-enter 360ms cubic-bezier(.2, .75, .25, 1) backwards;
  animation-delay: var(--routine-delay, 0ms);
}

@media (hover: hover) and (pointer: fine) {
  .metric,
  .sensor-card,
  .shelly-card,
  .routine-card,
  .chart-block {
    transition: border-color 180ms ease, background-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
  }

  .metric:hover,
  .sensor-card:hover,
  .shelly-card:hover,
  .routine-card:hover {
    border-color: #465762;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
  }
}

@media (max-width: 560px) {
  .shelly-metrics { grid-template-columns: 1fr 1fr; }
  .shelly-card > footer { align-items: stretch; flex-direction: column; }
}

.events-panel {
  margin-bottom: 18px;
}

.device-card {
  padding: 16px;
  background: var(--surface-soft);
}

.device-card header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.device-title {
  display: grid;
  gap: 3px;
}

.device-title strong {
  overflow-wrap: anywhere;
}

.device-meta {
  font-size: 0.88rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 94px;
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--normal);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.badge.warning {
  color: var(--warning);
}

.badge.critical {
  color: var(--critical);
}

.badge.offline {
  color: var(--muted);
}

.readings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.sensor-group-label {
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.sensor-card-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 1.35fr) minmax(0, 1fr);
  gap: 10px;
}

.sensor-card {
  min-width: 0;
  min-height: 150px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161c22;
}

.sensor-card header {
  align-items: start;
  margin-bottom: 18px;
}

.sensor-card header > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.sensor-card.is-detected {
  border-color: var(--critical);
  background: rgba(255, 69, 58, 0.08);
}

.sensor-card.is-warning {
  border-color: var(--warning);
  background: rgba(255, 176, 0, 0.06);
}

.sensor-card.is-failed {
  border-color: var(--critical);
}

.sensor-card.is-offline {
  border-color: var(--line);
  opacity: 0.72;
}

.sensor-card.is-detected .detector-status,
.sensor-card.is-detected .sensor-value {
  color: var(--critical);
}

.sensor-card.is-warning .detector-status {
  color: var(--warning);
}

.sensor-card.is-failed .detector-status {
  color: var(--critical);
}

.sensor-card.is-offline .detector-status,
.sensor-card.is-offline .sensor-value {
  color: var(--muted);
}

.mq2-card {
  min-height: 220px;
}

.mq2-card header {
  margin-bottom: 2px;
}

.mq2-gauge {
  position: relative;
  display: grid;
  width: 100%;
  max-width: 300px;
  min-height: 150px;
  margin: 0 auto;
  justify-items: center;
  color: var(--normal);
}

.mq2-gauge.is-caution {
  color: var(--warning);
}

.mq2-gauge.is-critical {
  color: var(--critical);
}

.mq2-gauge svg {
  display: block;
  width: 100%;
  height: 122px;
  overflow: visible;
}

.mq2-gauge-track,
.mq2-gauge-level {
  fill: none;
  stroke-linecap: round;
  stroke-width: 13;
}

.mq2-gauge-track {
  stroke: #33414b;
}

.mq2-gauge-level {
  stroke: currentColor;
}

.mq2-gauge-threshold {
  stroke: var(--text);
  stroke-width: 2;
}

.mq2-gauge-readout {
  position: absolute;
  top: 55px;
  left: 50%;
  display: grid;
  width: 100%;
  transform: translateX(-50%);
  justify-items: center;
  text-align: center;
}

.mq2-gauge-readout strong {
  color: currentColor;
  font-size: 1.45rem;
  line-height: 1;
}

.mq2-gauge-readout strong span {
  font-size: 0.68rem;
}

.mq2-gauge-readout small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.7rem;
}

.mq2-gauge-scale {
  position: absolute;
  right: 8px;
  bottom: 0;
  left: 8px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  color: var(--muted);
  font-size: 0.64rem;
}

.mq2-gauge-scale span:nth-child(2) {
  color: var(--text);
  text-align: center;
}

.mq2-gauge-scale span:last-child {
  text-align: right;
}

.mq2-detail {
  margin-top: 2px;
  text-align: center;
}

.mq2-diagnostics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.mq2-diagnostics span {
  min-width: 0;
  padding: 7px;
  border: 1px solid rgba(224, 224, 224, 0.08);
  border-radius: 6px;
  background: #12181d;
}

.mq2-diagnostics small,
.mq2-diagnostics strong {
  display: block;
  overflow-wrap: anywhere;
}

.mq2-diagnostics small {
  color: var(--muted);
  font-size: 0.61rem;
}

.mq2-diagnostics strong {
  margin-top: 3px;
  color: var(--text);
  font-size: 0.68rem;
}

.mq2-diagnostic-warning,
.calibration-warning {
  margin: 8px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--warning);
  border-radius: 6px;
  background: rgba(255, 176, 0, 0.07);
  color: var(--warning);
  font-size: 0.7rem;
  line-height: 1.45;
}

.mq2-calibration-button {
  width: 100%;
  margin-top: 8px;
}

.mq2-calibration-submit {
  border-color: var(--normal);
  color: var(--normal);
}

.calibration-warning {
  margin: 0;
  color: var(--text);
}

.sensor-model {
  color: var(--normal);
  font-size: 0.7rem;
  font-weight: 800;
}

.sensor-reading-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.sensor-reading-grid span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.72rem;
}

.sensor-reading-grid strong {
  color: var(--normal);
  font-size: 1.1rem;
}

.fire-sensor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.fire-sensor {
  min-height: 116px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161c22;
}

.fire-sensor.is-detected {
  border-color: var(--critical);
  background: rgba(255, 69, 58, 0.08);
}

.fire-sensor.is-warning {
  border-color: var(--warning);
  background: rgba(255, 176, 0, 0.06);
}

.fire-sensor.is-failed {
  border-color: var(--critical);
}

.fire-sensor header {
  align-items: center;
  margin-bottom: 12px;
}

.sensor-name {
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 800;
}

.detector-status {
  color: var(--ok);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.fire-sensor.is-detected .detector-status,
.fire-sensor.is-detected .sensor-value {
  color: var(--critical);
}

.fire-sensor.is-warning .detector-status {
  color: var(--warning);
}

.fire-sensor.is-failed .detector-status {
  color: var(--critical);
}

.sensor-value {
  display: block;
  color: var(--normal);
  font-size: 1.35rem;
  line-height: 1.1;
}

.sensor-detail {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.76rem;
}

.device-health {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(224, 224, 224, 0.08);
  color: var(--muted);
  font-size: 0.78rem;
}

.physical-alarm {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 12px;
  padding: 11px 12px;
  border: 1px solid var(--critical);
  border-radius: 6px;
  background: rgba(255, 69, 58, 0.06);
}

.physical-alarm.is-silenced {
  border-color: var(--warning);
  background: rgba(255, 176, 0, 0.06);
}

.physical-alarm-indicator {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--critical);
  box-shadow: 0 0 0 4px rgba(255, 69, 58, 0.12);
}

.physical-alarm.is-silenced .physical-alarm-indicator {
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(255, 176, 0, 0.12);
}

.physical-alarm strong {
  color: var(--text);
  font-size: 0.86rem;
}

.physical-alarm p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.physical-alarm-silence {
  margin-top: 10px;
  border-color: var(--critical);
  background: var(--critical);
  color: #ffffff;
  font-weight: 800;
}

.physical-alarm-silence:hover:not(:disabled) {
  border-color: #ff655d;
  background: #ff655d;
}

.physical-alarm-silence:disabled {
  cursor: wait;
  opacity: 0.65;
}

.device-health strong {
  color: var(--text);
  font-weight: 700;
}

.device-health .needs-review {
  color: var(--warning);
}

.device-health .failed {
  color: var(--critical);
}

.reading {
  min-height: 66px;
  padding: 10px;
  border: 1px solid rgba(224, 224, 224, 0.08);
  border-radius: 8px;
  background: #161c22;
}

.reading span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

.reading strong {
  color: var(--normal);
  font-size: 1.15rem;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-top: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

td strong {
  color: var(--text);
  font-weight: 700;
}

.severity {
  color: var(--normal);
  font-weight: 800;
}

.severity.warning {
  color: var(--warning);
}

.severity.critical {
  color: var(--critical);
}

.alert-origin {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 800;
}

.alert-origin.smoke {
  border-color: var(--warning);
  color: var(--warning);
}

.alert-origin.flame,
.alert-origin.combined {
  border-color: var(--critical);
  color: var(--critical);
}

.alert-origin.temperature {
  border-color: var(--normal);
  color: var(--normal);
}

.alert-origin.connectivity {
  border-color: #9eacb8;
  color: #c7d0d8;
}

.care-cell {
  min-width: 190px;
}

.alert-actions {
  display: flex;
  gap: 7px;
}

.alert-action-button,
.button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #161c22;
  color: var(--text);
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 750;
}

.alert-action-button:hover,
.alert-action-button:focus-visible,
.button:hover,
.button:focus-visible {
  border-color: var(--normal);
  color: var(--normal);
  outline: none;
}

.alert-action-button.resolve,
.button-primary {
  border-color: var(--critical);
  color: var(--critical);
}

.button.button-primary.mq2-calibration-submit {
  border-color: var(--normal);
  color: var(--normal);
}

.alert-action-button:disabled,
.button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.care-state {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.care-recognized {
  color: var(--warning);
}

.care-resolved {
  color: var(--ok);
}

.care-detail {
  display: block;
  max-width: 220px;
  margin: 4px 0 7px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.68rem;
  text-overflow: ellipsis;
}

.alert-dialog {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.alert-dialog::backdrop {
  background: rgba(5, 8, 11, 0.76);
}

.alert-form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.dialog-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.dialog-close {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #161c22;
  color: var(--text);
  cursor: pointer;
  font-size: 1.45rem;
  line-height: 1;
}

.dialog-close:hover,
.dialog-close:focus-visible {
  border-color: var(--normal);
  outline: none;
}

.alert-dialog-summary,
.form-message {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.form-field {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
}

.form-field input,
.form-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #161c22;
  color: var(--text);
  padding: 10px 11px;
}

.form-field input:focus,
.form-field textarea:focus {
  border-color: var(--normal);
  outline: none;
}

.form-field input[readonly] {
  color: var(--muted);
  cursor: default;
}

.form-field textarea {
  min-height: 96px;
  resize: vertical;
}

.form-message:not(:empty) {
  color: var(--warning);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.incident-dialog {
  width: min(1080px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.incident-dialog::backdrop {
  background: rgba(5, 8, 11, 0.76);
}

.incident-content {
  padding: 20px;
}

.incident-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.incident-fact {
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #161c22;
}

.incident-fact span,
.incident-fact small {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
}

.incident-fact strong {
  display: block;
  margin: 5px 0 2px;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 0.86rem;
}

.incident-status {
  padding: 14px 0 8px;
}

.incident-chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
}

.incident-chart-grid.is-connectivity-event {
  display: none;
}

.incident-chart-grid .chart-block + .chart-block {
  border-left: 1px solid var(--line);
}

.incident-chart-wide {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  border-left: 0 !important;
}

.incident-chart-canvas {
  height: 260px !important;
  min-height: 260px;
  max-height: 260px;
  flex-basis: 260px;
}

.alerts-table tr[data-alert-id] {
  cursor: pointer;
}

.alerts-table tr[data-alert-id]:hover,
.alerts-table tr[data-alert-id]:focus-visible {
  background: rgba(0, 163, 255, 0.05);
  outline: none;
}

.button {
  min-height: 40px;
  padding-inline: 14px;
}

.chart-heading {
  gap: 18px;
  padding-bottom: 16px;
}

.chart-title-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.live-indicator {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
}

.live-indicator::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  content: "";
}

.live-indicator.is-active {
  border-color: rgba(46, 207, 122, 0.55);
  color: var(--ok);
}

.live-indicator.is-active::before {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(46, 207, 122, 0.55);
}

.range-control {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 0.8rem;
}

.range-control select {
  min-height: 38px;
  padding: 0 32px 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #161c22;
  color: var(--text);
}

.range-control select:focus-visible {
  border-color: var(--normal);
  outline: none;
}

.download-link {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
}

.download-link:hover,
.download-link:focus-visible {
  border-color: var(--normal);
  color: var(--normal);
  outline: none;
}

.chart-status {
  min-height: 20px;
  margin: 0;
  padding: 0 18px 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}

.chart-block {
  min-width: 0;
  margin: 0;
  padding: 18px;
}

.chart-block + .chart-block {
  border-left: 1px solid var(--line);
}

.chart-block-wide {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  border-left: 0 !important;
}

.chart-block-wide.chart-block + .chart-block {
  border-left: 0;
}

.chart-block-compact .chart-canvas {
  height: 190px !important;
  min-height: 190px;
  max-height: 190px;
  flex-basis: 190px;
}

.chart-block figcaption {
  margin-bottom: 14px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 800;
}

.chart-canvas {
  position: relative;
  display: block;
  min-width: 0;
  width: 100%;
  height: 300px !important;
  min-height: 300px;
  max-height: 300px;
  flex: 0 0 300px;
  overflow: hidden;
  contain: size layout paint;
}

.chart-canvas canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 100%;
  cursor: crosshair;
}

.chart-canvas canvas:focus-visible {
  outline: 2px solid var(--normal);
  outline-offset: -2px;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  display: none;
  width: min(230px, calc(100% - 20px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #10161b;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.38);
  pointer-events: none;
  transform: translateX(-50%);
}

.chart-tooltip.is-visible {
  display: grid;
  gap: 6px;
}

.chart-tooltip strong {
  color: var(--text);
  font-size: 0.76rem;
}

.chart-tooltip span {
  color: var(--muted);
  font-size: 0.72rem;
}

.chart-tooltip b {
  color: var(--text);
  font-weight: 700;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 28px 18px;
  text-align: center;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes alarm-flash {
  50% {
    border-color: var(--critical);
    box-shadow: 0 0 0 4px rgba(255, 69, 58, 0.2);
  }
}

@keyframes signal-wave {
  0% {
    opacity: 0.55;
    transform: scale(0.7);
  }
  70%,
  100% {
    opacity: 0;
    transform: scale(1.65);
  }
}

@keyframes routine-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .icon-button.is-loading svg,
  .status-panel.is-new-alarm,
  .status-panel .signal span::after,
  .motion-enabled .routine-card {
    animation: none;
  }

  .motion-enabled .motion-reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

@media (max-width: 1020px) {
  .metric-grid,
  .layout-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sensor-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layout-grid .panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-block + .chart-block {
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .status-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-lockup {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .brand-logo {
    width: min(100%, 300px);
    max-height: 72px;
  }

  .topbar-actions {
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .topbar-actions .icon-button:first-of-type {
    flex: 0 0 44px;
    margin-left: auto;
  }

  .session-user {
    min-width: 0;
    text-align: left;
  }

  .sync-status {
    text-align: left;
  }

  .signal {
    width: 92px;
    align-self: center;
  }

  .status-panel {
    min-height: 0;
    padding: 18px;
  }

  .status-panel strong {
    font-size: 2.6rem;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    min-height: 104px;
    padding: 14px;
  }

  .metric strong {
    font-size: 1.65rem;
  }

  .metric:last-child {
    grid-column: 1 / -1;
  }

  .panel-heading {
    padding: 15px 14px 11px;
  }

  .panel-heading-actions {
    width: 100%;
  }

  .routines-panel .panel-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .routine-grid {
    grid-template-columns: 1fr;
    padding: 0 12px 12px;
  }

  .panel-heading-actions .download-link {
    flex: 1 1 140px;
    justify-content: center;
  }

  .device-grid {
    padding: 0 12px 12px;
  }

  .readings,
  .fire-sensor-grid,
  .sensor-card-grid {
    grid-template-columns: 1fr;
  }

  .device-card > header,
  .sensor-card header {
    flex-wrap: wrap;
  }

  .sensor-card .detector-status {
    margin-left: auto;
  }

  .chart-heading,
  .range-control {
    align-items: stretch;
    flex-direction: column;
  }

  .chart-title-line {
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
  }

  .chart-heading .download-link,
  .range-control select {
    width: 100%;
  }

  .chart-heading .download-link {
    justify-content: center;
  }

  .chart-block {
    padding: 14px 10px;
  }

  .chart-canvas {
    height: 260px !important;
    min-height: 260px;
    max-height: 260px;
    flex-basis: 260px;
  }

  .chart-block-compact .chart-canvas {
    height: 180px !important;
    min-height: 180px;
    max-height: 180px;
    flex-basis: 180px;
  }

  .table-wrap {
    overflow: visible;
  }

  .alerts-table,
  .alerts-table tbody,
  .alerts-table tr,
  .alerts-table td {
    display: block;
    width: 100%;
  }

  .alerts-table {
    min-width: 0;
  }

  .alerts-table thead {
    display: none;
  }

  .alerts-table tr {
    padding: 11px 14px;
    border-top: 1px solid var(--line);
  }

  .alerts-table td {
    display: grid;
    min-width: 0;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 9px;
    align-items: start;
    padding: 5px 0;
    border: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .alerts-table td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
  }

  .alerts-table td[colspan] {
    display: block;
  }

  .alerts-table td[colspan]::before {
    content: none;
  }

  .care-cell {
    min-width: 0;
  }

  .alert-actions {
    flex-wrap: wrap;
  }

  .alert-action-button {
    flex: 1 1 110px;
  }

  .alert-dialog {
    width: calc(100% - 24px);
    max-height: calc(100dvh - 24px);
  }

  .incident-dialog {
    width: calc(100% - 16px);
    max-height: calc(100dvh - 16px);
  }

  .incident-content {
    padding: 14px;
  }

  .incident-summary,
  .incident-chart-grid {
    grid-template-columns: 1fr;
  }

  .incident-chart-grid .chart-block + .chart-block {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .incident-chart-wide {
    grid-column: auto;
  }

  .alert-form {
    padding: 16px;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions .button {
    width: 100%;
  }
}

@media (max-width: 440px) {
  .metric-grid,
  .sensor-reading-grid {
    grid-template-columns: 1fr;
  }

  .metric:last-child {
    grid-column: auto;
  }

  .topbar-actions {
    align-items: center;
  }

  .topbar-actions .session-user {
    flex: 1 1 150px;
  }

  .sync-status {
    min-width: 90px;
    flex: 1 1 100px;
  }

  .topbar-actions .icon-button:first-of-type {
    margin-left: 0;
  }

  .alerts-table td {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .mq2-diagnostics {
    grid-template-columns: 1fr;
  }

  .routine-card-header,
  .routine-footer {
    align-items: flex-start;
  }
}
