/* ── Theme Variables ─────────────────────────────────────── */
/* Base: inherit from JupyterLab theme if available (no data-lzw-theme set). */
.lzw-root {
  --lzw-bg-0: var(--jp-layout-color0, #fff);
  --lzw-bg-1: var(--jp-layout-color1, #f5f5f5);
  --lzw-bg-2: var(--jp-layout-color2, #eee);
  --lzw-fg-0: var(--jp-ui-font-color1, #333);
  --lzw-fg-1: var(--jp-ui-font-color2, #666);
  --lzw-fg-2: #767676;
  --lzw-border: var(--jp-border-color1, #e0e0e0);
  --lzw-border-light: var(--jp-border-color2, #f0f0f0);
  --lzw-accent: var(--jp-brand-color1, #2196f3);
  --lzw-accent-fg: #fff;
  --lzw-input-bg: var(--jp-layout-color0, #fff);
  --lzw-error: #c62828;
  --lzw-success: #2e7d32;
  --lzw-warning: #e65100;
  --lzw-info: #1565c0;
  --lzw-badge-info-bg: #e3f2fd;
  --lzw-badge-running-bg: #fff3e0;
  --lzw-badge-success-bg: #e8f5e9;
  --lzw-badge-error-bg: #ffebee;
  --lzw-tag-warning-bg: #fff3cd;
  --lzw-tag-warning-fg: #856404;
  --lzw-modal-overlay: rgba(0, 0, 0, 0.4);
  --lzw-toggle-knob: #fff;
}

/* Light: explicit self-managed theme. Overrides --jp-* to avoid host theme leaking
   (e.g. Colab dark mode setting --jp-ui-font-color1 to light gray). */
.lzw-root[data-lzw-theme="light"] {
  --lzw-bg-0: #fff;
  --lzw-bg-1: #f5f5f5;
  --lzw-bg-2: #eee;
  --lzw-fg-0: #333;
  --lzw-fg-1: #666;
  --lzw-fg-2: #767676;
  --lzw-border: #e0e0e0;
  --lzw-border-light: #f0f0f0;
  --lzw-accent: #2196f3;
  --lzw-accent-fg: #fff;
  --lzw-accent-bg-subtle: rgba(33, 150, 243, 0.12);
  --lzw-accent-bg-medium: rgba(33, 150, 243, 0.2);
  --lzw-accent-border: rgba(33, 150, 243, 0.3);
  --lzw-accent-bg-faint: rgba(33, 150, 243, 0.08);
  --lzw-accent-border-faint: rgba(33, 150, 243, 0.25);
  --lzw-success-bg-medium: rgba(46, 125, 50, 0.2);
  --lzw-success-border: rgba(46, 125, 50, 0.3);
  --lzw-input-bg: #fff;
}

.lzw-root[data-lzw-theme="dark"] {
  --lzw-bg-0: #1e1e1e;
  --lzw-bg-1: #2d2d2d;
  --lzw-bg-2: #3c3c3c;
  --lzw-fg-0: #e0e0e0;
  --lzw-fg-1: #aaa;
  --lzw-fg-2: #8a8a8a;
  --lzw-border: #555;
  --lzw-border-light: #444;
  --lzw-accent: #64b5f6;
  --lzw-accent-fg: #1e1e1e;
  --lzw-accent-bg-subtle: rgba(100, 181, 246, 0.12);
  --lzw-accent-bg-medium: rgba(100, 181, 246, 0.15);
  --lzw-accent-border: rgba(100, 181, 246, 0.3);
  --lzw-accent-bg-faint: rgba(100, 181, 246, 0.08);
  --lzw-accent-border-faint: rgba(100, 181, 246, 0.25);
  --lzw-success-bg-medium: rgba(129, 199, 132, 0.15);
  --lzw-success-border: rgba(129, 199, 132, 0.3);
  --lzw-input-bg: #2d2d2d;
  --lzw-error: #f28b82;
  --lzw-success: #81c784;
  --lzw-warning: #ffb74d;
  --lzw-info: #90caf9;
  --lzw-badge-info-bg: #1a3a5c;
  --lzw-badge-running-bg: #3e2a10;
  --lzw-badge-success-bg: #1a3a1c;
  --lzw-badge-error-bg: #3c1a1a;
  --lzw-tag-warning-bg: #3e3010;
  --lzw-tag-warning-fg: #ffcc80;
  --lzw-modal-overlay: rgba(0, 0, 0, 0.6);
  --lzw-toggle-knob: #e0e0e0;
}

/* ── Root ────────────────────────────────────────────────── */
.lzw-root {
  font-family: var(--jp-ui-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
  font-size: 13px;
  box-sizing: border-box;
  width: 100%;
  min-height: 620px;
  resize: vertical;
  border: 1px solid var(--lzw-border);
  border-radius: 6px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  background: var(--lzw-bg-0);
  color: var(--lzw-fg-0);
}

.lzw-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

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

/* Reset host environment styles.
   VS Code Jupyter sets `background: #fff !important` on .cell-output-ipywidget-background.
   Colab sets background-color on table/button elements.
   We must use !important to override both. */
.lzw-root table,
.lzw-root thead,
.lzw-root tbody,
.lzw-root tr,
.lzw-root th,
.lzw-root td,
.lzw-root input,
.lzw-root select {
  background-color: inherit !important;
  color: inherit !important;
}

/* Buttons: reset base but allow active/accent overrides */
.lzw-root button {
  background-color: inherit;
  color: inherit;
}

/* Restore explicit colors for active/selected button states */
.lzw-root .lzw-segment__btn--active,
.lzw-root .lzw-chip--active,
.lzw-root .lzw-tabs__btn--active {
  background-color: var(--lzw-accent) !important;
  color: var(--lzw-accent-fg) !important;
}

/* ── Header ─────────────────────────────────────────────── */
.lzw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  height: 40px;
  border-bottom: 1px solid var(--lzw-border);
  background: var(--lzw-bg-1);
  flex-shrink: 0;
}

.lzw-header__title {
  font-weight: 600;
  font-size: 14px;
}

.lzw-header__right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Tabs ────────────────────────────────────────────────── */
.lzw-tabs {
  display: flex;
  border-bottom: 1px solid var(--lzw-border);
  background: var(--lzw-bg-1);
  flex-shrink: 0;
}

.lzw-tabs__btn {
  padding: 6px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--lzw-fg-1);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.lzw-tabs__btn:hover {
  color: var(--lzw-fg-0);
}

.lzw-tabs__btn--active {
  color: var(--lzw-accent);
  border-bottom-color: var(--lzw-accent);
  font-weight: 600;
}

/* ── Content ─────────────────────────────────────────────── */
.lzw-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

/* ── Badges ──────────────────────────────────────────────── */
.lzw-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
}

.lzw-badge--muted {
  background: var(--lzw-bg-2);
  color: var(--lzw-fg-1);
}

.lzw-badge--info {
  background: var(--lzw-badge-info-bg);
  color: var(--lzw-info);
}

.lzw-badge--running {
  background: var(--lzw-badge-running-bg);
  color: var(--lzw-warning);
}

.lzw-badge--success {
  background: var(--lzw-badge-success-bg);
  color: var(--lzw-success);
}

.lzw-badge--error {
  background: var(--lzw-badge-error-bg);
  color: var(--lzw-error);
}

/* ── Tags ────────────────────────────────────────────────── */
.lzw-tag {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  margin-left: 4px;
  vertical-align: middle;
}

.lzw-tag--muted {
  background: var(--lzw-bg-2);
  color: var(--lzw-fg-1);
}

.lzw-tag--warning {
  background: var(--lzw-tag-warning-bg);
  color: var(--lzw-tag-warning-fg);
}

/* ── Accordion ───────────────────────────────────────────── */
.lzw-accordion {
  margin-bottom: 8px;
}

.lzw-accordion__trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--lzw-fg-0);
  text-align: left;
}

.lzw-accordion__trigger:hover {
  color: var(--lzw-accent);
}

.lzw-accordion__arrow {
  font-size: 12px;
  width: 12px;
  text-align: center;
}

.lzw-accordion__body {
  padding: 4px 0 4px 18px;
}

/* ── Form elements ───────────────────────────────────────── */
.lzw-form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.lzw-label {
  min-width: 90px;
  font-size: 12px;
  color: var(--lzw-fg-1);
}

.lzw-select,
.lzw-input {
  padding: 3px 6px;
  border: 1px solid var(--lzw-border);
  border-radius: 3px;
  font-size: 12px;
  background: var(--lzw-bg-0);
  color: var(--lzw-fg-0);
}

.lzw-select option {
  background: var(--lzw-bg-0);
  color: var(--lzw-fg-0);
}

.lzw-input--sm {
  width: 60px;
}

.lzw-muted {
  color: var(--lzw-fg-1);
  font-size: 12px;
}

/* ── Table ───────────────────────────────────────────────── */
.lzw-table-wrap {
  overflow-x: auto;
}

.lzw-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.lzw-table--compact {
  width: auto;
}

/* ── Column Settings Grid ──────────────────────────────── */
.lzw-columns-grid {
  display: grid;
  grid-template-columns: minmax(14rem, 2.4fr) minmax(4.5rem, 0.8fr) minmax(4.5rem, 0.8fr) minmax(12rem, 1.8fr);
  font-size: 12px;
  min-width: 100%;
}

.lzw-columns-grid__header {
  display: contents;
}

.lzw-columns-grid__header > div {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 2px solid var(--lzw-border);
  font-weight: 600;
  color: var(--lzw-fg-1);
}

.lzw-columns-grid__row {
  display: contents;
}

.lzw-columns-grid__row > div {
  padding: 3px 8px;
  border-bottom: 1px solid var(--lzw-border-light);
  display: flex;
  align-items: center;
}

.lzw-columns-grid__row.lzw-row--excluded > div {
  opacity: 0.5;
}

/* ── Search Space Grid ────────────────────────────────── */
.lzw-search-space-grid {
  display: grid;
  grid-template-columns: minmax(14rem, 2.6fr) minmax(9rem, 1.2fr) minmax(16rem, 2.2fr);
  font-size: 12px;
  min-width: 100%;
}

.lzw-search-space-grid__header {
  display: contents;
}

.lzw-search-space-grid__header > div {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 2px solid var(--lzw-border);
  font-weight: 600;
  color: var(--lzw-fg-1);
}

.lzw-search-space-grid__group-wrap {
  display: contents;
}

.lzw-search-space-grid__group {
  display: contents;
}

.lzw-search-space-grid__group > div {
  grid-column: 1 / -1;
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 1px solid var(--lzw-border);
}

.lzw-search-space-grid__row {
  display: contents;
}

.lzw-search-space-grid__row > div {
  padding: 3px 8px;
  border-bottom: 1px solid var(--lzw-border-light);
  display: flex;
  align-items: center;
}

.lzw-table th {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 2px solid var(--lzw-border);
  font-weight: 600;
  color: var(--lzw-fg-1);
}

.lzw-table td {
  padding: 3px 8px;
  border-bottom: 1px solid var(--lzw-border-light);
}

.lzw-table__name {
  font-weight: 500;
  overflow-wrap: anywhere;
}

.lzw-table__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.lzw-table__num--uniq {
  white-space: nowrap;
}

.lzw-table__cell--excl {
  text-align: center;
}

.lzw-row--excluded {
  opacity: 0.5;
}

/* ── Data Tab ────────────────────────────────────────────── */
.lzw-data-tab__shape {
  font-size: 12px;
  color: var(--lzw-fg-1);
  margin-bottom: 8px;
}

.lzw-feature-summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 0;
  border-top: 1px solid var(--lzw-border-light);
  font-size: 12px;
  color: var(--lzw-fg-1);
}

/* ── Sub-tabs ────────────────────────────────────────────── */
.lzw-subtabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--lzw-border-light);
  margin-bottom: 8px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--lzw-bg-0);
}

.lzw-subtabs__btn {
  padding: 4px 12px;
  border: 1px solid var(--lzw-border);
  border-radius: 4px;
  background: var(--lzw-bg-0);
  cursor: pointer;
  font-size: 12px;
  color: var(--lzw-fg-1);
}

.lzw-subtabs__btn--active {
  background: var(--lzw-accent);
  color: var(--lzw-accent-fg);
  border-color: var(--lzw-accent);
}

.lzw-subtabs__right {
  margin-left: auto;
}

/* ── Buttons ─────────────────────────────────────────────── */
.lzw-btn {
  padding: 5px 16px;
  border: 1px solid var(--lzw-border);
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  background: var(--lzw-bg-0);
  color: var(--lzw-fg-0);
}

.lzw-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.lzw-btn--primary {
  background: var(--lzw-accent);
  color: var(--lzw-accent-fg);
  border-color: var(--lzw-accent);
}

.lzw-btn--primary:hover:not(:disabled) {
  opacity: 0.9;
}

.lzw-btn--accent-outline {
  background: transparent;
  color: var(--lzw-accent);
  border-color: var(--lzw-accent);
}

.lzw-btn--accent-outline:hover:not(:disabled) {
  background: var(--lzw-accent-bg-subtle);
}

/* ── DynForm ─────────────────────────────────────────────── */
.lzw-dynform__section {
  margin-bottom: 8px;
}

.lzw-dynform__section-title {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 4px;
  color: var(--lzw-fg-0);
}

.lzw-dynform__section-body {
  padding-left: 12px;
}

/* ── Config Tab ──────────────────────────────────────────── */
.lzw-config-tab__body {
  padding-top: 4px;
}

/* ── Progress ─────────────────────────────────────────────── */
.lzw-progress__header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.lzw-progress__title {
  font-weight: 600;
  font-size: 14px;
}

.lzw-progress__bar-wrap {
  height: 8px;
  background: var(--lzw-bg-2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.lzw-progress__bar {
  height: 100%;
  background: var(--lzw-accent);
  border-radius: 4px;
  transition: width 0.8s ease-out;
}

.lzw-progress__bar--indeterminate {
  width: 30%;
  animation: lzw-indeterminate 1.5s ease-in-out infinite;
}

@keyframes lzw-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(333%); }
}

.lzw-progress__info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--lzw-fg-1);
  margin-bottom: 12px;
}

.lzw-progress__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.lzw-progress__folds {
  margin-top: 12px;
  font-family: monospace;
  font-size: 12px;
  color: var(--lzw-fg-1);
}

.lzw-progress__fold-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.lzw-progress__fold-label {
  min-width: 80px;
}

/* ── Results ─────────────────────────────────────────────── */
.lzw-results__header {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.lzw-results-error {
  padding: 12px 0;
}

.lzw-pre {
  font-family: monospace;
  font-size: 11px;
  background: var(--lzw-bg-2);
  padding: 8px;
  border-radius: 4px;
  overflow-x: auto;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ── Plot Viewer ─────────────────────────────────────────── */
.lzw-plot-viewer__container {
  margin-top: 8px;
  min-height: 200px;
}

.lzw-plot-viewer__canvas {
  width: 100%;
}

/* ── Numeric Stepper ─────────────────────────────────────── */
.lzw-stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--lzw-border);
  border-radius: 3px;
  overflow: hidden;
}

.lzw-stepper__btn {
  width: 24px;
  height: 24px;
  border: none;
  background: var(--lzw-bg-1);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--lzw-fg-0);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}

.lzw-stepper__btn:hover {
  background: var(--lzw-bg-2);
}

.lzw-stepper__input {
  width: 75px;
  border: none;
  border-left: 1px solid var(--lzw-border);
  border-right: 1px solid var(--lzw-border);
  text-align: center;
  font-size: 12px;
  padding: 2px 4px;
  background: var(--lzw-bg-0);
  color: var(--lzw-fg-0);
  -moz-appearance: textfield;
}

.lzw-stepper__input::-webkit-outer-spin-button,
.lzw-stepper__input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ── Segment buttons ─────────────────────────────────────── */
.lzw-segment {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--lzw-border);
  border-radius: 4px;
  overflow: hidden;
}

.lzw-segment__btn {
  padding: 2px 8px;
  border: none;
  border-right: 1px solid var(--lzw-border);
  background: var(--lzw-bg-0);
  cursor: pointer;
  font-size: 11px;
  color: var(--lzw-fg-1);
  white-space: nowrap;
}

.lzw-segment__btn:last-child {
  border-right: none;
}

.lzw-segment__btn--active {
  background: var(--lzw-accent);
  color: var(--lzw-accent-fg);
}

.lzw-segment__btn:hover:not(.lzw-segment__btn--active) {
  background: var(--lzw-bg-2);
}

.lzw-segment--wrap {
  gap: 4px;
}

.lzw-segment--wrap .lzw-segment__btn {
  border-radius: 4px;
  border-right: 1px solid var(--lzw-border);
}

/* ── Search Space ────────────────────────────────────────── */
.lzw-search-space__range {
  display: flex;
  align-items: center;
  gap: 4px;
}

.lzw-search-space__log {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--lzw-fg-1);
  margin-left: 4px;
}

/* ── PredTable ───────────────────────────────────────────── */
.lzw-pred-table__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.lzw-pred-table__pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
}

/* ── Inference ───────────────────────────────────────────── */
.lzw-inference-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lzw-inference-actions code {
  background: var(--lzw-bg-2);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

/* ── Disabled tabs ───────────────────────────────────────── */
.lzw-tabs__btn--disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Config footer ───────────────────────────────────────── */
.lzw-config-tab__footer {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid var(--lzw-border-light);
}

/* ── Toggle ─────────────────────────────────────────────── */
.lzw-toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.lzw-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.lzw-toggle__slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--lzw-bg-2);
  border-radius: 10px;
  transition: background 0.2s;
}

.lzw-toggle__slider::before {
  content: "";
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background: var(--lzw-toggle-knob);
  border-radius: 50%;
  transition: transform 0.2s;
}

.lzw-toggle input:checked + .lzw-toggle__slider {
  background: var(--lzw-accent);
}

.lzw-toggle input:checked + .lzw-toggle__slider::before {
  transform: translateX(16px);
}

/* ── Checkbox group (evaluation metrics) ─────────────────── */
.lzw-checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.lzw-checkbox-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  cursor: pointer;
}

/* ── Chip buttons (multi-select toggle) ──────────────────── */
.lzw-chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.lzw-chip {
  padding: 2px 8px;
  border: 1px solid var(--lzw-border);
  border-radius: 12px;
  background: var(--lzw-bg-0);
  cursor: pointer;
  font-size: 11px;
  color: var(--lzw-fg-1);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.lzw-chip--active {
  background: var(--lzw-accent);
  color: var(--lzw-accent-fg);
  border-color: var(--lzw-accent);
}

.lzw-chip:hover:not(.lzw-chip--active) {
  background: var(--lzw-bg-2);
}

/* ── Tag Input ───────────────────────────────────────────── */
.lzw-tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border: 1px solid var(--lzw-border);
  border-radius: 3px;
  background: var(--lzw-bg-0);
  min-width: 160px;
  cursor: text;
}

.lzw-tag-input__field {
  border: none;
  outline: none;
  background: transparent;
  font-size: 12px;
  min-width: 80px;
  flex: 1;
  color: var(--lzw-fg-0);
}

.lzw-tag--removable {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.lzw-tag__remove {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 0 1px;
  color: var(--lzw-fg-1);
}

.lzw-tag__remove:hover {
  color: var(--lzw-error);
}

/* ── KV Editor ───────────────────────────────────── */
.lzw-kv-editor {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 240px;
}

.lzw-kv-editor__row {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Placeholder ─────────────────────────────────────────── */
.lzw-tab-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

/* ── Modal ───────────────────────────────────────────────── */
.lzw-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--lzw-modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.lzw-modal {
  background: var(--lzw-bg-1);
  border-radius: 8px;
  padding: 16px;
  max-width: 600px;
  max-height: 70vh;
  overflow: auto;
  width: 90%;
}
/* ── Theme Toggle ─────────────────────────────────────────── */
.lzw-theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--lzw-border);
  border-radius: 6px;
  background: var(--lzw-bg-0);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  transition: background 0.15s, border-color 0.15s;
}

.lzw-theme-toggle:hover {
  background: var(--lzw-bg-2);
}

.lzw-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 600;
}

/* ── Section Card ───────────────────────────────────────── */
.lzw-section-card {
  background: var(--lzw-bg-1);
  border: 1px solid var(--lzw-border);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
}

.lzw-section-card__title {
  font-size: 11px;
  font-weight: 600;
  color: var(--lzw-fg-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}

/* ── Distribution Bar ───────────────────────────────────── */
.lzw-dist-row {
  display: grid;
  grid-template-columns: 80px 1fr 50px;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--lzw-fg-1);
}

.lzw-dist-bar-bg {
  height: 14px;
  background: var(--lzw-bg-2);
  border-radius: 3px;
  overflow: hidden;
}

.lzw-dist-bar {
  height: 100%;
  background: var(--lzw-accent);
  opacity: 0.6;
  border-radius: 3px;
}

.lzw-dist-count {
  text-align: right;
  font-family: monospace;
  font-size: 11px;
}

/* ── Cutoff Chips ───────────────────────────────────────── */
.lzw-cutoff-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.lzw-cutoff-chip {
  background: var(--lzw-bg-2);
  border: 1px solid var(--lzw-border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  color: var(--lzw-fg-1);
  font-family: monospace;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.lzw-cutoff-chip:hover {
  border-color: var(--lzw-fg-2);
}

.lzw-cutoff-chip--selected {
  background: var(--lzw-accent-bg-subtle);
  border-color: var(--lzw-accent);
  color: var(--lzw-accent);
  font-weight: 600;
}

/* dark mode cutoff-chip handled by --lzw-accent-bg-subtle variable */

/* ── Period Flow ────────────────────────────────────────── */
.lzw-period-flow {
  display: flex;
  gap: 2px;
  margin: 8px 0;
  height: 28px;
  align-items: stretch;
}

.lzw-period-block {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  font-family: monospace;
}

.lzw-period-block--train {
  background: var(--lzw-accent-bg-medium);
  color: var(--lzw-accent);
  border: 1px solid var(--lzw-accent-border);
}

.lzw-period-block--valid {
  background: var(--lzw-success-bg-medium);
  color: var(--lzw-success);
  border: 1px solid var(--lzw-success-border);
}

.lzw-period-block--unused {
  background: var(--lzw-bg-2);
  color: var(--lzw-fg-2);
  border: 1px dashed var(--lzw-border);
}

/* dark mode period-block handled by --lzw-accent-bg-medium / --lzw-success-bg-medium variables */

/* ── Fold Preview ───────────────────────────────────────── */
.lzw-fold-preview {
  font-family: monospace;
  font-size: 11px;
  line-height: 1.8;
  color: var(--lzw-fg-1);
}

.lzw-fold-line {
  display: grid;
  grid-template-columns: 50px 1fr 60px 60px;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 3px;
}

.lzw-fold-line:nth-child(even) {
  background: var(--lzw-bg-2);
}

.lzw-fold-header {
  font-weight: 600;
  color: var(--lzw-fg-2);
  font-size: 10px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--lzw-border);
  padding-bottom: 4px;
  margin-bottom: 4px;
}

.lzw-train-tag {
  background: var(--lzw-accent-bg-medium);
  color: var(--lzw-accent);
  border-radius: 2px;
  padding: 0 4px;
  font-size: 10px;
}

.lzw-valid-tag {
  background: var(--lzw-success-bg-medium);
  color: var(--lzw-success);
  border-radius: 2px;
  padding: 0 4px;
  font-size: 10px;
}

/* dark mode train-tag/valid-tag handled by CSS variables */

/* ── Fold Visualization Row ─────────────────────────────── */
.lzw-fold-vis-row {
  margin-bottom: 6px;
}

.lzw-fold-vis-label {
  font-size: 10px;
  color: var(--lzw-fg-2);
  margin-bottom: 2px;
  font-family: monospace;
}

/* ── Summary Badge ──────────────────────────────────────── */
.lzw-summary-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--lzw-bg-2);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--lzw-fg-1);
  margin-top: 12px;
}

.lzw-summary-badge__num {
  font-family: monospace;
  font-weight: 600;
  color: var(--lzw-accent);
}

/* ── Info Box ───────────────────────────────────────────── */
.lzw-info-box {
  background: var(--lzw-accent-bg-faint);
  border: 1px solid var(--lzw-accent-border-faint);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--lzw-fg-1);
  margin-top: 8px;
  line-height: 1.5;
}

/* dark mode info-box handled by CSS variables */
