/* ═══════════════════════════════════════════════════════════════
   pathways-v4 — scoped styles
   Top-down approach: start with final credential, define prerequisites.
   All selectors are prefixed with .pv4- except where re-using
   global classes that already exist.
   ═══════════════════════════════════════════════════════════════ */

/* ── Canvas drop area ──────────────────────────────────────────── */
.pv4-canvas {
    position: relative;
    width: 100%;
    min-width: 2000px;
    height: 100%;
    min-height: 2000px;
    overflow: auto;
    background-color: #fafafa;
    background-image:
        linear-gradient(rgba(0,0,0,.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,0,0,.04) 1px, transparent 1px);
    background-size: 32px 32px;
}

.pv4-canvas-drag-over {
    background-color: #e8f4fd;
    outline: 2px dashed #3b82f6;
    outline-offset: -4px;
}

/* ── SVG overlay ───────────────────────────────────────────────── */
.pv4-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}

/* ── Empty state hint ──────────────────────────────────────────── */
.pv4-empty-hint {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #aaa;
    user-select: none;
    pointer-events: none;
}

.pv4-empty-icon {
    font-size: 56px;
    margin-bottom: 16px;
    display: block;
    opacity: 0.35;
}

/* ── Credential node ───────────────────────────────────────────── */
.pv4-node {
    position: absolute;
    width: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: move;
    user-select: none;
    z-index: 10;
}

.pv4-node-img-wrapper {
    position: relative;
    width: 102px;
    height: 102px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    transition: box-shadow 0.15s;
}

.pv4-node:hover .pv4-node-img-wrapper {
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

/* ── Final credential highlight ────────────────────────────────── */
.pv4-node-final .pv4-node-img-wrapper {
    box-shadow: 0 0 0 3px #22c55e, 0 4px 16px rgba(0,0,0,.2);
}

.pv4-final-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #22c55e;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    margin-top: 4px;
    letter-spacing: 0.03em;
}

/* ── Legend final dot ──────────────────────────────────────────── */
.pv4-final-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #16a34a;
    flex-shrink: 0;
}

.pv4-legend-final-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pv4-node-image {
    width: 100px;
    height: 100px;
    display: block;
    border-radius: 6px;
    object-fit: contain;
}

/* ── Connector (left only — incoming arrow target) ─────────────── */
.pv4-connector {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border: 2px solid #9ca3af;
    border-radius: 50%;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    transition: background 0.15s, border-color 0.15s;
    pointer-events: none;
}

.pv4-connector-left { left: -7px; }

/* ── Node name label ───────────────────────────────────────────── */
.pv4-node-name {
    font-size: 11px;
    text-align: center;
    margin-top: 6px;
    max-width: 130px;
    word-break: break-word;
    color: #374151;
    line-height: 1.3;
}

/* ── Incoming connection labels below the node ─────────────────── */
.pv4-node-conn-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    justify-content: center;
    max-width: 145px;
    margin-top: 3px;
}

/* ── Node context-menu button ──────────────────────────────────── */
.pv4-node-menu-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 11px;
    color: #6b7280;
    z-index: 30;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s;
}

.pv4-node:hover .pv4-node-menu-btn {
    opacity: 1;
}

/* ── Node context menu ─────────────────────────────────────────── */
.pv4-node-menu {
    position: absolute;
    top: -10px;
    right: 20px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    padding: 6px 0;
    list-style: none;
    margin: 0;
    min-width: 160px;
    z-index: 100;
}

.pv4-node-menu li {
    padding: 8px 14px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    color: #374151;
}

.pv4-node-menu li:hover {
    background: #f3f4f6;
    color: #ca0a0a;
}

/* ── Sidebar drag item ─────────────────────────────────────────── */
.pv4-sidebar-drag-item {
    display: inline-block;
    cursor: grab;
}

.pv4-sidebar-drag-item:active {
    cursor: grabbing;
}

.pv4-add-btn {
    cursor: pointer;
    color: #374151;
}

.pv4-add-btn:hover {
    color: #22c55e;
}

/* ── Toolbar legend ────────────────────────────────────────────── */
.pv4-legend {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-left: auto;
    font-size: 11px;
    color: #6b7280;
}

.pv4-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.pv4-legend-hint {
    font-style: italic;
    white-space: nowrap;
}

/* ── Dialog overlay ────────────────────────────────────────────── */
.pv4-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100010;
}

.pv4-dialog {
    background: #fff;
    border-radius: 10px;
    padding: 28px 32px;
    min-width: 360px;
    max-width: 480px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
}

.pv4-dialog-error {
    border-top: 4px solid #ca0a0a;
}

.pv4-dialog-title {
    margin-top: 0;
    margin-bottom: 4px;
    font-size: 16px;
    color: #111;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px;
}

.pv4-dialog-subtitle {
    font-size: 13px;
    font-weight: normal;
    color: #6b7280;
}

.pv4-form-group {
    margin-bottom: 16px;
    padding: 2px;
}

.pv4-form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

.pv4-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

.pv4-input:focus {
    border-color: #3b82f6;
}

.pv4-optional-badge {
    font-weight: normal;
    font-size: 10px;
    color: #9ca3af;
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pv4-radio-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.pv4-radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-weight: normal;
}

.pv4-radio-label input[type="radio"] {
    margin: 0;
}

.pv4-radio-pill {
    border: 1px solid #d1d5db;
    border-radius: 999px;
    padding: 4px 14px;
    font-size: 12px;
    color: #374151;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.pv4-radio-label input[type="radio"]:checked + .pv4-radio-pill {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.pv4-radio-label input[type="radio"]:checked + .pv4-radio-pill.mandatory {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}

.pv4-radio-label input[type="radio"]:checked + .pv4-radio-pill.optional {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.pv4-hint {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 6px;
    margin-bottom: 0;
}

.pv4-dialog-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;             /* always visible — never compressed by taller content */
}

/* ── Connection context menu (floating at click position) ──────── */
.pv4-conn-ctx-menu {
    position: fixed;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,.15);
    min-width: 140px;
    z-index: 100020;
    overflow: hidden;
}

.pv4-ctx-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    color: #374151;
    transition: background 0.12s;
}

.pv4-ctx-item:hover {
    background: #f3f4f6;
}

.pv4-ctx-item-danger {
    color: #ca0a0a;
}

.pv4-ctx-item-danger:hover {
    background: #fef2f2;
}

/* ── Large dialog ──────────────────────────────────────────────── */
.pv4-dialog-large {
    min-width: 1050px;
    max-width: 1250px;
    width: 90vw;
    max-height: 90vh;
    overflow: hidden;           /* outer scroll removed — inner cols scroll instead */
    display: flex;
    flex-direction: column;
}

/* ── Two-column layout ─────────────────────────────────────────── */
.pv4-dialog-cols {
    display: flex;
    gap: 20px;
    flex: 1 1 auto;             /* take remaining height between title and footer */
    min-height: 0;              /* allow flex item to shrink below content size */
    overflow-y: auto;           /* scroll lives here, not on the outer dialog */
}

.pv4-dialog-col-left {
    flex: 0 0 75%;
    max-width: 75%;
    border-right: 1px solid #e5e7eb;
    padding-right: 20px;
    box-sizing: border-box;
    overflow-y: auto;
}

.pv4-dialog-col-right {
    flex: 1;
    min-width: 0;
    padding: 1px;
    overflow-y: auto;
}

/* ── Toggle switch ─────────────────────────────────────────────── */
.pv4-toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    cursor: pointer;
    margin: 0;
    flex-shrink: 0;
}

.pv4-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.pv4-toggle-track {
    position: absolute;
    inset: 0;
    background: #d1d5db;
    border-radius: 999px;
    transition: background 0.2s;
}

.pv4-toggle input:checked ~ .pv4-toggle-track {
    background: #22c55e;
}

.pv4-toggle.disabled .pv4-toggle-track {
    opacity: 0.45;
    cursor: not-allowed;
}

.pv4-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.pv4-toggle input:checked ~ .pv4-toggle-track .pv4-toggle-thumb {
    transform: translateX(18px);
}

/* ── Credential pick list ──────────────────────────────────────── */
.pv4-cred-pick-list {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    max-height: 220px;
    overflow-y: auto;
}

.pv4-cred-pick-item {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.12s;
}

.pv4-cred-pick-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pv4-cred-label-input {
    margin-top: 6px;
    font-size: 12px;
    padding: 4px 8px !important;
    height: auto;
}

.pv4-cred-pick-item:last-child {
    border-bottom: none;
}

.pv4-cred-pick-item.disabled {
    opacity: 0.5;
}

.pv4-cred-pick-item.selected {
    background: #f0fdf4;
}

.pv4-cred-pick-img {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: contain;
    flex-shrink: 0;
}

.pv4-cred-pick-name {
    flex: 1;
    font-size: 13px;
    color: #374151;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── On-canvas badge in dialog list ───────────────────────────── */
.pv4-on-canvas-badge {
    font-size: 10px;
    color: #22c55e;
    flex-shrink: 0;
    margin-right: 4px;
}

/* ── Error message ─────────────────────────────────────────────── */
.pv4-error-msg {
    color: #ca0a0a;
    font-size: 12px;
    margin-top: 6px;
    margin-bottom: 0;
}

/* ── Right panel ───────────────────────────────────────────────── */
.pv4-right-panel-title {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin: 0 0 12px;
}

.pv4-right-conn-item {
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}

.pv4-right-conn-item:hover {
    border-color: #3b82f6;
    background: #eff6ff;
}

.pv4-right-conn-item.active {
    border-color: #2563eb;
    background: #dbeafe;
}

.pv4-conn-type-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.pv4-badge-standard { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }
.pv4-badge-or       { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }
.pv4-badge-and      { background: #fdf4ff; color: #7c3aed; border: 1px solid #e9d5ff; }
.pv4-badge-optional { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }

.pv4-right-conn-cred {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #374151;
    margin-bottom: 4px;
}

.pv4-right-conn-group-targets {
    margin-top: 4px;
}

.pv4-right-conn-label {
    font-size: 11px;
    color: #6b7280;
    font-style: italic;
    display: block;
    margin-bottom: 4px;
}

.pv4-conn-status {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 999px;
}

.status-on  { background: #f0fdf4; color: #16a34a; }
.status-off { background: #f9fafb; color: #9ca3af; }

/* ── Paths Check modal ─────────────────────────────────────────── */
.pv4-paths-dialog {
    min-width: 700px;
    max-width: 1100px;
    width: 85vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    position: fixed;
        top: 0%;
        left: 0%;
}

.pv4-paths-body {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    padding: 4px 2px;
}

.pv4-path-item {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 12px;
    background: #fafafa;
}

.pv4-path-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6b7280;
    margin-bottom: 10px;
}

.pv4-path-steps {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.pv4-path-step-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pv4-path-step {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 12px;
}

.pv4-path-step-info {
    display: flex;
    flex-direction: column;
    max-width: 160px;
}

.pv4-path-step-name {
    font-size: 13px;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pv4-path-step-label {
    font-size: 11px;
    color: #6b7280;
    font-style: italic;
    margin-top: 2px;
}

.pv4-path-arrow {
    color: #9ca3af;
    font-size: 14px;
    flex-shrink: 0;
}

/* ── Logic gate sidebar items ──────────────────────────────────── */
.pv4-logic-gate-section {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.pv4-logic-gate-section-title {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.pv4-logic-gate-items {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.pv4-logic-gate-drag-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: grab;
    user-select: none;
}

.pv4-logic-gate-drag-item:active {
    cursor: grabbing;
}

.pv4-logic-gate-shape {
    width: 54px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.05em;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,.12);
    transition: box-shadow 0.15s, transform 0.12s;
}

.pv4-logic-gate-drag-item:hover .pv4-logic-gate-shape {
    box-shadow: 0 4px 14px rgba(0,0,0,.2);
    transform: translateY(-1px);
}

.pv4-logic-gate-shape-and {
    background: #fdf4ff;
    color: #7c3aed;
    border: 2px solid #d8b4fe;
}

.pv4-logic-gate-shape-or {
    background: #eff6ff;
    color: #2563eb;
    border: 2px solid #93c5fd;
}

.pv4-logic-gate-label {
    font-size: 10px;
    color: #6b7280;
}

/* ── Canvas logic gate node ────────────────────────────────────── */
.pv4-logic-node-body {
    position: relative;
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    transition: box-shadow 0.15s;
}

.pv4-node:hover .pv4-logic-node-body {
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

.pv4-logic-node-body-and {
    background: #fdf4ff;
    border: 3px solid #a855f7;
}

.pv4-logic-node-body-or {
    background: #eff6ff;
    border: 3px solid #3b82f6;
}

.pv4-logic-node-text {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0.05em;
    user-select: none;
}

.pv4-logic-node-text-and { color: #7c3aed; }
.pv4-logic-node-text-or  { color: #2563eb; }
