.mg-flowchart-page,
.mg-flowchart-page body {
    width: 100%;
    min-height: 100%;
    margin: 0;
}

body.mg-flowchart-page {
    overflow: hidden;
    background: #262626;
}

body.mg-flowchart-page::before,
body.mg-flowchart-page::after {
    display: none;
}

.mg-flowchart-page .mg-flowchart-app {
    min-height: 100vh;
}

.mg-flowchart-page .mg-flowchart-shell {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.mg-flowchart-page .mg-flowchart-graph {
    height: 100vh;
    min-height: 100vh;
}

.mg-flowchart-app {
    --ink: #ffe135;
    --paper: #303030;
    --mint: #ffe135;
    --coral: #f3c614;
    --line: #ffe135;
    --grid: rgba(255, 225, 53, 0.14);
    --text: #fffced;
    --surface: #414141;
    --button: #7b3ff2;
    --button-hover: #9a73f7;
    color: var(--text);
    font-family: Arial, sans-serif;
    text-transform: uppercase;
}

.mg-flowchart-app * { box-sizing: border-box; }
.mg-flowchart-app button, .mg-flowchart-app input, .mg-flowchart-app textarea { font: inherit; }
.mg-flowchart-app button { color: inherit; }
.mg-flowchart-app input, .mg-flowchart-app textarea, .mg-flowchart-app button, .mg-flowchart-app input::placeholder { text-transform: uppercase; }
.mg-flowchart-shell { min-height: 72vh; background: var(--paper); border: 2px solid var(--ink); border-radius: 7px; overflow: hidden; }
.mg-flowchart-home { max-width: 850px; margin: 0 auto; padding: clamp(28px, 6vw, 72px) clamp(18px, 5vw, 56px); }
.mg-flowchart-eyebrow { margin: 0 0 6px; color: var(--mint); font-size: 0.74rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.mg-flowchart-title { margin: 0; font-family: inherit; font-size: clamp(2.4rem, 6vw, 4.8rem); font-weight: 700; line-height: 0.95; }
.mg-flowchart-subtitle { max-width: 510px; margin: 18px 0 36px; font-size: 1rem; line-height: 1.5; }
.mg-flowchart-search-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.mg-flowchart-search { width: 100%; min-height: 58px; padding: 12px 16px; border: 2px solid var(--ink); border-radius: 5px; background: var(--surface); color: var(--text); outline: none; }
.mg-flowchart-search:focus { outline: 2px solid var(--button); outline-offset: 2px; }
.mg-flowchart-back { display: inline-flex; align-items: center; justify-content: center; border: 2px solid var(--ink); border-radius: 5px; background: var(--button); color: #ffffff; cursor: pointer; font-weight: 800; }
.mg-flowchart-icon-button, .mg-flowchart-root__add, .mg-flowchart-node__add { display: inline-flex; align-items: center; justify-content: center; border: 0; padding: 0; background: transparent; cursor: pointer; font-size: 2rem; line-height: 1; }
.mg-flowchart-back:hover { background: var(--button-hover); color: #ffffff; }
.mg-flowchart-category-list { display: grid; gap: 10px; margin: 28px 0 0; }
.mg-flowchart-category { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; padding: 17px 18px; border: 2px solid var(--ink); border-radius: 5px; background: var(--surface); color: inherit; cursor: pointer; text-align: left; }
.mg-flowchart-category:hover, .mg-flowchart-category:focus-visible { background: var(--mint); }
.mg-flowchart-category__name { font-weight: 800; }
.mg-flowchart-category__arrow { font-size: 1.35rem; }
.mg-flowchart-empty { margin: 28px 0 0; color: #48636b; }
.mg-flowchart-graph { position: relative; height: min(78vh, 860px); min-height: 540px; display: grid; grid-template-rows: auto 1fr; background: #262626; }
.mg-flowchart-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px; border-bottom: 2px solid var(--ink); background: var(--paper); }
.mg-flowchart-back { min-height: 42px; padding: 8px 12px; gap: 7px; font-size: 0.9rem; }
.mg-flowchart-graph-title { min-width: 0; overflow: hidden; font-family: inherit; font-size: clamp(1.4rem, 3vw, 2.2rem); line-height: 1; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.mg-flowchart-viewport { position: relative; overflow: hidden; touch-action: none; cursor: grab; background-color: #262626; background-image: radial-gradient(var(--grid) 1px, transparent 1px); background-size: 22px 22px; }
.mg-flowchart-viewport.is-panning { cursor: grabbing; }
.mg-flowchart-world { position: absolute; width: 8000px; height: 6000px; transform-origin: 0 0; will-change: transform; }
.mg-flowchart-lines { position: absolute; width: 8000px; height: 6000px; overflow: visible; pointer-events: none; }
.mg-flowchart-lines line { stroke: var(--line); stroke-width: 3; vector-effect: non-scaling-stroke; }
.mg-flowchart-root { position: absolute; left: 4000px; top: 3000px; transform: translate(-50%, -50%); display: flex; align-items: center; gap: 10px; min-width: 170px; max-width: 290px; padding: 15px; border: 3px solid var(--ink); border-radius: 5px; background: var(--coral); color: #171717; font-weight: 800; text-align: center; }
.mg-flowchart-root__title { flex: 1; overflow-wrap: anywhere; line-height: 1.2; }
.mg-flowchart-root__add { position: absolute; top: 50%; left: calc(100% + 10px); width: auto; height: auto; transform: translateY(-50%); }
.mg-flowchart-node { position: absolute; display: flex; flex-direction: column; width: max-content; min-width: 0; max-width: none; padding: 0; border: 2px solid var(--ink); border-radius: 5px; background: var(--surface); overflow: visible; }
.mg-flowchart-node__header { display: flex; align-items: center; gap: 4px; min-height: 33px; padding: 3px; border-bottom: 1px solid var(--ink); background: var(--mint); color: #171717; cursor: move; }
.mg-flowchart-node__controls { position: absolute; top: calc(100% + 4px); left: 50%; z-index: 1; display: flex; flex-direction: row; align-items: center; gap: 4px; transform: translateX(-50%); }
.mg-flowchart-node__delete { width: 32px; height: 32px; border: 0; padding: 0; background: transparent; cursor: pointer; font-size: 1.4rem; line-height: 1; }
.mg-flowchart-node__title { min-width: 0; flex: 1; overflow: hidden; font-size: 0.74rem; font-weight: 800; line-height: 1.1; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.mg-flowchart-node__title-editor { min-width: 0; height: 26px; border: 0; padding: 2px 4px; background: transparent; color: inherit; font-size: 0.78rem; font-weight: 800; outline: 0; text-align: center; overflow: hidden; }
.mg-flowchart-node__title-editor[readonly],
.mg-flowchart-node__editor[readonly] { cursor: grab; }
.mg-flowchart-node__title-editor:focus { background: rgba(255, 255, 255, 0.55); }
.mg-flowchart-node__body { width: auto; min-height: 0; padding: 0; overflow: visible; font-size: 0.92rem; line-height: 1.45; overflow-wrap: normal; white-space: pre; }
.mg-flowchart-node--label { width: max-content; max-width: none; min-height: 0; background: var(--coral); color: #171717; }
.mg-flowchart-node--label .mg-flowchart-node__header { min-height: 100%; border-bottom: 0; background: transparent; }
.mg-flowchart-node--label .mg-flowchart-node__title-editor { overflow: visible; font-size: 0.9rem; text-align: center; white-space: nowrap; }
.mg-flowchart-node__title-editor.mg-flowchart-node--label-font { font-size: 0.9rem; }
.mg-flowchart-node--label .mg-flowchart-node__body { display: none; }
.mg-flowchart-node--label.is-editing { width: max-content; max-width: none; }
.mg-flowchart-node__body a { color: #17617a; text-decoration: underline; }
.mg-flowchart-node__editor { display: block; min-width: 0; height: auto; min-height: 0; padding: 10px; border: 0; resize: none; outline: 0; background: transparent; color: inherit; font-size: 0.92rem; line-height: 1.45; white-space: pre; overflow: hidden; }
.mg-flowchart-node__editor:focus { background: rgba(255, 255, 255, 0.38); }
.mg-flowchart-node-type-dialog { position: absolute; z-index: 5; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(23, 33, 38, 0.35); }
.mg-flowchart-node-type-dialog__panel { width: min(330px, 100%); padding: 20px; border: 2px solid var(--ink); border-radius: 5px; background: var(--paper); text-align: center; }
.mg-flowchart-node-type-dialog__panel p { margin: 0 0 16px; font-weight: 800; }
.mg-flowchart-node-type-dialog__panel div { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mg-flowchart-node-type-dialog button { min-height: 42px; border: 2px solid var(--ink); border-radius: 4px; background: var(--button); color: #ffffff; cursor: pointer; font-weight: 800; }
.mg-flowchart-node-type-dialog button:hover { background: var(--button-hover); }
.mg-flowchart-node-type-dialog__cancel { width: 100%; margin-top: 9px; background: var(--surface) !important; }
.mg-flowchart-password { max-width: 460px; margin: 10vh auto; padding: 34px; text-align: center; }
.mg-flowchart-password form { display: grid; gap: 12px; margin-top: 24px; }
.mg-flowchart-password input { min-height: 48px; border: 2px solid var(--ink); border-radius: 4px; padding: 10px 12px; }
.mg-flowchart-password button { min-height: 48px; border: 2px solid var(--ink); border-radius: 4px; background: var(--button); color: #ffffff; cursor: pointer; font-weight: 800; }
.mg-flowchart-status { min-height: 1.5em; margin: 14px 0 0; color: #9c281b; font-size: 0.85rem; }

@media (max-width: 640px) {
    .mg-flowchart-shell { min-height: 78vh; border-width: 1px; box-shadow: none; }
    .mg-flowchart-graph { height: calc(100vh - 90px); min-height: 500px; }
    .mg-flowchart-toolbar { padding: 9px; }
    .mg-flowchart-back { min-height: 36px; padding: 6px 8px; font-size: 0; }
    .mg-flowchart-back::before { content: '←'; font-size: 1.2rem; }
}
