/**
 * Designer Module Styles
 * Visual dialog builder with node-based workflow design
 */

:root {
    --bg-primary: #1e1e2e;
    --bg-secondary: #181825;
    --bg-tertiary: #313244;
    --text-primary: #cdd6f4;
    --text-secondary: #a6adc8;
    --accent-blue: #89b4fa;
    --accent-green: #a6e3a1;
    --accent-yellow: #f9e2af;
    --accent-red: #f38ba8;
    --accent-purple: #cba6f7;
    --accent-teal: #94e2d5;
    --border-color: #45475a;
    --node-talk: #89b4fa;
    --node-hear: #a6e3a1;
    --node-set: #f9e2af;
    --node-if: #cba6f7;
    --node-for: #f38ba8;
    --node-call: #94e2d5;
    --node-send: #fab387;
    --grid-size: 20px;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.designer-container {
    display: grid;
    grid-template-columns: 240px 1fr 280px;
    grid-template-rows: 48px 1fr 32px;
    height: 100vh;
}

/* Header */
.designer-header {
    grid-column: 1 / -1;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
}

.designer-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--accent-blue);
}

.designer-logo svg {
    width: 24px;
    height: 24px;
}

.designer-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.toolbar-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    transition: all 0.15s;
}

.toolbar-btn:hover {
    background: var(--border-color);
}

.toolbar-btn.primary {
    background: var(--accent-blue);
    color: var(--bg-primary);
    border-color: var(--accent-blue);
}

.toolbar-btn.primary:hover {
    background: #7aa8f0;
}

.toolbar-btn svg {
    width: 16px;
    height: 16px;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 8px;
}

/* Toolbox Panel */
.toolbox-panel {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 12px;
}

.toolbox-section {
    margin-bottom: 16px;
}

.toolbox-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding: 0 4px;
}

.toolbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: grab;
    transition: all 0.15s;
    margin-bottom: 4px;
    border: 1px solid transparent;
}

.toolbox-item:hover {
    background: var(--bg-tertiary);
}

.toolbox-item:active {
    cursor: grabbing;
}

.toolbox-item.dragging {
    opacity: 0.5;
}

.toolbox-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--bg-primary);
}

.toolbox-icon.talk { background: var(--node-talk); }
.toolbox-icon.hear { background: var(--node-hear); }
.toolbox-icon.set { background: var(--node-set); }
.toolbox-icon.if { background: var(--node-if); }
.toolbox-icon.for { background: var(--node-for); }
.toolbox-icon.call { background: var(--node-call); }
.toolbox-icon.send { background: var(--node-send); }
.toolbox-icon.get { background: #74c7ec; }
.toolbox-icon.wait { background: #f5c2e7; }
.toolbox-icon.switch { background: #b4befe; }

.toolbox-info {
    flex: 1;
    min-width: 0;
}

.toolbox-name {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 2px;
}

.toolbox-desc {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Canvas Area */
.canvas-container {
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
}

.canvas-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(var(--border-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--border-color) 1px, transparent 1px);
    background-size: var(--grid-size) var(--grid-size);
    opacity: 0.3;
}

.canvas {
    position: absolute;
    inset: 0;
    overflow: auto;
}

.canvas-inner {
    position: relative;
    width: 3000px;
    height: 2000px;
    min-width: 100%;
    min-height: 100%;
}

/* Nodes */
.node {
    position: absolute;
    min-width: 180px;
    max-width: 280px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: move;
    user-select: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: box-shadow 0.15s, border-color 0.15s;
}

.node:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.node.selected {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(137, 180, 250, 0.3);
}

.node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px 6px 0 0;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.node-header.talk { background: var(--node-talk); color: var(--bg-primary); }
.node-header.hear { background: var(--node-hear); color: var(--bg-primary); }
.node-header.set { background: var(--node-set); color: var(--bg-primary); }
.node-header.if { background: var(--node-if); color: var(--bg-primary); }
.node-header.for { background: var(--node-for); color: var(--bg-primary); }
.node-header.call { background: var(--node-call); color: var(--bg-primary); }
.node-header.send { background: var(--node-send); color: var(--bg-primary); }
.node-header.get { background: #74c7ec; color: var(--bg-primary); }
.node-header.wait { background: #f5c2e7; color: var(--bg-primary); }
.node-header.switch { background: #b4befe; color: var(--bg-primary); }

.node-header svg {
    width: 14px;
    height: 14px;
}

.node-body {
    padding: 12px;
}

.node-field {
    margin-bottom: 8px;
}

.node-field:last-child {
    margin-bottom: 0;
}

.node-field-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.node-field-input {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 6px 8px;
    color: var(--text-primary);
    font-size: 12px;
    font-family: 'Consolas', 'Monaco', monospace;
}

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

.node-field-select {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 6px 8px;
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
}

/* Connection Ports */
.node-port {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    cursor: crosshair;
    transition: all 0.15s;
}

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

.node-port.input {
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
}

.node-port.output {
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
}

.node-port.output-true {
    right: -6px;
    top: 35%;
    background: var(--accent-green);
    border-color: var(--accent-green);
}

.node-port.output-false {
    right: -6px;
    top: 65%;
    background: var(--accent-red);
    border-color: var(--accent-red);
}

/* Connections SVG */
.connections-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: visible;
}

.connection {
    fill: none;
    stroke: var(--border-color);
    stroke-width: 2;
    pointer-events: stroke;
    cursor: pointer;
}

.connection:hover {
    stroke: var(--accent-blue);
    stroke-width: 3;
}

.connection.drawing {
    stroke: var(--accent-blue);
    stroke-dasharray: 5, 5;
}

/* Properties Panel */
.properties-panel {
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
}

.properties-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.properties-header svg {
    width: 16px;
    height: 16px;
    color: var(--accent-blue);
}

.properties-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.properties-content {
    padding: 16px;
}

.property-group {
    margin-bottom: 16px;
}

.property-group-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.property-field {
    margin-bottom: 12px;
}

.property-label {
    font-size: 12px;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.property-input {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 8px 10px;
    color: var(--text-primary);
    font-size: 13px;
}

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

.property-textarea {
    min-height: 80px;
    resize: vertical;
    font-family: 'Consolas', 'Monaco', monospace;
}

.property-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}

.property-checkbox input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-blue);
}

/* Status Bar */
.status-bar {
    grid-column: 1 / -1;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 12px;
    color: var(--text-secondary);
    gap: 16px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-item svg {
    width: 14px;
    height: 14px;
}

.status-spacer {
    flex: 1;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.zoom-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.zoom-btn:hover {
    background: var(--border-color);
}

.zoom-value {
    min-width: 40px;
    text-align: center;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px;
    min-width: 160px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: none;
}

.context-menu.visible {
    display: block;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.context-menu-item:hover {
    background: var(--bg-tertiary);
}

.context-menu-item.danger {
    color: var(--accent-red);
}

.context-menu-separator {
    height: 1px;
    background: var(--border-color);
    margin: 4px 8px;
}

/* File Browser Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.visible {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-weight: 600;
    font-size: 16px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: 400px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.file-item:hover {
    background: var(--bg-tertiary);
}

.file-item.selected {
    background: var(--accent-blue);
    color: var(--bg-primary);
}

.file-icon {
    width: 20px;
    height: 20px;
}

.file-name {
    flex: 1;
    font-size: 14px;
}

.file-path {
    font-size: 11px;
    color: var(--text-secondary);
}

.file-item.selected .file-path {
    color: var(--bg-tertiary);
}

/* HTMX indicators */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Minimap */
.minimap {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 160px;
    height: 100px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    opacity: 0.9;
}

.minimap-viewport {
    position: absolute;
    border: 1px solid var(--accent-blue);
    background: rgba(137, 180, 250, 0.1);
}

.minimap-node {
    position: absolute;
    background: var(--accent-blue);
    border-radius: 1px;
}
