:root {
  --red: #ff375f;
  --red-dark: #bf1238;
  --navy: #1d1d1f;
  --blue: #007aff;
  --green: #248a3d;
  --gold: #b26a00;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --soft: #f5f5f7;
  --surface: #ffffff;
  --line: #e5e5ea;
  --line-dark: #d1d1d6;
  --warn: #fff8e6;
  --bad: #fff0f3;
  --good: #edf8f1;
  --radius: 8px;
  --shadow: 0 18px 45px rgba(0, 0, 0, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, #fbfbfd 0%, #f2f3f7 58%, #eceef3 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Source Sans 3", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2 {
  margin: 0;
  color: var(--navy);
  letter-spacing: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: rgba(255, 255, 255, .72);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(22px);
  padding: 20px;
}

.brand {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 0 18px;
  text-align: left;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: linear-gradient(145deg, #ff5f78, #ff2d55);
  color: #fff;
  font-weight: 800;
}

.brand strong {
  display: block;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Source Sans 3", system-ui, sans-serif;
  font-size: 24px;
  line-height: 1;
}

.brand span span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.field {
  margin-bottom: 14px;
}

.field.compact {
  margin-bottom: 12px;
}

label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .7px;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: rgba(255, 255, 255, .86);
  color: var(--ink);
  outline: 0;
  padding: 9px 11px;
}

input:focus,
select:focus {
  border-color: rgba(0, 122, 255, .45);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, .12);
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.span-filter {
  grid-column: 1 / -1;
}

.quick-markers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 14px;
}

.quick-chip {
  min-height: 27px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .82);
  color: var(--muted);
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
}

.quick-chip:hover {
  color: var(--blue);
  border-color: rgba(0, 122, 255, .28);
}

.laser-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.inventory-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 12px;
}

.inventory-meta b {
  color: var(--ink);
  font-size: 14px;
}

.inventory-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.laser-list span {
  border-top: 4px solid var(--laser);
  background: var(--soft);
  border-radius: 6px;
  padding: 7px 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
  text-align: center;
}

.laser-list b {
  display: block;
  color: var(--ink);
  font-size: 13px;
}

.inventory-list {
  display: grid;
  gap: 8px;
}

.inventory-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .76);
  padding: 10px;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.inventory-item:hover {
  transform: translateY(-1px);
  border-color: rgba(0, 122, 255, .24);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .05);
}

.inventory-item.selected {
  border-color: rgba(0, 122, 255, .36);
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .06);
}

.inventory-item b,
.inventory-item span,
.inventory-item small {
  display: block;
}

.inventory-item span {
  color: var(--ink);
  font-size: 13px;
}

.inventory-item small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.workspace-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.3px;
  text-transform: uppercase;
}

.workspace-head h1 {
  font-family: -apple-system, BlinkMacSystemFont, "Source Sans 3", system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.03;
}

.subline {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

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

.help-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.builder-card {
  margin-bottom: 14px;
}

.builder-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

.builder-field {
  margin-bottom: 0;
}

.suggestion-copy {
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
}

.help-tile {
  display: block;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .74);
  color: var(--ink);
  padding: 13px;
  text-align: left;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .05);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.help-tile:hover {
  transform: translateY(-2px);
  border-color: rgba(0, 122, 255, .28);
  box-shadow: 0 16px 36px rgba(0, 0, 0, .08);
}

.help-tile b,
.help-tile span {
  display: block;
}

.help-tile b {
  color: var(--ink);
  font-size: 15px;
}

.help-tile span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.secondary-btn,
.danger-btn,
.icon-btn {
  border-radius: 6px;
  border: 1px solid transparent;
  min-height: 38px;
  padding: 8px 14px;
  font-weight: 800;
  background: rgba(255, 255, 255, .86);
}

.secondary-btn {
  color: var(--blue);
  border-color: transparent;
  box-shadow: inset 0 0 0 1px var(--line);
}

.secondary-btn:hover {
  background: #fff;
}

.danger-btn {
  color: #fff;
  background: #1d1d1f;
}

.icon-btn {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
  font-size: 20px;
  line-height: 1;
}

.icon-btn.ghost {
  color: var(--muted);
  background: #fff;
  border-color: var(--line-dark);
}

.mini-actions,
.row-actions {
  display: inline-flex;
  gap: 6px;
}

.mini-actions .icon-btn,
.row-actions .icon-btn {
  font-size: 16px;
  font-weight: 900;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric,
.panel-card {
  background: rgba(255, 255, 255, .82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.metric {
  padding: 16px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric span {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .7px;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  color: var(--blue);
  font-family: -apple-system, BlinkMacSystemFont, "Source Sans 3", system-ui, sans-serif;
  font-size: 40px;
  line-height: 1;
  margin: 7px 0 4px;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(270px, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

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

.span-2 {
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-head h2 {
  font-size: 20px;
}

.card-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.selected-table-wrap,
.matrix-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .6px;
  text-transform: uppercase;
}

td small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.fluor-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--dot);
}

.sign {
  display: inline-flex;
  min-width: 64px;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.sign.good,
.guidance.good {
  background: var(--good);
  color: var(--green);
}

.sign.warn,
.guidance.warn {
  background: var(--warn);
  color: var(--gold);
}

.sign.bad,
.guidance.bad {
  background: var(--bad);
  color: var(--red-dark);
}

.guidance-list {
  display: grid;
  gap: 9px;
}

.guidance-list.wide {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.guidance {
  border-radius: var(--radius);
  padding: 12px;
}

.guidance b,
.guidance span {
  display: block;
}

.guidance span {
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.35;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: #f2f2f7;
}

.segmented button {
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  font-weight: 800;
}

.segmented button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 6px rgba(0, 0, 0, .12);
}

.detail-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 13px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-title b,
.detail-title small {
  display: block;
}

.detail-title b {
  color: var(--navy);
  font-size: 19px;
}

.detail-title small {
  color: var(--muted);
}

.fluor-dot.large {
  width: 18px;
  height: 18px;
  margin-right: 0;
}

.detail-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.detail-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.detail-list dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.detail-list dd {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.plot-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.plot-toolbar b,
.plot-toolbar span {
  display: block;
}

.plot-toolbar b {
  color: var(--navy);
}

.plot-toolbar span,
.plot-toolbar div:last-child {
  color: var(--muted);
  font-size: 13px;
}

.scope-switch {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px;
  background: #f2f2f7;
}

.scope-switch button {
  min-height: 28px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 800;
}

.scope-switch button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 5px rgba(0, 0, 0, .14);
}

.chart-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbfd;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .75);
}

canvas {
  display: block;
  width: 100%;
  min-width: 1240px;
  background: #fbfbfd;
}

.channel-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.channel-strip div {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.channel-strip span {
  width: 18px;
  height: 5px;
  border-radius: 999px;
}

.spectral-legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px 18px;
  margin-top: 12px;
}

.legend-row {
  display: grid;
  grid-template-columns: 26px 1fr 72px 52px;
  align-items: center;
  gap: 7px;
  border: 0;
  border-radius: 0;
  padding: 4px 0;
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
}

.legend-swatch {
  width: 25px;
  height: 3px;
  border-radius: 999px;
  background: var(--dot);
}

.legend-row b {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-count {
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.matrix th,
.matrix td {
  text-align: center;
}

.matrix tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  text-align: left;
}

.matrix td {
  min-width: 64px;
  font-weight: 800;
}

.matrix .self {
  background: var(--navy);
  color: #fff;
}

.matrix .cool {
  background: #edf6fb;
  color: var(--blue);
}

.matrix .mild {
  background: #eef5e8;
  color: var(--green);
}

.matrix .warm {
  background: var(--warn);
  color: var(--gold);
}

.matrix .hot {
  background: var(--bad);
  color: var(--red-dark);
}

.empty-cell,
.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 32px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  transform: translateY(16px);
  opacity: 0;
  background: var(--navy);
  color: #fff;
  border-radius: 7px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  transition: .18s ease;
  pointer-events: none;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.welcome-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(245, 245, 247, .72);
  backdrop-filter: blur(24px);
  animation: welcomeFade .28s ease both;
}

.welcome-overlay.leaving {
  animation: welcomeOut .28s ease both;
}

.welcome-card {
  width: min(520px, 100%);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 18px;
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 28px 80px rgba(0, 0, 0, .16);
  padding: 28px;
  text-align: center;
}

.welcome-card h2 {
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1;
  font-weight: 850;
}

.welcome-card p:not(.eyebrow) {
  max-width: 390px;
  margin: 12px auto 0;
  color: var(--muted);
  line-height: 1.45;
}

.welcome-spectrum {
  height: 72px;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 7px;
  margin-bottom: 18px;
}

.welcome-spectrum span {
  width: 14px;
  height: 28px;
  border-radius: 999px 999px 4px 4px;
  background: var(--blue);
  animation: spectralPulse 1.05s ease-in-out infinite;
}

.welcome-spectrum span:nth-child(2) {
  height: 54px;
  background: #34c759;
  animation-delay: .08s;
}

.welcome-spectrum span:nth-child(3) {
  height: 68px;
  background: #ffcc00;
  animation-delay: .16s;
}

.welcome-spectrum span:nth-child(4) {
  height: 45px;
  background: #ff9500;
  animation-delay: .24s;
}

.welcome-spectrum span:nth-child(5) {
  height: 60px;
  background: #ff2d55;
  animation-delay: .32s;
}

.welcome-steps {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0;
}

.welcome-steps span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 800;
}

.app-footer {
  padding: 18px 28px 24px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

@keyframes spectralPulse {
  0%,
  100% {
    transform: scaleY(.72);
    opacity: .72;
  }
  50% {
    transform: scaleY(1);
    opacity: 1;
  }
}

@keyframes welcomeFade {
  from {
    opacity: 0;
    transform: scale(.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes welcomeOut {
  to {
    opacity: 0;
    transform: scale(.98);
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

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

  .guidance-list.wide {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 18px;
  }

  .workspace-head,
  .card-head {
    display: grid;
  }

  .inventory-list,
  .summary-grid,
  .panel-grid,
  .help-strip,
  .builder-row {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 8px;
  }

  .detail-list div,
  .legend-row {
    grid-template-columns: 1fr;
  }

  .plot-toolbar {
    display: grid;
  }
}
