/* ---------- Graph editor ---------- */

.graph-page {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: calc(100vh - 50px - 48px);
    min-height: 480px;
}

.graph-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
}

.graph-toolbar h1 {
    margin: 0 8px 0 0;
}

/* Toolbar button that opens a file picker: the transparent file input lies on top of the button. */
.toolbar-file {
    position: relative;
    display: inline-flex;
}

.toolbar-file .toolbar-file-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.import-warnings {
    margin: 4px 0 0;
    padding-left: 20px;
}

.toolbar-separator {
    width: 1px;
    align-self: stretch;
    margin: 4px 2px;
    background: var(--neutral-stroke-divider-rest, #e0e0e0);
}

.save-state {
    font-size: 0.85rem;
    color: var(--neutral-foreground-hint, #616161);
}

.graph-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    gap: 8px;
}

.graph-body.with-panel {
    grid-template-columns: 230px minmax(0, 1fr) 330px;
}

/* Viewers have no palette. */
.graph-body:not(:has(.graph-palette)) {
    grid-template-columns: minmax(0, 1fr);
}

.graph-body.with-panel:not(:has(.graph-palette)) {
    grid-template-columns: minmax(0, 1fr) 330px;
}

.graph-palette,
.graph-panel {
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    overflow-y: auto;
    min-height: 0;
    box-sizing: border-box;
}

.graph-panel h2 {
    margin: 0;
    overflow-wrap: anywhere;
}

.graph-panel h3 {
    font-size: 0.95rem;
    margin: 8px 0 0;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.panel-description {
    margin: 0;
    font-size: 0.9rem;
}

.panel-state {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.panel-issue {
    font-size: 0.85rem;
    padding: 6px 8px;
    border-radius: 6px;
}

.issue-error { color: #c42b1c; }
.issue-warning { color: #8a6100; }
.panel-issue.issue-error { background: #c42b1c1a; }
.panel-issue.issue-warning { background: #d4a0001f; }

.panel-widget {
    border-top: 1px solid var(--neutral-stroke-divider-rest, #e0e0e0);
    padding-top: 8px;
}

.panel-actions {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--neutral-stroke-divider-rest, #e0e0e0);
}

.palette-groups {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.palette-category {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--neutral-foreground-hint, #616161);
    margin-bottom: 4px;
}

.palette-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 2px 2px 2px 10px;
    border: 1px solid var(--neutral-stroke-divider-rest, #e0e0e0);
    border-radius: 6px;
    margin-bottom: 4px;
    cursor: grab;
    background: var(--neutral-layer-1, #fff);
    font-size: 0.9rem;
}

.palette-item:hover {
    border-color: var(--accent-fill-rest, #0f6cbd);
}

.palette-hint {
    font-size: 0.8rem;
    margin: 0;
}

.graph-main {
    position: relative;
    min-height: 0;
    overflow: hidden;
}

.graph-canvas {
    position: absolute;
    inset: 0;
    outline: none;
    touch-action: none;
    user-select: none;
}

.graph-canvas:focus-visible {
    box-shadow: inset 0 0 0 2px var(--accent-fill-rest, #0f6cbd);
}

.graph-svg {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

.graph-canvas.mode-pan .graph-svg { cursor: grabbing; }
.graph-canvas.mode-link .graph-svg { cursor: crosshair; }
.graph-canvas.mode-dragnode .graph-svg { cursor: move; }

.graph-grid-dot {
    fill: var(--neutral-stroke-rest, #c8c8c8);
}

.graph-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    max-width: none;
}

.graph-tooltip {
    position: absolute;
    max-width: 320px;
    padding: 6px 8px;
    border-radius: 6px;
    background: rgba(30, 30, 30, 0.92);
    color: #fff;
    font: 0.8rem ui-monospace, "Cascadia Mono", Consolas, monospace;
    pointer-events: none;
    overflow-wrap: anywhere;
    z-index: 5;
}

.graph-node { cursor: pointer; }

.graph-node-body {
    fill: var(--neutral-layer-1, #fff);
    stroke: var(--neutral-stroke-rest, #b3b3b3);
    stroke-width: 1;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15));
}

.graph-node.selected .graph-node-body {
    stroke: var(--accent-fill-rest, #0f6cbd);
    stroke-width: 2.5;
}

.graph-node.not-live .graph-node-body { stroke-dasharray: 5 4; }
.graph-node.missing .graph-node-body { stroke: #9e9e9e; fill: var(--neutral-layer-2, #f5f5f5); }
.graph-node.has-error .graph-node-body { stroke: #c42b1c; stroke-width: 2; }

.graph-node-strip {
    fill: hsl(var(--category-hue, 200) 55% 50%);
}

.graph-node-title {
    font-size: 14px;
    font-weight: 600;
    fill: var(--neutral-foreground-rest, #1b1b1b);
}

.graph-node-sub,
.graph-node-status,
.graph-node-flag {
    font-size: 11px;
    fill: var(--neutral-foreground-hint, #616161);
}

.graph-node-status.health-ok { fill: #2e7d32; }
.graph-node-status.health-warning { fill: #8a6100; }
.graph-node-status.health-error { fill: #c42b1c; }

.graph-node-dot {
    fill: none;
    stroke: #9e9e9e;
    stroke-width: 2;
}

.graph-node.state-running .graph-node-dot { fill: #2e9e44; stroke: #2e9e44; }
.graph-node.state-faulted .graph-node-dot { fill: #c42b1c; stroke: #c42b1c; }
.graph-node.state-starting .graph-node-dot,
.graph-node.state-stopping .graph-node-dot { fill: #d4a000; stroke: #d4a000; }
.graph-node.state-stopped .graph-node-dot,
.graph-node.state-created .graph-node-dot { fill: #9e9e9e; }

.graph-port circle {
    fill: hsl(var(--port-hue, 200) 65% 50%);
    stroke: var(--neutral-layer-1, #fff);
    stroke-width: 2;
    cursor: crosshair;
}

.graph-node.missing .graph-port circle { fill: #9e9e9e; }

.graph-port-label {
    font-size: 11px;
    fill: var(--neutral-foreground-rest, #1b1b1b);
    pointer-events: none;
}

.graph-port.port-ok circle { stroke: hsl(var(--port-hue, 200) 65% 35%); stroke-width: 3; r: 8px; }
.graph-port.port-active circle { r: 8px; }
.graph-port.port-dim { opacity: 0.25; }

.graph-link-path {
    fill: none;
    stroke: hsl(var(--port-hue, 200) 55% 50%);
    stroke-width: 2.5;
    opacity: 0.75;
}

/* Data flows: the dashes move along the link. */
.graph-link.active .graph-link-path {
    stroke-dasharray: 8 6;
    animation: graph-flow 0.8s linear infinite;
}

.graph-link.selected .graph-link-path {
    stroke-width: 4.5;
    opacity: 1;
}

.graph-link.has-error .graph-link-path { stroke: #c42b1c; stroke-dasharray: 4 4; }
.graph-link.pending .graph-link-path { stroke-dasharray: 3 5; opacity: 0.55; }

.graph-link-path.temp {
    stroke: var(--accent-fill-rest, #0f6cbd);
    stroke-dasharray: 6 4;
    opacity: 1;
}

@keyframes graph-flow {
    to { stroke-dashoffset: -14; }
}

@media (prefers-reduced-motion: reduce) {
    .graph-link.active .graph-link-path { animation: none; }
}

.graph-link-badge {
    fill: var(--neutral-layer-1, #fff);
    stroke: hsl(var(--port-hue, 200) 55% 50%);
}

.graph-link-badge.dropped { stroke: #c42b1c; }

.graph-link-text {
    font-size: 11px;
    fill: var(--neutral-foreground-rest, #1b1b1b);
    font-variant-numeric: tabular-nums;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-form fluent-text-field,
.settings-form fluent-text-area,
.settings-json {
    width: 100%;
}

.settings-json {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.field-error {
    color: #c42b1c;
    font-size: 0.8rem;
}

.plan-issues,
.plan-changes {
    margin: 0;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.plan-changes .change-removeinstance,
.plan-changes .change-stop,
.plan-changes .change-disconnect { color: #a4262c; }
.plan-changes .change-createinstance,
.plan-changes .change-start,
.plan-changes .change-connect { color: #2e7d32; }

@media (max-width: 1000px) {
    .graph-page {
        height: auto;
    }

    .graph-body,
    .graph-body.with-panel {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .graph-main {
        height: 65vh;
        order: -1;
    }

    .graph-palette {
        max-height: 40vh;
    }
}

/* Relay priority (NodePanel) */
.relay-ports { margin: 4px 0 8px; font-size: 0.85rem; }
.relay-ports summary { cursor: pointer; margin-bottom: 4px; }
.relay-ports fluent-select { margin-bottom: 6px; }
.relay-traffic { opacity: 0.75; }
.relay-traffic.relay-warning { color: #8a6100; opacity: 1; }
.relay-flag.relay-throttled { fill: #8a6100; }
.relay-flag.relay-blocked { fill: #c42b1c; }

/* Export as a program (AppExportDialog) */
.app-export .export-section {
    border-top: 1px solid var(--neutral-stroke-divider-rest);
    padding-top: 8px;
    margin-top: 12px;
}

.app-export .export-section h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
}

.app-export .export-section h4 {
    font-size: var(--type-ramp-base-font-size);
    margin: 12px 0 4px;
}

.app-export .export-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px 16px;
    align-items: end;
    margin: 8px 0;
}

.app-export .export-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.app-export .export-field > fluent-select,
.app-export .export-field > fluent-text-field,
.app-export .export-field > fluent-number-field {
    width: 100%;
    min-width: 0;
}

.app-export .export-grid.export-wifi {
    grid-template-columns: 1fr 1fr auto;
}

.app-export .kofa-table {
    margin: 8px 0;
}
