:root {
  color-scheme: dark;
  --bg: #06080b;
  --surface: #101820;
  --surface-strong: #142230;
  --line: #2d3c49;
  --text: #f4f8fb;
  --muted: #aab8c4;
  --dim: #778796;
  --green: #4ade80;
  --green-bg: #123220;
  --yellow: #facc15;
  --yellow-bg: #352d11;
  --red: #ff3b3b;
  --red-dark: #7f1010;
  --blue: #38bdf8;
  --blue-bg: #0d2b3a;
  --button: #182433;
  --button-hover: #223548;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(20, 34, 48, 0.95), rgba(6, 8, 11, 1) 38rem),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

body.night-mode {
  --bg: #020304;
  --surface: #0b1015;
  --surface-strong: #111922;
  --button: #111a24;
  --button-hover: #172434;
  --text: #dce6ee;
  --muted: #8d9ca8;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

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

.command-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 360px);
  gap: 18px;
  align-items: stretch;
  padding: 14px 0 18px;
  background: linear-gradient(180deg, rgba(6, 8, 11, 0.98), rgba(6, 8, 11, 0.82));
  backdrop-filter: blur(12px);
}

.identity-block {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  border-left: 5px solid var(--yellow);
  padding-left: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--yellow);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(1.8rem, 3.2vw, 3.2rem);
  line-height: 1.03;
}

h2 {
  margin-bottom: 0;
  font-size: 1.1rem;
}

.subheader,
.section-note,
.detail-line,
.mapping {
  color: var(--muted);
}

.subheader {
  margin-bottom: 0;
  font-size: 1.05rem;
}

.all-off-button {
  display: flex;
  min-height: 104px;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  border: 2px solid #ff8585;
  border-radius: 8px;
  background: linear-gradient(180deg, #e62929, var(--red-dark));
  color: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.all-off-button span {
  font-size: 2.4rem;
  font-weight: 900;
}

.all-off-button small {
  color: #ffe2e2;
  font-size: 0.86rem;
  font-weight: 700;
}

.all-off-button:active,
.control-card:active,
.secondary-button:active {
  transform: translateY(1px);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr)) minmax(230px, 1.25fr);
  gap: 10px;
  margin-bottom: 14px;
}

.status-badge {
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 24, 32, 0.86);
  padding: 12px;
}

.status-badge span {
  display: block;
  color: var(--dim);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.status-badge strong {
  display: block;
  margin-top: 7px;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 1rem;
}

.status-badge.ok strong,
.state-pill.on {
  color: var(--green);
}

.status-badge.warn strong,
.state-pill.active {
  color: var(--yellow);
}

.status-badge.fault strong,
.state-pill.fault {
  color: var(--red);
}

.fault-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  border: 1px solid #ff8585;
  border-radius: 8px;
  background: rgba(127, 16, 16, 0.9);
  padding: 12px 14px;
  color: #fff;
}

.fault-banner strong {
  border-radius: 4px;
  background: #fff;
  color: var(--red-dark);
  padding: 4px 8px;
  font-size: 0.8rem;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 16px;
  align-items: start;
}

.command-section,
.profile-section {
  grid-column: 1;
}

.profile-section {
  margin-top: 16px;
}

.side-rail {
  display: grid;
  grid-column: 2;
  grid-row: 1 / span 2;
  gap: 16px;
}

.console-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 24, 32, 0.78);
  padding: 16px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-heading.compact {
  margin-bottom: 16px;
}

.section-note {
  margin-bottom: 0;
  font-size: 0.86rem;
}

.control-grid {
  display: grid;
  gap: 12px;
}

.channel-grid {
  grid-template-columns: repeat(2, minmax(230px, 1fr));
}

.profile-grid {
  grid-template-columns: repeat(2, minmax(230px, 1fr));
}

.control-card {
  display: flex;
  min-height: 148px;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button);
  padding: 16px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.control-card:hover,
.control-card:focus-visible {
  background: var(--button-hover);
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.control-card.is-on {
  border-color: rgba(74, 222, 128, 0.8);
  background: linear-gradient(180deg, rgba(18, 50, 32, 0.95), rgba(24, 36, 51, 0.95));
}

.control-card.is-fault {
  border-color: rgba(255, 59, 59, 0.9);
  background: linear-gradient(180deg, rgba(127, 16, 16, 0.82), rgba(24, 36, 51, 0.95));
}

.control-card.is-active {
  border-color: rgba(250, 204, 21, 0.85);
  background: linear-gradient(180deg, rgba(53, 45, 17, 0.95), rgba(24, 36, 51, 0.95));
}

.card-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.control-label {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.15;
}

.state-pill {
  flex: 0 0 auto;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
}

.mapping {
  display: block;
  min-height: 20px;
  font-size: 0.92rem;
  font-weight: 700;
}

.detail-line {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
}

.detail-line b {
  color: var(--text);
  font-weight: 700;
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.console-input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #070b10;
  color: var(--text);
  padding: 10px 12px;
}

.console-input:focus {
  border-color: var(--blue);
  outline: 2px solid rgba(56, 189, 248, 0.35);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b1118;
  padding: 12px;
}

.toggle-row small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.toggle-row input {
  width: 24px;
  height: 24px;
  accent-color: var(--yellow);
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.secondary-button {
  min-height: 48px;
  border: 1px solid rgba(56, 189, 248, 0.8);
  border-radius: 8px;
  background: var(--blue-bg);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

.secondary-button.muted {
  border-color: var(--line);
  background: #101820;
  color: var(--muted);
}

.event-log {
  display: grid;
  max-height: 460px;
  gap: 8px;
  margin: 0;
  overflow: auto;
  padding: 0;
  list-style: none;
}

.event-log li {
  border-left: 3px solid var(--blue);
  background: #0b1118;
  padding: 10px;
}

.event-log li.fault {
  border-left-color: var(--red);
}

.event-log time {
  display: block;
  color: var(--dim);
  font-size: 0.72rem;
  font-weight: 700;
}

.event-log strong {
  display: block;
  margin: 4px 0;
  color: var(--text);
  font-size: 0.9rem;
}

.event-log span {
  color: var(--muted);
  font-size: 0.8rem;
}

.safety-footer {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding: 16px 0 4px;
  color: #ffd6d6;
  font-size: 0.94rem;
  font-weight: 800;
  text-align: center;
}

@media (max-width: 1180px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .command-section,
  .profile-section,
  .side-rail {
    grid-column: 1;
    grid-row: auto;
  }

  .side-rail {
    grid-template-columns: 1fr 1fr;
  }
}

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

  .command-header {
    grid-template-columns: 1fr;
  }

  .all-off-button {
    min-height: 92px;
  }

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

  .status-badge.wide {
    grid-column: 1 / -1;
  }

  .channel-grid,
  .profile-grid,
  .side-rail,
  .settings-actions {
    grid-template-columns: 1fr;
  }

  .control-card {
    min-height: 136px;
  }
}

@media (max-width: 480px) {
  .status-strip {
    grid-template-columns: 1fr;
  }

  .section-heading,
  .card-row {
    align-items: start;
    flex-direction: column;
  }

  .state-pill {
    align-self: flex-start;
  }
}

