/**
 * CompuGoo - Application Styles
 *
 * Layout and application-specific styles.
 * Component styles are in design-system/styles/design-system.css
 */

/* ========== RESET & BASE ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a1a;
    color: #ffffff;
    overflow: hidden;
    height: 100vh;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ========== LOGIN SCREEN ========== */
.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.login-container {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 48px;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.login-logo {
    font-size: 42px;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.login-subtitle {
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    margin-bottom: 32px;
}

.login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 14px 24px;
    background: #fff;
    color: #333;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.login-btn:hover {
    background: #f5f5f5;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.login-btn:active {
    transform: translateY(0);
}

.login-btn svg {
    flex-shrink: 0;
}

.login-note {
    color: rgba(255, 255, 255, 0.4);
    font-size: 12px;
    margin-top: 24px;
}

.login-error {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #fca5a5;
    padding: 12px;
    border-radius: 8px;
    margin-top: 16px;
    font-size: 14px;
}

/* User menu in toolbar */
.user-menu {
    position: relative;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.user-avatar:hover {
    border-color: #667eea;
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    padding: 8px 0;
    min-width: 200px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    display: none;
}

.user-dropdown.open {
    display: block;
}

.user-dropdown-header {
    padding: 12px 16px;
    border-bottom: 1px solid #3a3a3a;
}

.user-dropdown-email {
    font-size: 14px;
    color: #fff;
    word-break: break-all;
}

.user-dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    color: #ccc;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.user-dropdown-item:hover {
    background: #3a3a3a;
    color: #fff;
}

/* ========== TOOLBAR ========== */
.toolbar {
    background: #242424;
    border-bottom: 1px solid #3a3a3a;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 56px;
    flex-shrink: 0;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.project-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
}

.sync-status {
    font-size: 10px;
    transition: color 0.3s;
}

.sync-status.online { color: #4caf50; }
.sync-status.syncing { color: #ff9800; }
.sync-status.offline { color: #757575; }

/* Project Selector Button */
.project-selector-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.9);
    padding: 4px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    transition: all 0.15s;
}

.project-selector-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.project-selector-arrow {
    font-size: 10px;
    opacity: 0.7;
}

/* Project List Styles */
.projects-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.project-list-loading {
    color: rgba(255, 255, 255, 0.5);
    font-style: italic;
    padding: 20px;
    text-align: center;
}

.project-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.project-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

.project-item.current {
    background: rgba(33, 150, 243, 0.15);
    border-color: rgba(33, 150, 243, 0.4);
}

.project-item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.project-item-name {
    font-weight: 500;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-item-meta {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    display: flex;
    gap: 12px;
}

.project-item-role {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 500;
}

.project-item-role.owner {
    background: rgba(33, 150, 243, 0.2);
    color: #64b5f6;
}

.project-item-role.editor {
    background: rgba(76, 175, 80, 0.2);
    color: #81c784;
}

.project-item-role.operator {
    background: rgba(255, 152, 0, 0.2);
    color: #ffb74d;
}

.project-item-role.viewer {
    background: rgba(156, 39, 176, 0.2);
    color: #ba68c8;
}

.project-item-actions {
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.15s;
}

.project-item:hover .project-item-actions {
    opacity: 1;
}

.project-item-action {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.7);
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
}

.project-item-action:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.project-item-action.danger:hover {
    background: rgba(244, 67, 54, 0.3);
    color: #ef5350;
}

.projects-section {
    margin-bottom: 24px;
}

.projects-section h3 {
    margin-bottom: 12px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Collaborators Overlay Styles */
.collaborators-section {
    margin-bottom: 24px;
}

.collaborators-section h3 {
    margin-bottom: 12px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.invite-form {
    display: flex;
    gap: 12px;
    align-items: center;
}

.invite-form .ds-input__field {
    flex: 1;
}

.invite-form .ds-input__select {
    width: 120px;
}

.collaborator-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    margin-bottom: 8px;
}

.collaborator-item:last-child {
    margin-bottom: 0;
}

.collaborator-email {
    flex: 1;
    color: white;
}

.collaborator-role {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 500;
    background: rgba(33, 150, 243, 0.2);
    color: #64b5f6;
    margin-right: 12px;
}

.collaborator-actions {
    display: flex;
    gap: 8px;
}

.collaborator-remove {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    padding: 4px;
    font-size: 16px;
    transition: color 0.15s;
}

.collaborator-remove:hover {
    color: #ef5350;
}

.toolbar-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.15s;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.toolbar-btn.primary {
    background: #2196f3;
    border-color: #1976d2;
}

.toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
}

#zoom-level {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.7);
    min-width: 50px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
}

/* ========== MAIN CONTENT ========== */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative; /* Create stacking context for absolutely positioned tabs and sidebars */
}

/* ========== SIDEBARS ========== */
.sidebar {
    background: #242424;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease; /* Animate sliding in/out */
    position: absolute; /* Don't affect canvas layout */
    top: 0;
    bottom: 0;
    overflow: visible; /* Allow toggle tab to escape sidebar bounds */
    will-change: transform; /* Optimize sidebar animations */
    z-index: 400; /* Above canvas, below tabs */
}

.sidebar-left {
    width: 280px;
    left: 0;
    border-right: 1px solid #3a3a3a;
}

.sidebar-right {
    width: 320px;
    right: 0;
    border-left: 1px solid #3a3a3a;
}

.sidebar.collapsed {
    transform: translateX(-100%); /* Slide off-screen to left */
    pointer-events: none; /* Allow clicks to pass through to canvas */
}

.sidebar-right.collapsed {
    transform: translateX(100%); /* Slide off-screen to right */
    pointer-events: none; /* Allow clicks to pass through to canvas */
}

/* Sidebar Toggle Tab - Positioned absolutely within main-content */
.sidebar-toggle-tab {
    position: absolute;
    top: 80px; /* Near the top */
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    color: rgba(255, 255, 255, 0.7);
    width: 24px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: left 0.3s ease, right 0.3s ease, transform 0.2s ease; /* Explicit ease timing to match sidebars */
    z-index: 500; /* Below notifications (3000) but above canvas elements */
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    will-change: left, right; /* Hint browser to optimize these properties */
}

/* Left toggle */
.sidebar-toggle-left {
    left: 280px; /* Start at right edge of open sidebar (280px) */
    border-left: none;
    border-radius: 0 8px 8px 0;
}

/* Right toggle */
.sidebar-toggle-right {
    right: 320px; /* Start at left edge of open sidebar (320px) */
    border-right: none;
    border-radius: 8px 0 0 8px;
}

/* When left sidebar is COLLAPSED, move toggle to left edge */
.sidebar-left.collapsed ~ .sidebar-toggle-left {
    left: 0; /* Move to left edge when collapsed */
}

/* When left sidebar is OPEN, keep toggle at right edge of sidebar */
.sidebar-left:not(.collapsed) ~ .sidebar-toggle-left {
    left: 280px; /* Stay at right edge of 280px sidebar */
}

/* When right sidebar is COLLAPSED, move toggle to right edge */
.sidebar-right.collapsed ~ .sidebar-toggle-right {
    right: 0; /* Move to right edge when collapsed */
}

/* When right sidebar is OPEN, move toggle to left edge of sidebar */
.sidebar-right:not(.collapsed) ~ .sidebar-toggle-right {
    right: 320px; /* Move to left edge of 320px sidebar */
}

.sidebar-toggle-tab:hover {
    background: #3a3a3a;
    color: white;
    transform: scale(1.05);
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #3a3a3a;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.sidebar-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    line-height: 1;
}

.sidebar-close:hover {
    color: white;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* Custom minimalist scrollbar for sidebars */
.sidebar-content::-webkit-scrollbar {
    width: 8px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 10px;
    transition: background 0.3s ease, opacity 0.3s ease;
}

.sidebar-content:hover::-webkit-scrollbar-thumb {
    background: #3B82F6;
    opacity: 0.6;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: #3B82F6;
    opacity: 1;
}

.sidebar-content::-webkit-scrollbar-thumb:active {
    background: #2563EB;
    opacity: 1;
}

/* Firefox scrollbar styling */
.sidebar-content {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

.sidebar-content:hover {
    scrollbar-color: #3B82F6 transparent;
}

/* ========== LIBRARY ========== */
.search-input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: white;
    font-size: 13px;
    margin-bottom: 16px;
}

.search-input:focus {
    outline: none;
    border-color: #2196f3;
    background: rgba(0, 0, 0, 0.4);
}

.library-category {
    margin-bottom: 16px;
}

.library-category-title {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.library-node {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    padding: 10px 12px;
    margin-bottom: 6px;
    cursor: grab;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.library-node:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(4px);
}

.library-node:active {
    cursor: grabbing;
}

.library-node-icon {
    font-size: 20px;
    line-height: 1;
}

.library-node-info {
    flex: 1;
}

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

.library-node-desc {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
}

/* ========== INSPECTOR ========== */
.inspector-empty {
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
    padding: 32px 16px;
    font-size: 13px;
}

.inspector-section {
    margin-bottom: 20px;
}

.inspector-section label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

/* ========== CANVAS ========== */
.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #1a1a1a;
    /* NO margins - sidebars float over canvas, don't shift it */
}

.canvas-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
}

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

/* Wires SVG - The None-Then-Auto Pattern */
.wires-svg {
    position: absolute;
    inset: 0;
    pointer-events: none;  /* Container transparent - clicks pass through */
    z-index: 1;  /* Below nodes */
    overflow: visible;  /* Allow wires to render outside viewport */
    width: 100%;
    height: 100%;
}

#wires-container {
    pointer-events: stroke;  /* Only wire strokes are clickable */
}

.wire-path {
    fill: none;
    stroke-width: 2;
    stroke: #4a5568;
    transition: stroke 0.15s;
    pointer-events: stroke;
    cursor: pointer;
}

.wire-path:hover {
    stroke-width: 3;
    filter: url(#wire-glow);
}

.wire-path.selected {
    stroke: #2196f3;
    stroke-width: 3;
}

/* Nodes Container */
.nodes-container {
    position: absolute;
    inset: 0;
    transform-origin: 0 0;
    z-index: 2;
    pointer-events: none;  /* Container transparent, individual nodes re-enable */
}

/* Collaborator Cursors */
.cursors-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.collaborator-cursor {
    position: absolute;
    transition: left 0.1s, top 0.1s;
}

.cursor-pointer {
    width: 0;
    height: 0;
    border-left: 8px solid currentColor;
    border-right: 4px solid transparent;
    border-top: 4px solid transparent;
    border-bottom: 8px solid currentColor;
}

.cursor-label {
    position: absolute;
    left: 12px;
    top: 2px;
    background: currentColor;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    white-space: nowrap;
}

/* Canvas Info */
.canvas-info {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    z-index: 5;
}

.canvas-info > div {
    margin-bottom: 4px;
}

.canvas-info > div:last-child {
    margin-bottom: 0;
}

/* ========== GRAPH NODES ========== */
.graph-node {
    position: absolute;
    cursor: move;
    transition: box-shadow 0.15s;
    user-select: none;
    pointer-events: auto;  /* Explicit: nodes are clickable */
    z-index: 1;  /* Establish stacking context - keeps ports relative to their node */
}

.graph-node.selected {
    box-shadow: 0 0 0 2px #2196f3;
    z-index: 100;  /* Bring selected node and ALL its children to front */
}

.graph-node.selecting {
    box-shadow: 0 0 0 2px rgba(99, 189, 245, 0.5);
    z-index: 50;  /* Hover state above normal but below selected */
}

.graph-node.dragging {
    opacity: 0.8;
    z-index: 1000;  /* Dragging node appears above everything */
}

/* Node Ports */
.node-port {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #3a3a3a;
    background: #2a2a2a;
    cursor: crosshair;
    transition: all 0.15s;
    z-index: 10;
    pointer-events: auto;  /* Explicit: ports are clickable */
}

.node-port:hover {
    transform: scale(1.3);
    border-color: #2196f3;
}

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

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

.node-port.connected {
    background: #4caf50;
    border-color: #66bb6a;
}

/* Source port when starting a connection */
.node-port.port-connecting {
    animation: pulse 0.6s ease-in-out infinite;
    box-shadow: 0 0 16px rgba(33, 150, 243, 0.8);
    border-color: #2196f3;
    z-index: 20;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.5); }
}

/* Target ports during wire connection */
.node-port.port-compatible-perfect {
    animation: glow-green 1s ease-in-out infinite;
    border-color: #4caf50;
    box-shadow: 0 0 12px rgba(76, 175, 80, 0.8);
    transform: scale(1.2);
}

.node-port.port-compatible {
    animation: glow-yellow 1s ease-in-out infinite;
    border-color: #ffc107;
    box-shadow: 0 0 10px rgba(255, 193, 7, 0.6);
    transform: scale(1.15);
}

.node-port.port-incompatible {
    border-color: #666;
    opacity: 0.3;
    cursor: not-allowed;
}

@keyframes glow-green {
    0%, 100% { box-shadow: 0 0 8px rgba(76, 175, 80, 0.6); }
    50% { box-shadow: 0 0 16px rgba(76, 175, 80, 1); }
}

@keyframes glow-yellow {
    0%, 100% { box-shadow: 0 0 6px rgba(255, 193, 7, 0.4); }
    50% { box-shadow: 0 0 12px rgba(255, 193, 7, 0.8); }
}

/* Port types */
.node-port[data-type="video"] { background: #1e90ff; }
.node-port[data-type="audio"] { background: #9b59b6; }
.node-port[data-type="event"] { background: #00ff88; }
.node-port[data-type="number"] { background: #ff6b35; }
.node-port[data-type="boolean"] { background: #8a2be2; }

/* Port Labels Layer - Dedicated overlay for all labels */
.port-labels-layer {
    position: absolute;
    inset: 0;  /* Cover entire node */
    pointer-events: none;  /* Transparent to clicks */
    z-index: 100;  /* Always on top of node content */
}

/* Port Labels */
.port-label {
    position: absolute;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    pointer-events: none;
    /* Dark halo for contrast against any background */
    text-shadow:
        -1px -1px 2px rgba(0, 0, 0, 0.8),
        1px -1px 2px rgba(0, 0, 0, 0.8),
        -1px 1px 2px rgba(0, 0, 0, 0.8),
        1px 1px 2px rgba(0, 0, 0, 0.8),
        0 0 4px rgba(0, 0, 0, 0.9);
}

.port-label.input {
    left: 18px;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.port-label.output {
    right: 18px;
    text-align: right;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========== OVERLAYS ========== */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.overlay.active {
    display: flex;
}

.overlay-content {
    background: #242424;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.overlay-header {
    padding: 16px 20px;
    border-bottom: 1px solid #3a3a3a;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.overlay-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.overlay-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 32px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 1;
}

.overlay-close:hover {
    color: white;
}

.overlay-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.overlay-footer {
    padding: 16px 20px;
    border-top: 1px solid #3a3a3a;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ========== TOUCH PANEL ========== */
.touch-panel-container {
    width: 90vw;
    height: 90vh;
}

.view-selector {
    display: flex;
    gap: 12px;
    align-items: center;
}

.view-selector select {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
}

.touch-panel-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    border-radius: 4px;
    overflow: hidden;
}

.touch-panel-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
}

#touch-panel-elements {
    position: absolute;
    inset: 0;
}

.touch-panel-element {
    position: absolute;
    background: rgba(42, 42, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    padding: 12px;
    cursor: move;
    transition: box-shadow 0.15s;
}

.touch-panel-element:hover {
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.5);
}

.touch-panel-element.selected {
    box-shadow: 0 0 0 2px #2196f3;
}

/* Touch panel container in edit mode - support absolute positioning */
#touch-panel-container.edit-mode {
    position: relative;
    min-height: 2000px;
    min-width: 2000px;
}

/* Drag handle bar (only visible in edit mode) */
.touch-panel-drag-handle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.8), rgba(99, 102, 241, 0.8));
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    cursor: move !important;
    user-select: none;
    position: relative;
    z-index: 10;
    border-radius: 8px 8px 0 0;
    margin: -1px -1px 0 -1px; /* Extend to edges */
    flex-shrink: 0; /* Don't shrink if container is too small */
}

.touch-panel-drag-handle:hover {
    background: linear-gradient(135deg, rgba(79, 150, 255, 0.9), rgba(119, 122, 255, 0.9));
}

.touch-panel-drag-handle:active {
    cursor: grabbing !important;
}

.drag-handle-icon {
    font-size: 16px;
}

.drag-handle-title {
    flex: 1;
    font-weight: 600;
    font-size: 13px;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.drag-handle-grip {
    font-size: 16px;
    opacity: 0.7;
    letter-spacing: -2px;
    color: white;
}

/* Nodes with drag handles use flex layout to prevent content cutoff */
.touch-panel-node.has-drag-handle {
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden;
}

/* Content area fills remaining space after drag handle */
.touch-panel-node.has-drag-handle > *:not(.touch-panel-drag-handle) {
    flex: 1;
    min-height: 0; /* Allow content to shrink if needed */
    overflow: auto; /* Add scroll if content is too large */
}

/* Adjust node content to account for drag handle */
#touch-panel-container.edit-mode .touch-panel-node {
    padding-top: 0; /* Remove top padding since handle provides it */
}

/* Draggable elements */
.touch-panel-node.draggable {
    cursor: move !important;
    transition: box-shadow 0.2s ease;
}

.touch-panel-node.draggable:hover {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
}

/* Dragging state */
.touch-panel-node.dragging {
    opacity: 0.8;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    z-index: 1000;
    cursor: grabbing !important;
    transition: none;
}

/* Resizable elements */
.touch-panel-node.resizable {
    position: relative;
}

/* Resize handles */
.resize-handle {
    position: absolute;
    background: rgba(59, 130, 246, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.3);
    z-index: 100;
    transition: background 0.2s ease;
}

.resize-handle:hover {
    background: rgba(99, 179, 255, 1);
}

/* Corner handles */
.resize-handle-se {
    bottom: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    cursor: se-resize;
    border-radius: 0 0 4px 0;
}

.resize-handle-sw {
    bottom: -4px;
    left: -4px;
    width: 12px;
    height: 12px;
    cursor: sw-resize;
    border-radius: 0 0 0 4px;
}

.resize-handle-ne {
    top: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    cursor: ne-resize;
    border-radius: 0 4px 0 0;
}

.resize-handle-nw {
    top: -4px;
    left: -4px;
    width: 12px;
    height: 12px;
    cursor: nw-resize;
    border-radius: 4px 0 0 0;
}

/* Edge handles */
.resize-handle-n {
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 8px;
    cursor: n-resize;
    border-radius: 4px 4px 0 0;
}

.resize-handle-s {
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 8px;
    cursor: s-resize;
    border-radius: 0 0 4px 4px;
}

.resize-handle-e {
    top: 50%;
    right: -4px;
    transform: translateY(-50%);
    width: 8px;
    height: 40px;
    cursor: e-resize;
    border-radius: 0 4px 4px 0;
}

.resize-handle-w {
    top: 50%;
    left: -4px;
    transform: translateY(-50%);
    width: 8px;
    height: 40px;
    cursor: w-resize;
    border-radius: 4px 0 0 4px;
}

/* Resizing state */
.touch-panel-node.resizing {
    opacity: 0.9;
    box-shadow: 0 8px 32px rgba(59, 130, 246, 0.4);
    z-index: 1000;
    transition: none;
}

.touch-panel-node.resizing .resize-handle {
    background: rgba(99, 179, 255, 1);
}

/* ========== NODE INSPECTOR ========== */

.touch-panel-node-inspector {
    position: fixed;
    background: rgba(25, 25, 35, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
    width: 280px;
    z-index: 10000;
    backdrop-filter: blur(10px);
    animation: inspectorSlideIn 0.2s ease-out;
}

@keyframes inspectorSlideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.inspector-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(99, 102, 241, 0.2));
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px 12px 0 0;
}

.inspector-icon {
    font-size: 20px;
}

.inspector-title {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
    color: white;
}

.inspector-close {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.inspector-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.inspector-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 500px;
    overflow-y: auto;
}

.inspector-section h4 {
    margin: 0 0 10px 0;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.6;
    font-weight: 600;
}

.inspector-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease;
    user-select: none;
}

.inspector-checkbox:hover {
    background: rgba(255, 255, 255, 0.05);
}

.inspector-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #3b82f6;
}

.inspector-checkbox span {
    flex: 1;
    font-size: 14px;
}

/* Element items in inspector */
.inspector-element-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    margin-bottom: 8px;
    gap: 12px;
}

.inspector-element-label {
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    flex-shrink: 0;
}

.inspector-element-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.inspector-element-btn {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: rgba(255, 255, 255, 0.9);
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.inspector-element-btn:hover {
    background: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.5);
}

.inspector-element-btn.primary {
    background: rgba(34, 197, 94, 0.15);
    border-color: rgba(34, 197, 94, 0.3);
}

.inspector-element-btn.primary:hover {
    background: rgba(34, 197, 94, 0.25);
    border-color: rgba(34, 197, 94, 0.5);
}

.inspector-element-btn.secondary {
    background: rgba(100, 100, 100, 0.15);
    border-color: rgba(150, 150, 150, 0.3);
}

.inspector-element-btn.secondary:hover {
    background: rgba(100, 100, 100, 0.25);
    border-color: rgba(150, 150, 150, 0.5);
}

.inspector-action-btn {
    width: 100%;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    margin-bottom: 6px;
}

.inspector-action-btn:last-child {
    margin-bottom: 0;
}

.inspector-action-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
}

.inspector-action-btn:active {
    transform: scale(0.98);
}

/* Color picker rows in inspector */
.inspector-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.inspector-color-reset {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: all 0.2s ease;
}

.inspector-color-reset:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
}

/* ========== SPLIT ELEMENTS ========== */

/* Split elements look like normal nodes when NOT in edit mode */
.touch-panel-split-element {
    /* Default styling matches regular nodes */
}

/* Purple outline and special styling ONLY in edit mode */
.edit-mode .touch-panel-split-element {
    border: 2px solid rgba(147, 51, 234, 0.5) !important;
    background: rgba(15, 15, 25, 0.95) !important;
}

/* Split element header - subtle in normal mode, purple gradient in edit mode */
.split-element-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    cursor: default;
    user-select: none;
}

/* Purple gradient header ONLY in edit mode */
.edit-mode .split-element-header {
    background: linear-gradient(135deg, rgba(147, 51, 234, 0.3), rgba(168, 85, 247, 0.3));
    cursor: move;
}

.split-element-label {
    font-size: 13px;
    font-weight: 600;
    color: white;
    flex: 1;
}

/* Hide delete button when NOT in edit mode */
.split-element-delete {
    display: none;
}

/* Show delete button ONLY in edit mode */
.edit-mode .split-element-delete {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: rgba(239, 68, 68, 1);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    padding: 0;
    transition: all 0.2s ease;
}

.split-element-delete:hover {
    background: rgba(239, 68, 68, 0.4);
    border-color: rgba(239, 68, 68, 0.6);
}

.split-element-content {
    padding: 12px;
    overflow: auto;
    height: calc(100% - 41px); /* Subtract header height */
}

/* ========== SHARED CONTROLS ========== */

/* Base shared control styles */
.shared-control {
    margin-bottom: 16px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.control-label {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    display: block;
    margin-bottom: 6px;
}

.control-value {
    font-size: 12px;
    font-weight: 600;
    color: rgba(100, 150, 255, 1);
    background: rgba(100, 150, 255, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
}

/* Slider control */
.shared-control-slider {
    display: flex;
    flex-direction: column;
}

.control-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    -webkit-appearance: none;
}

.control-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(100, 150, 255, 1);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.control-slider::-webkit-slider-thumb:hover {
    background: rgba(120, 170, 255, 1);
    transform: scale(1.1);
}

.control-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(100, 150, 255, 1);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.control-slider::-moz-range-thumb:hover {
    background: rgba(120, 170, 255, 1);
    transform: scale(1.1);
}

/* Button control */
.shared-control-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: rgba(100, 150, 255, 0.2);
    border: 1px solid rgba(100, 150, 255, 0.4);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.shared-control-button:hover {
    background: rgba(100, 150, 255, 0.3);
    border-color: rgba(100, 150, 255, 0.6);
    transform: translateY(-1px);
}

.shared-control-button:active {
    transform: translateY(0);
}

.shared-control-button--primary {
    background: rgba(100, 150, 255, 1);
    border-color: rgba(100, 150, 255, 1);
}

.shared-control-button--primary:hover {
    background: rgba(120, 170, 255, 1);
    border-color: rgba(120, 170, 255, 1);
}

.shared-control-button--danger {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
}

.shared-control-button--danger:hover {
    background: rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.6);
}

.button-icon {
    font-size: 18px;
}

.button-label {
    font-size: 14px;
}

/* Trigger button (large) */
.shared-control-trigger {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px;
    background: linear-gradient(135deg, rgba(100, 150, 255, 0.2), rgba(100, 200, 255, 0.2));
    border: 2px solid rgba(100, 150, 255, 0.4);
    border-radius: 16px;
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    width: 100%;
}

.shared-control-trigger:hover {
    background: linear-gradient(135deg, rgba(100, 150, 255, 0.3), rgba(100, 200, 255, 0.3));
    border-color: rgba(100, 150, 255, 0.6);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(100, 150, 255, 0.3);
}

.shared-control-trigger:active,
.shared-control-trigger.triggering {
    transform: scale(0.95);
    background: linear-gradient(135deg, rgba(100, 150, 255, 0.4), rgba(100, 200, 255, 0.4));
}

.trigger-icon {
    font-size: 48px;
}

.trigger-label {
    font-size: 18px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Toggle control */
.shared-control-toggle {
    display: flex;
    align-items: center;
}

.toggle-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    cursor: pointer;
    user-select: none;
}

.toggle-label {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
}

.toggle-input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 48px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    transition: background 0.3s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    top: 3px;
    left: 3px;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-input:checked + .toggle-slider {
    background: rgba(100, 150, 255, 1);
}

.toggle-input:checked + .toggle-slider::before {
    transform: translateX(24px);
}

/* Dropdown control */
.shared-control-dropdown {
    display: flex;
    flex-direction: column;
}

.control-select {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
}

.control-select:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(100, 150, 255, 0.5);
}

.control-select:focus {
    border-color: rgba(100, 150, 255, 1);
}

/* Color picker control */
.shared-control-color {
    display: flex;
    flex-direction: column;
}

.color-picker-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-color-input {
    width: 60px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    cursor: pointer;
    background: transparent;
}

.color-value {
    font-size: 13px;
    font-family: monospace;
    color: rgba(255, 255, 255, 0.7);
}

/* Number input control */
.shared-control-number {
    display: flex;
    flex-direction: column;
}

.control-number-input {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.control-number-input:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(100, 150, 255, 0.5);
}

.control-number-input:focus {
    border-color: rgba(100, 150, 255, 1);
}

/* Text input control */
.shared-control-text {
    display: flex;
    flex-direction: column;
}

.control-text-input {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.control-text-input:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(100, 150, 255, 0.5);
}

.control-text-input:focus {
    border-color: rgba(100, 150, 255, 1);
}

/* Joystick control */
.shared-control-joystick-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.joystick-wrapper {
    position: relative;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 12px;
}

.joystick-wrapper::before {
    content: '';
    position: absolute;
    width: 4px;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    left: 50%;
    transform: translateX(-50%);
}

.joystick-wrapper::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    top: 50%;
    transform: translateY(-50%);
}

.joystick-handle {
    position: absolute;
    width: 40px;
    height: 40px;
    background: rgba(100, 150, 255, 1);
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: grab;
    transition: transform 0.1s ease-out;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.joystick-handle:active {
    cursor: grabbing;
    background: rgba(120, 170, 255, 1);
}

/* ========== COLLABORATORS ========== */
.invite-form {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.invite-form input,
.invite-form select {
    flex: 1;
}

.collaborators-section {
    margin-bottom: 24px;
}

.collaborators-section h3 {
    font-size: 14px;
    margin-bottom: 12px;
}

.collaborator-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    margin-bottom: 6px;
}

.collaborator-email {
    font-size: 13px;
}

.collaborator-role {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ========== CONTEXT MENU ========== */
.context-menu {
    position: fixed;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    padding: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: none;
    z-index: 2000;
}

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

.context-menu-item {
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.15s;
}

.context-menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.context-menu-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 4px 0;
}

/* ========== NOTIFICATIONS ========== */
.notification-container {
    position: fixed;
    top: 72px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.notification {
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    padding: 12px 16px;
    min-width: 300px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.notification-icon {
    font-size: 20px;
}

.notification-content {
    flex: 1;
}

.notification-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 2px;
}

.notification-message {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
}

.notification-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 18px;
    cursor: pointer;
    padding: 0;
}

.notification-close:hover {
    color: white;
}

.notification.success { border-left: 3px solid #4caf50; }
.notification.error { border-left: 3px solid #f44336; }
.notification.warning { border-left: 3px solid #ff9800; }
.notification.info { border-left: 3px solid #2196f3; }

/* ========== WIRES ========== */
/* Minimal CSS - inline styles take precedence */
.wire {
    fill: none;
    stroke: rgba(99, 189, 245, 0.8);
    stroke-width: 8;  /* Default thick for clicking */
    pointer-events: stroke;  /* Clickable on stroke */
    cursor: pointer;
    opacity: 1;
    transition: stroke-width 0.15s, filter 0.15s;
}

.wire.selected {
    stroke: #ffff00;
    stroke-width: 10;
    filter: drop-shadow(0 0 12px rgba(255, 255, 0, 0.8));
}

.wire.temp-wire {
    stroke: rgba(255, 255, 255, 0.5);
    stroke-width: 2;
    stroke-dasharray: 5, 5;
    pointer-events: none;  /* Temp wires not clickable */
}

/* ========== LIBRARY ========== */
.library-category {
    margin-bottom: 24px;
}

.library-category-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 8px;
}

.library-node-item {
    display: flex;
    gap: 12px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: grab;
    transition: all 0.15s;
}

.library-node-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateX(2px);
}

.library-node-item.library-item-selected {
    background: rgba(33, 150, 243, 0.2);
    border-color: rgba(33, 150, 243, 0.5);
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.3);
    transform: translateX(4px);
}

.library-node-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.library-node-icon {
    font-size: 24px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    flex-shrink: 0;
}

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

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

.library-node-desc {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ========== INSPECTOR ========== */
.inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    margin-bottom: 16px;
}

.inspector-title-section {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.inspector-icon {
    font-size: 32px;
}

.inspector-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.inspector-quick-actions {
    display: flex;
    gap: 6px;
}

.inspector-quick-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 18px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.inspector-quick-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.inspector-quick-btn:active {
    transform: translateY(0);
}

.inspector-quick-btn.danger:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
}

.inspector-section {
    margin-bottom: 20px;
}

.inspector-section-header {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 12px;
}

.inspector-section-header.collapsible {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-left: 20px;
}

.inspector-section-header.collapsible::before {
    content: '▼';
    position: absolute;
    left: 0;
    font-size: 10px;
    transition: transform 0.2s ease;
    opacity: 0.6;
}

.inspector-section.collapsed .inspector-section-header.collapsible::before {
    transform: rotate(-90deg);
}

.inspector-section-header.collapsible:hover {
    color: rgba(255, 255, 255, 0.8);
}

.inspector-section-header.collapsible:hover::before {
    opacity: 1;
}

.inspector-section.collapsed > *:not(.inspector-section-header) {
    display: none;
}

.inspector-value {
    font-size: 13px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.9);
}

.inspector-value.mono {
    font-family: 'Courier New', monospace;
    font-size: 11px;
}

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

.inspector-property label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 6px;
}

.inspector-input {
    width: 100%;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: white;
    font-size: 13px;
}

.inspector-input:focus {
    outline: none;
    border-color: #2196f3;
    background: rgba(0, 0, 0, 0.4);
}

.inspector-input[type="checkbox"] {
    width: auto;
}

.inspector-description {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 4px;
}

.inspector-data-editor {
    width: 100%;
    padding: 8px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: white;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    resize: vertical;
}

.inspector-data-editor:focus {
    outline: none;
    border-color: #2196f3;
}

.inspector-data-editor.error {
    border-color: #f44336;
}

.inspector-button {
    width: 100%;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 8px;
}

.inspector-button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.inspector-button.danger {
    background: rgba(244, 67, 54, 0.1);
    border-color: rgba(244, 67, 54, 0.3);
    color: #f44336;
}

.inspector-button.danger:hover {
    background: rgba(244, 67, 54, 0.2);
}

.inspector-empty {
    text-align: center;
    padding: 60px 20px;
    color: rgba(255, 255, 255, 0.4);
}

/* ========== TOUCH PANEL ========== */
.touch-panel-layout-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding: 20px;
    align-items: start;
}

.touch-panel-layout-free {
    position: relative;
    padding: 20px;
}

.touch-panel-node {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

/* Size-specific grid placement for larger nodes */
.touch-panel-node--large {
    grid-column: span 2;
}

.touch-panel-node--xlarge {
    grid-column: span 2;
}

/* Make node shells fill their containers in touch panel */
.touch-panel-node .node-shell {
    width: 100% !important;
    max-width: 100%;
    box-sizing: border-box;
}

/* Remove fixed widths from graph nodes in touch panel */
.touch-panel-node .graph-node {
    width: 100% !important;
    position: relative !important;
    left: auto !important;
    top: auto !important;
}

.touch-panel-empty {
    text-align: center;
    padding: 100px 20px;
    color: rgba(255, 255, 255, 0.4);
}

/* ========== UTILITIES ========== */
.hidden {
    display: none !important;
}

.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* ========== MODEL MANAGER MODAL ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
}

.modal-container {
    background: #1e1e1e;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.show .modal-container {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    background: #2a2a2a;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.modal-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    color: rgba(255, 255, 255, 0.9);
}

.modal-footer {
    padding: 16px 24px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.modal-btn.primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.modal-btn.primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.modal-btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.modal-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.modal-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.library-item {
    position: relative;
}

.library-item:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}


/* ========== ROLE-BASED UI RESTRICTIONS ========== */

/* Viewer role - disable all interactions */
body.role-viewer .touch-panel-container {
    pointer-events: none;
}

body.role-viewer .touch-panel-node button,
body.role-viewer .touch-panel-node input,
body.role-viewer .touch-panel-node select,
body.role-viewer .touch-panel-node textarea {
    pointer-events: none;
    opacity: 0.7;
}

body.role-viewer .touch-panel-drag-handle,
body.role-viewer .resize-handle {
    display: none !important;
}

/* Operator role - can interact with touch panel but not edit */
body.role-operator .touch-panel-drag-handle,
body.role-operator .resize-handle {
    display: none !important;
}

body.role-operator #touch-panel-edit-mode,
body.role-operator #add-touch-panel-view,
body.role-operator #duplicate-touch-panel-view,
body.role-operator #rename-touch-panel-view,
body.role-operator #delete-touch-panel-view {
    display: none !important;
}

/* Role indicator badge */
.role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    margin-left: 8px;
}

.role-badge.owner {
    background: rgba(76, 175, 80, 0.2);
    color: #81c784;
}

.role-badge.editor {
    background: rgba(33, 150, 243, 0.2);
    color: #64b5f6;
}

.role-badge.operator {
    background: rgba(255, 152, 0, 0.2);
    color: #ffb74d;
}

.role-badge.viewer {
    background: rgba(158, 158, 158, 0.2);
    color: #bdbdbd;
}
