/* Matrix / linear algebra tab */
.diff-cat-pill.active.diff-theme-matrix,
.diff-theme-matrix .diff-cat-pill.active {
  border-color: rgba(251, 191, 36, 0.55);
  color: #fde68a;
  background: rgba(251, 191, 36, 0.12);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.28);
}
.diff-theme-matrix .diff-mode-select:focus {
  outline: none;
  border-color: rgba(251, 191, 36, 0.55);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.15);
}
.diff-theme-matrix .diff-preset-chip:hover {
  border-color: rgba(251, 191, 36, 0.35);
}
.diff-theme-matrix .diff-rail-dot.active {
  background: #fbbf24;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.6);
}
.matrix-run-btn.loading {
  pointer-events: none;
  position: relative;
}
.matrix-run-btn.loading::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  border: 2px solid transparent;
  border-top-color: #fbbf24;
  animation: diffSpin 0.8s linear infinite;
}
#matrixStepsHost {
  margin-top: 0.65rem;
}
.matrix-trial-badge {
  margin-bottom: 0.5rem;
}

/* Matrix workspace panel — allow native select menus to render */
#tab-matrix .matrix-workspace-panel {
  overflow: visible;
  --matrix-cell-w: 52px;
  --matrix-cell-h: 44px;
  --matrix-gap: 6px;
}

/* Dimension bar */
.matrix-dim-bar {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: end;
  gap: 0.65rem 0.75rem;
  margin: 0.5rem 0 0.75rem;
  padding: 0.55rem 0.65rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(251, 191, 36, 0.2);
  box-shadow: 0 0 20px rgba(251, 191, 36, 0.06);
}
.matrix-dim-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}
.matrix-dim-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.4);
}
.matrix-dim-select {
  width: 5rem;
  min-width: 5rem;
  max-width: 100%;
  flex: none;
  box-sizing: border-box;
  padding: 0.45rem 2rem 0.45rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  font-size: 0.88rem;
  font-family: inherit;
  line-height: 1.2;
  color: #fff;
  background-color: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(251, 191, 36, 0.25);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23fbbf24' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  color-scheme: dark;
}
.matrix-dim-select option {
  background: #0f172a;
  color: #fff;
}
.matrix-dim-select:focus {
  outline: none;
  border-color: rgba(251, 191, 36, 0.55);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.15);
  position: relative;
  z-index: 2;
}
.matrix-dim-badge {
  justify-self: end;
  align-self: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #fde68a;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.3);
  white-space: nowrap;
}
@media (max-width: 520px) {
  .matrix-dim-bar {
    grid-template-columns: 1fr 1fr;
  }
  .matrix-dim-badge {
    grid-column: 1 / -1;
    justify-self: start;
  }
}

/* Slot tabs */
.matrix-slot-header {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0.35rem 0 0.85rem;
}
.matrix-slot-label {
  margin: 0;
}
.matrix-slot-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.matrix-add-slot-btn {
  flex-shrink: 0;
}
.matrix-slot-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.matrix-slot-tab {
  padding: 0.35rem 0.85rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.matrix-slot-tab:hover {
  color: rgba(255, 255, 255, 0.85);
  border-color: rgba(251, 191, 36, 0.3);
}
.matrix-slot-tab.active {
  border-color: rgba(251, 191, 36, 0.55);
  color: #fde68a;
  background: rgba(251, 191, 36, 0.12);
}
.matrix-slot-tab .slot-remove {
  margin-left: 0.35rem;
  opacity: 0.5;
  font-size: 0.75rem;
}
.matrix-slot-tab .slot-remove:hover {
  opacity: 1;
}

/* Grid — shrink-wrap to computed rows × cols (dimensions set inline in JS) */
.matrix-grid-host {
  display: inline-block;
  vertical-align: top;
  min-height: 3.5rem;
  margin: 0.35rem 0 0.75rem;
  width: auto;
  max-width: 100%;
}
.matrix-grid-error {
  margin: 0.5rem 0;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-size: 0.82rem;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

/* Framed matrix bracket container — tight [ grid ] row */
.matrix-grid-wrap {
  display: inline-block;
  vertical-align: top;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(251, 191, 36, 0.05), rgba(0, 0, 0, 0.34));
  border: 1px solid rgba(251, 191, 36, 0.22);
  box-shadow:
    0 0 28px rgba(251, 191, 36, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}
.matrix-grid-row {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: fit-content;
  max-width: 100%;
}
/* Override legacy absolute bracket pseudo-elements if cached */
.matrix-grid-wrap::before,
.matrix-grid-wrap::after {
  content: none !important;
  display: none !important;
}
.matrix-bracket {
  flex: 0 0 auto;
  font-size: 1.85rem;
  font-weight: 300;
  line-height: 1;
  color: rgba(251, 191, 36, 0.38);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}

.matrix-grid {
  display: grid;
  flex: 0 0 auto;
  margin: 0;
  box-sizing: border-box;
}

/* Shared editable cell styling (matrix grid + vector b) */
.matrix-grid input,
.matrix-vec-grid input {
  box-sizing: border-box;
  min-height: 44px;
  padding: 0.45rem 0.35rem;
  text-align: center;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.07), rgba(0, 0, 0, 0.38));
  color: #f8fafc;
  font-size: 0.88rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -2px 6px rgba(0, 0, 0, 0.35),
    0 1px 2px rgba(0, 0, 0, 0.2);
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.15s ease,
    background 0.2s ease;
}
.matrix-grid input {
  width: 100%;
  height: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
}
.matrix-grid input[type='number'] {
  appearance: textfield;
  -moz-appearance: textfield;
}
.matrix-grid input[type='number']::-webkit-outer-spin-button,
.matrix-grid input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.matrix-grid input:hover,
.matrix-vec-grid input:hover {
  border-color: rgba(251, 191, 36, 0.38);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -2px 6px rgba(0, 0, 0, 0.3),
    0 0 14px rgba(251, 191, 36, 0.14);
}
.matrix-grid input:focus,
.matrix-vec-grid input:focus,
.matrix-grid input:focus-visible,
.matrix-vec-grid input:focus-visible {
  border-color: rgba(251, 191, 36, 0.65);
  outline: none;
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 0 0 3px rgba(251, 191, 36, 0.18),
    0 4px 16px rgba(251, 191, 36, 0.16);
}
.matrix-grid input:not(:placeholder-shown),
.matrix-vec-grid input:not(:placeholder-shown) {
  background: linear-gradient(145deg, rgba(251, 191, 36, 0.09), rgba(0, 0, 0, 0.36));
  border-color: rgba(251, 191, 36, 0.24);
  color: #fde68a;
}

/* Vector b — matching glass frame, sized to entry count */
#matrixVecWrap {
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}
.matrix-vec-grid {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: var(--matrix-gap, 6px);
  width: fit-content;
  max-width: 100%;
  padding: 0.65rem 1.15rem;
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(251, 191, 36, 0.04), rgba(0, 0, 0, 0.3));
  border: 1px solid rgba(251, 191, 36, 0.18);
  box-shadow:
    0 0 18px rgba(251, 191, 36, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.matrix-vec-grid input {
  width: var(--matrix-cell-w, 52px);
  min-width: var(--matrix-cell-w, 52px);
  flex: 0 0 auto;
}

@media (max-width: 520px) {
  #tab-matrix .matrix-workspace-panel {
    --matrix-cell-w: 44px;
    --matrix-cell-h: 40px;
    --matrix-gap: 4px;
  }
  .matrix-grid-wrap {
    padding: 0.65rem 0.7rem;
    gap: 0.25rem;
  }
  .matrix-bracket {
    font-size: 1.45rem;
  }
  .matrix-grid input,
  .matrix-vec-grid input {
    padding: 0.35rem 0.25rem;
    font-size: 0.82rem;
  }
  .matrix-vec-grid input {
    width: var(--matrix-cell-w, 44px);
    min-width: var(--matrix-cell-w, 44px);
  }
}

/* Augment preview */
.matrix-augment-preview {
  overflow-x: auto;
  padding: 0.5rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.matrix-augment-preview .matrix-result-table td.augment-divider {
  border-left: 2px solid rgba(251, 191, 36, 0.45);
  padding-left: 0.65rem;
}
