* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #030303;
  color: #e6e6e6;
  font-family: Arial, Helvetica, sans-serif;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: 46px 34px 1fr;
  width: 100vw;
  height: 100vh;
  background: #030303;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 10px;
  border-bottom: 1px solid #8b130d;
  background: #050505;
}

.brand {
  min-width: 220px;
}

.title {
  font-size: 15px;
  font-weight: 700;
  color: #f2f2f2;
}

.subtitle {
  margin-top: 2px;
  font-size: 11px;
  color: #8f9aa3;
}

.controls {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.controls button,
.controls select {
  height: 28px;
  border: 1px solid #8b130d;
  border-radius: 4px;
  background: #111;
  color: #f1f1f1;
}

.contract-select.hidden {
  display: none;
}

.event-set-select.hidden,
.event-button.hidden,
.signal-list-toggle.hidden,
.signal-drawer.hidden,
.event-info.hidden {
  display: none;
}

.event-set-select {
  max-width: 230px;
}

.event-button {
  min-width: 64px !important;
  font-size: 12px;
}

.signal-list-toggle {
  min-width: 68px !important;
  font-size: 12px;
}

.controls button {
  min-width: 36px;
  padding: 0 9px;
  cursor: pointer;
}

.controls button:hover,
.controls select:hover {
  border-color: #d63622;
}

.link-toggle {
  height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 7px;
  border: 1px solid #8b130d;
  border-radius: 4px;
  background: #111;
  color: #f1f1f1;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.link-toggle:hover {
  border-color: #d63622;
}

.link-toggle input {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: #d6291f;
}

.time-readout,
.zoom-readout {
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  border: 1px solid #2c2c2c;
  border-radius: 4px;
  color: #d8d8d8;
  background: #0b0b0b;
  white-space: nowrap;
  font-size: 12px;
}

.timeline-row {
  display: flex;
  align-items: center;
  padding: 5px 10px;
  border-bottom: 1px solid #2a0505;
  background: #060606;
}

#timeline {
  width: 100%;
  accent-color: #d6291f;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(260px, 1fr));
  grid-template-rows: minmax(0, 1fr);
  gap: 1px;
  min-height: 0;
  overflow-x: auto;
  background: #8b130d;
}

.panel {
  position: relative;
  display: grid;
  grid-template-rows: 26px 1fr;
  min-width: 0;
  min-height: 0;
  background: #000;
  border: 1px solid #8b130d;
}

.panel.active {
  border-color: #e5d900;
}

.panel.active .panel-header {
  border-bottom-color: #8e8200;
}

.panel-header {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 3px 6px;
  border-bottom: 1px solid #3a0706;
  background: #030303;
}

.period-select {
  width: 72px;
  height: 21px;
  flex: 0 0 72px;
  margin-right: 7px;
  padding: 0 3px;
  border: 1px solid #5f1b17;
  border-radius: 3px;
  background: #101010;
  color: #f2f2f2;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.period-select:hover,
.period-select:focus {
  border-color: #d63622;
  outline: none;
}

.panel-values {
  flex: 1;
  min-width: 0;
  color: #cfd4d8;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
}

.panel canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: #000;
  cursor: crosshair;
}

.tooltip {
  position: fixed;
  z-index: 20;
  min-width: 210px;
  padding: 8px 9px;
  border: 1px solid #9f1b14;
  background: rgba(0, 0, 0, 0.92);
  color: #f2f2f2;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  font-size: 12px;
  line-height: 1.45;
}

.tooltip.hidden {
  display: none;
}

.event-info {
  position: fixed;
  z-index: 12;
  right: 12px;
  bottom: 12px;
  max-width: min(620px, calc(100vw - 24px));
  padding: 7px 10px;
  border: 1px solid #8852c7;
  border-radius: 4px;
  background: rgba(8, 5, 14, 0.94);
  color: #eee6ff;
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
}

.signal-drawer {
  position: fixed;
  z-index: 18;
  top: 88px;
  right: 10px;
  bottom: 10px;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  width: min(360px, calc(100vw - 20px));
  border: 1px solid #8852c7;
  border-radius: 6px;
  background: rgba(5, 4, 8, 0.97);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.6);
}

.signal-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 13px 10px;
  border-bottom: 1px solid #38234f;
}

.signal-drawer-eyebrow {
  color: #8f9aa3;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
}

.signal-drawer-title {
  margin-top: 3px;
  color: #f3ecff;
  font-size: 17px;
  font-weight: 700;
}

.signal-drawer-close {
  width: 28px;
  height: 28px;
  border: 1px solid #5e3d82;
  border-radius: 4px;
  background: #121016;
  color: #e8dcff;
  font-size: 20px;
  line-height: 20px;
  cursor: pointer;
}

.signal-rule-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid #2c2138;
}

.signal-rule-filter {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border: 1px solid #453255;
  border-radius: 4px;
  color: #ded2eb;
  font-size: 11px;
  cursor: pointer;
}

.signal-rule-filter input {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: #a66bee;
}

.signal-list-status {
  padding: 8px 12px;
  border-bottom: 1px solid #2c2138;
  color: #9e96a8;
  font-size: 11px;
  line-height: 1.4;
}

.signal-list {
  min-height: 0;
  overflow-y: auto;
  padding: 7px;
}

.signal-row {
  display: block;
  width: 100%;
  margin: 0 0 6px;
  padding: 9px 10px;
  border: 1px solid #30263a;
  border-left: 3px solid #9a70c7;
  border-radius: 4px;
  background: #0c0a0f;
  color: #eee8f7;
  text-align: left;
  cursor: pointer;
}

.signal-row.long {
  border-left-color: #ff5c54;
}

.signal-row.short {
  border-left-color: #28ced5;
}

.signal-row:hover {
  border-color: #a66bee;
  background: #14101a;
}

.signal-load-more {
  width: 100%;
  padding: 8px;
  border: 1px solid #5e3d82;
  border-radius: 4px;
  background: #16111e;
  color: #decaff;
  font-size: 12px;
  cursor: pointer;
}

.signal-load-more:hover {
  border-color: #b681ff;
}

.signal-row-meta {
  color: #aaa0b8;
  font-size: 11px;
}

.signal-row-title {
  margin-top: 3px;
  color: #f4edff;
  font-size: 13px;
  font-weight: 700;
}

.signal-row-details,
.signal-list-empty {
  margin-top: 3px;
  color: #9e96a8;
  font-size: 11px;
  line-height: 1.4;
}

.tooltip .row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.tooltip .name {
  color: #8f9aa3;
}

.tooltip .value {
  color: #f2f2f2;
}

.up {
  color: #ff3731;
}

.down {
  color: #00dce8;
}

.ma5 {
  color: #d8d8d8;
}

.ma10 {
  color: #e5d900;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-rows: 78px 34px 1fr;
  }

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

  .controls {
    overflow-x: auto;
  }

  .grid {
    grid-template-columns: repeat(4, minmax(260px, 1fr));
  }
}
