/* Flowchart editor (draw.html). Builds on style.css: same tokens, app bar, sidebar and buttons. */

.chart-name {
  min-width: 0; flex: 0 1 360px; font: inherit; font-size: 18px; font-weight: 700; letter-spacing: -0.2px; color: var(--ink);
  border: 1.5px solid transparent; border-radius: 7px; background: transparent; padding: 5px 8px; text-overflow: ellipsis;
}
.chart-name:hover { border-color: var(--rule); }
.chart-name:focus { outline: none; border-color: var(--ink); background: var(--card); }
.seg.hist button { display: grid; place-items: center; padding: 6px 9px; }
.seg.hist button:disabled { color: var(--rule); cursor: default; background: transparent; }

/* ---- sidebar: your charts ---- */
.charts-head { display: flex; align-items: center; justify-content: space-between; padding-right: 12px; border-bottom: 1px solid var(--rule); }
.chart-list { flex: 1; overflow-y: auto; padding: 6px 0; scrollbar-width: thin; }
.chart-item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px; padding: 8px 10px 8px 16px;
  border-left: 3px solid transparent; cursor: pointer;
}
.chart-item:hover { background: var(--chip); }
.chart-item.active { background: var(--bg); border-left-color: var(--orange); }
.chart-item .nm { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-item .when { grid-column: 1; font-size: 12px; color: var(--muted); }
.chart-item .acts { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.chart-item:hover .acts, .chart-item.active .acts, .chart-item:focus-within .acts { opacity: 1; }
.chart-item .acts button {
  font: inherit; font-size: 12px; border: 1px solid transparent; background: none; color: var(--muted); border-radius: 5px;
  padding: 3px 6px; cursor: pointer;
}
.chart-item .acts button:hover { border-color: var(--rule); color: var(--ink); background: var(--card); }
.chart-item .acts button.sure { border-color: var(--red); color: var(--red); background: var(--card); }

/* ---- the canvas ---- */
.body > .main { position: relative; }
.stage {
  position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none;
  background-color: var(--bg);
  background-image: radial-gradient(circle, #C9CBC1 1.1px, transparent 1.3px);
}
.canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; user-select: none; -webkit-user-select: none; }
.canvas.panning, .canvas.space { cursor: grab; }
.canvas.panning:active { cursor: grabbing; }
.canvas [data-node] { cursor: move; }
.canvas [data-edge] { cursor: pointer; }
.canvas [data-port] { cursor: crosshair; }
.canvas.connecting, .canvas.connecting * { cursor: crosshair !important; }
body.present .canvas [data-node], body.present .canvas [data-edge] { cursor: pointer; }

/* diagram UI (not exported) */
.fc-port { fill: var(--card); stroke: var(--blue); stroke-width: 1.6; }
.fc-port-hit { fill: transparent; }
[data-port]:hover .fc-port { fill: var(--blue); }
.fc-sel { fill: none; stroke: var(--blue); stroke-width: 1.4; stroke-dasharray: 5 4; pointer-events: none; }
.fc-target .fc-shape { stroke: var(--blue); stroke-width: 2.6; }
.fc-temp { fill: none; stroke: var(--blue); stroke-width: 1.8; stroke-dasharray: 6 4; pointer-events: none; }
.fc-marquee { fill: rgba(29, 74, 255, .06); stroke: var(--blue); stroke-width: 1; stroke-dasharray: 4 3; pointer-events: none; }
.fc-hit { fill: none; stroke: transparent; stroke-width: 14; }
.fc-edge-g.sel .fc-edge { stroke: var(--blue); stroke-width: 2.2; }
.fc-ghost { opacity: .55; pointer-events: none; }
.fc-node, .fc-edge-g { transition: opacity .2s; }

/* present: spotlight the current step and where it can go next */
.spot .fc-node:not(.lit):not(.next), .spot .fc-edge-g:not(.lit), .spot .fc-label:not(.lit) { opacity: .22; }
.fc-label { transition: opacity .2s; }
.spot .fc-node.next { opacity: .7; }
.fc-node.lit .fc-shape { stroke: var(--orange); stroke-width: 3.2; }
.fc-node.lit .fc-junction { fill: var(--orange); }
.fc-edge-g.lit .fc-edge { stroke: var(--orange); stroke-width: 2.6; }
.fc-edge-g.lit .fc-label { fill: var(--orange); }

/* in-place text editing */
.text-edit {
  position: absolute; z-index: 5; margin: 0; padding: 0; border: 0; outline: none; resize: none; overflow: hidden;
  background: transparent; color: var(--ink); text-align: center; line-height: 1.286; white-space: pre-wrap;
  font-family: "Avenir Next", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.text-edit.mono { font-family: Menlo, "JetBrains Mono", monospace; }
.text-edit.label { background: var(--card); border: 1.5px solid var(--blue); border-radius: 4px; font-weight: 600; }

/* ---- floating tools ---- */
.palette {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%); z-index: 4; display: flex; flex-direction: column; gap: 4px;
  padding: 6px; background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow);
}
.palette button {
  position: relative; display: grid; place-items: center; width: 52px; height: 44px; border: 1px solid transparent; border-radius: 7px;
  background: none; cursor: grab; color: var(--ink); touch-action: none;
}
.palette button:hover { background: var(--chip); border-color: var(--rule); }
.palette button:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.palette button .k { position: absolute; right: 3px; bottom: 1px; font: 10px Menlo, monospace; color: var(--muted); }
.palette svg { overflow: visible; }

.props {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4; display: flex; align-items: center; gap: 6px;
  width: max-content;
  padding: 5px 6px; background: var(--card); border: 1.5px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow);
  max-width: calc(100% - 24px); flex-wrap: wrap; justify-content: center; animation: drop .16s ease-out;
}
@keyframes drop { from { opacity: 0; transform: translate(-50%, -6px); } }
.props .grp { display: flex; align-items: center; gap: 2px; }
.props .grp + .grp { border-left: 1px solid var(--rule); padding-left: 6px; }
.props button {
  font: inherit; font-size: 13px; display: grid; place-items: center; min-width: 32px; height: 30px; padding: 0 7px;
  border: 1px solid transparent; border-radius: 6px; background: none; color: var(--ink); cursor: pointer;
}
.props button:hover { background: var(--chip); border-color: var(--rule); }
.props button[aria-pressed="true"] { background: var(--ink); color: var(--card); }
.props button.danger:hover { color: var(--red); border-color: var(--red); background: var(--card); }
.props .sw { width: 22px; min-width: 22px; height: 22px; padding: 0; border: 1.5px solid var(--ink); border-radius: 50%; }
.props .sw[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--card), 0 0 0 3.5px var(--blue); background-clip: padding-box; }
.props .sw.none { background: linear-gradient(135deg, var(--card) 45%, var(--red) 45%, var(--red) 55%, var(--card) 55%); }

.zoom-ctl {
  position: absolute; right: 14px; bottom: 14px; z-index: 4; display: flex; border: 1.5px solid var(--ink); border-radius: 8px;
  background: var(--card); overflow: hidden; box-shadow: var(--shadow);
}
.zoom-ctl button {
  font: inherit; font-size: 13px; min-width: 34px; height: 32px; padding: 0 8px; border: 0; border-right: 1px solid var(--rule);
  background: none; color: var(--ink); cursor: pointer; font-variant-numeric: tabular-nums;
}
.zoom-ctl button:last-child { border-right: 0; }
.zoom-ctl button:hover { background: var(--chip); }
#zoomPct { min-width: 56px; }
.hint { position: absolute; left: 82px; bottom: 14px; z-index: 3; margin: 0; font-size: 12.5px; color: var(--muted); pointer-events: none; }
.hint b { color: var(--blue); font-weight: 600; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 200px; padding: 5px; display: flex; flex-direction: column;
  background: var(--card); border: 1.5px solid var(--ink); border-radius: 9px; box-shadow: var(--shadow);
}
.menu button { font: inherit; font-size: 14px; text-align: left; padding: 7px 10px; border: 0; border-radius: 6px; background: none; color: var(--ink); cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--chip); outline: none; }
.menu hr { border: 0; border-top: 1px solid var(--rule); margin: 4px 2px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 9px 14px; font-size: 14px; color: var(--card); background: var(--ink); border-radius: 8px; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- Python -> flowchart panel ---- */
.code-panel {
  flex: 0 0 400px; display: flex; flex-direction: column; min-height: 0; background: var(--card); border-left: 1.5px solid var(--ink);
  animation: slide-in .22s cubic-bezier(.2, .7, .3, 1);
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.code-panel .panel-head { padding-right: 8px; align-items: center; }
.code-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px 14px 14px; overflow-y: auto; }
.ex-pick { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.ex-pick select { flex: 1; font: inherit; font-size: 14px; padding: 5px 6px; border: 1.5px solid var(--rule); border-radius: 6px; background: var(--card); color: var(--ink); }
.code {
  flex: 1 1 260px; min-height: 200px; resize: none; font: 13px/1.5 Menlo, "JetBrains Mono", monospace; tab-size: 4; color: var(--ink);
  padding: 10px 12px; border: 1.5px solid var(--ink); border-radius: 8px; background: #FFFFFB; white-space: pre; overflow: auto;
}
.code:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; }
.code-body .btn.primary { justify-content: center; }
.code-msg { margin: 0; font-size: 13px; min-height: 1em; }
.code-msg.err { color: var(--red); }
.code-msg.ok { color: var(--green); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; line-height: 1.45; margin: 0; }
.small code { font-size: 11.5px; background: var(--chip); padding: 0 3px; border-radius: 3px; }

/* ---- dry run ---- */
.ptabs button { padding: 5px 10px; font-size: 13px; }
.ptabs button[aria-selected="true"] { background: var(--ink); color: var(--card); font-weight: 600; }
.code-panel .panel-head { gap: 8px; padding: 6px 8px 6px 10px; }
.gen-row { display: flex; gap: 8px; }
.gen-row #generate { flex: 1; }
.trace-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px 14px 12px; overflow: hidden; }
.tr-note { margin: 0; padding: 8px 10px; font-size: 13px; line-height: 1.4; background: #FFF0C7; border: 1.5px solid var(--yellow); border-radius: 7px; }
.tr-in-label { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.tr-in-label span { font-weight: 400; }
.tr-in-label code { font-size: 11.5px; }
.tr-stdin {
  flex: none; resize: vertical; min-height: 34px; max-height: 120px; font: 13px/1.45 Menlo, "JetBrains Mono", monospace; padding: 6px 9px;
  border: 1.5px solid var(--rule); border-radius: 7px; background: #FFFFFB; color: var(--ink);
}
.tr-stdin:focus { outline: none; border-color: var(--ink); }
.tr-predict { flex: none; display: flex; align-items: center; gap: 8px; }
.tr-predict .check { font-size: 13px; cursor: pointer; }
.tr-predict input { accent-color: var(--orange); }
.tr-score { margin-left: auto; font-size: 12.5px; font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }
.tr-ask {
  flex: none; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; background: #FFF4EB;
  border: 2px solid var(--ink); border-radius: 9px; box-shadow: var(--shadow);
}
.tr-ask.nudge { animation: nudge .35s; }
@keyframes nudge { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.ask-head { display: flex; justify-content: space-between; font-size: 11.5px; font-weight: 700; color: var(--orange); text-transform: uppercase; letter-spacing: .5px; }
.ask-q { margin: 0; font-size: 13.5px; line-height: 1.4; }
.ask-q code { font: 600 12.5px Menlo, "JetBrains Mono", monospace; background: var(--card); border: 1px solid var(--rule); border-radius: 4px; padding: 0 4px; }
.ask-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; }
.ask-row > code { font: 600 13px Menlo, "JetBrains Mono", monospace; color: var(--blue); }
.ask-row input {
  flex: 1; min-width: 90px; font: 13px Menlo, "JetBrains Mono", monospace; padding: 5px 8px; color: var(--ink);
  border: 1.5px solid var(--rule); border-radius: 6px; background: #FFFFFB;
}
.ask-row input:focus { outline: none; border-color: var(--ink); }
.ask-choice button { padding: 5px 12px; font: 600 13px Menlo, "JetBrains Mono", monospace; }
.ask-choice button.on { background: var(--ink); color: var(--card); }
.ask-row.ok input { border-color: var(--green); background: #E6F4E9; }
.ask-row.bad input { border-color: var(--red); background: #FBE5E5; }
.ask-fb { font-size: 13px; font-weight: 700; }
.ask-row.ok .ask-fb { color: var(--green); }
.ask-row.bad .ask-fb { color: var(--red); font-family: Menlo, "JetBrains Mono", monospace; white-space: pre-wrap; }
.ask-row.shown .ask-fb { color: var(--blue); font-family: Menlo, "JetBrains Mono", monospace; white-space: pre-wrap; }
.ask-btns { display: flex; gap: 8px; align-items: center; }
.ask-warn { font-size: 12.5px; color: var(--red); }
.tr-ctl { display: flex; align-items: center; gap: 4px; flex: none; }
.tbtn {
  display: grid; place-items: center; width: 34px; height: 32px; border: 1.5px solid var(--rule); border-radius: 7px; background: var(--card);
  color: var(--ink); cursor: pointer;
}
.tbtn:hover:not(:disabled) { border-color: var(--ink); }
.tbtn:disabled { color: var(--rule); cursor: default; }
.tr-play { min-width: 92px; justify-content: center; margin: 0 2px; }
.tr-speed { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.tr-speed input { width: 76px; accent-color: var(--orange); }
.tr-status { flex: none; display: flex; flex-direction: column; gap: 2px; min-height: 38px; }
.tr-pos { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tr-msg { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.tr-msg.err { color: var(--red); }
.tr-msg.ok { color: var(--green); }
.tr-msg.turn { color: var(--orange); }
.tr-msg.q { color: var(--orange); font-family: Menlo, monospace; font-size: 13px; }
.tr-code {
  flex: 0 1 auto; max-height: 30%; min-height: 60px; overflow: auto; margin: 0; padding: 6px 0; list-style: none; counter-reset: ln;
  font: 12.5px/1.6 Menlo, "JetBrains Mono", monospace; background: #FFFFFB; border: 1.5px solid var(--ink); border-radius: 8px; white-space: pre;
}
.tr-code li { counter-increment: ln; padding-right: 10px; border-left: 3px solid transparent; transition: background .15s; }
.tr-code li::before { content: counter(ln); display: inline-block; width: 2.6em; padding-right: .9em; text-align: right; color: var(--rule); }
.tr-code li.cur { background: #FFE3D4; border-left-color: var(--orange); }
.tr-code li.cur::before { color: var(--orange); font-weight: 700; }
.tr-code li.err { background: #FADADA; border-left-color: var(--red); }
.tr-tabs { flex: none; align-self: flex-start; }
.tr-tabs button[aria-selected="true"] { background: var(--ink); color: var(--card); font-weight: 600; }
.tr-now { flex: 1 1 0; min-height: 80px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.tr-head { font-size: 11.5px; font-weight: 700; color: var(--orange); text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }
.tr-empty { margin: 0; font-size: 13px; color: var(--muted); }
.tr-vars { width: 100%; border-collapse: collapse; font: 13px Menlo, "JetBrains Mono", monospace; }
.tr-vars th, .tr-vars td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--chip); vertical-align: top; }
.tr-vars th { width: 1%; white-space: nowrap; font-weight: 600; color: var(--blue); }
.tr-vars td { word-break: break-all; }
.tr-vars tr.changed td, .tr-vars tr.new td { background: #FFE3D4; font-weight: 700; animation: flash .7s ease-out; }
.tr-vars tr.new th::after { content: " new"; font: 600 10px "Avenir Next", system-ui, sans-serif; color: var(--orange); }
@keyframes flash { from { background: #FFB98F; } }
.tr-out {
  flex: 1 0 60px; margin: 0; padding: 8px 10px; overflow: auto; font: 12.5px/1.5 Menlo, monospace; white-space: pre-wrap; word-break: break-word;
  background: var(--ink); color: #E9EAE3; border-radius: 8px;
}
.tr-out .muted { color: #8C8E85; }
.tr-out .err { color: #FF8A80; }
.tr-table-wrap { flex: 1 1 0; min-height: 80px; overflow: auto; border: 1.5px solid var(--ink); border-radius: 8px; background: var(--card); }
.tr-table { border-collapse: collapse; font: 12.5px Menlo, "JetBrains Mono", monospace; min-width: 100%; }
.tr-table th {
  position: sticky; top: 0; z-index: 1; background: var(--ink); color: var(--card); text-align: left; padding: 6px 8px; font-weight: 600; white-space: nowrap;
}
.tr-table th sub { font-size: 9.5px; opacity: .7; margin-left: 2px; }
.tr-table td { padding: 4px 8px; border-bottom: 1px solid var(--chip); border-right: 1px solid var(--chip); white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.tr-table td:first-child { color: var(--muted); text-align: right; }
.tr-table tbody tr { cursor: pointer; }
.tr-table tbody tr:hover { background: var(--bg); }
.tr-table tr.cur td { background: #FFE3D4; }
.tr-table b.yes { color: var(--green); }
.tr-table b.no { color: var(--red); }
.tr-table .tr-empty { padding: 14px; white-space: normal; text-align: left; }

/* dry run on the chart */
.fc-node.lit { filter: drop-shadow(0 0 7px rgba(245, 78, 0, .55)); }
.fc-node.wait .fc-shape { stroke: var(--orange); stroke-width: 2.2; stroke-dasharray: 6 4; }
.fc-node.err .fc-shape { stroke: var(--red); stroke-width: 3.2; }
.fc-node.err { filter: drop-shadow(0 0 7px rgba(212, 47, 47, .5)); }
.fc-edge-g.flow .fc-edge { stroke-dasharray: 8 5; animation: flow .7s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -13; } }
.fc-token { fill: var(--orange); stroke: var(--card); stroke-width: 2.5; pointer-events: none; filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .35)); }
.fc-badge rect { fill: var(--orange); stroke: var(--ink); stroke-width: 1.2; }
.fc-badge text { font: 700 11px "Avenir Next", system-ui, sans-serif; fill: white; }
.fc-badge { pointer-events: none; }
#dryRun.on { border-color: var(--ink); background: var(--chip); }

/* ---- present mode ---- */
.present-bar { display: none; }
body.present .appbar, body.present .sidebar, body.present .palette, body.present .props, body.present .hint,
body.present .code-panel, body.present .zoom-ctl { display: none !important; }
body.present .stage { background-image: none; background-color: var(--card); }
body.present .present-bar {
  display: flex; align-items: center; gap: 12px; position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 6;
  padding: 6px 6px 6px 14px; font-size: 13.5px; color: var(--muted); background: var(--card); border: 1.5px solid var(--rule);
  border-radius: 10px; white-space: nowrap; transition: opacity .3s;
}
body.present.idle .present-bar { opacity: 0; }

@media (max-width: 900px) {
  .chart-name { font-size: 15px; flex: 1 1 auto; }
  #toggleCode .lbl, #exportBtn .lbl, #present .lbl, #dryRun .lbl { display: none; }
  .seg.hist { display: none; }
  .hint { display: none; }
  .palette { left: 8px; padding: 4px; }
  .palette button { width: 44px; height: 40px; }
  .palette button .k { display: none; }
  .code-panel { position: fixed; inset: auto 0 0 0; height: 70vh; z-index: 65; border-left: 0; border-top: 1.5px solid var(--ink); box-shadow: 0 -6px 20px rgba(0, 0, 0, .12); }
  .chart-item .acts { opacity: 1; }
}
