:root {
  --spine-orange: #f47c13;
  --spine-orange-dark: #c95f05;
  --bg: #f3f4f5;
  --panel: #ffffff;
  --panel-subtle: #f8f8f8;
  --control: #ffffff;
  --control-muted: #f1f2f3;
  --ink: #151719;
  --muted: #6c737c;
  --line: #d7dbe0;
  --line-strong: #b8bec6;
  --danger: #b42318;
  --plot-bg: #ffffff;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --Dash-Spacing: 4px;
  --Dash-Fill-Inverse-Strong: var(--control);
  --Dash-Fill-Interactive-Strong: var(--spine-orange);
  --Dash-Fill-Interactive-Weak: rgba(244, 124, 19, 0.14);
  --Dash-Fill-Disabled: var(--line);
  --Dash-Stroke-Strong: var(--line);
  --Dash-Text-Strong: var(--ink);
  --Dash-Text-Weak: var(--muted);
  --Dash-Text-Disabled: var(--muted);
  --Dash-Shading-Strong: rgba(0, 0, 0, 0.18);
  --Dash-Shading-Weak: rgba(0, 0, 0, 0.08);
}

body:has(#theme-toggle input:checked) {
  --bg: #111214;
  --panel: #191b1e;
  --panel-subtle: #202327;
  --control: #111214;
  --control-muted: #24272b;
  --ink: #f2f3f4;
  --muted: #a7adb5;
  --line: #34383e;
  --line-strong: #565c65;
  --danger: #ff8a7a;
  --plot-bg: #151719;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.35;
}

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

button {
  border: 0;
}

input,
textarea {
  color-scheme: light;
}

body:has(#theme-toggle input:checked) input,
body:has(#theme-toggle input:checked) textarea {
  color-scheme: dark;
}

.app-root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px 26px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

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

#title {
  margin: 0;
  color: var(--ink);
  font-size: 30px;
  font-weight: 850;
  line-height: 1;
  letter-spacing: 0;
}

.app-kicker {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.spine-logo {
  width: auto;
  height: 44px;
  object-fit: contain;
}

body:has(#theme-toggle input:checked) .spine-logo {
  filter: invert(1) hue-rotate(180deg) contrast(1.05);
}

.session-block {
  display: flex;
  align-items: center;
  gap: 8px;
}

.experiment-chip,
.logout-link {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
}

.logout-link {
  text-decoration: none;
}

.experiment-chip {
  background: var(--panel-subtle);
  color: var(--ink);
}

.logout-link:hover {
  border-color: var(--spine-orange);
  color: var(--spine-orange);
}

.version-block {
  display: flex;
  align-items: center;
  gap: 10px;
}

.version-chip {
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.theme-control {
  display: flex;
  align-items: center;
}

.theme-toggle-label {
  width: 92px;
  height: 30px;
  position: relative;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--control-muted);
  cursor: pointer;
}

.theme-toggle-label::before {
  content: "Light";
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 22px;
  border-radius: 999px;
  background: var(--spine-orange);
  color: #ffffff;
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  transform: translateX(0);
  transition: transform 140ms ease;
}

.theme-toggle-label::after {
  content: "Dark";
  position: absolute;
  right: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
}

body:has(#theme-toggle input:checked) .theme-toggle-label::before {
  content: "Dark";
  transform: translateX(34px);
}

body:has(#theme-toggle input:checked) .theme-toggle-label::after {
  content: "Light";
  left: 10px;
  right: auto;
}

.theme-toggle-label input {
  position: absolute;
  width: 0;
  height: 0;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.app-main {
  flex: 1;
  min-height: 0;
  padding: 18px;
}

.workbench {
  height: calc(100vh - 112px);
  min-height: 720px;
  display: grid;
  grid-template-columns: minmax(430px, 500px) minmax(0, 1fr);
  gap: 18px;
}

.control-rail,
.viewer-panel,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.control-rail {
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.control-section {
  position: relative;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin-bottom: 12px;
}

.control-section:first-child {
  padding-top: 0;
}

.control-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.section-title,
.panel-title,
.login-title {
  margin: 0;
  color: var(--ink);
  font-size: 17px;
  font-weight: 850;
  line-height: 1.2;
}

.field-label {
  display: block;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.inline-label {
  margin-top: 0;
}

.text-input,
textarea,
.dash-dropdown,
.Select-control {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--ink);
}

.text-input,
textarea {
  padding: 9px 11px;
}

.text-input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

.text-input:focus,
textarea:focus,
.dash-dropdown:focus,
.Select.is-focused > .Select-control,
.Select-control:hover {
  border-color: var(--spine-orange);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(244, 124, 19, 0.16);
}

.control-dropdown {
  width: 100%;
}

.dash-dropdown {
  background: var(--control);
  color: var(--ink);
  overflow: hidden;
}

.dash-dropdown-trigger {
  min-height: 38px;
  padding: 0 11px;
}

.dash-dropdown-content {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.dash-dropdown-search-container {
  border-color: var(--line);
  background: var(--control-muted);
}

.dash-dropdown-search {
  color: var(--ink);
}

.dash-dropdown-value,
.dash-dropdown-value-count,
.dash-dropdown-trigger-icon,
.dash-dropdown-clear,
.dash-dropdown-action-button,
.dash-dropdown-option {
  color: var(--ink);
  fill: var(--ink);
}

.dash-dropdown-placeholder,
.dash-dropdown-action-button {
  color: var(--muted);
}

.dash-dropdown-option {
  background: var(--control);
  box-shadow: 0 -1px 0 0 var(--line) inset;
}

.dash-dropdown-option:hover,
.dash-dropdown-option:focus-within {
  background: rgba(244, 124, 19, 0.12);
}

.dash-dropdown-option input {
  accent-color: var(--spine-orange);
}

body:has(#theme-toggle input:checked) .dash-dropdown,
body:has(#theme-toggle input:checked) .dash-dropdown-content,
body:has(#theme-toggle input:checked) .dash-dropdown-search-container,
body:has(#theme-toggle input:checked) .dash-dropdown-option {
  background: var(--control) !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}

body:has(#theme-toggle input:checked) .dash-dropdown-option:hover,
body:has(#theme-toggle input:checked) .dash-dropdown-option:focus-within {
  background: rgba(244, 124, 19, 0.18) !important;
}

body:has(#theme-toggle input:checked) .dash-dropdown-value,
body:has(#theme-toggle input:checked) .dash-dropdown-value *,
body:has(#theme-toggle input:checked) .dash-dropdown-value-count,
body:has(#theme-toggle input:checked) .dash-dropdown-trigger-icon,
body:has(#theme-toggle input:checked) .dash-dropdown-clear,
body:has(#theme-toggle input:checked) .dash-dropdown-action-button,
body:has(#theme-toggle input:checked) .dash-dropdown-option,
body:has(#theme-toggle input:checked) .dash-dropdown-option *,
body:has(#theme-toggle input:checked) .dash-dropdown-search {
  color: var(--ink) !important;
  fill: var(--ink) !important;
}

body:has(#theme-toggle input:checked) .dash-dropdown-placeholder,
body:has(#theme-toggle input:checked) .dash-dropdown-action-button {
  color: var(--muted) !important;
}

.Select-control,
.Select-menu-outer,
.Select-menu,
.Select-option,
.VirtualizedSelectOption,
.VirtualizedSelectFocusedOption,
.Select-input,
.Select-input > input {
  background: var(--control);
  color: var(--ink);
}

.Select-menu-outer *,
.VirtualizedSelectOption *,
.VirtualizedSelectFocusedOption *,
.Select-control * {
  color: var(--ink);
}

.Select-placeholder,
.Select--single > .Select-control .Select-value {
  color: var(--muted);
  line-height: 38px;
}

.Select-value-label,
.Select-input > input {
  color: var(--ink) !important;
}

.Select--multi .Select-value {
  border-color: var(--line);
  background: var(--control-muted);
  color: var(--ink);
}

.Select--multi .Select-value-icon {
  border-right-color: var(--line);
  color: var(--muted);
}

.Select--multi .Select-value-icon:hover {
  background: color-mix(in srgb, var(--spine-orange) 12%, var(--control-muted));
  color: var(--spine-orange);
}

.Select-clear-zone,
.Select-arrow-zone {
  color: var(--muted);
}

.Select-menu-outer {
  border-color: var(--line);
  box-shadow: var(--shadow);
  z-index: 40;
}

.Select-option.is-focused {
  background: rgba(244, 124, 19, 0.12);
}

.VirtualizedSelectFocusedOption {
  background: rgba(244, 124, 19, 0.12);
}

.Select-option.is-selected {
  background: var(--spine-orange);
  color: #ffffff;
}

.Select-option.is-selected * {
  color: #ffffff;
}

body:has(#theme-toggle input:checked) .Select-control,
body:has(#theme-toggle input:checked) .Select-menu-outer,
body:has(#theme-toggle input:checked) .Select-menu,
body:has(#theme-toggle input:checked) .Select-option,
body:has(#theme-toggle input:checked) .VirtualizedSelectOption,
body:has(#theme-toggle input:checked) .VirtualizedSelectFocusedOption,
body:has(#theme-toggle input:checked) .Select-input,
body:has(#theme-toggle input:checked) .Select-input > input {
  background: var(--control) !important;
  color: var(--ink) !important;
}

body:has(#theme-toggle input:checked) .Select-option.is-focused,
body:has(#theme-toggle input:checked) .VirtualizedSelectFocusedOption {
  background: rgba(244, 124, 19, 0.18) !important;
}

body:has(#theme-toggle input:checked) .Select-option.is-selected {
  background: var(--spine-orange) !important;
  color: #ffffff !important;
}

body:has(#theme-toggle input:checked) .Select-menu-outer *,
body:has(#theme-toggle input:checked) .VirtualizedSelectOption *,
body:has(#theme-toggle input:checked) .VirtualizedSelectFocusedOption *,
body:has(#theme-toggle input:checked) .Select-control * {
  color: inherit !important;
}

.entry-grid {
  display: grid;
  grid-template-columns: 120px repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

#input-entry {
  grid-column: 2 / -1;
  min-width: 0;
  width: 100%;
}

.button-row,
.split-control,
.inline-control {
  display: grid;
  gap: 8px;
}

.button-row {
  grid-template-columns: 1fr 1fr 1fr;
  margin-top: 12px;
}

.split-control {
  grid-template-columns: 1fr 1fr;
}

.inline-control {
  grid-template-columns: 74px minmax(0, 1fr);
  align-items: end;
  margin-top: 14px;
}

.primary-button,
.secondary-button {
  min-height: 40px;
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 850;
  line-height: 1;
}

.primary-button {
  background: var(--spine-orange);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--spine-orange-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--control-muted);
  color: var(--ink);
}

.secondary-button:hover {
  border-color: var(--spine-orange);
  color: var(--spine-orange);
}

.source-toggle,
.full-width {
  width: 100%;
}

.log-panel {
  position: relative;
  margin-top: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-subtle);
}

.log-panel.has-error {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, var(--panel-subtle));
}

.log-summary {
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  list-style: none;
}

.log-summary::-webkit-details-marker {
  display: none;
}

.log-alert-icon {
  display: none;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--danger);
  color: #ffffff;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.log-panel.has-error .log-alert-icon {
  display: inline-flex;
}

.log-panel.has-error .log-summary {
  color: var(--danger);
}

.log-panel[open] .log-summary {
  border-bottom: 1px solid var(--line);
}

.log-panel[open] .log-popover {
  position: absolute;
  z-index: 50;
  top: calc(100% + 8px);
  right: 0;
  width: min(420px, calc(100vw - 48px));
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.status-log {
  min-height: 84px;
  margin: 0;
  border: 0;
  border-radius: 0 0 6px 6px;
  resize: vertical;
  border-color: #272a2e;
  background: #17191c;
  color: #f0f1f2;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.4;
}

.log-panel:not([open]) .log-popover {
  display: none;
}

.stacked-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.control-block {
  min-width: 0;
}

.draw-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.option-group-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.viewer-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-toolbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.panel-title {
  font-size: 18px;
}

.panel-subtitle,
.login-copy {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.viewer-body {
  flex: 1;
  min-height: 0;
  background: var(--plot-bg);
}

.viewer-empty {
  width: 100%;
  height: 100%;
  min-height: 590px;
  background: var(--plot-bg);
}

.viewer-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.viewer-meta.muted {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.meta-chip {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--panel-subtle);
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
}

.event-graph,
#graph-evd {
  width: 100%;
  height: 100%;
  min-height: 590px;
}

.login-shell {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 28px 16px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 20px;
}

.login-title {
  text-align: left;
  font-size: 17px;
}

.login-copy {
  margin: 6px 0 18px;
  text-align: left;
}

.login-field {
  margin-top: 14px;
}

.login-error {
  min-height: 18px;
  margin: 8px 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
  text-align: left;
}

@media (max-width: 1260px) {
  .workbench {
    grid-template-columns: minmax(390px, 450px) minmax(0, 1fr);
  }
}

@media (max-width: 1060px) {
  .workbench {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

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

  .control-section {
    border-bottom: 0;
    padding: 0;
  }

  .viewer-panel {
    min-height: 720px;
  }
}

@media (max-width: 760px) {
  .app-header {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 12px 14px;
  }

  .spine-logo {
    display: none;
  }

  .theme-control,
  .version-block,
  .session-block {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .app-main {
    padding: 10px;
  }

  .control-rail,
  .stacked-controls,
  .draw-options,
  .split-control,
  .button-row {
    grid-template-columns: 1fr;
  }

  .entry-grid {
    grid-template-columns: 112px repeat(3, minmax(0, 1fr));
  }

  .viewer-panel {
    min-height: 620px;
  }
}
