/* Luma Quant — custom factor upload page + custom-factor badges (loaded after factor-library.css) */
.lib-upload-control { width: auto !important; }
a.lib-upload-btn {
  display: inline-flex; align-items: center; justify-content: center; height: 38px; padding: 0 14px; border-radius: 8px;
  background: linear-gradient(180deg, #4d8dff 0%, #3b73e0 100%); color: #fff; font-weight: 700; font-size: 13px;
  text-decoration: none; white-space: nowrap; box-shadow: 0 2px 12px rgba(77,141,255,0.28);
}
a.lib-upload-btn:hover { filter: brightness(1.1); }
a.lib-upload-cta {
  display: inline-flex; align-items: center; gap: 10px; margin-left: auto; padding: 8px 12px; border-radius: 8px;
  border: 1px dashed rgba(77,141,255,0.5); background: rgba(77,141,255,0.06); color: var(--muted); font-size: 12px; text-decoration: none;
}
a.lib-upload-cta strong { color: #93c5fd; font-size: 12.5px; white-space: nowrap; }
a.lib-upload-cta:hover { border-color: var(--accent); }
.lib-badge.fu-badge { color: #c4b5fd; border-color: rgba(196,181,253,0.45); background: rgba(139,92,246,0.10); }
.lib-badge.fu-badge-run { color: #fbbf24; border-color: rgba(251,191,36,0.35); }
.lib-badge.fu-badge-bad { color: #f87171; border-color: rgba(248,113,113,0.4); }
.fr-src.custom { color: #c4b5fd; border-color: rgba(196,181,253,0.45); margin-left: 6px; white-space: nowrap; }

/* upload page */
.fu-head h2 code { font-size: .75em; color: #c4b5fd; }
.fu-lead { margin: 8px 0 0; max-width: 880px; color: #c3cad8; font-size: 13.5px; line-height: 1.65; }
.fu-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; margin-top: 16px; }
.fu-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.fu-step h4, .fu-ref h4 { margin: 0 0 12px; }
.fu-step-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.fu-step-head h4 { margin: 0; }
.fu-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.fu-actions.start { justify-content: flex-start; margin-top: 10px; }
button.fr-btn:disabled { opacity: .55; cursor: wait; filter: none; }
button.fr-btn.danger { color: #fca5a5; border-color: rgba(248,113,113,0.45); }
button.fr-btn.danger.armed { background: #b91c1c; color: #fff; border-color: transparent; }
a.fr-btn-link {
  display: inline-flex; align-items: center; padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 650;
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); text-decoration: none;
}
a.fr-btn-link:hover { filter: brightness(1.12); }

.fu-editor {
  display: grid; grid-template-columns: auto minmax(0, 1fr); border: 1px solid var(--input-border); border-radius: 8px;
  background: var(--input-bg); overflow: hidden;
}
.fu-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(77,141,255,0.18); }
.fu-gutter, .fu-editor textarea { font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.fu-gutter {
  margin: 0; padding: 10px 8px 10px 10px; min-width: 38px; text-align: right; color: #4b5671; background: #0b111d;
  border-right: 1px solid var(--line); overflow: hidden; user-select: none; height: 460px; box-sizing: border-box; white-space: pre;
}
.fu-gutter .bad { color: #fff; background: #b91c1c; border-radius: 3px; padding: 0 3px; }
.fu-editor textarea {
  width: 100%; height: 460px; box-sizing: border-box; margin: 0; padding: 10px 12px; border: 0; border-radius: 0;
  background: transparent; color: #e6e9f0; resize: vertical; white-space: pre; overflow: auto; tab-size: 4; box-shadow: none !important;
}
.fu-code-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.fu-code-meta strong { color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.fu-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 14px; }
.fu-field { min-width: 0; }
.fu-field.wide { grid-column: 1 / -1; }
.fu-field label, .fu-bi-label { display: block; margin: 12px 0 6px; font-size: 12.5px; font-weight: 650; color: var(--ink); }
.fu-hint { display: block; font-weight: 400; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.fu-fields > .fu-note { grid-column: 1 / -1; }
.fu-actions .fu-hint { display: inline; margin: 0 0 0 4px; }
.fu-form textarea, .fu-form input, .fu-step select { width: 100%; box-sizing: border-box; font-size: 13px; }
.fu-form textarea { resize: vertical; min-height: 38px; line-height: 1.5; border-radius: 6px; font-family: inherit; }
.fu-bi-pair input, .fu-bi-pair textarea { padding-right: 56px; }
.fu-form input[readonly] { color: var(--muted); }
.fu-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important; font-size: 12.5px !important; }
.fu-bi { margin-top: 2px; }
.fu-bi-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fu-bi-pair > div { position: relative; min-width: 0; }
.fu-lang { position: absolute; right: 8px; top: 6px; font-size: 10px; color: #5b6478; pointer-events: none; z-index: 1; }
.fu-invalid > input, .fu-invalid > textarea, .fu-invalid > select, .fu-invalid.fu-editor { border-color: #f87171 !important; }
.fu-invalid > div > input, .fu-invalid > div > textarea { border-color: #f87171 !important; }
.fu-err { color: #fca5a5; font-size: 12px; margin-top: 5px; grid-column: 1 / -1; }
.fu-editor .fu-err { padding: 6px 10px 8px; border-top: 1px solid rgba(248,113,113,0.4); background: rgba(185,28,28,0.12); }

.fu-note { margin: 10px 0 0; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; line-height: 1.55; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); }
.fu-note.ok { border-color: rgba(52,211,153,0.4); background: rgba(16,185,129,0.08); }
.fu-note.warn { border-color: rgba(248,113,113,0.45); background: rgba(185,28,28,0.10); }
.fu-note.run { border-color: rgba(251,191,36,0.4); background: rgba(251,191,36,0.07); }
.fu-note ul { margin: 6px 0 0; padding-left: 18px; }
.fu-note a { color: #93c5fd; }
.fu-p { margin: 0; font-size: 13px; line-height: 1.6; color: #c3cad8; }
.fu-p.muted, .muted { color: var(--muted); }

.fu-wait { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.fu-spin { display: inline-block; width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(147,197,253,0.3); border-top-color: #93c5fd; animation: fu-spin .8s linear infinite; vertical-align: -2px; margin-right: 8px; }
@keyframes fu-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .fu-spin { animation: none; } }
.fu-test-status { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.fu-test-status.ok { color: #34d399; }
.fu-test-status.bad { color: #f87171; }
.fu-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.fu-kpi { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.fu-kpi span { display: block; font-size: 11px; color: var(--muted); }
.fu-kpi strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.fu-sub { margin: 14px 0 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.fu-scroll { overflow-x: auto; }
.fu-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.fu-table th, .fu-table td { padding: 5px 8px; border-bottom: 1px solid var(--line-soft); text-align: left; white-space: nowrap; }
.fu-table th { color: var(--muted); font-weight: 650; font-size: 11.5px; }
.fu-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.fu-table td:nth-child(2) { white-space: normal; min-width: 120px; }
.fu-table.dist td:nth-child(2) { white-space: nowrap; min-width: 0; }
.fu-two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fu-two > div { min-width: 0; }
.fu-errlist { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.6; }
.fu-errlist code { color: #fca5a5; white-space: pre-wrap; overflow-wrap: anywhere; }

/* reference column */
.fu-ref { position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto; min-width: 0; }
.fu-ref details { border-top: 1px solid var(--line-soft); padding: 8px 0; }
.fu-ref details:first-of-type { border-top: 0; padding-top: 0; }
.fu-ref summary { cursor: pointer; font-size: 13px; font-weight: 650; color: #93c5fd; padding: 2px 0; }
.fu-ref details[open] summary { margin-bottom: 8px; }
.fu-vars { width: 100%; border-collapse: collapse; font-size: 12px; line-height: 1.5; }
.fu-vars td { vertical-align: top; padding: 6px 0; border-bottom: 1px solid var(--line-soft); color: #c3cad8; }
.fu-vars td:first-child { width: 42%; padding-right: 10px; }
.fu-vars code, .fu-list code, .fu-use code { color: #e6e9f0; font-size: 11.5px; overflow-wrap: anywhere; }
.fu-type { color: var(--muted); font-size: 11px; margin-top: 2px; }
.fu-list { margin: 0; padding-left: 16px; font-size: 12px; line-height: 1.55; color: #c3cad8; }
.fu-list li { margin-bottom: 5px; }
.fu-ref input[type="search"] { width: 100%; box-sizing: border-box; height: 32px; margin-bottom: 6px; font-size: 12.5px; }
.fu-uses { max-height: 260px; overflow-y: auto; }
.fu-use { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line-soft); font-size: 12px; color: #c3cad8; }
.fu-use .fu-hint { margin: 0; }
.fu-codeview { margin: 10px 0 4px; }
.fu-codeview summary { cursor: pointer; font-size: 12.5px; color: #93c5fd; }
.fu-codeview pre { margin: 8px 0 0; padding: 12px 14px; border-radius: 8px; background: var(--bg-soft); border: 1px solid var(--line); color: #e6e9f0; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-x: auto; white-space: pre; }

@media (max-width: 1100px) {
  .fu-grid { grid-template-columns: 1fr; }
  .fu-ref { position: static; max-height: none; }
}
@media (max-width: 700px) {
  .fu-bi-pair, .fu-two { grid-template-columns: 1fr; }
  .fu-gutter, .fu-editor textarea { height: 360px; }
  a.lib-upload-cta { margin-left: 0; width: 100%; justify-content: space-between; }
  .fu-step-head { align-items: flex-start; }
}
