/* OTUI Editor is licensed for **personal, non-commercial use only**.
Commercial use, resale, or closed-source redistribution is strictly prohibited.
Contributions are welcome via pull requests. */


:root {
    --primary: #3b82f6;
    --accent: #10b981;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-code: #1a1a1a;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --border-primary: #334155;
    --border-light: #475569;
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --font-mono: 'Courier New', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* HEADER */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, rgba(30, 41, 59, 0.95) 100%);
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
    backdrop-filter: blur(10px);
    z-index: 100;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-left, .header-center, .header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.15rem;
}

.logo-icon {
    background: linear-gradient(135deg, var(--primary) 0%, #2563eb 100%);
    color: white;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-md);
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.logo-icon:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.project-info {
    margin-left: 2rem;
}

.project-name {
    font-weight: 600;
    color: var(--text-secondary);
}

/* BUTTONS */
.btn {
    padding: 0.6rem 1.2rem;
    border: 1px solid rgba(51, 65, 85, 0.6);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.8) 0%, rgba(30, 41, 59, 0.9) 100%);
    color: var(--text-primary);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(8px);
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
    transition: left 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:hover::before {
    left: 100%;
}

.btn:hover {
    background: linear-gradient(135deg, rgba(71, 85, 105, 0.9) 0%, rgba(51, 65, 85, 0.95) 100%);
    border-color: rgba(71, 85, 105, 0.8);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: all 0.1s ease;
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-sm {
    padding: 0.5rem 0.9rem;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent) 0%, #059669 100%);
    color: white;
    border-color: rgba(16, 185, 129, 0.5);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-accent:hover {
    background: linear-gradient(135deg, #14d99f 0%, var(--accent) 100%);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    border-color: rgba(20, 217, 159, 0.6);
    transform: translateY(-2px) scale(1.02);
}

.btn-accent:active {
    transform: translateY(0) scale(1);
}

.btn-secondary {
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.7) 0%, rgba(30, 41, 59, 0.8) 100%);
    color: var(--text-primary);
    border-color: rgba(51, 65, 85, 0.5);
    backdrop-filter: blur(8px);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, rgba(71, 85, 105, 0.8) 0%, rgba(51, 65, 85, 0.9) 100%);
    border-color: rgba(71, 85, 105, 0.7);
}

.btn-icon-only {
    background: transparent;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.btn-icon-only:hover {
    background: var(--bg-tertiary);
    color: white;
}

/* BODY */
.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-width: 0; /* Allow flex items to shrink below their content size */
    min-height: 0; /* Allow flex items to shrink below their content size */
}

/* SIDEBARS */
.sidebar {
    width: 260px;
    min-width: 200px;
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.98) 100%);
    border-right: 1px solid rgba(51, 65, 85, 0.4);
    display: flex;
    flex-direction: column;
    flex-shrink: 1;
    flex-grow: 0;
    backdrop-filter: blur(10px);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    min-height: 0;
    height: 100%;
}

.sidebar-right {
    border-right: none;
    border-left: 1px solid rgba(51, 65, 85, 0.4);
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    min-width: 200px;
    /* No max-width constraint - allow fluid expansion */
    /* flex-shrink: 1 allows it to shrink when needed */
}

/* Resize handle for right sidebar */
.sidebar-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    cursor: col-resize;
    background: transparent;
    z-index: 10;
    transition: background 0.2s ease;
}

.sidebar-resize-handle:hover {
    background: var(--primary);
    opacity: 0.6;
}

.sidebar-resize-handle:active {
    background: var(--primary);
    opacity: 1;
}

.sidebar-header {
    padding: 0.85rem 1rem;
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.6) 0%, rgba(30, 41, 59, 0.8) 100%);
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: blur(8px);
    transition: background 0.3s ease;
    flex-shrink: 0;
}

.sidebar-header:hover {
    background: linear-gradient(135deg, rgba(71, 85, 105, 0.7) 0%, rgba(51, 65, 85, 0.9) 100%);
}

.sidebar-content {
    flex: 1 1 0%;
    overflow-y: auto !important;
    overflow-x: hidden;
    padding: 0.75rem;
    min-height: 0;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

/* WORKSPACE */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-width: 0; /* Allow workspace to shrink when sidebar expands */
    overflow: hidden;
}

.workspace-toolbar {
    padding: 0.65rem 1.2rem;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.98) 100%);
    border-bottom: 1px solid rgba(51, 65, 85, 0.4);
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-shrink: 0;
    z-index: 90;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.toolbar-separator {
    width: 1px;
    height: 28px;
    background: linear-gradient(180deg, transparent, rgba(51, 65, 85, 0.6), transparent);
    margin: 0 0.25rem;
}

.zoom-level {
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.7) 0%, rgba(30, 41, 59, 0.8) 100%);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    min-width: 60px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid rgba(51, 65, 85, 0.4);
    backdrop-filter: blur(8px);
    transition: all 0.3s ease;
}

.zoom-level:hover {
    background: linear-gradient(135deg, rgba(71, 85, 105, 0.8) 0%, rgba(51, 65, 85, 0.9) 100%);
    border-color: rgba(71, 85, 105, 0.6);
}

/* CANVAS */
.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #111;
}

.editor-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: auto;
}

.editor-content {
    position: relative;
    min-width: 800px;
    min-height: 600px;
    background: linear-gradient(135deg, #1a1a1a 0%, #0f0f0f 100%);
    padding: 2rem;
    transform-origin: top left;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.editor-grid {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: repeating-linear-gradient(0deg, transparent, transparent 19px, #334155 20px),
                repeating-linear-gradient(90deg, transparent, transparent 19px, #334155 20px);
    opacity: 0.3;
    pointer-events: none;
    z-index: 1;
}

/* WIDGETS */
.widget {
    position: absolute;
    /* Default styles - will be overridden by OTUI styles when loaded */
    background: transparent;
    border: 1px dashed rgba(255, 255, 255, 0.05);
    /* Removed min-width/min-height - OTUI styles will set exact sizes (even 1-3px for separators) */
    cursor: move;
    user-select: none;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    z-index: 10;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Ensure OTUI styles can override */
    box-sizing: border-box;
}

/* Labels should be just text - no frame, no background, no border */
.widget.UILabel {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    min-height: 20px !important;
    max-height: 20px !important;
    height: auto !important;
}

.widget.UIGameLabel {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    min-height: 20px !important;
    max-height: 20px !important;
    height: auto !important;
}

.widget.UITextEdit {
    min-height: 20px !important;
    max-height: 20px !important;
    height: auto !important;
}
.widget.UILabel .widget-content {
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
}


.widget:hover {
    box-shadow: var(--shadow-lg);
    z-index: 20;
    transform: translateY(-1px);
}

.widget.selected {
    /* Selection indicator - use outline to not interfere with OTUI borders */
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.4), 0 4px 16px rgba(59, 130, 246, 0.2);
    z-index: 30;
    animation: pulse-selection 2s ease-in-out infinite;
}

@keyframes pulse-selection {
    0%, 100% { box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.4), 0 4px 16px rgba(59, 130, 246, 0.2); }
    50% { box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.6), 0 4px 20px rgba(59, 130, 246, 0.3); }
}

.widget.dragging {
    opacity: 0.9;
    z-index: 9999;
    box-shadow: var(--shadow-lg);
    /* No transform/rotation - widget shows exactly where it will drop */
}

.widget.drag-over {
    outline: 3px dashed var(--accent);
    background: rgba(16, 185, 129, 0.2);
}

.widget-label {
    position: absolute;
    top: -22px;
    left: 0;
    font-size: 0.525rem; /* 25% smaller than 0.7rem */
    background: var(--bg-secondary);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    color: var(--text-secondary);
    pointer-events: none;
    z-index: 5;
    /* Make label less intrusive when OTUI styles are applied */
    opacity: 0.4;
    transition: opacity 0.2s;
}

.widget:hover .widget-label {
    background: var(--primary);
    color: white;
    opacity: 1;
}

.widget-content {
    /* Default styles - will be overridden by OTUI styles */
    padding: 12px;
    color: white;
    font-size: 9.75px; /* 25% smaller than 13px */
    text-align: center;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* Ensure OTUI styles can override */
    box-sizing: border-box;
    pointer-events: none;
    z-index: 20;
}

.widget.UILabel .widget-content {
    position: relative;
    pointer-events: auto;
}

/* RESIZE HANDLES */
.resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--primary);
    border: 2px solid white;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 40;
}

.widget.selected .resize-handle {
    opacity: 1;
}

.resize-handle.nw { top: -6px; left: -6px; cursor: nw-resize; }
.resize-handle.ne { top: -6px; right: -6px; cursor: ne-resize; }
.resize-handle.sw { bottom: -6px; left: -6px; cursor: sw-resize; }
.resize-handle.se { bottom: -6px; right: -6px; cursor: se-resize; }
.resize-handle.n  { top: -6px; left: 50%; cursor: n-resize; transform: translateX(-50%); }
.resize-handle.s  { bottom: -6px; left: 50%; cursor: s-resize; transform: translateX(-50%); }
.resize-handle.w  { left: -6px; top: 50%; cursor: w-resize; transform: translateY(-50%); }
.resize-handle.e  { right: -6px; top: 50%; cursor: e-resize; transform: translateY(-50%); }

/* WIDGET TOOLTIP */
.widget-tooltip {
    position: absolute;
    background: rgba(15, 23, 42, 0.95);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    line-height: 1.5;
    z-index: 10000;
    pointer-events: none;
    border: 1px solid var(--border-light);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.widget-tooltip strong {
    color: var(--primary);
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

.widget-tooltip br {
    line-height: 1.8;
}

/* WIDGET PALETTE */
.widget-category {
    margin-bottom: 0.75rem;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.widget-category-header {
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.65rem 0.85rem;
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.5) 0%, rgba(30, 41, 59, 0.7) 100%);
    cursor: pointer;
    user-select: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
}

.widget-category-header:hover {
    background: linear-gradient(135deg, rgba(71, 85, 105, 0.7) 0%, rgba(51, 65, 85, 0.9) 100%);
    transform: translateX(2px);
}

.widget-category.collapsed .widget-list {
    display: none;
}

.widget-list {
    background: var(--bg-secondary);
}

.widget-item {
    padding: 0.6rem 0.85rem;
    cursor: grab;
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    margin: 0.15rem 0.25rem;
}

.widget-item:hover {
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.6) 0%, rgba(30, 41, 59, 0.8) 100%);
    transform: translateX(4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

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

/* PANELS */
.panel {
    border: 1px solid rgba(51, 65, 85, 0.4);
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    overflow: hidden;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.6) 0%, rgba(15, 23, 42, 0.8) 100%);
    backdrop-filter: blur(8px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.panel:hover {
    border-color: rgba(71, 85, 105, 0.5);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.panel-header {
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.5) 0%, rgba(30, 41, 59, 0.7) 100%);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 0.9rem;
    backdrop-filter: blur(8px);
    transition: background 0.3s ease;
}

.panel-header:hover {
    background: linear-gradient(135deg, rgba(71, 85, 105, 0.6) 0%, rgba(51, 65, 85, 0.8) 100%);
}

.panel-badge {
    background: linear-gradient(135deg, var(--primary) 0%, #2563eb 100%);
    color: white;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
    transition: all 0.3s ease;
}

.panel-badge:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.4);
}

.panel-content {
    padding: 0.75rem;
    background: var(--bg-secondary);
    min-width: 0; /* Allow shrinking below content size */
    overflow-x: hidden; /* Prevent horizontal overflow */
    width: 100%; /* Take full width of parent */
    box-sizing: border-box; /* Include padding in width calculation */
}

/* HIERARCHY */
.hierarchy-tree {
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal overflow */
    font-size: 0.8rem;
    margin-top: 0.4rem;
    width: 100%;
    min-width: 0; /* Allow shrinking below content size */
}

.tree-node {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    transition: background 0.2s;
    gap: 6px;
    font-size: 0.8rem;
    min-width: 0; /* Allow shrinking */
    width: fit-content; /* Fit content, don't expand parent */
    max-width: 100%; /* But don't exceed parent */
}

.tree-node:hover {
    background: var(--bg-tertiary);
}

.tree-node.selected {
    background: var(--primary);
    color: white;
}

.tree-node ul {
    margin-left: 20px;
    list-style: none;
    border-left: 1px dashed var(--border-light);
    padding-left: 10px;
    min-width: 0; /* Allow shrinking */
    width: fit-content; /* Fit content */
    max-width: 100%; /* But don't exceed parent */
}

.tree-node input {
    background: transparent;
    border: 1px solid transparent;
    color: inherit;
    font: inherit;
    min-width: 80px; /* Minimum width for usability */
    max-width: 100%; /* Don't exceed parent */
    width: auto; /* Fit content instead of 100% */
    flex: 0 1 auto; /* Don't grow, allow shrinking */
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-node input:focus {
    background: rgba(255,255,255,0.15);
    border-color: var(--primary);
    outline: none;
    width: auto; /* Still fit content when focused */
    min-width: 80px; /* But maintain minimum */
}

/* CODE PANEL */
.code-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-primary);
    gap: 0.5rem;
}

.code-tab {
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    border-bottom: 2px solid transparent;
}

.code-tab:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.code-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: transparent;
}

#codeModal .code-tab {
    color: var(--text-primary);
}

#codeModal .code-tab.active {
    background: var(--primary);
    color: white;
    border-bottom-color: var(--primary);
}

.code-block {
    background: var(--bg-code);
    padding: 0.85rem;
    border-radius: var(--radius-md);
    height: 220px;
    overflow: auto;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.4;
    display: none;
    white-space: pre;
}

.code-block.active {
    display: block;
}

.code-block code {
    font-family: inherit;
}

/* Code modal specific styles */
#codeModal .code-block {
    height: 100%;
    background: #1e1e1e;
    color: #d4d4d4;
    font-size: 0.9rem;
    line-height: 1.6;
    padding: 1.5rem;
    margin: 0;
    border-radius: 0;
}

#codeModal .code-tabs {
    background: var(--bg-secondary);
    padding: 0.5rem 1rem;
    margin: 0;
    border-bottom: 1px solid var(--border-primary);
}

.code-modal-content {
    max-width: 95vw;
    width: 1400px;
    height: 90vh;
}

.code-modal-body {
    padding: 0;
    height: calc(90vh - 80px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.code-modal-content-wrapper {
    flex: 1;
    overflow: auto;
    position: relative;
    background: #1e1e1e;
}

/* PREVIEW */
.preview-panel {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
}

.preview-window-container {
    background: #111;
    border: 2px solid #444;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 1100px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.preview-header {
    padding: 1rem 1.5rem;
    background: #222;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #444;
}

.preview-content {
    padding: 2rem;
    background: #1a1a1a;
}

.preview-window {
    width: 800px;
    height: 600px;
    margin: 0 auto;
    background: #111;
    border: 3px solid #444;
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 40px rgba(0,0,0,0.5);
}

/* MODAL */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

/* Ensure modals are centered when displayed */
.modal[style*="display: flex"],
.modal[style*="display:block"] {
    display: flex !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.modal-close {
    background: transparent;
    border: 2px solid var(--border-light);
    color: var(--text-secondary);
    font-size: 1.25rem;
    font-weight: bold;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

.modal-close:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
    color: #ef4444;
    transform: scale(1.1);
}

.modal-close:active {
    transform: scale(0.95);
}

.modal-body {
    padding: 2rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    transition: border 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    border-color: var(--primary);
}

.form-group textarea {
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
}

.form-group select {
    cursor: pointer;
}

/* AI Generator specific styles */
#aiProgress {
    background: linear-gradient(135deg, rgba(51, 65, 85, 0.7) 0%, rgba(30, 41, 59, 0.8) 100%);
    border: 1px solid rgba(51, 65, 85, 0.5);
    transition: all 0.3s ease;
}

#aiCodePreview {
    font-family: var(--font-mono);
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

#aiGeneratedCode {
    animation: slideDown 0.3s ease;
}

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

/* TOAST */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--accent);
    color: white;
    padding: 14px 28px;
    border-radius: var(--radius-md);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    font-weight: bold;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* FOOTER */
.app-footer {
    padding: 0.5rem 1.5rem;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.98) 100%);
    border-top: 1px solid rgba(51, 65, 85, 0.4);
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    flex-shrink: 0;
    backdrop-filter: blur(10px);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

.status-left,
.status-right {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

/* SCROLLBARS */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: #64748b;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* SELECTION */
::selection {
    background: var(--primary);
    color: white;
}

/* RESPONSIVE */
@media (max-width: 1400px) {
    .sidebar { width: 240px; }
    .widget-item { font-size: 0.8rem; }
}

@media (max-width: 1200px) {
    .sidebar { width: 220px; }
    .app-header { padding: 0.5rem 1rem; }
}

.no-selection-message {
    text-align: center;
    color: #64748b;
    padding: 1.5rem;
    font-style: italic;
    font-size: 0.85rem;
}

#editingIndicator {
    font-size: 0.8rem;
    color: var(--accent);
    font-weight: 600;
}

/* FINAL: Ensure hierarchy inputs are visible */
.tree-node input {
    min-width: 80px;
    cursor: text;
}

/* OTCv8 PREVIEW STYLES */
#previewModal .modal-content {
    background: #0a0a0a;
    border: 2px solid #2a2a2a;
}

#previewModal .modal-header {
    background: #1a1a1a;
    border-bottom: 1px solid #2a2a2a;
    color: #d4d4d4;
}

#previewModal .modal-header h2 {
    color: #d4d4d4;
    font-family: 'Tahoma', 'Arial', sans-serif;
}

#otcv8Preview {
    background: #000000;
    position: relative;
}

#previewWindow {
    background: #000000;
    position: relative;
    border: none;
    box-shadow: none;
}

#previewContent {
    background: #000000;
}

/* OTCv8 Widget Styles - More accurate to actual client */
.otcv8-widget {
    pointer-events: none;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    font-smooth: never;
    -webkit-font-smoothing: none;
}

/* Prevent text selection in preview */
#previewWindow * {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: default;
}

/* OTCv8 specific widget styling */
#previewWindow .otcv8-widget.otcv8-uiwindow {
    box-shadow: inset 1px 1px 0 rgba(255,255,255,0.1), inset -1px -1px 0 rgba(0,0,0,0.8), 0 2px 4px rgba(0,0,0,0.5);
}

#previewWindow .otcv8-widget.otcv8-uibutton {
    transition: none;
}

#previewWindow .otcv8-widget.otcv8-uibutton:hover {
    background: #323232;
}

#previewWindow .otcv8-widget.otcv8-uiprogressbar,
#previewWindow .otcv8-widget.otcv8-uihealthbar,
#previewWindow .otcv8-widget.otcv8-uimanabar,
#previewWindow .otcv8-widget.otcv8-uiexperiencebar {
    border: 1px solid #3a3a3a;
}

/* Cookie Consent Dialog */
.cookie-consent {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    max-width: 500px;
    z-index: 10000;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.cookie-consent-content {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
}

.cookie-consent-header h3 {
    margin: 0 0 1rem 0;
    font-size: 1.2rem;
    color: var(--text-primary);
}

.cookie-consent-body {
    margin-bottom: 1.5rem;
}

.cookie-consent-body ul {
    margin: 10px 0;
    padding-left: 20px;
    color: var(--text-secondary);
}

.cookie-consent-body li {
    margin: 8px 0;
    font-size: 0.9rem;
}

.cookie-consent-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Widget Library Template Item */
.template-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    transition: all 0.2s ease;
}

.template-item:hover {
    background: var(--bg-secondary);
    border-color: var(--border-light);
}

.template-item-info {
    flex: 1;
}

.template-item-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.template-item-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

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

.template-item-actions .btn {
    padding: 6px 12px;
    font-size: 0.85rem;
}
