:root {
    --bg: #eef8fd;
    --panel: linear-gradient(180deg, #53c4f6 0%, #41b8f2 100%);
    --line: #ffffff;
    --primary: #1aa7ec;
    --primary-2: #0d8dd1;
    --mint: #dff8ec;
    --mint-border: #6ecb9b;
    --pink: #ffe5ea;
    --pink-border: #ec8fa4;
    --yellow: #fff6d8;
    --yellow-border: #e2be59;
    --shadow: 0 18px 40px rgba(28, 126, 172, 0.18);
    --radius: 22px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    /* font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; */
    background:
        radial-gradient(circle at top left, rgba(84, 190, 245, 0.12), transparent 26%),
        linear-gradient(180deg, #f6fbfe 0%, #ebf8fd 100%);
    color: #14324a;
}

.page {
    min-height: 100%;
    padding: 28px;
}

.hero {
    max-width: 1300px;
    margin: 0 auto 20px;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 14px;
    flex-wrap: wrap;
}

.brand h1 {
    margin: 0;
    font-size: clamp(40px, 5vw, 82px);
    line-height: .95;
    letter-spacing: -0.04em;
    color: #000;
    font-weight: 900;
}

.brand .accent {
    color: var(--primary);
}

.subtitle {
    margin: 14px 0 22px;
    font-size: clamp(18px, 2vw, 30px);
    font-weight: 700;
    color: #111;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.chip {
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(35, 135, 198, 0.12);
    color: #20384a;
    padding: 12px 18px;
    border-radius: 999px;
    box-shadow: 0 8px 20px rgba(31, 108, 151, 0.08);
    font-weight: 600;
}

.board-shell {
    max-width: 1300px;
    margin: 18px auto 0;
    background: var(--panel);
    border-radius: 34px;
    box-shadow: var(--shadow);
    padding: 24px;
    position: relative;
    min-height: 720px;
    overflow: hidden;
}

.board-shell::before {
    content: "";
    position: absolute;
    inset: auto -120px -140px auto;
    width: 420px;
    height: 420px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.22), transparent 70%);
    pointer-events: none;
}

.window-dots {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    padding-left: 8px;
}

.window-dots span {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.45);
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.4);
}

#drawflow {
    width: 100%;
    height: 100vh;
    background-color: #ffffff;
    background-image: radial-gradient(#dcdcdc 1.2px, transparent 1.2px);
    background-size: 22px 22px;
}

.drawflow .parent-drawflow {
    background: transparent !important;
}

.drawflow .parent-drawflow {
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
    background-size: 32px 32px;
}

.drawflow-node {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    min-width: auto !important;
    overflow: visible !important;
}

.drawflow-node .drawflow_content_node {
    padding: 0 !important;
    background: transparent !important;
    overflow: visible !important;
}

.flow-node {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 150px;
    min-height: 72px;
    padding: 18px 22px;
    text-align: center;
    font-weight: 700;
    color: #256d45;
    background: var(--mint);
    border: 2px dashed var(--mint-border);
    box-shadow: 0 10px 18px rgba(10, 98, 146, 0.10);
    position: relative;
}

.flow-node.process {
    border-radius: 16px;
}

.flow-node.start,
.flow-node.end {
    min-width: 92px;
    min-height: 92px;
    border-radius: 999px;
    background: #e9f8ff;
    border: 2px dashed #79bce4;
    color: var(--primary-2);
}

.flow-node.decision {
    width: 120px;
    height: 120px;
    min-width: 120px;
    min-height: 120px;
    transform: rotate(45deg);
    border-radius: 14px;
    background: var(--yellow);
    border: 2px dashed var(--yellow-border);
    color: #b88400;
    padding: 0;
}

.flow-node.decision>span {
    transform: rotate(-45deg);
    display: inline-block;
    max-width: 76px;
    line-height: 1.15;
}

.flow-node.data {
    min-width: 150px;
    min-height: 74px;
    background: #eefcff;
    border: 2px dashed #67b9e9;
    /* color: #1a85c5; */
    clip-path: polygon(14% 0, 100% 0, 86% 100%, 0 100%);
}

.flow-node.alert {
    min-width: 108px;
    min-height: 108px;
    border-radius: 999px;
    background: var(--pink);
    border: 2px dashed var(--pink-border);
    color: #c14a62;
}

.flow-node.tag {
    min-width: 78px;
    min-height: 42px;
    padding: 8px 16px;
    border-radius: 10px;
    background: #fff4f4;
    border: 2px solid #ef8787;
    color: #c43f3f;
    font-size: 14px;
    box-shadow: 0 8px 16px rgba(170, 68, 68, 0.10);
}

.drawflow-node .input,
.drawflow-node .output {
    width: 14px;
    height: 14px;
    border: 3px solid #fff;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.24);
}

.drawflow-node .input {
    left: -8px;
}

.drawflow-node .output {
    right: -8px;
    overflow: visible !important;
    z-index: 20;
}

.drawflow-node .output[data-out-label]::after {
    content: attr(data-out-label);
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #9ac7ea;
    color: #0d4573;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.drawflow-node .output .output-label {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #9ac7ea;
    color: #0d4573;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 21;
}

.drawflow .connection .main-path {
    stroke: rgba(0, 0, 0, 0.95);
    stroke-width: 3px;
    fill: none;
}

.drawflow .connection.selected .main-path {
    stroke: #ffdc71;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 18px;
}

.legend-item {
    background: rgba(255, 255, 255, 0.88);
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 700;
    color: #214458;
    box-shadow: 0 8px 16px rgba(20, 90, 126, 0.08);
}

@media (max-width: 768px) {
    .page {
        padding: 16px;
    }

    .board-shell {
        padding: 16px;
        min-height: 620px;
    }

    #drawflow {
        height: 520px;
    }

    .toolbar {
        position: static;
        margin-bottom: 12px;
    }
}

.drawflow-node {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    min-width: auto !important;
}

.drawflow-node .drawflow_content_node {
    padding: 0 !important;
    background: transparent !important;
}

/* base */
.flow-node,
.node {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 150px;
    min-height: 72px;
    padding: 18px 22px;
    text-align: center;
    font-weight: 700;
    color: #256d45;
    background: #dff8ec;
    border: 2px dashed #6ecb9b;
    box-shadow: 0 10px 18px rgba(10, 98, 146, 0.10);
    position: relative;
    border-radius: 16px;
}

/* inner text */
.node .child {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-align: center;
    line-height: 1.2;
    font-size: 14px;
    font-weight: bold !important;
    color: black !important;
}

/* process */
.flow-node.process,
.node.process {
    border-radius: 16px;
}

/* start / end */
.flow-node.start,
.flow-node.end,
.node.start,
.node.end {
    min-width: 92px;
    min-height: 92px;
    width: 92px;
    height: 92px;
    border-radius: 999px;
    background: #e9f8ff;
    border: 2px dashed #79bce4;
    color: #0d8dd1;
}

/* decision */
.flow-node.decision,
.node.decision {
    width: 120px;
    height: 120px;
    min-width: 120px;
    min-height: 120px;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

.node.decision .decision-inner,
.flow-node.decision {
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(45deg);
    border-radius: 14px;
    background: #fff6d8;
    border: 2px dashed #e2be59;
    color: #b88400;
    box-shadow: 0 10px 18px rgba(10, 98, 146, 0.10);
}

.node.decision .child,
.flow-node.decision>span {
    transform: rotate(-45deg);
    max-width: 76px;
    line-height: 1.15;
    text-align: center;
}

/* switch case */
.node.switchcase {
    min-width: 240px;
    min-height: 120px;
    background: #eefcff;
    border: 2px dashed #67b9e9;
    /* color: #1a85c5; */
    border-radius: 18px;
    display: block;
    padding: 16px;
}

.node.switchcase .switchcase-inner {
    width: 100%;
}

.node.switchcase .case-list {
    margin-top: 12px;
    display: grid;
    gap: 8px;
}

.node.switchcase .case-item {
    background: rgba(255, 255, 255, .7);
    border: 1px dashed #67b9e9;
    border-radius: 12px;
    padding: 8px 10px;
    font-size: 14px;
}

/* connectors */
.drawflow-node .input,
.drawflow-node .output {
    width: 14px;
    height: 14px;
    border: 3px solid #fff;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.24);
}

/* เฉพาะ decision ให้ขยับเพิ่ม */
.node.decision .output {
    right: -200px !important;
}

.node.decision .input {
    left: -200px !important;
}

.switchcase .output {
    right: -110px !important;
}

.start .input {
    display: none;
}

.drawflow-node.selected .drawflow_content_node {
    filter: drop-shadow(0 0 0 rgba(0, 0, 0, 0));
}

.drawflow-node.selected .node,
.drawflow-node.selected .flow-node {
    outline: 3px solid #4da3ff !important;
    outline-offset: 4px;
}

.process .input {
    left: -20px !important;
}

.process .output {
    right: -20px !important;
}

.start .output {
    right: 40px !important;
}

/* custom context menu */
#nodeMenu {
    position: fixed;
    z-index: 99999;
    min-width: 150px;
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    box-shadow: 0 14px 35px rgba(0, 0, 0, 0.35);
    padding: 6px;
    display: none;
}

#nodeMenu button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: #f8fafc;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

#nodeMenu button:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* ===== context menus ===== */
#nodeMenu,
#canvasMenu,
#lineMenu {
    position: fixed;
    z-index: 99999;
    min-width: 170px;
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    box-shadow: 0 14px 35px rgba(0, 0, 0, 0.35);
    padding: 6px;
    display: none;
}

#nodeMenu button,
#canvasMenu button,
#lineMenu button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: #f8fafc;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

#nodeMenu button:hover,
#canvasMenu button:hover,
#lineMenu button:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* ===== selected connection ===== */
.drawflow .connection.conn-selected .main-path {
    stroke: #ffdc71 !important;
    filter: drop-shadow(0 0 1px rgba(255, 220, 113, 0.65));
}

/* optional visual tag for style */
.drawflow .connection[data-conn-style="straight"] .main-path {
    stroke-linejoin: round;
}

.drawflow .connection[data-conn-style="elbowed"] .main-path {
    stroke-linejoin: round;
}

.drawflow .connection[data-conn-style="curved"] .main-path {
    stroke-linejoin: round;
}

.drawflow-delete {
    display: none;
}

/* dim other nodes when focusing a single node */
.flow-dim {
    opacity: 0.25 !important;
    filter: grayscale(80%);
    pointer-events: none;
}

.flow-highlight {
    z-index: 9999;
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.18);
}