/* ============================================================
   Refinery — "Refraction" design system
   A precision optimization instrument. A prism splits raw
   materials into value: tiers run cool→warm (supplier indigo →
   maker teal → seller coral). Gold is reserved exclusively for
   PROFIT — the solve action, the achieved figure, the proof bar.
   ============================================================ */

:root {
  color-scheme: dark;

  /* base — blue-ink, never pure black */
  --ink-0:  #0B0E14;   /* app background */
  --ink-1:  #12161F;   /* stage */
  --ink-2:  #171C27;   /* panels */
  --ink-3:  #1E2532;   /* raised / inputs */
  --ink-4:  #283040;   /* hover */
  --hair:   #2A3242;   /* hairlines */
  --hair-2: #363F52;

  /* spectrum tiers (the refraction) */
  --supplier: #6E7BF2;   /* indigo */
  --maker:    #3FB8B0;   /* teal */
  --seller:   #E8935A;   /* coral */
  --supplier-soft: rgba(110,123,242,0.14);
  --maker-soft:    rgba(63,184,176,0.14);
  --seller-soft:   rgba(232,147,90,0.14);

  /* the one reserved accent: profit */
  --gold:      #F5C451;
  --gold-deep: #C99A2E;
  --gold-soft: rgba(245,196,81,0.13);

  /* semantic */
  --good: #4FD1A1;
  --bad:  #F16B6B;

  /* text */
  --text:   #EEF1F7;
  --text-2: #A7B0C0;
  --text-3: #6C7689;

  --shadow-1: 0 2px 8px rgba(0,0,0,0.28);
  --shadow-2: 0 10px 30px rgba(0,0,0,0.40);
  --shadow-3: 0 24px 60px rgba(0,0,0,0.52);

  /* spacing scale (8pt-ish) */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  --r1: 8px;  --r2: 12px; --r3: 18px; --r4: 26px;

  --fdisplay: "Space Grotesk", system-ui, sans-serif;
  --fui: "Hanken Grotesk", system-ui, sans-serif;
  --fmono: "JetBrains Mono", ui-monospace, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ink-0);
  color: var(--text);
  font: 400 14px/1.5 var(--fui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--fdisplay); font-weight: 600; margin: 0; letter-spacing: -0.01em; }
::selection { background: var(--gold-soft); }

*:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }

/* ============================================================
   App grid: command bar / (stage + panel) / status
   ============================================================ */
.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr;
}

/* ---------------- command bar ---------------- */
.cmdbar {
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s3) var(--s5);
  background: linear-gradient(180deg, var(--ink-2), rgba(18,22,31,0.7));
  border-bottom: 1px solid var(--hair);
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: var(--s3); }
.brand-glyph {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid rgba(245,196,81,0.25);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--fdisplay); font-weight: 700; font-size: 1.05rem; letter-spacing: -0.02em; }
.brand-sub { font-family: var(--fmono); font-size: 0.66rem; color: var(--text-3); letter-spacing: 0.04em; text-transform: uppercase; }

.cmdbar-actions { display: flex; align-items: center; gap: var(--s4); }
.file-menu { display: flex; gap: var(--s1); background: var(--ink-1); padding: var(--s1); border-radius: var(--r2); border: 1px solid var(--hair); }

.chip {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  border-radius: var(--r1);
  padding: 7px 13px;
  cursor: pointer;
  font-weight: 500;
  transition: background 140ms var(--ease), color 140ms var(--ease);
}
.chip:hover { background: var(--ink-3); color: var(--text); }
.chip.solid { background: var(--ink-3); border-color: var(--hair-2); color: var(--text); }
.chip.solid:hover { background: var(--ink-4); }

.solve {
  display: inline-flex; align-items: center; gap: var(--s2);
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  color: #241C05;
  border: none;
  border-radius: var(--r2);
  padding: 9px 20px 9px 16px;
  font-family: var(--fdisplay);
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255,255,255,0.25) inset, var(--shadow-1);
  transition: transform 120ms var(--ease), filter 120ms var(--ease);
}
.solve:hover { filter: brightness(1.06); }
.solve:active { transform: translateY(1px); }
.solve:disabled { filter: grayscale(0.5) brightness(0.7); cursor: not-allowed; box-shadow: none; }
.solve-key { width: 8px; height: 8px; border-radius: 50%; background: #241C05; opacity: 0.55; }
.solve.working .solve-key { animation: pulse 900ms var(--ease) infinite; }
@keyframes pulse { 0%,100% { opacity: 0.25; } 50% { opacity: 0.9; } }

/* ---------------- stage + panel share row 2 ---------------- */
.stage {
  grid-row: 2;
  position: relative;
  min-height: 0;
  background:
    radial-gradient(1200px 700px at 30% -10%, rgba(110,123,242,0.06), transparent 60%),
    radial-gradient(900px 600px at 100% 120%, rgba(232,147,90,0.05), transparent 55%),
    var(--ink-1);
  /* leave room for the panel on the right */
  margin-right: 340px;
  overflow: hidden;
}
.cy { position: absolute; inset: 0; }

/* dotted engineering grid on the stage */
.stage::before {
  content: "";
  position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,0.045) 1px, transparent 1px);
  background-size: 26px 26px;
  pointer-events: none;
}

/* ---------------- floating palette ---------------- */
.palette {
  position: absolute;
  top: var(--s4); left: var(--s4);
  display: flex; align-items: center; gap: var(--s1);
  padding: var(--s2);
  background: rgba(23,28,39,0.82);
  backdrop-filter: blur(14px);
  border: 1px solid var(--hair);
  border-radius: var(--r2);
  box-shadow: var(--shadow-2);
  z-index: 20;
}
.palette-label { font-family: var(--fmono); font-size: 0.66rem; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em; padding: 0 var(--s2) 0 var(--s1); }
.palette-div { width: 1px; height: 22px; background: var(--hair); margin: 0 var(--s1); }
.tool {
  display: inline-flex; align-items: center; gap: var(--s2);
  background: transparent; border: 1px solid transparent;
  color: var(--text-2); border-radius: var(--r1);
  padding: 6px 11px; cursor: pointer; font-weight: 500;
  transition: background 120ms var(--ease), color 120ms var(--ease), border-color 120ms var(--ease);
}
.tool:hover { background: var(--ink-3); color: var(--text); }
.tool-dot { width: 9px; height: 9px; border-radius: 3px; }
.tool.supplier .tool-dot { background: var(--supplier); }
.tool.maker .tool-dot { background: var(--maker); }
.tool.seller .tool-dot { background: var(--seller); }
.tool.supplier:hover { border-color: var(--supplier); }
.tool.maker:hover { border-color: var(--maker); }
.tool.seller:hover { border-color: var(--seller); }
.tool.ghost { color: var(--text-3); font-family: var(--fmono); font-size: 0.78rem; }

.cy-hint {
  position: absolute; bottom: var(--s4); left: 50%; transform: translateX(-50%);
  font-family: var(--fmono); font-size: 0.72rem; color: var(--text-3);
  background: rgba(11,14,20,0.7); padding: var(--s1) var(--s3); border-radius: 999px;
  border: 1px solid var(--hair); pointer-events: none; z-index: 15;
}

/* empty state */
.empty { position: absolute; inset: 0; display: grid; place-items: center; z-index: 18; }
.empty-card {
  text-align: center; max-width: 380px; padding: var(--s6);
  background: rgba(23,28,39,0.6); backdrop-filter: blur(8px);
  border: 1px solid var(--hair); border-radius: var(--r4);
}
.empty-glyph { font-size: 2.4rem; color: var(--maker); margin-bottom: var(--s3); }
.empty-card h2 { font-size: 1.3rem; margin-bottom: var(--s2); }
.empty-card p { color: var(--text-2); margin: 0 0 var(--s5); }

/* ---------------- context panel ---------------- */
.panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 340px;
  background: var(--ink-2);
  border-left: 1px solid var(--hair);
  overflow-y: auto;
  z-index: 30;
  display: flex; flex-direction: column;
}
/* panel sits over stage's reserved margin via absolute; place it in row 2 */
.stage, .panel { grid-row: 2; }

.ctx { padding: var(--s5); }
.ctx-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s4); }
.ctx-head h2 { font-size: 1rem; }
.ctx-kind {
  font-family: var(--fmono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--hair-2); color: var(--text-2);
}
.ctx-kind.supplier { color: var(--supplier); border-color: rgba(110,123,242,0.4); background: var(--supplier-soft); }
.ctx-kind.maker { color: var(--maker); border-color: rgba(63,184,176,0.4); background: var(--maker-soft); }
.ctx-kind.seller { color: var(--seller); border-color: rgba(232,147,90,0.4); background: var(--seller-soft); }
.ctx-note { color: var(--text-3); font-size: 0.85rem; }

.run-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); margin-bottom: var(--s5); }
.tally-row { display: flex; gap: var(--s2); margin-bottom: var(--s4); }
.tally {
  flex: 1; text-align: center; padding: var(--s3) var(--s2);
  background: var(--ink-1); border: 1px solid var(--hair); border-radius: var(--r2);
}
.tally-n { font-family: var(--fdisplay); font-weight: 700; font-size: 1.3rem; display: block; }
.tally-l { font-family: var(--fmono); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.tally.supplier .tally-n { color: var(--supplier); }
.tally.maker .tally-n { color: var(--maker); }
.tally.seller .tally-n { color: var(--seller); }

/* fields */
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-family: var(--fmono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
input, select, textarea {
  width: 100%; background: var(--ink-1); border: 1px solid var(--hair);
  border-radius: var(--r1); padding: 9px 11px; font-family: var(--fmono); font-size: 0.86rem;
  transition: border-color 120ms var(--ease);
}
input:hover, select:hover, textarea:hover { border-color: var(--hair-2); }
input:focus, select:focus, textarea:focus { border-color: var(--gold); outline: none; }
textarea { resize: vertical; min-height: 60px; font-family: var(--fui); }
input[readonly] { color: var(--text-2); }

.insp-body { display: flex; flex-direction: column; gap: var(--s4); }
.insp-title-row { display: flex; flex-direction: column; gap: 5px; }
.insp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.subcard {
  background: var(--ink-1); border: 1px solid var(--hair);
  border-radius: var(--r2); padding: var(--s3); display: flex; flex-direction: column; gap: var(--s3);
}
.subcard-head { display: flex; align-items: center; justify-content: space-between; }
.subcard-head h3 { font-family: var(--fmono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-2); font-weight: 600; }
.recipe-row { display: grid; grid-template-columns: 1fr 62px auto; gap: var(--s2); align-items: end; }
.mini-btn { background: var(--ink-3); border: 1px solid var(--hair); color: var(--text-2); border-radius: var(--r1); padding: 6px 10px; cursor: pointer; font-size: 0.8rem; transition: background 120ms var(--ease); }
.mini-btn:hover { background: var(--ink-4); color: var(--text); }
.icon-btn { background: transparent; border: 1px solid var(--hair); color: var(--text-2); border-radius: var(--r1); padding: 6px 12px; cursor: pointer; font-weight: 500; transition: background 120ms var(--ease); }
.icon-btn:hover { background: var(--ink-3); color: var(--text); }
.icon-btn.danger:hover { background: rgba(241,107,107,0.14); color: var(--bad); border-color: rgba(241,107,107,0.4); }
.toggle { display: flex; align-items: center; gap: var(--s2); color: var(--text-2); font-size: 0.86rem; cursor: pointer; }
.toggle input { width: auto; }
.hint { color: var(--text-3); font-size: 0.78rem; }

/* ============================================================
   RESULT DOCK — the signature: achieved vs proven ceiling
   ============================================================ */
.result {
  position: absolute;
  left: 50%; bottom: var(--s5);
  transform: translateX(-50%);
  /* center within the stage area (which is offset by the 340px panel) */
  margin-right: 340px;
  width: min(760px, calc(100vw - 340px - 48px));
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: var(--s5);
  padding: var(--s5);
  background: rgba(18,22,31,0.86);
  backdrop-filter: blur(20px);
  border: 1px solid var(--hair-2);
  border-radius: var(--r4);
  box-shadow: var(--shadow-3);
  z-index: 45;
  animation: dock-in 420ms var(--ease);
}
@keyframes dock-in { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }
.result-close { position: absolute; top: var(--s3); right: var(--s3); background: transparent; border: none; color: var(--text-3); cursor: pointer; font-size: 0.9rem; padding: 4px; }
.result-close:hover { color: var(--text); }

.result-headline { display: flex; align-items: baseline; gap: var(--s4); margin-bottom: var(--s4); }
.result-status {
  font-family: var(--fmono); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em;
  padding: 4px 10px; border-radius: 999px; color: var(--good);
  border: 1px solid rgba(79,209,161,0.4); background: rgba(79,209,161,0.1);
}
.result-status.feasible { color: var(--gold); border-color: rgba(245,196,81,0.4); background: var(--gold-soft); }
.result-figure { display: flex; flex-direction: column; }
.result-achieved { font-family: var(--fdisplay); font-weight: 700; font-size: 2.6rem; line-height: 1; color: var(--gold); letter-spacing: -0.02em; }
.result-achieved-label { font-family: var(--fmono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); margin-top: 5px; }

/* the proof bar */
.proofbar-track {
  position: relative; height: 22px; border-radius: 11px;
  background: var(--ink-0); border: 1px solid var(--hair);
  overflow: hidden;
}
.proofbar-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
  border-radius: 11px 0 0 11px;
  transition: width 900ms var(--ease);
}
.proofbar-gap {
  position: absolute; top: 0; bottom: 0; width: 0%;
  background-image: repeating-linear-gradient(45deg, transparent, transparent 5px, rgba(241,107,107,0.28) 5px, rgba(241,107,107,0.28) 10px);
  transition: left 900ms var(--ease), width 900ms var(--ease);
}
.proofbar-ceiling { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--good); transition: left 900ms var(--ease); }
.proofbar-tick { position: absolute; top: -4px; left: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.proofbar-scale { display: flex; justify-content: space-between; margin-top: var(--s2); font-family: var(--fmono); font-size: 0.66rem; color: var(--text-3); }

.result-side { display: flex; flex-direction: column; gap: var(--s3); border-left: 1px solid var(--hair); padding-left: var(--s5); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-family: var(--fmono); font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.stat-val { font-family: var(--fmono); font-size: 1.05rem; font-weight: 500; }
.stat-val.ceiling { color: var(--good); }
.result-caption { font-size: 0.8rem; color: var(--text-2); line-height: 1.5; margin: 2px 0 0; }
.result-caption strong { color: var(--text); font-weight: 600; }

/* plan detail drawer */
.detail {
  position: absolute; right: 356px; bottom: var(--s5);
  width: 420px; max-height: 60vh; display: flex; flex-direction: column;
  background: rgba(18,22,31,0.95); backdrop-filter: blur(20px);
  border: 1px solid var(--hair-2); border-radius: var(--r3);
  box-shadow: var(--shadow-3); z-index: 46;
}
.detail-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s4) var(--s4) var(--s3); border-bottom: 1px solid var(--hair); }
.detail-head h2 { font-size: 0.95rem; }
.detail-body { margin: 0; padding: var(--s4); overflow: auto; font-family: var(--fmono); font-size: 11.5px; line-height: 1.55; color: var(--text-2); white-space: pre; }

/* ---------------- status line ---------------- */
.statusline {
  grid-row: 3;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s2) var(--s5);
  background: var(--ink-2); border-top: 1px solid var(--hair);
  z-index: 40;
}
.status-msg { font-family: var(--fmono); font-size: 0.75rem; color: var(--text-2); }
.status-msg.error { color: var(--bad); }
.issues { background: transparent; border: 1px solid var(--hair); border-radius: 999px; padding: 3px 12px; cursor: pointer; font-family: var(--fmono); font-size: 0.72rem; }
.issues.ok { color: var(--good); border-color: rgba(79,209,161,0.3); }
.issues.bad { color: var(--bad); border-color: rgba(241,107,107,0.4); }
.issues-list {
  position: absolute; right: var(--s5); bottom: 44px; width: min(420px, 90vw);
  max-height: 40vh; overflow-y: auto; padding: var(--s3);
  background: var(--ink-2); border: 1px solid rgba(241,107,107,0.4); border-radius: var(--r2);
  box-shadow: var(--shadow-3); z-index: 50;
}
.issue { font-family: var(--fmono); font-size: 0.76rem; color: #f3b0a0; padding: 6px 4px; border-bottom: 1px solid var(--hair); }
.issue:last-child { border-bottom: none; }

/* ---------------- Cytoscape HTML node cards ---------------- */
.ncard { pointer-events: none; width: 176px; }
.ncard-inner {
  width: 176px; box-sizing: border-box;
  font-family: var(--fui); text-align: left;
  display: flex; flex-direction: column;
  border-radius: 14px; overflow: hidden;
}
.ncard-head { display: flex; align-items: center; gap: 7px; padding: 9px 12px 0; }
.ncard-dot { width: 8px; height: 8px; border-radius: 3px; flex: 0 0 auto; }
.ncard-inner.supplier .ncard-dot { background: var(--supplier); }
.ncard-inner.maker .ncard-dot { background: var(--maker); }
.ncard-inner.seller .ncard-dot { background: var(--seller); }
.ncard-title {
  font-family: var(--fdisplay); font-weight: 600; font-size: 0.9rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em;
}
.ncard-stats { display: flex; flex-direction: column; gap: 2px; padding: 4px 12px 10px; }
.ncard-stat { font-family: var(--fmono); font-size: 0.66rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ncard-stat.strong { color: var(--text-2); }

/* optimal-plan footer — its own tinted band so the number never crowds the recipe */
.ncard-plan {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 7px 12px;
  background: linear-gradient(180deg, rgba(245,196,81,0.10), rgba(245,196,81,0.05));
  border-top: 1px solid rgba(245,196,81,0.22);
}
.ncard-plan-val {
  font-family: var(--fmono); font-size: 0.9rem; font-weight: 600; color: var(--gold);
  line-height: 1; letter-spacing: -0.01em;
}
.ncard-plan.unused {
  background: rgba(255,255,255,0.02); border-top-color: var(--hair);
}
.ncard-plan.unused .ncard-plan-val { color: var(--text-3); font-weight: 400; font-size: 0.74rem; font-style: italic; }
.ncard-chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.ncard-chip {
  font-family: var(--fmono); font-size: 0.56rem; letter-spacing: 0.03em; text-transform: lowercase;
  padding: 2px 7px; border-radius: 999px; white-space: nowrap; line-height: 1.2;
}
.ncard-chip.mode { background: rgba(255,255,255,0.1); color: var(--text-2); }
.ncard-chip.mod { background: rgba(245,196,81,0.18); color: var(--gold); }
/* idle (unused) cards recede */
.ncard-inner.is-unused { opacity: 0.45; }

.hidden { display: none !important; }

/* ---------------- responsive ---------------- */
@media (max-width: 920px) {
  .stage { margin-right: 0; }
  .panel { width: 300px; transform: translateX(100%); transition: transform 220ms var(--ease); }
  .panel.open { transform: translateX(0); }
  .result { margin-right: 0; grid-template-columns: 1fr; width: min(560px, calc(100vw - 32px)); }
  .result-side { border-left: none; border-top: 1px solid var(--hair); padding-left: 0; padding-top: var(--s4); }
  .detail { right: var(--s4); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
