:root {
  --bg: #0a0e12;
  --surface: #111820;
  --surface2: #161f2a;
  --border: #243044;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3dd6c6;
  --accent-dim: #2a9d90;
  --warn: #e8b84a;
  --danger: #f07178;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --sidebar-w: 360px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

.sidebar-panel {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.85rem;
  margin-bottom: 0.85rem;
}

.sidebar-brand {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  flex-shrink: 0;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  padding: 0.45rem 0.4rem;
  line-height: 1;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  background: rgba(61, 214, 198, 0.06);
}

.sidebar-brand h1 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.35;
}

.sidebar-panel-title {
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 0.45rem;
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.btn-danger-outline {
  color: var(--danger);
  border-color: rgba(240, 113, 120, 0.35);
  background: transparent;
}

.btn-danger-outline:hover {
  border-color: var(--danger);
  background: rgba(240, 113, 120, 0.08);
}

.badge {
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.35rem 0.6rem;
  border-radius: 2px;
  border: 1px solid var(--border);
}

.badge-ok {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.badge-warn {
  border-color: #5c4a20;
  color: var(--warn);
}

.badge-err {
  border-color: #5c3035;
  color: var(--danger);
}

.layout {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 0;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 1rem;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: rgba(15, 20, 28, 0.6);
}

.results-panel {
  padding: 0.65rem 1rem 0.5rem;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.results-merged {
  flex-shrink: 0;
  margin-bottom: 0.35rem;
  padding: 0.5rem 0.65rem 0.4rem;
  border: 1px solid var(--border);
  background: rgba(17, 24, 32, 0.55);
}

.results-merged .results-title {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.results-merged .kpi-grid {
  margin-bottom: 0.35rem;
}

.results-expand summary {
  cursor: pointer;
  font-size: 0.72rem;
  color: var(--accent-dim);
  list-style: none;
  user-select: none;
}

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

.results-expand summary::before {
  content: "▸ ";
  font-family: var(--mono);
  color: var(--accent);
}

.results-expand[open] summary::before {
  content: "▾ ";
}

.results-expanded-body {
  margin-top: 0.4rem;
  max-height: 10rem;
  overflow-y: auto;
}

.results-expand-hint {
  margin: 0 0 0.35rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  flex-shrink: 0;
}


.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.5rem 0.65rem;
}

.kpi h3 {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.kpi-val {
  margin: 0.3rem 0 0;
  font-size: 1.2rem;
  font-weight: 500;
}

.kpi-val.accent {
  color: var(--accent);
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.preset-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.preset-row select,
.preset-row input {
  flex: 1;
}

.params-form details {
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 0.55rem;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
  padding: 0 0.75rem 0.75rem;
}

.mode-option {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
  background: var(--bg);
  font-size: 0.82rem;
}

.mode-option:has(input:checked) {
  border-color: var(--accent-dim);
  background: rgba(61, 214, 198, 0.06);
}

.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-option small {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.3;
}

.params-form details.boost-only-section.boost-disabled,
.params-form details.interval-only-section.interval-disabled {
  opacity: 0.45;
  pointer-events: none;
}

summary {
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  font-weight: 500;
  font-size: 0.84rem;
  list-style: none;
}

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

summary::before {
  content: "▸ ";
  color: var(--accent);
  font-family: var(--mono);
}

details[open] summary::before {
  content: "▾ ";
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
  padding: 0 0.75rem 0.75rem;
}

.field-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.field-grid label.span2 {
  grid-column: span 1;
}

.field-grid label.check {
  flex-direction: row;
  align-items: center;
  color: var(--text);
}

.field-hint {
  margin: 0 0.75rem 0.65rem;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--muted);
}

.derived-field {
  padding: 0.45rem 0.5rem;
  background: var(--bg);
  border: 1px dashed var(--border);
}

.derived-label {
  font-size: 0.76rem;
  color: var(--muted);
}

.derived-val {
  display: block;
  font-size: 1rem;
  margin: 0.2rem 0;
  color: var(--accent);
}

.derived-hint {
  font-size: 0.68rem;
  color: var(--muted);
}

.detail-block {
  margin-bottom: 1rem;
}

.detail-block h3 {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.detail-table td {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  vertical-align: top;
}

.detail-table td:first-child {
  width: 38%;
  color: var(--muted);
  background: var(--surface2);
}

.detail-table td:last-child {
  font-family: var(--mono);
  font-size: 0.78rem;
  word-break: break-word;
}

.slip-block {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.slip-header {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.35rem;
}

.slip-title-block {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.65rem;
  min-width: 0;
}

.slip-title-block h3 {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 600;
}

.slip-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem 0.5rem;
  margin-left: auto;
}

.btn-compact {
  padding: 0.35rem 0.6rem;
  font-size: 0.76rem;
}

.slip-count {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.slip-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  overscroll-behavior: contain;
}

.slip-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.72rem;
  min-width: max-content;
}

.slip-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #1a2433;
  color: var(--muted);
  font-weight: 500;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

.slip-table tbody td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid rgba(36, 48, 68, 0.6);
  border-right: 1px solid rgba(36, 48, 68, 0.4);
  font-family: var(--mono);
  font-size: 0.68rem;
  white-space: nowrap;
  vertical-align: middle;
}

.slip-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.slip-table tbody tr.slip-row-normal.hit td {
  color: #4ade80;
}

.slip-table tbody tr.slip-row-normal.miss td {
  color: #f0f4f8;
}

.slip-table tbody tr.slip-row-boost.hit td {
  color: #ff4d4f;
}

.slip-table tbody tr.slip-row-boost.miss td {
  color: #facc15;
}

.slip-table thead .th-cell {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  min-width: max-content;
}

.slip-table thead .th-sort-label {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  color: var(--muted);
}

.slip-table thead .th-sort-label:hover {
  color: var(--accent);
}

.slip-table thead th.sort-asc .sort-mark::after {
  content: " ↑";
  opacity: 1;
}

.slip-table thead th.sort-desc .sort-mark::after {
  content: " ↓";
  opacity: 1;
}

.slip-table thead .sort-mark {
  font-size: 0.65rem;
  opacity: 0.35;
}

.slip-table thead .th-cell input {
  width: 3.2rem;
  min-width: 2.5rem;
  flex: 0 1 auto;
  padding: 0.2rem 0.3rem;
  font-size: 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.slip-hint {
  margin: 0;
  font-size: 0.68rem;
  color: var(--muted);
}

.col-settings-inline {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  position: relative;
}

.col-settings-inline summary {
  cursor: pointer;
  color: var(--muted);
  list-style: none;
  white-space: nowrap;
}

.col-settings-inline summary::-webkit-details-marker {
  display: none;
}

.col-settings-inline[open] {
  z-index: 5;
}

.col-settings-panel {
  display: none;
}

.col-settings-inline[open] .col-settings-panel {
  display: block;
  position: absolute;
  right: 0;
  top: calc(100% + 0.2rem);
  min-width: 15rem;
  max-width: min(90vw, 20rem);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.5rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.col-settings-inline[open] #columnSettingsList {
  max-height: 11rem;
}

details.detail-block {
  flex-shrink: 0;
  max-height: 9rem;
  overflow-y: auto;
}

#columnSettingsList {
  list-style: none;
  margin: 0.35rem 0;
  padding: 0;
  max-height: 12rem;
  overflow-y: auto;
}

.col-setting-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(36, 48, 68, 0.5);
}

.col-setting-item span {
  flex: 1;
  font-size: 0.76rem;
}

.btn-xs {
  padding: 0.15rem 0.35rem;
  font-size: 0.7rem;
  min-width: 1.6rem;
}

.slip-block.slip-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  margin: 0;
  padding: 1rem 1.25rem;
  background: var(--bg);
  border: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.slip-fullscreen .slip-scroll {
  flex: 1;
  min-height: 0;
}

body.slip-fs-active {
  overflow: hidden;
}

details.detail-block summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

input[type="number"],
input[type="text"],
select {
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.4rem 0.45rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 2px;
}

input:focus,
select:focus {
  outline: 1px solid var(--accent-dim);
  border-color: var(--accent-dim);
}

.btn {
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.45rem 0.75rem;
  border-radius: 2px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}

.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #041412;
}

.btn-primary:hover {
  background: var(--accent);
}

.btn-ghost:hover {
  border-color: var(--muted);
}

.sidebar-actions .btn-primary {
  padding: 0.5rem 0.65rem;
  font-size: 0.86rem;
}

.footer {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0.5rem;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 10;
  font-size: 0.82rem;
  padding: 0.65rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

@media (max-width: 960px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  body {
    display: block;
  }

  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
    min-height: auto;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 45vh;
  }

  .results-panel {
    min-height: 50vh;
  }

  .slip-scroll {
    min-height: 40vh;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
