/* ═══════════════════════════════════════════════
   AGENT COMPOSITION DESIGNER — Canvas + Node Editor
   ═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg-page: hsl(40, 30%, 97%);
    --bg-white: hsl(0, 0%, 100%);
    --bg-warm: hsl(35, 40%, 95%);
    --bg-soft: hsl(30, 20%, 93%);
    --bg-card: hsl(0, 0%, 100%);
    --border: hsl(30, 15%, 88%);
    --border-hover: hsl(30, 20%, 78%);
    --text-0: hsl(220, 20%, 16%);
    --text-1: hsl(220, 10%, 38%);
    --text-2: hsl(220, 8%, 55%);
    --text-3: hsl(220, 6%, 68%);
    --accent: hsl(245, 58%, 56%);
    --accent-light: hsl(245, 58%, 64%);
    --accent-bg: hsl(245, 60%, 96%);
    --accent-border: hsl(245, 50%, 88%);
    --teal: hsl(170, 50%, 45%);
    --amber: hsl(38, 92%, 55%);
    --coral: hsl(12, 80%, 62%);
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius: 10px;
    --radius-lg: 16px;
    --radius-pill: 100px;
    --transition: 200ms ease;
    --shadow-sm: 0 1px 3px hsla(220, 20%, 16%, 0.06);
    --shadow-md: 0 4px 16px hsla(220, 20%, 16%, 0.08);
    --shadow-lg: 0 8px 32px hsla(220, 20%, 16%, 0.1);
    --shadow-btn: 0 2px 8px hsla(245, 58%, 56%, 0.2);

    --node-bg: hsl(0, 0%, 100%);
    --node-border: hsl(30, 15%, 85%);
    --node-selected: hsl(245, 58%, 56%);
    --port-size: 12px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--sans);
    background: var(--bg-page);
    color: var(--text-0);
    min-height: 100vh;
    overflow-x: hidden;
}

.comp-app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.comp-app>#shared-footer {
    margin-top: auto;
}

/* ─── Intro ─── */

.comp-main {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 40px 32px 60px;
}

.comp-intro {
    text-align: center;
    margin-bottom: 28px;
}

.section-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent);
    margin-bottom: 8px;
}

.section-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 12px;
    color: var(--text-0);
}

.section-subtitle {
    font-size: 1rem;
    color: var(--text-2);
    max-width: 520px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ─── Workspace Layout ─── */

.comp-workspace {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 16px;
    min-height: 600px;
}

/* ─── Sidebar ─── */

.comp-sidebar {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.sb-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sb-section:last-child {
    border-bottom: none;
}

.sb-heading {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-2);
    margin-bottom: 12px;
}

.sb-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-2);
    margin: 8px 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sb-label:first-of-type {
    margin-top: 0;
}

.sb-input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-page);
    font-family: var(--sans);
    font-size: 0.8rem;
    color: var(--text-0);
    transition: border-color 200ms ease;
}

.sb-input:focus {
    outline: none;
    border-color: var(--accent);
}

.sb-select {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-page);
    font-family: var(--sans);
    font-size: 0.8rem;
    color: var(--text-0);
    cursor: pointer;
}

.sb-textarea {
    width: 100%;
    min-height: 60px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-page);
    font-family: var(--sans);
    font-size: 0.78rem;
    color: var(--text-0);
    resize: vertical;
    line-height: 1.5;
}

.sb-textarea:focus,
.sb-select:focus {
    outline: none;
    border-color: var(--accent);
}

.sb-add-btn {
    width: 100%;
    font-size: 0.82rem;
}

.sb-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: auto;
}

.sb-action-btn {
    width: 100%;
    font-size: 0.75rem;
    padding: 8px 12px;
    text-align: center;
    justify-content: center;
}

.btn-delete {
    width: 100%;
    padding: 8px 12px;
    margin-top: 12px;
    border: 1px solid hsl(0, 50%, 85%);
    border-radius: 6px;
    background: hsl(0, 60%, 96%);
    color: hsl(0, 60%, 45%);
    font-family: var(--sans);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 200ms ease;
}

.btn-delete:hover {
    background: hsl(0, 60%, 90%);
    border-color: hsl(0, 50%, 70%);
}

/* ─── Pattern Buttons ─── */

.sb-patterns {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pattern-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-page);
    cursor: pointer;
    transition: all 200ms ease;
    text-align: left;
}

.pattern-btn:hover {
    background: var(--accent-bg);
    border-color: var(--accent-border);
    transform: translateY(-1px);
}

.pattern-btn.active {
    background: var(--accent-bg);
    border-color: var(--accent);
}

.pattern-icon {
    font-size: 1.2rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-warm);
    border-radius: 6px;
    flex-shrink: 0;
}

.pattern-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.pattern-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-0);
}

.pattern-desc {
    font-size: 0.66rem;
    color: var(--text-3);
    font-family: var(--mono);
}

/* ─── Canvas ─── */

.comp-canvas-wrap {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-warm);
    border-bottom: 1px solid var(--border);
}

.canvas-status {
    font-family: var(--mono);
    font-size: 0.68rem;
    color: var(--text-2);
}

.canvas-tools {
    display: flex;
    gap: 4px;
}

.tool-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-white);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 200ms ease;
    color: var(--text-1);
}

.tool-btn:hover {
    border-color: var(--accent-border);
    background: var(--accent-bg);
}

.tool-btn.active {
    border-color: var(--accent);
    background: var(--accent-bg);
    color: var(--accent);
}

.comp-canvas {
    position: relative;
    flex: 1;
    min-height: 550px;
    background:
        radial-gradient(circle, hsl(30, 10%, 88%) 1px, transparent 1px);
    background-size: 24px 24px;
    overflow: hidden;
    cursor: default;
}

.comp-canvas svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.comp-canvas svg line {
    pointer-events: stroke;
    cursor: pointer;
}

#nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

/* ─── Empty State ─── */

.canvas-empty {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-3);
    pointer-events: none;
    z-index: 0;
}

.canvas-empty .empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.3;
    animation: float 3s ease-in-out infinite;
}

.canvas-empty p {
    font-size: 0.88rem;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

/* ─── Agent Nodes ─── */

.agent-node {
    position: absolute;
    width: 180px;
    background: var(--node-bg);
    border: 2px solid var(--node-border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    cursor: grab;
    user-select: none;
    transition: box-shadow 200ms ease, border-color 200ms ease;
    z-index: 3;
}

.agent-node:hover {
    box-shadow: var(--shadow-lg);
}

.agent-node.selected {
    border-color: var(--node-selected);
    box-shadow: 0 0 0 3px hsla(245, 58%, 56%, 0.15), var(--shadow-lg);
}

.agent-node.dragging {
    cursor: grabbing;
    box-shadow: 0 12px 40px hsla(220, 20%, 16%, 0.18);
    z-index: 10;
}

.node-header {
    padding: 10px 12px 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.node-icon {
    font-size: 0.9rem;
}

.node-name {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-0);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-body {
    padding: 0 12px 10px;
}

.node-role {
    font-size: 0.68rem;
    color: var(--text-2);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-model {
    font-family: var(--mono);
    font-size: 0.62rem;
    color: var(--teal);
    margin-top: 4px;
    font-weight: 500;
}

/* ─── Ports ─── */

.node-ports {
    display: flex;
    justify-content: space-between;
    padding: 0 0 8px;
    margin: 0 12px;
}

.port {
    width: var(--port-size);
    height: var(--port-size);
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-white);
    cursor: crosshair;
    transition: all 200ms ease;
    position: relative;
}

.port:hover {
    border-color: var(--accent);
    background: var(--accent-bg);
    transform: scale(1.3);
}

.port.input {
    margin-left: -6px;
}

.port.output {
    margin-right: -6px;
}

.port.active {
    border-color: var(--amber);
    background: hsl(38, 90%, 90%);
    animation: portPulse 1s ease infinite;
}

@keyframes portPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 hsla(38, 90%, 55%, 0.4);
    }

    50% {
        box-shadow: 0 0 0 4px hsla(38, 90%, 55%, 0);
    }
}

/* ─── Connection Lines ─── */

#connections-layer .connection-path {
    stroke: var(--accent);
    stroke-width: 2;
    stroke-linecap: round;
    fill: none;
    opacity: 0.5;
    transition: opacity 200ms ease, stroke 200ms ease;
    pointer-events: stroke;
    cursor: pointer;
}

#connections-layer .connection-path:hover {
    opacity: 1;
    stroke-width: 3;
}

/* Temp connection line while dragging */
#temp-connection {
    stroke: var(--accent);
    stroke-width: 2;
    stroke-dasharray: 6 4;
    opacity: 0.5;
    fill: none;
}

/* ─── CTA Bar ─── */

.comp-cta-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-top: 40px;
    padding: 28px 32px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.comp-cta-text p {
    font-size: 0.92rem;
    color: var(--text-1);
}

.comp-cta-text strong {
    color: var(--text-0);
}

.comp-cta-pricing {
    font-size: 0.75rem !important;
    color: var(--teal) !important;
    font-weight: 600;
    margin-top: 6px;
}

/* ─── Buttons ─── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 22px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: var(--shadow-btn);
}

.btn-primary:hover {
    background: var(--accent-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px hsla(245, 58%, 56%, 0.25);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-1);
}

.btn-ghost:hover {
    background: var(--bg-soft);
    border-color: var(--border-hover);
    color: var(--text-0);
}

.btn-lg {
    padding: 14px 28px;
    font-size: 0.88rem;
    border-radius: 12px;
}

/* ─── Toast ─── */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: var(--text-0);
    color: white;
    border-radius: var(--radius);
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 300ms cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 200;
    pointer-events: none;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ─── Responsive ─── */

@media (max-width: 900px) {
    .comp-workspace {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .comp-sidebar {
        order: 2;
    }

    .comp-canvas-wrap {
        min-height: 450px;
    }

    .comp-cta-bar {
        flex-direction: column;
        text-align: center;
        gap: 16px;
    }

    .comp-main {
        padding: 24px 16px 40px;
    }

    .section-title {
        font-size: 1.6rem;
    }
}