:root {
    --flow-bg: #f4efe6;
    --flow-ink: #17201c;
    --flow-muted: #687970;
    --flow-green: #315f53;
    --flow-coral: #d9664f;
    --flow-teal: #6fb7aa;
    --flow-line: rgba(23, 32, 28, .12);
    --flow-panel: rgba(255, 255, 255, .76);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-width: 320px;
    overflow-x: hidden;
}

button, input, textarea, select { font: inherit; }

.flow-app {
    width: min(1540px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 32px;
}

.flow-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
}

.title-wrap { display: flex; align-items: center; gap: 14px; }
.title-wrap .tool-page-icon { width: 48px !important; height: 48px !important; font-size: 27px; }
.title-wrap h1 { margin: 1px 0 4px !important; font-size: clamp(1.65rem, 3vw, 2.35rem) !important; }
.eyebrow, .panel-kicker { margin: 0; color: var(--flow-coral); font-size: .66rem; font-weight: 900; letter-spacing: .16em; }
.subtitle { margin: 0; color: var(--flow-muted); font-size: .9rem; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.save-state { color: var(--flow-muted); font-size: .78rem; font-weight: 750; white-space: nowrap; }
.save-state i, .status-pill i { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--flow-teal); box-shadow: 0 0 0 4px rgba(111,183,170,.14); }

.workspace {
    min-height: 690px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.72);
    border-radius: 22px;
    background: rgba(255,255,255,.56);
    box-shadow: 0 24px 70px rgba(23,32,28,.16);
    backdrop-filter: blur(20px);
}

.topbar {
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--flow-line);
    background: rgba(255,255,255,.72) !important;
}

.mode-switch { display: flex; gap: 6px; padding: 4px; border-radius: 14px; background: rgba(23,32,28,.06); }
.mode-btn {
    min-width: 174px;
    min-height: 52px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    border: 0 !important;
    border-radius: 11px !important;
    background: transparent !important;
    color: var(--flow-muted) !important;
    text-align: left;
    box-shadow: none !important;
}
.mode-btn:hover { transform: none !important; }
.mode-btn.active { background: #fff !important; color: var(--flow-green) !important; box-shadow: 0 6px 18px rgba(23,32,28,.09) !important; }
.mode-icon { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 8px; background: rgba(49,95,83,.1); font-size: .78rem; font-weight: 900; }
.mode-btn b, .mode-btn small { display: block; }
.mode-btn b { font-size: .88rem; }
.mode-btn small { margin-top: 1px; font-size: .64rem; font-weight: 600; opacity: .7; }

.document-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.direction-field { display: flex; align-items: center; gap: 8px; margin-right: 4px; color: var(--flow-muted); font-size: .75rem; font-weight: 800; }
.direction-field select { min-height: 38px; padding: 0 30px 0 10px; }
.action-btn, .icon-btn { min-height: 40px; padding: 0 13px !important; }
.icon-btn { width: 40px; padding: 0 !important; font-size: 1.15rem; }
.optimize-btn { border-color: transparent !important; background: var(--flow-green) !important; color: #fff !important; box-shadow: 0 9px 22px rgba(49,95,83,.22); }
.optimize-btn:hover { background: #274e44 !important; }

.workspace-body { min-height: 610px; display: grid; grid-template-columns: 350px minmax(0, 1fr); }
.side-panel { min-width: 0; padding: 20px; border-right: 1px solid var(--flow-line); background: rgba(247,241,231,.38); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.panel-heading h2 { margin: 3px 0 0; font-size: 1rem; }
.text-btn { padding: 6px 9px !important; border: 0 !important; background: transparent !important; font-size: .72rem; }

#code-editor {
    width: 100%;
    height: 424px;
    resize: none;
    padding: 17px !important;
    border: 1px solid rgba(23,32,28,.1) !important;
    border-radius: 14px !important;
    background: #17201c !important;
    color: #e9f0ec !important;
    caret-color: #8ed6c7;
    font: 500 .82rem/1.75 "Cascadia Code", "SFMono-Regular", Consolas, monospace !important;
    tab-size: 2;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.02), 0 12px 28px rgba(23,32,28,.12);
}
#code-editor:focus { box-shadow: 0 0 0 4px rgba(49,95,83,.16), 0 12px 28px rgba(23,32,28,.12) !important; }

.syntax-help { margin-top: 13px; padding: 12px; border: 1px solid var(--flow-line); border-radius: 12px; background: rgba(255,255,255,.55); }
.syntax-help p { display: flex; justify-content: space-between; margin: 0 0 9px; color: var(--flow-ink); font-size: .72rem; }
.syntax-help p span { color: var(--flow-green); font-weight: 800; }
.syntax-help p span.error { color: var(--flow-coral); }
.syntax-help > code { display: block; padding: 8px 9px; border-radius: 8px; background: rgba(49,95,83,.08) !important; color: var(--flow-green) !important; font-size: .67rem; }
.syntax-help > div { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-top: 9px; color: var(--flow-muted); font-size: .63rem; }
.syntax-help > div span { display: flex; align-items: center; gap: 5px; }
.shape { width: 14px; height: 10px; display: inline-block; border: 1.5px solid var(--flow-green); background: rgba(111,183,170,.16); }
.shape.round { border-radius: 999px; }
.shape.diamond { width: 10px; height: 10px; transform: rotate(45deg); }

.visual-panel { padding-bottom: 12px; }
.panel-tip { margin: -2px 0 16px; color: var(--flow-muted); font-size: .72rem; line-height: 1.55; }
.shape-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.shape-card { position: relative; min-height: 104px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 10px !important; background: rgba(255,255,255,.58) !important; color: var(--flow-muted) !important; font-size: .69rem; cursor: grab !important; }
.shape-card:hover { border-color: rgba(49,95,83,.35) !important; color: var(--flow-green) !important; }
.shape-card:active { cursor: grabbing !important; }
.shape-card.dragging { border-color: var(--flow-green) !important; opacity: .58; transform: scale(.97) !important; }
.drag-grip { position: absolute; top: 7px; right: 8px; color: rgba(104,121,112,.55); font-style: normal; font-size: .8rem; letter-spacing: -2px; }
.node-preview { width: 75px; height: 34px; display: grid; place-items: center; border: 1.5px solid var(--flow-green); background: #fff; color: var(--flow-green); font-style: normal; font-size: .67rem; font-weight: 850; }
.node-preview.round { border-radius: 999px; }
.node-preview.diamond { width: 45px; height: 45px; transform: rotate(45deg); }
.node-preview.diamond b { transform: rotate(-45deg); font-size: .62rem; }
.node-preview.circle { width: 37px; height: 37px; border-radius: 50%; color: var(--flow-coral); }
.connector-box, .selection-box { margin-top: 14px; padding: 12px; border: 1px solid var(--flow-line); border-radius: 12px; background: rgba(255,255,255,.54); }
.connector-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; color: var(--flow-ink); font-size: .72rem; font-weight: 850; }
kbd { padding: 2px 6px; border: 1px solid var(--flow-line); border-radius: 5px; background: #fff; color: var(--flow-muted); font: 700 .58rem/1.4 inherit; }
.connect-btn, .danger-btn { width: 100%; min-height: 38px; }
.connect-btn.active { background: var(--flow-coral) !important; color: #fff !important; }
.connect-btn span { margin-right: 5px; }
.connector-box p, .selection-box p { min-height: 30px; margin: 8px 1px 0; color: var(--flow-muted); font-size: .64rem; line-height: 1.45; }
.node-label-field { display: grid; gap: 6px; margin: 2px 0 11px; color: var(--flow-ink); font-size: .66rem; font-weight: 800; }
.node-label-field[hidden] { display: none; }
.node-label-field input { width: 100%; min-height: 39px; padding: 0 10px; font-size: .75rem; font-weight: 650; }
.node-label-field small { color: var(--flow-muted); font-size: .58rem; font-weight: 600; line-height: 1.4; }
.danger-btn { color: var(--flow-coral) !important; }

.canvas-panel { min-width: 0; display: grid; grid-template-rows: 50px minmax(500px, 1fr) 34px; background: rgba(255,255,255,.42); }
.canvas-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0 15px; border-bottom: 1px solid var(--flow-line); background: rgba(255,255,255,.58); }
.status-pill { color: var(--flow-green); font-size: .69rem; font-weight: 850; }
.status-pill i { width: 6px; height: 6px; margin-right: 5px; }
.graph-stats { margin-left: 12px; color: var(--flow-muted); font-size: .65rem; }
.zoom-controls { display: flex; align-items: center; gap: 3px; }
.zoom-controls button { min-width: 30px; height: 30px; padding: 0 8px !important; border: 0 !important; background: transparent !important; box-shadow: none !important; }
.zoom-controls button:hover { background: rgba(49,95,83,.08) !important; transform: none !important; }
.zoom-controls span { width: 46px; color: var(--flow-muted); text-align: center; font-size: .65rem; font-weight: 800; }
#zoom-fit { width: auto; font-size: .65rem; }

.canvas-wrap {
    position: relative;
    min-height: 500px;
    overflow: hidden;
    background-color: rgba(255,255,255,.64);
    background-image: radial-gradient(circle, rgba(49,95,83,.18) 1px, transparent 1.3px);
    background-size: 22px 22px;
    cursor: grab;
    touch-action: none;
}
.canvas-wrap.panning { cursor: grabbing; }
.canvas-wrap.connecting { cursor: crosshair; }
.canvas-wrap.drag-over { outline: 3px solid rgba(49,95,83,.32); outline-offset: -5px; background-color: rgba(234,243,239,.82); }
#flow-canvas { width: 100%; height: 100%; min-height: 500px; display: block; user-select: none; }
.flow-node { cursor: move; }
.flow-node .node-body { fill: #fffdf9; stroke: #315f53; stroke-width: 1.7; filter: url(#node-shadow); transition: stroke-width .15s, fill .15s; }
.flow-node.type-diamond .node-body { fill: #f8ede8; stroke: #d9664f; }
.flow-node.type-round .node-body { fill: #eaf3ef; }
.flow-node.type-circle .node-body { fill: #315f53; }
.flow-node text { fill: #17201c; font: 750 13px "Segoe UI", "Microsoft YaHei", sans-serif; text-anchor: middle; pointer-events: none; }
.flow-node.type-circle text { fill: white; font-size: 10px; }
.flow-node.selected .node-body { stroke-width: 3; }
.flow-node.selected .selection-ring { opacity: 1; }
.selection-ring { fill: none; stroke: rgba(49,95,83,.35); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0; pointer-events: none; }
.node-port { opacity: 0; transition: opacity .15s, r .15s; cursor: crosshair; }
.flow-node.editable:hover .node-port, .flow-node.editable.selected .node-port { opacity: 1; }
.node-port-halo { fill: #fffdf9; stroke: #315f53; stroke-width: 1.5; }
.node-port-core { fill: #315f53; pointer-events: none; }
.node-port:hover .node-port-halo { fill: #eaf3ef; stroke-width: 2.5; }
.connection-target .node-body { fill: #dff1ea !important; stroke: #315f53 !important; stroke-width: 3 !important; }
#connection-preview { fill: none; stroke: #d9664f; stroke-width: 2.2; stroke-dasharray: 7 5; marker-end: url(#arrow); opacity: 0; pointer-events: none; }
#connection-preview.active { opacity: 1; }
.flow-edge { cursor: pointer; }
.flow-edge .edge-hit { fill: none; stroke: transparent; stroke-width: 14; }
.flow-edge .edge-path { fill: none; stroke: #687970; stroke-width: 1.7; marker-end: url(#arrow); }
.flow-edge:hover .edge-path, .flow-edge.selected .edge-path { stroke: #d9664f; stroke-width: 2.5; }
.edge-label-bg { fill: rgba(255,253,249,.95); stroke: rgba(23,32,28,.08); }
.edge-label { fill: #687970; font: 700 11px "Segoe UI", "Microsoft YaHei", sans-serif; text-anchor: middle; pointer-events: none; }
.canvas-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; color: var(--flow-muted); pointer-events: none; }
.canvas-empty[hidden] { display: none; }
.canvas-empty span { font-size: 36px; color: var(--flow-green); }
.canvas-empty b { margin-top: 8px; color: var(--flow-ink); }
.canvas-empty p { margin: 5px 0; font-size: .72rem; }
.canvas-toast { position: absolute; left: 50%; bottom: 18px; max-width: calc(100% - 32px); padding: 9px 14px; border-radius: 999px; background: rgba(23,32,28,.9); color: #fff; font-size: .7rem; font-weight: 700; opacity: 0; transform: translate(-50%, 8px); transition: .2s; pointer-events: none; }
.canvas-toast.show { opacity: 1; transform: translate(-50%, 0); }
.canvas-footer { display: flex; justify-content: flex-end; align-items: center; gap: 16px; padding: 0 15px; border-top: 1px solid var(--flow-line); color: var(--flow-muted); font-size: .61rem; }
.mouse-dot { display: inline-block; width: 8px; height: 11px; margin-right: 4px; border: 1px solid currentColor; border-radius: 5px; vertical-align: -2px; }

dialog { width: min(420px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 30px 90px rgba(23,32,28,.3); }
dialog::backdrop { background: rgba(23,32,28,.42); backdrop-filter: blur(4px); }
#rename-form { padding: 25px; text-align: center; }
.dialog-mark { width: 44px; height: 44px; display: grid; place-items: center; margin: 0 auto 13px; border-radius: 12px; background: rgba(49,95,83,.1); color: var(--flow-green); font-weight: 900; }
#rename-form h2 { margin: 0; font-size: 1.1rem; }
#rename-form p { margin: 7px 0 16px; color: var(--flow-muted); font-size: .76rem; }
#rename-input { width: 100%; min-height: 44px; padding: 0 12px; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 14px; }
.dialog-actions button { min-height: 42px; }

@media (max-width: 1050px) {
    .topbar { align-items: stretch; flex-direction: column; }
    .document-actions { justify-content: flex-start; flex-wrap: wrap; }
    .workspace-body { grid-template-columns: 310px minmax(0, 1fr); }
}

@media (max-width: 760px) {
    .flow-app { width: min(100% - 16px, 1540px); padding-top: 12px; }
    .flow-header { align-items: flex-start; flex-direction: column; }
    .header-actions { width: 100%; justify-content: space-between; }
    .mode-switch { width: 100%; }
    .mode-btn { min-width: 0; flex: 1; }
    .workspace-body { display: block; }
    .side-panel { border-right: 0; border-bottom: 1px solid var(--flow-line); }
    #code-editor { height: 300px; }
    .canvas-panel { grid-template-rows: 50px 480px 34px; }
    #flow-canvas { min-height: 480px; }
    .direction-field span, .graph-stats { display: none; }
}

@media (max-width: 480px) {
    .document-actions { gap: 6px; }
    .action-btn { padding: 0 9px !important; font-size: .72rem; }
    .icon-btn { display: none; }
    .mode-btn small { display: none; }
    .mode-btn { min-height: 44px; justify-content: center; }
    .canvas-toolbar { padding: 0 8px; }
    .canvas-footer { justify-content: center; }
    .canvas-footer span:not(:first-child) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
