:root {
    --bg: #fff;
    --panel: #f0f0f0;
    --panel-alt: #e4e4e4;
    --hover: #d8d8d8;
    --border: #cdcdcd;
    --text: #1f1f1f;
    --muted: #5f6368;
    --accent: #2f6fb0;
    --accent-hover: #265d95;
    --accent-text: #fff;
    --warning: #fff4d6;
    --warning-text: #6b4e00;
    --error: #c62828;
    --mapped: #1b6e33;

    /* Canvas palette, taken from the desktop app so both versions read the same. */
    --chip-src-bg: #E3F2FD;
    --chip-src-border: #1976D2;
    --col-src-bg: #F5F9FF;
    --chip-tgt-bg: #E8F5E9;
    --chip-tgt-border: #388E3C;
    --col-tgt-bg: #F5FBF5;
    --functoid-bg: #FFF8E1;
    --functoid-border: #F9A825;
    --link: #428BCA;
    --link-highlight: #0D47A1;

    /* The two column widths are rewritten by canvas.js while a splitter is dragged. They live on
       the root element, which Blazor never re-renders, so a resize survives a server render. */
    --col-src-w: 16rem;
    --col-tgt-w: 16rem;

    --sidebar-w: 7.75rem;
    --status-h: 1.75rem;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 13px/1.5 "Segoe UI", system-ui, sans-serif;
}

h1 { font-size: 1.6rem; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .5rem; }

/* ---- Shell ---- */

/* Sidebar plus content as a flex row, so the canvas can size itself against the remaining
   space instead of subtracting a fixed toolbar height. */
.shell { display: flex; height: 100vh; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---- Sidebar ---- */

.sidebar {
    flex: 0 0 var(--sidebar-w);
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: .25rem;
    padding: .5rem .4rem;
    background: var(--panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.brand { font-weight: 600; letter-spacing: .02em; padding: .1rem .2rem .3rem; }

.side-section {
    margin-top: .5rem;
    padding: 0 .2rem;
    font-size: .65rem;
    font-weight: 600;
    letter-spacing: .08em;
    color: var(--muted);
}

/* Icon above caption, like the desktop app's ribbon-style buttons. Used on both <button> and
   <label> (the file pickers), so everything here has to work for either element. */
.side-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .15rem;
    width: 100%;
    padding: .4rem .25rem;
    font: inherit;
    text-align: center;
    color: var(--text);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
}

.side-btn svg { width: 20px; height: 20px; flex: 0 0 auto; }
.side-btn .cap { font-size: .7rem; line-height: 1.2; }

/* The loaded file name, clipped rather than allowed to widen the sidebar. */
.side-btn .file {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .62rem;
    color: var(--muted);
}

.side-btn:hover:not(:disabled):not(.disabled) { background: var(--panel-alt); border-color: var(--border); }
.side-btn:disabled, .side-btn.disabled { opacity: .45; cursor: default; pointer-events: none; }
.side-btn.accent { color: var(--accent); }

/* A toggle that is on gets the accent as a filled state, so it is readable without the tooltip. */
.side-btn.on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

/* Beats the generic .side-btn:hover, which would otherwise grey out an active toggle. */
.side-btn.on:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.side-btn.on .file { color: var(--accent-text); }
.side-btn input[type=file] { display: none; }

button {
    font: inherit;
    padding: .3rem .7rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--panel-alt);
    color: var(--text);
    cursor: pointer;
}

button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ---- Banners ---- */

.banner {
    flex: 0 0 auto;
    padding: .5rem .75rem;
    border-bottom: 1px solid var(--border);
}

.banner.error {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    background: var(--error);
    color: #fff;
}

.banner.error button { background: transparent; border: none; color: #fff; }
.banner.warning { background: var(--warning); color: var(--warning-text); }
.banner.warning summary { cursor: pointer; font-weight: 600; }
.banner.warning ul { margin: .5rem 0 0; padding-left: 1.2rem; }
.banner.warning li { margin-bottom: .35rem; }

.hint { color: var(--muted); }
.pad { padding: .6rem; }
.error-text { color: var(--error); margin: 0 0 .5rem; }

/* ---- Canvas ---- */

/* Source column, splitter, the functoid area, splitter, target column. The link overlay is
   absolutely positioned over the whole grid, which is why this is the positioning context. */
.canvas {
    position: relative;
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--col-src-w) 5px minmax(0, 1fr) 5px var(--col-tgt-w);
    background: var(--border);
    gap: 0;
}

.col { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.col-src { background: var(--col-src-bg); }
.col-tgt { background: var(--col-tgt-bg); }

.col-head {
    flex: 0 0 auto;
    padding: .35rem .5rem .2rem;
    font-size: .65rem;
    font-weight: 600;
    letter-spacing: .08em;
    color: var(--muted);
    background: var(--panel);
}

/* Sibling of the header, above the scrolling body: it must not scroll away with the fields. */
.search {
    flex: 0 0 auto;
    margin: 0 .5rem .35rem;
    padding: .25rem .4rem;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
}

.col-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: .1rem 0 2rem;
    border-top: 1px solid var(--border);
}

/* No left padding: the row's inline style sets padding-left for the tree indent and would
   otherwise override it away, leaving depth-0 chips flush against the column edge. */
.row { display: flex; padding: 1px .5rem 1px 0; }

/* A chip is the link endpoint: canvas.js reads its bounding box, so it must be the element that
   carries data-anchor and must not be wider than the text it holds. */
.chip {
    display: inline-flex;
    align-items: baseline;
    gap: .35rem;
    max-width: 100%;
    padding: .12rem .45rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg);
    cursor: pointer;
    user-select: none;
}

.chip.src { background: var(--chip-src-bg); border-color: var(--chip-src-border); }
.chip.tgt { background: var(--chip-tgt-bg); border-color: var(--chip-tgt-border); }

/* Containers are structure, not endpoints: no fill, and the twisty carries the affordance. */
.chip.container { background: transparent; border-color: transparent; font-weight: 600; color: var(--muted); }
.chip.container:hover { background: rgba(0, 0, 0, .05); }

.chip.selected { outline: 2px solid var(--accent); outline-offset: 0; }
.chip.mapped { box-shadow: inset 3px 0 0 var(--mapped); }
.chip:hover { filter: brightness(.97); }

.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-type { flex: 0 0 auto; font-size: .8em; color: var(--muted); }
.twisty { flex: 0 0 auto; width: .7rem; color: var(--muted); }

/* ---- Functoid area ---- */

/* overflow:hidden, not auto: there are no scrollbars here, panning is the way around. It is still a
   scroll container, so canvas.js can move it with scrollLeft/scrollTop. */
.canvas-mid {
    background: var(--bg);
    overflow: hidden;
    position: relative;
    touch-action: none;
    cursor: grab;
}

.canvas-mid.panning { cursor: grabbing; }

/* Bigger than the viewport so functoids can be dragged out and the area panned to reach them. */
.canvas-inner { position: relative; width: 3000px; height: 2000px; }

.canvas-hint {
    position: absolute;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    color: var(--muted);
    pointer-events: none;
}

.functoid {
    position: absolute;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
    min-width: 6.5rem;
    max-width: 12rem;
    padding: .25rem .45rem;
    background: var(--functoid-bg);
    border: 1px solid var(--functoid-border);
    border-radius: 4px;
    cursor: move;
    user-select: none;
    touch-action: none;
}

.functoid-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.functoid-inputs { font-size: .75rem; color: var(--muted); }

/* ---- Link overlay ---- */

/* Transparent to the mouse as a whole, so chips underneath stay clickable; only the hit paths
   opt back in, and only along their stroke. */
.link-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}

.link-path { fill: none; stroke: var(--link); stroke-width: 1.6; }
.link-path.hl { stroke: var(--link-highlight); stroke-width: 2.6; }

.link-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 12;
    pointer-events: stroke;
    cursor: context-menu;
}

/* ---- Splitters ---- */

.splitter { background: var(--border); cursor: col-resize; touch-action: none; }
.splitter:hover { background: var(--accent); }

/* ---- Context menu ---- */

.ctx-backdrop { position: fixed; inset: 0; z-index: 40; }

.ctx-menu {
    position: fixed;
    z-index: 41;
    min-width: 12rem;
    padding: .2rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.ctx-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    width: 100%;
    padding: .3rem .5rem;
    font: inherit;
    text-align: left;
    color: var(--text);
    background: transparent;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

.ctx-item:hover { background: var(--panel-alt); }
.ctx-item.danger { color: var(--error); }
.ctx-arrow { color: var(--muted); }
.ctx-sep { height: 1px; margin: .2rem .3rem; background: var(--border); }

/* Hover-revealed submenu: no state on the server for opening it. */
.ctx-sub {
    display: none;
    position: absolute;
    top: -.2rem;
    left: 100%;
    min-width: 11rem;
    padding: .2rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.ctx-item.has-sub:hover > .ctx-sub, .ctx-sub:hover { display: block; }

/* ---- Status ---- */

.status {
    flex: 0 0 auto;
    height: var(--status-h);
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 0 .75rem;
    background: var(--panel);
    border-top: 1px solid var(--border);
    color: var(--muted);
}

.status > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Indeterminate: the AI call gives no progress to report, only that it is running. */
.progress {
    flex: 0 0 8rem;
    height: .4rem;
    border-radius: 2px;
    background: var(--panel-alt);
    overflow: hidden;
}

.progress::after {
    content: "";
    display: block;
    width: 40%;
    height: 100%;
    background: var(--accent);
    animation: progress-slide 1.1s ease-in-out infinite;
}

@keyframes progress-slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
}

/* ---- BizTalk script panel ---- */

.script-panel {
    flex: 0 0 auto;
    max-height: 40vh;
    padding: .4rem .75rem .6rem;
    background: var(--panel);
    border-top: 1px solid var(--border);
    overflow: auto;
}

.script-panel summary { cursor: pointer; color: var(--muted); font-weight: 600; }

.script-panel textarea {
    width: 100%;
    min-height: 8rem;
    margin-top: .4rem;
    padding: .4rem;
    font: 12px/1.45 Consolas, "Cascadia Mono", monospace;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    resize: vertical;
}

/* ---- Modal ---- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(30rem, calc(100vw - 2rem));
    padding: 1.25rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.modal h2 { color: var(--text); font-size: 1rem; text-transform: none; letter-spacing: 0; }
.modal label { display: block; margin-bottom: .75rem; color: var(--muted); }
.modal input, .modal select, .modal textarea {
    display: block;
    width: 100%;
    margin-top: .2rem;
    padding: .35rem .5rem;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
}

.modal textarea.code {
    font: 12px/1.45 Consolas, "Cascadia Mono", monospace;
    resize: vertical;
}

.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: .6rem 1.25rem;
    background: #ffc;
    color: #333;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, .2);
    z-index: 1000;
}

#blazor-error-ui .dismiss { cursor: pointer; float: right; }
