/* KS4 Flowchart builder — Phase 3a styling
 * Layout: toolbar on top, then a 3-column body (palette / canvas / inspector).
 * All classes are namespaced under .fc-* to keep the page completely
 * self-contained when embedded in an <iframe>. */

:root {
  --fc-bg:           #f4f6fb;
  --fc-panel-bg:     #ffffff;
  --fc-panel-border: #c8d3e6;
  --fc-toolbar-bg:   #1f2330;
  --fc-toolbar-text: #e6e8ef;
  --fc-text:         #1f2330;
  --fc-muted:        #5a6478;
  --fc-accent:       #7c4dff;
  --fc-success:      #4caf50;
  --fc-danger:       #ef5350;
  --fc-insert:       #4dd0e1;

  /* Node colours */
  --fc-node-start:   #455a64;
  --fc-node-end:     #455a64;
  --fc-node-input:   #fff3c4;
  --fc-node-input-border:  #f9a825;
  --fc-node-assign:  #e8f5e9;
  --fc-node-assign-border: #4caf50;
  --fc-node-if:      #f3e5f5;
  --fc-node-if-border:     #9c27b0;
  --fc-node-loop:    #ffe0b2;
  --fc-node-loop-border:   #ef6c00;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--fc-text);
  background: var(--fc-bg);
}

.fc-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Toolbar ---------- */
.fc-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  background: var(--fc-toolbar-bg);
  color: var(--fc-toolbar-text);
  border-bottom: 1px solid #000;
  flex-shrink: 0;
}

.fc-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  margin-right: auto;
}

.fc-status {
  font-size: 0.78rem;
  color: #b2bcd4;
  margin-right: 0.6rem;
}

.fc-btn {
  appearance: none;
  border: 0;
  background: var(--fc-accent);
  color: white;
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.42rem 0.85rem;
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.fc-btn:hover { filter: brightness(1.1); }
.fc-btn--reset { background: var(--fc-danger); }
.fc-btn--link  { background: transparent; border: 1px solid #4a5266; color: #d7e3f5; }
.fc-btn--link:hover { background: #2a2f3e; filter: none; }

/* ---------- Body layout ---------- */
.fc-body {
  display: grid;
  grid-template-columns: 200px 1fr 280px;
  flex: 1;
  min-height: 0;
}
@media (max-width: 900px) {
  .fc-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
}

.fc-section-title {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fc-muted);
}

/* ---------- Palette ---------- */
.fc-palette {
  background: var(--fc-panel-bg);
  border-right: 1px solid var(--fc-panel-border);
  padding: 0.9rem 0.8rem;
  overflow-y: auto;
}

.fc-palette-btn {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.5rem 0.7rem;
  margin-bottom: 0.4rem;
  border: 1px solid var(--fc-panel-border);
  border-radius: 6px;
  background: white;
  color: var(--fc-text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.fc-palette-btn:hover {
  border-color: var(--fc-accent);
  background: #f6f0ff;
}
.fc-palette-btn:active { transform: translateY(1px); }
.fc-palette-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  font-size: 0.95rem;
  font-weight: 700;
}
.fc-palette-btn--input  .fc-palette-icon { background: var(--fc-node-input);  border: 1px solid var(--fc-node-input-border); }
.fc-palette-btn--output .fc-palette-icon { background: var(--fc-node-input);  border: 1px solid var(--fc-node-input-border); }
.fc-palette-btn--assign .fc-palette-icon { background: var(--fc-node-assign); border: 1px solid var(--fc-node-assign-border); }
.fc-palette-btn--if     .fc-palette-icon { background: var(--fc-node-if);     border: 1px solid var(--fc-node-if-border); }
.fc-palette-btn--while  .fc-palette-icon { background: var(--fc-node-loop);   border: 1px solid var(--fc-node-loop-border); }
.fc-palette-btn--for    .fc-palette-icon { background: var(--fc-node-loop);   border: 1px solid var(--fc-node-loop-border); }

.fc-hint {
  margin: 0.8rem 0 0;
  padding: 0.6rem;
  background: #f0f4fb;
  border-radius: 5px;
  font-size: 0.78rem;
  color: var(--fc-muted);
  line-height: 1.45;
}
.fc-insertion-demo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--fc-insert);
  color: white;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.85rem;
  vertical-align: middle;
}

/* ---------- Canvas ---------- */
.fc-canvas-wrap {
  background:
    radial-gradient(circle, #d4dae6 1px, transparent 1px) 0 0/22px 22px,
    var(--fc-bg);
  overflow: auto;
  position: relative;
}

.fc-canvas {
  /* Drawn at its natural size (1 SVG unit = 1px). Stretching it to fill
     the canvas area scaled the viewBox up and made every shape oversized. */
  display: block;
  margin: 0 auto;
}

/* Node groups inside SVG */
.fc-node {
  cursor: pointer;
}
.fc-node text {
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  fill: var(--fc-text);
  user-select: none;
}
.fc-node--selected .fc-shape {
  stroke-width: 3 !important;
  filter: drop-shadow(0 0 4px rgba(124, 77, 255, 0.45));
}

.fc-shape-start, .fc-shape-end {
  fill: var(--fc-node-start);
  stroke: #263238;
  stroke-width: 1.5;
}
.fc-node--terminator text { fill: white; font-weight: 600; }

.fc-shape-input, .fc-shape-output {
  fill: var(--fc-node-input);
  stroke: var(--fc-node-input-border);
  stroke-width: 1.5;
}
.fc-shape-assign {
  fill: var(--fc-node-assign);
  stroke: var(--fc-node-assign-border);
  stroke-width: 1.5;
}
.fc-shape-if {
  fill: var(--fc-node-if);
  stroke: var(--fc-node-if-border);
  stroke-width: 1.5;
}
.fc-shape-loop {
  fill: var(--fc-node-loop);
  stroke: var(--fc-node-loop-border);
  stroke-width: 1.5;
}

.fc-connector {
  stroke: #5a6478;
  stroke-width: 1.5;
  fill: none;
}
.fc-connector-label {
  font-size: 11px;
  font-weight: 700;
  fill: #5a6478;
  text-anchor: middle;
}

/* Insertion points */
.fc-insertion {
  cursor: pointer;
}
.fc-insertion-pad {
  fill: transparent;
}
.fc-insertion-bullet {
  fill: var(--fc-insert);
  opacity: 0;
  transition: opacity 0.15s;
}
.fc-insertion-bullet-text {
  fill: white;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  dominant-baseline: central;
}
.fc-insertion:hover .fc-insertion-bullet,
.fc-insertion:hover .fc-insertion-bullet-text,
.fc-insertion--active .fc-insertion-bullet,
.fc-insertion--active .fc-insertion-bullet-text { opacity: 1; }
.fc-insertion--active .fc-insertion-bullet { fill: var(--fc-accent); }

/* Empty-branch placeholder — also acts as an insertion point */
.fc-empty-branch {
  fill: rgba(124, 77, 255, 0.08);
  stroke: #b2bcd4;
  stroke-dasharray: 4 3;
  stroke-width: 1;
  transition: fill 0.15s, stroke 0.15s;
}
.fc-empty-insertion:hover .fc-empty-branch {
  fill: rgba(124, 77, 255, 0.18);
  stroke: var(--fc-accent);
}
.fc-empty-branch--active {
  fill: rgba(124, 77, 255, 0.28) !important;
  stroke: var(--fc-accent) !important;
  stroke-dasharray: none !important;
  stroke-width: 2 !important;
}
.fc-empty-branch-text {
  fill: var(--fc-muted);
  font-style: italic;
  font-size: 11px;
  text-anchor: middle;
  pointer-events: none;
}
.fc-empty-insertion { cursor: pointer; }

/* ---------- Inspector ---------- */
.fc-inspector {
  background: var(--fc-panel-bg);
  border-left: 1px solid var(--fc-panel-border);
  padding: 0.9rem 0.85rem;
  overflow-y: auto;
}

.fc-empty {
  color: var(--fc-muted);
  font-style: italic;
  font-size: 0.9rem;
  margin: 0;
}

.fc-inspector-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.fc-inspector-kind-chip {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #eef3fb;
  color: var(--fc-muted);
}

.fc-field {
  margin: 0.55rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.fc-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--fc-muted);
}
.fc-field input {
  appearance: none;
  border: 1px solid var(--fc-panel-border);
  border-radius: 5px;
  padding: 0.42rem 0.55rem;
  font: inherit;
  font-size: 0.88rem;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  background: #fbfcfe;
}
.fc-field input:focus {
  outline: none;
  border-color: var(--fc-accent);
  box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.15);
}
.fc-field-hint {
  font-size: 0.72rem;
  color: var(--fc-muted);
}

.fc-inspector-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.8rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--fc-panel-border);
}
.fc-inspector-actions button {
  appearance: none;
  border: 1px solid var(--fc-panel-border);
  background: white;
  color: var(--fc-text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.7rem;
  border-radius: 5px;
  cursor: pointer;
}
.fc-inspector-actions button:hover { background: #f6f0ff; }
.fc-inspector-actions .fc-delete {
  color: white;
  background: var(--fc-danger);
  border-color: var(--fc-danger);
}
.fc-inspector-actions .fc-delete:hover { filter: brightness(1.08); background: var(--fc-danger); }

/* ---------- Phase 3c: Code panel ---------- */
.fc-inspector { display: flex; flex-direction: column; gap: 0; }
.fc-inspector-pane { flex: 1; overflow-y: auto; }
.fc-inspector-pane + .fc-code-pane { border-top: 1px solid var(--fc-panel-border); }

.fc-code-pane {
  display: flex;
  flex-direction: column;
  background: #1f2330;
  color: #d7e3f5;
  padding: 0.7rem 0.85rem 0.55rem;
  max-height: 55%;
  flex-shrink: 0;
}
.fc-code-pane[hidden] { display: none; }

.fc-code-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}
.fc-code-pane .fc-section-title {
  color: #4dd0e1;
  margin: 0;
}
.fc-code-hint {
  font-size: 0.72rem;
  font-style: italic;
  color: #6c7689;
}

.fc-code {
  flex: 1;
  margin: 0 0 0.5rem;
  padding: 0.6rem 0.7rem;
  background: #11141c;
  color: #d7e3f5;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  border-radius: 5px;
  border: 1px solid #2a2f3e;
  overflow: auto;
  white-space: pre;
  min-height: 80px;
  max-height: 260px;
}

.fc-code-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.fc-code-actions .fc-btn {
  font-size: 0.82rem;
  padding: 0.4rem 0.7rem;
}
.fc-btn--disabled {
  opacity: 0.45;
  pointer-events: none;
  cursor: not-allowed;
}
.fc-btn--secondary {
  background: transparent;
  border: 1px solid #4a5266;
  color: #d7e3f5;
}
.fc-btn--secondary:hover { background: #2a2f3e; filter: none; }
.fc-btn--secondary[aria-pressed="true"] {
  background: var(--fc-accent);
  border-color: var(--fc-accent);
  color: white;
}

/* ---------- Phase 3b: Run drawer + executing-node spotlight ---------- */

/* While executing, dim everything except the active node so the
   orange spotlight reads at a glance from across the classroom. */
.fc-canvas--executing .fc-node:not(.fc-node--executing) .fc-shape,
.fc-canvas--executing .fc-node:not(.fc-node--executing) text {
  opacity: 0.32;
  transition: opacity 0.25s;
}
.fc-canvas--executing .fc-empty-branch,
.fc-canvas--executing .fc-empty-branch-text {
  opacity: 0.35;
}
.fc-canvas--executing .fc-connector,
.fc-canvas--executing .fc-connector-label {
  opacity: 0.45;
}
.fc-canvas--executing .fc-insertion { display: none; }

.fc-node--executing .fc-shape {
  stroke: #ff5722 !important;
  stroke-width: 4 !important;
  fill: #ffe0b2 !important;
  filter: drop-shadow(0 0 10px rgba(255, 87, 34, 0.85));
  animation: fc-exec-pulse 1.3s ease-in-out infinite;
  transition: none;
}
.fc-node--executing text {
  font-weight: 700;
}

@keyframes fc-exec-pulse {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(255, 87, 34, 0.55)); }
  50%      { filter: drop-shadow(0 0 16px rgba(255, 87, 34, 1)); }
}

.fc-run-drawer {
  display: flex;
  flex-direction: column;
  height: 260px;
  background: #1f2330;
  color: #e6e8ef;
  border-top: 1px solid #000;
  flex-shrink: 0;
}
.fc-run-drawer[hidden] { display: none; }

.fc-run-header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.85rem;
  background: #181c27;
  border-bottom: 1px solid #2a2f3e;
  font-size: 0.85rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.fc-run-title {
  color: #4dd0e1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
}
.fc-run-step-counter {
  font-size: 0.78rem;
  color: #9aa3b8;
  margin-right: auto;
}
.fc-run-step-btn {
  appearance: none;
  border: 1px solid #3a4154;
  background: #1f2330;
  color: #e6e8ef;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
  min-height: 30px;
}
.fc-run-step-btn:hover:not(:disabled) { background: #2a2f3e; }
.fc-run-step-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.fc-run-step-btn--primary {
  background: var(--fc-accent);
  border-color: var(--fc-accent);
  color: white;
}
.fc-run-step-btn--primary:hover:not(:disabled) { filter: brightness(1.1); background: var(--fc-accent); }

.fc-run-body {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  flex: 1;
  min-height: 0;
}
@media (max-width: 900px) {
  .fc-run-body { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}

.fc-run-output-pane, .fc-run-vars-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.fc-run-output-pane { border-right: 1px solid #2a2f3e; }
@media (max-width: 900px) {
  .fc-run-output-pane { border-right: 0; border-bottom: 1px solid #2a2f3e; }
}

.fc-run-pane-label {
  padding: 0.32rem 0.85rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #6c7689;
  border-bottom: 1px solid #2a2f3e;
}

.fc-run-console {
  flex: 1;
  margin: 0;
  padding: 0.65rem 0.85rem;
  background: #11141c;
  color: #d7e3f5;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.45;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.fc-run-console-error { color: var(--fc-danger); }

.fc-run-input-row {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.fc-run-input-prompt { color: #4dd0e1; }
.fc-run-input-field {
  background: transparent;
  border: 0;
  border-bottom: 1px dashed #4dd0e1;
  color: inherit;
  font: inherit;
  outline: none;
  padding: 1px 4px;
  min-width: 8ch;
}

.fc-run-vars {
  flex: 1;
  overflow: auto;
  padding: 0;
}
.fc-run-empty {
  margin: 0;
  padding: 0.7rem 0.85rem;
  color: #6c7689;
  font-style: italic;
  font-size: 0.82rem;
}

.fc-run-vars-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  color: #d7e3f5;
}
.fc-run-vars-table thead th {
  position: sticky;
  top: 0;
  background: #1f2330;
  text-align: left;
  font-weight: 700;
  color: #4dd0e1;
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid #2a2f3e;
}
.fc-run-vars-table tbody td {
  padding: 0.3rem 0.7rem;
  border-bottom: 1px solid #1c212e;
  white-space: nowrap;
}
.fc-run-var-changed {
  color: #ffd54f;
  background: rgba(255, 213, 79, 0.08);
}
