@import url("https://fonts.googleapis.com/css2?family=Aldrich&family=JetBrains+Mono:wght@500;600;700&display=swap");

:root {
  color-scheme: dark;
  --bg: #0b0b0b;
  --bg-2: #181512;
  --surface: rgba(224, 220, 209, 0.085);
  --surface-strong: rgba(231, 227, 215, 0.14);
  --surface-muted: #11100e;
  --text: #f3efe3;
  --muted: #a9a39a;
  --line: rgba(235, 226, 209, 0.22);
  --line-strong: rgba(243, 239, 227, 0.42);
  --clear: #72c8a3;
  --caution: #f0b544;
  --brake: #e66c37;
  --hold: #d84134;
  --invalid: #77736d;
  --accent: #e56832;
  --accent-2: #f5c15a;
  --rasputin: #c43d2d;
  --ice: #b7d3df;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(115deg, rgba(228, 83, 42, 0.18), transparent 28%),
    radial-gradient(circle at 74% -10%, rgba(245, 193, 90, 0.18), transparent 32%),
    linear-gradient(135deg, #090909, var(--bg-2) 48%, #090909);
  color: var(--text);
  font-family: "JetBrains Mono", "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(243, 239, 227, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(243, 239, 227, 0.025) 1px, transparent 1px),
    linear-gradient(115deg, transparent 0 58%, rgba(229, 104, 50, 0.08) 58% 59%, transparent 59%);
  background-size: 56px 56px, 56px 56px, 280px 280px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.86), transparent 78%);
  content: "";
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid rgba(245, 193, 90, 0.45);
  border-radius: 2px;
  background:
    linear-gradient(135deg, transparent 0 10px, rgba(245, 193, 90, 0.96) 10px),
    linear-gradient(180deg, rgba(245, 193, 90, 0.95), rgba(202, 95, 43, 0.95));
  color: #14110d;
  cursor: pointer;
  font-family: Aldrich, "JetBrains Mono", sans-serif;
  font-size: 13px;
  font-weight: 400;
  padding: 0 16px;
  text-transform: uppercase;
  box-shadow: 0 10px 24px rgba(229, 104, 50, 0.18);
  transition: border-color 150ms ease, filter 150ms ease, transform 150ms ease;
}

button:hover {
  border-color: rgba(255, 225, 149, 0.78);
  filter: brightness(1.08);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background:
    linear-gradient(135deg, transparent 0 10px, rgba(19, 18, 16, 0.88) 10px),
    rgba(19, 18, 16, 0.88);
  color: var(--accent-2);
  box-shadow: none;
}

button.secondary:hover {
  border-color: rgba(245, 193, 90, 0.78);
}

button.danger {
  border-color: rgba(216, 65, 52, 0.72);
  background:
    linear-gradient(135deg, transparent 0 10px, rgba(216, 65, 52, 0.95) 10px),
    linear-gradient(180deg, rgba(216, 65, 52, 0.95), rgba(125, 30, 26, 0.95));
  color: #fff4ed;
  box-shadow: 0 10px 24px rgba(216, 65, 52, 0.2);
}

button.danger:hover {
  border-color: rgba(255, 149, 124, 0.82);
}

button:disabled {
  border-color: var(--line);
  background: rgba(48, 46, 42, 0.8);
  color: var(--invalid);
  cursor: not-allowed;
  transform: none;
}

input,
select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(10, 10, 9, 0.86);
  color: var(--text);
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(245, 193, 90, 0.75);
  box-shadow: 0 0 0 3px rgba(229, 104, 50, 0.12);
}

.app-shell {
  position: relative;
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 32px;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background:
    linear-gradient(90deg, rgba(227, 222, 209, 0.13), rgba(18, 17, 15, 0.92) 38%),
    rgba(12, 11, 10, 0.92);
  box-shadow: var(--shadow);
  padding: 14px;
}

.topbar::after {
  position: absolute;
  inset: 0 auto 0 62%;
  width: 340px;
  pointer-events: none;
  background: repeating-linear-gradient(115deg, rgba(229, 104, 50, 0.24) 0 14px, transparent 14px 28px);
  opacity: 0.55;
  content: "";
}

.brand,
.top-actions,
.panel-heading,
.sensor-topline,
.sensor-meta,
.threshold-list div {
  display: flex;
  align-items: center;
}

.brand,
.top-actions {
  position: relative;
  z-index: 1;
}

.brand {
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border: 1px solid rgba(245, 193, 90, 0.6);
  border-radius: 2px;
  background:
    linear-gradient(135deg, rgba(245, 193, 90, 0.18), transparent 45%),
    rgba(11, 10, 9, 0.92);
  box-shadow: inset 0 0 26px rgba(229, 104, 50, 0.18), 0 12px 26px rgba(0, 0, 0, 0.34);
}

.brand-mark::before,
.brand-mark::after,
.brand-mark span::before,
.brand-mark span::after {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid var(--accent-2);
  border-radius: 50%;
  content: "";
}

.brand-mark::before {
  left: 8px;
  top: 8px;
}

.brand-mark::after {
  right: 8px;
  top: 8px;
}

.brand-mark span::before {
  left: 8px;
  bottom: 8px;
}

.brand-mark span::after {
  right: 8px;
  bottom: 8px;
}

.brand h1,
.panel h2 {
  margin: 0;
}

.brand h1 {
  font-family: Aldrich, "JetBrains Mono", sans-serif;
  font-size: 25px;
  font-weight: 700;
  line-height: 1.05;
  text-transform: uppercase;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
}

.top-actions {
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.wifi-connect {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.wifi-connect input {
  width: min(270px, 42vw);
}

.status-pill,
.source-tag,
.range-tag,
.sensor-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(8, 8, 7, 0.84);
  color: var(--muted);
  font-family: Aldrich, "JetBrains Mono", sans-serif;
  font-size: 13px;
  font-weight: 700;
  padding: 0 10px;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-pill::before {
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--invalid);
  box-shadow: 0 0 12px rgba(119, 115, 109, 0.75);
  content: "";
}

.status-pill.connected::before {
  background: var(--clear);
}

.status-pill.simulator::before {
  background: var(--caution);
}

.status-pill.wifi::before {
  background: var(--ice);
}

.state-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--line);
  box-shadow: var(--shadow);
}

.state-strip > div {
  min-width: 0;
  background:
    linear-gradient(180deg, rgba(231, 227, 215, 0.12), rgba(16, 15, 13, 0.9)),
    rgba(16, 15, 13, 0.9);
  padding: 15px 16px;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-family: Aldrich, "JetBrains Mono", sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.state-strip strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 25px;
  font-weight: 700;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state-strip[data-state="clear"] #stateLabel,
.sensor-card.clear .sensor-value,
.sensor-card.clear .sensor-status {
  color: var(--clear);
}

.state-strip[data-state="caution"] #stateLabel,
.sensor-card.caution .sensor-value,
.sensor-card.caution .sensor-status {
  color: var(--caution);
}

.state-strip[data-state="brake"] #stateLabel,
.sensor-card.brake .sensor-value,
.sensor-card.brake .sensor-status {
  color: var(--brake);
}

.state-strip[data-state="hold"] #stateLabel,
.sensor-card.hold .sensor-value,
.sensor-card.hold .sensor-status {
  color: var(--hold);
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 18px;
  align-items: start;
}

.workspace,
.side-rail {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel,
.sensor-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 2px;
  background:
    linear-gradient(135deg, rgba(243, 239, 227, 0.11), transparent 18%),
    var(--surface);
  box-shadow: var(--shadow);
}

.panel::before,
.sensor-card::before {
  position: absolute;
  left: 0;
  top: 0;
  width: 34px;
  height: 3px;
  background: var(--accent);
  content: "";
}

.panel {
  min-width: 0;
  padding: 17px;
}

.panel-heading {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-heading.compact {
  margin-bottom: 12px;
}

.panel h2 {
  font-family: Aldrich, "JetBrains Mono", sans-serif;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.1;
  text-transform: uppercase;
}

.map-panel {
  min-height: 420px;
}

.drone-map {
  position: relative;
  min-height: 340px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 2px;
  background:
    linear-gradient(to right, rgba(245, 193, 90, 0.08) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(245, 193, 90, 0.06) 1px, transparent 1px),
    radial-gradient(circle at 50% 50%, rgba(229, 104, 50, 0.14), transparent 45%),
    linear-gradient(135deg, #0c0c0b, #15130f);
  background-size: 44px 44px, 44px 44px, auto, auto;
}

.drone-map::after {
  position: absolute;
  right: 18px;
  bottom: 16px;
  width: 122px;
  height: 122px;
  border: 1px solid rgba(243, 239, 227, 0.18);
  border-radius: 50%;
  box-shadow: inset 0 0 0 22px rgba(243, 239, 227, 0.025);
  content: "";
}

.map-axis {
  position: absolute;
  background: rgba(243, 239, 227, 0.24);
}

.map-axis-x {
  left: 8%;
  right: 8%;
  top: 50%;
  height: 1px;
}

.map-axis-y {
  top: 8%;
  bottom: 8%;
  left: 50%;
  width: 1px;
}

.drone-body {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: 112px;
  height: 72px;
  border: 1px solid rgba(245, 193, 90, 0.62);
  border-radius: 2px;
  background:
    linear-gradient(135deg, transparent 0 14px, rgba(229, 104, 50, 0.22) 14px 15px, transparent 15px),
    rgba(13, 12, 11, 0.96);
  color: var(--text);
  font-family: Aldrich, "JetBrains Mono", sans-serif;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
  z-index: 3;
}

.drone-body::before,
.drone-body::after {
  position: absolute;
  left: 50%;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent-2);
  border-radius: 50%;
  background: #10100e;
  content: "";
  transform: translateX(-50%);
}

.drone-body::before {
  top: -34px;
}

.drone-body::after {
  bottom: -34px;
}

.sensor-beam {
  position: absolute;
  --beam-length: 84px;
  --beam-color: var(--invalid);
  z-index: 2;
}

.sensor-beam span {
  display: block;
  border-radius: 2px;
  background: var(--beam-color);
  box-shadow: 0 0 18px rgba(245, 193, 90, 0.18);
  opacity: 0.86;
}

.sensor-beam.front {
  bottom: calc(50% + 50px);
  left: 50%;
  width: 12px;
  height: var(--beam-length);
  transform: translateX(-50%);
}

.sensor-beam.rear {
  top: calc(50% + 50px);
  left: 50%;
  width: 12px;
  height: var(--beam-length);
  transform: translateX(-50%);
}

.sensor-beam.front span,
.sensor-beam.rear span {
  width: 100%;
  height: 100%;
}

.sensor-beam.left {
  right: calc(50% + 70px);
  top: 50%;
  width: var(--beam-length);
  height: 12px;
  transform: translateY(-50%);
}

.sensor-beam.right {
  left: calc(50% + 70px);
  top: 50%;
  width: var(--beam-length);
  height: 12px;
  transform: translateY(-50%);
}

.sensor-beam.left span,
.sensor-beam.right span {
  width: 100%;
  height: 100%;
}

.sensor-beam.down {
  left: calc(50% + 95px);
  top: calc(50% + 84px);
  width: var(--beam-length);
  height: var(--beam-length);
  transform: translate(-50%, -50%);
}

.sensor-beam.down span {
  width: 100%;
  height: 100%;
  border: 3px solid var(--beam-color);
  border-radius: 50%;
  background: transparent;
}

#historyCanvas {
  display: block;
  width: 100%;
  height: 260px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #0e0d0b;
}

.sensor-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
}

.sensor-card {
  min-width: 0;
  padding: 14px;
}

.sensor-topline {
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.sensor-name {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-family: Aldrich, "JetBrains Mono", sans-serif;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.sensor-value {
  display: block;
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
}

.sensor-status {
  min-height: 24px;
  font-size: 12px;
  padding: 0 8px;
}

.distance-track {
  position: relative;
  height: 7px;
  overflow: hidden;
  margin: 16px 0 12px;
  border-radius: 2px;
  background: rgba(243, 239, 227, 0.08);
}

.distance-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--invalid);
  transition: width 160ms ease, background 160ms ease;
}

.sensor-card.clear .distance-fill {
  background: var(--clear);
}

.sensor-card.caution .distance-fill {
  background: var(--caution);
}

.sensor-card.brake .distance-fill {
  background: var(--brake);
}

.sensor-card.hold .distance-fill {
  background: var(--hold);
}

.sensor-card.invalid {
  color: var(--invalid);
}

.sensor-meta {
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.threshold-list,
.metric-list,
.system-list {
  display: grid;
  gap: 8px;
}

.threshold-list div,
.metric-list div,
.system-row {
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(8, 8, 7, 0.42);
  padding: 0 12px;
}

.metric-list div,
.system-row {
  display: flex;
  align-items: center;
}

.metric-list div {
  min-width: 0;
}

.field-control {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.field-control span {
  color: var(--muted);
  font-family: Aldrich, "JetBrains Mono", sans-serif;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.full-width {
  width: 100%;
  margin-top: 10px;
}

.voice-command {
  display: grid;
  gap: 8px;
}

.voice-readout {
  display: grid;
  gap: 3px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background:
    linear-gradient(135deg, rgba(245, 193, 90, 0.08), transparent 34%),
    rgba(8, 8, 7, 0.42);
  padding: 8px 10px;
}

.voice-readout span {
  color: var(--muted);
  font-family: Aldrich, "JetBrains Mono", sans-serif;
  font-size: 12px;
  text-transform: uppercase;
}

.voice-readout strong {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.threshold-list span,
.metric-list span,
.system-row span {
  color: var(--muted);
  font-weight: 600;
}

.metric-list strong {
  overflow: hidden;
  max-width: 58%;
  color: var(--text);
  font-weight: 700;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.system-row {
  justify-content: flex-start;
  min-height: 58px;
}

.system-row > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.system-row strong,
.system-row span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.system-dot {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--invalid);
  box-shadow: 0 0 14px rgba(119, 115, 109, 0.35);
}

.system-row[data-status="ok"] .system-dot {
  background: var(--clear);
  box-shadow: 0 0 14px rgba(114, 200, 163, 0.38);
}

.system-row[data-status="warn"] .system-dot {
  background: var(--caution);
  box-shadow: 0 0 14px rgba(240, 181, 68, 0.38);
}

.system-row[data-status="bad"] .system-dot {
  background: var(--hold);
  box-shadow: 0 0 14px rgba(216, 65, 52, 0.38);
}

.system-row[data-status="ok"] strong {
  color: var(--clear);
}

.system-row[data-status="warn"] strong {
  color: var(--caution);
}

.system-row[data-status="bad"] strong {
  color: var(--hold);
}

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

.event-log li {
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.event-log strong {
  display: block;
  color: var(--text);
  font-size: 13px;
}

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

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

  .sensor-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 12px;
  }

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

  .topbar::after {
    left: auto;
    right: 0;
    width: 46%;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button,
  .top-actions .status-pill,
  .wifi-connect {
    flex: 1 1 150px;
    justify-content: center;
  }

  .wifi-connect {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(112px, auto);
    flex-basis: 100%;
    width: 100%;
  }

  .wifi-connect input {
    min-width: 0;
    width: 100%;
  }

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

  .state-strip > div,
  .panel {
    padding: 14px;
  }

  .state-strip strong {
    font-size: 21px;
  }

  .map-panel {
    min-height: auto;
  }

  .drone-map {
    min-height: 300px;
  }

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

@media (max-width: 460px) {
  .brand h1 {
    font-size: 21px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .state-strip {
    grid-template-columns: 1fr;
  }

  .drone-body {
    width: 92px;
    height: 62px;
  }

  .sensor-beam.left {
    right: calc(50% + 58px);
  }

  .sensor-beam.right {
    left: calc(50% + 58px);
  }
}
