/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}

:root {
    --background-color: #f6f6f6;
    --surface-color: #fff;
    --text-color: #222;
    --border-color: #e0e0e0;
    --hover-color: #f0f0f0;
    --primary-color: #007bff;
    --shadow-color: rgba(0,0,0,0.08);
    --menu-hover: #e0e0e0;
    --menu-active: #d0d0d0;
    --element-hover: #f5f5f5;
    --resizer-hover: #d0d0d0;
}

body.dark-mode {
    --background-color: #181a1b;
    --surface-color: #23272a;
    --text-color: #f6f6f6;
    --border-color: #333a40;
    --hover-color: #1f2326;
    --primary-color: #4f8cff;
    --shadow-color: rgba(0,0,0,0.32);
    --menu-hover: #1f2326;
    --menu-active: #2c3136;
    --element-hover: #23272a;
    --resizer-hover: #3a3f44;
}

body, html {
    height: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    overflow: hidden;
}

/* Menu Bar */
.menu-bar {
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    padding: 0 8px;
    height: 30px;
    align-items: center;
    z-index: 1000;
}

.menu-item {
    position: relative;
    padding: 0 0.75rem;
    height: 100%;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.menu-item:hover {
    background-color: var(--hover-color);
}

.menu-item .menu-dropdown {
    display: none;
}
.menu-item.open {
    background: var(--menu-hover);
}
.menu-item.open .menu-dropdown {
    display: block;
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 2px 8px var(--shadow-color);
    min-width: 200px;
}

.menu-option {
    padding: 4px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-option:hover, .menu-option:focus {
    background: var(--menu-hover);
    color: var(--primary-color);
}

.menu-option:active {
    background: var(--menu-active);
    color: var(--primary-color);
}

.menu-separator {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.25rem 0;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Toolbar */
.toolbar {
    background-color: var(--surface-color);
    padding: 0.5rem 1rem;
    box-shadow: 0 1px 3px var(--shadow-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-img {
    width: 24px;
    height: 24px;
    margin-left: -2px;
    margin-right: 6px;
}

.logo-img:hover {
    transform: rotate(180deg);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.logo-icon {
    font-size: 1.2rem;
}

.toolbar-actions {
    display: flex;
    gap: 1rem;
}

.tool-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    background-color: var(--primary-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tool-btn:hover {
    background-color: #0056b3;
}

/* Main Content Area */
.main-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.toolbox-header {
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: grab;
    user-select: none;
}

.toolbox-title {
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
    color: var(--text-color);
}

.toolbox-controls {
    display: flex;
    gap: 0;
    align-items: center;
}

.undock-btn>i, .close-btn>i {
    font-size: 10px;
    /* rotate: 270deg; */
}

.toolbox-content {
    overflow-y: auto;
}

.toolbar-controls {
    display: flex;
    gap: 0.5rem;
}

/* Elements Panel */
.elements-panel {
    border-right: 1px solid var(--border-color);
}

.element-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 6px 4px;
}

.element-item {
    padding: 2px 8px;
    background-color: var(--surface-color);
    /* border: 1px solid var(--border-color); */
    border-radius: 4px;
    cursor: move;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-color);
}

.element-item:hover, .element-item:focus {
    background: var(--element-hover);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.element-item>i {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Canvas Container */
.canvas-container {
    background: var(--surface-color);
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-color);
    padding: 1rem;
    overflow: auto;
    min-width: 0;
}

.canvas {
    background-color: var(--surface-color);
    min-height: 100%;
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-color);
    padding: 2rem;
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 4px;
    padding: 2rem;
    text-align: center;
    color: var(--text-color);
}

.drop-zone.drag-over {
    background: rgba(79, 140, 255, 0.08);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Properties Panel */
.properties-panel {
    border-left: 1px solid var(--border-color);
}

.no-selection {
    color: var(--text-color);
    font-style: italic;
}

/* Dock Zones */
.dock-zone {
    position: absolute;
    background-color: rgba(0, 123, 255, 0.1);
    border: 2px dashed var(--primary-color);
    z-index: 100;
    pointer-events: none;
}

.dock-zone.active {
    background-color: rgba(0, 123, 255, 0.2);
    border-style: solid;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.modal-content {
    position: relative;
    background-color: var(--surface-color);
    margin: 2rem auto;
    padding: 2rem;
    width: 90%;
    max-width: 1200px;
    border-radius: 8px;
    max-height: 90vh;
    overflow-y: auto;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
}

.close:hover {
    color: #333;
}

/* Builder Elements */
.builder-element {
    position: relative;
    padding: 0.5rem;
    margin: 0.5rem 0;
    border: 1px solid transparent;
}

.builder-element:hover {
    border-color: var(--primary-color);
}

.builder-element.selected {
    border-color: var(--primary-color);
    background-color: rgba(0, 123, 255, 0.1);
}

.element-controls {
    position: absolute;
    top: -1.5rem;
    right: 0;
    display: none;
    gap: 0.5rem;
}

.builder-element:hover .element-controls {
    display: flex;
}

.element-control-btn {
    padding: 0.25rem 0.5rem;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-color);
}

.element-control-btn:hover, .element-control-btn:focus {
    background: var(--menu-hover);
    color: var(--primary-color);
}

.element-control-btn:active {
    background: var(--menu-active);
    color: var(--primary-color);
}

.docks-layout {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: calc(100vh - 30px);
    width: 100vw;
    background: var(--background-color);
    margin: 0;
    padding: 0;
}

.dock-row {
    display: grid;
    grid-template-columns: minmax(0, 240px) 1fr minmax(0, 260px);
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
}

.dock-left, .dock-right {
    display: flex;
    flex-direction: column;
    background: var(--surface-color);
    min-width: 180px;
    max-width: 320px;
    padding: 0;
    gap: 0;
    border-right: 1px solid var(--border-color);
    z-index: 1;
    overflow: hidden;
    height: 100%;
    flex: 1 1 0;
    position: relative;
}
.dock-left {
    padding-right: 6px;
}
.dock-right {
    padding-left: 6px;
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.dock-top, .dock-bottom {
    display: flex;
    flex-direction: row;
    min-height: 48px;
    background: var(--surface-color);
    padding: 0;
    gap: 0;
    z-index: 1;
    overflow: hidden;
    width: 100%;
    flex: 0 0 auto;
    position: relative;
}

.dock-top {
    border-bottom: solid 1px var(--border-color);
}
.dock-bottom {
    box-shadow: 0 -1px var(--border-color);
    border-bottom: none;
    margin: 0;
    padding: 0;
    padding-top: 6px;
}

.toolbox {
    background: var(--surface-color);
    border-radius: 0;
    box-shadow: 0 2px 8px var(--shadow-color);
    border: 1px solid var(--border-color);
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 2;
    flex: 1 1 0;
    margin: 0;
    overflow: hidden;
    color: var(--text-color);
}

.dock-left .toolbox, .dock-right .toolbox {
    width: 100%;
    min-height: 48px;
    max-height: none;
}
.dock-top .toolbox, .dock-bottom .toolbox {
    height: 100%;
    min-width: 120px;
    max-width: none;
}

.dock-left .toolbox:first-child,
.dock-right .toolbox:first-child {
    border-top: none;
}

.dock-left .toolbox:has(+ .toolbox-resizer):last-child,
.dock-left .toolbox:last-child {
    border-bottom: none;
}

.dock-left .toolbox {
    border-left: none;
}

.dock-right .toolbox {
    border-right: none;
}

.dock-top .toolbox {
    border-top: none;
    border-bottom: none;
}

.dock-bottom .toolbox {
    border-bottom: none;
}

.toolbox[style*="position: fixed"] {
    border-radius: 8px;
    min-width: 220px;
    min-height: 120px;
    max-width: 400px;
    max-height: 80vh;
    z-index: 2000;
    margin: 0;
    box-shadow: 0 0 0 1px var(--border-color), 0 12px 32px var(--shadow-color);
    border: none;
    background: var(--surface-color);
    color: var(--text-color);
}

/* Make the original toolbox invisible during drag */
.toolbox.dragging {
    opacity: 0 !important;
    pointer-events: none; /* Make sure it doesn't interfere with anything */
}

.toolbox-resizer {
    background: var(--surface-color);
    z-index: 10;
    position: relative;
    flex: 0 0 6px;
    cursor: row-resize;
    width: 100%;
    height: 6px;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dock-left .toolbox-resizer, .dock-right .toolbox-resizer {
    cursor: row-resize;
    width: 100%;
    height: 6px;
}
.dock-top .toolbox-resizer, .dock-bottom .toolbox-resizer {
    cursor: col-resize;
    width: 6px;
    height: 100%;
}

.toolbox-resizer:hover {
    background: var(--resizer-hover);
}

.toolbox-resizer i {
    font-size: 8px;
    color: var(--text-color);
    opacity: 0.6;
}

/* Dock Resizers */
.dock-resizer {
    position: absolute;
    background: var(--surface-color);
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: col-resize;
}

.dock-resizer-left {
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
}

.dock-resizer-right {
    left: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
}

.dock-resizer-bottom {
    left: 0;
    right: 0;
    top: 0;
    height: 6px;
    cursor: row-resize;
}

.dock-resizer:hover {
    background: var(--resizer-hover);
}

.dock-resizer i {
    font-size: 8px;
    color: var(--text-color);
    opacity: 0.6;
}

.toolbox-controls>button {
    height: 18px;
    width: 18px;
    display: flex;
    padding: 0;
    margin: 0;
    background: none;
    border: none;
    border-radius: 2px;
    color: var(--text-color);
    justify-content: center;
    align-items: center;
}

.toolbox-controls>button:hover {
    background: var(--border-color);
    color: var(--text-color);
}

.canvas-area {
    background: var(--surface-color);
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-color);
    margin: 12px 0;
    padding: 0 12px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    grid-column: 2;
    grid-row: 1 / span 1;
}

@media (max-width: 900px) {
    .dock-row {
        grid-template-columns: 1fr;
    }
    .dock-left, .dock-right {
        display: none;
    }
}

.dock-left.dock-empty, .dock-right.dock-empty {
    min-width: 0 !important;
    max-width: 0 !important;
    width: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    border: none !important;
}
.dock-top.dock-empty, .dock-bottom.dock-empty {
    min-height: 0 !important;
    max-height: 0 !important;
    height: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    border: none !important;
}

/* Dock highlighting for drag feedback */
.dock-highlight {
    background: rgba(0, 123, 255, 0.1) !important;
}

/* More specific highlight styles for each dock */
.dock-left.dock-highlight,
.dock-right.dock-highlight,
.dock-top.dock-highlight,
.dock-bottom.dock-highlight {
    background: var(--border-color) !important;
    z-index: 100 !important;
}

.toolbox-placeholder {
    background: var(--border-color);
    opacity: 0.5;
    min-height: 24px;
    min-width: 24px;
}

.dock-left.dock-highlight>.toolbox-placeholder {
    border-right: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
}
.dock-right.dock-highlight>.toolbox-placeholder {
    border-left: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
}

/* Focus states for accessibility */
.menu-option:focus, .panel-btn:focus, .toolbox .undock-btn:focus, .toolbox .close-btn:focus, .element-control-btn:focus, .element-item:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 1px;
}

/* Elements Toolbox Search and Categories */

.element-search-wrapper {
    position: sticky;
    top: 0;
    width: 100%;
    padding: 4px;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-color);
}

.element-search-icon {
    position: absolute;
    left: 14px;
    top: 10px;
    /* transform: translateY(-50%); */
    color: var(--text-color);
    font-size: 14px;
    pointer-events: none;
    z-index: 2;
}

.element-search {
    width: 100%;
    padding: 0px 8px 0px 32px;
    position: sticky;
    top: 10px;
    height: 26px;
    border-radius: 4px;
    border: none;
    font-size: 14px;
    background: var(--menu-hover);
    color: var(--text-color);
    box-sizing: border-box;
}

.element-category {
    margin-bottom: 2px;
    border-radius: 4px;
    background: none;
}

.element-category-header {
    font-weight: 600;
    font-size: 12px;
    padding: 0px 8px;
    height: 24px;
    background: var(--hover-color);
    color: var(--text-color);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    user-select: none;
    gap: 6px;
}

.element-category-header>i {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Remove the triangle arrow */
.element-category-header::before {
    display: none;
}

.element-category-chevron {
    font-size: 13px;
    color: var(--text-color);
    margin-right: 2px;
}

.element-category.collapsed .element-category-chevron {
    transform: rotate(-90deg);
}

.element-category-items {
    padding: 2px 0 2px 0;
    overflow: hidden;
}

.element-category.collapsed .element-category-items {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
    padding: 0;
}

.element-category:not(.collapsed) .element-category-items {
    opacity: 1;
    max-height: 500px;
}

.dock-left:not(.dock-empty), .dock-right:not(.dock-empty) {
    visibility: visible !important;
    pointer-events: auto !important;
    width: auto;
    min-width: 180px;
    max-width: 320px;
}
.dock-top:not(.dock-empty), .dock-bottom:not(.dock-empty) {
    visibility: visible !important;
    pointer-events: auto !important;
    height: auto;
    min-height: 48px;
}

/* --- Add for bottom dock horizontal resizer between toolboxes --- */
.dock-top .toolbox-resizer,
.dock-bottom .toolbox-resizer {
    width: 6px;
    height: 100%;
    min-width: 6px;
    max-width: 12px;
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-color);
    border-top: none;
    border-bottom: none;
    box-shadow: none;
    z-index: 10;
    position: relative;
    /* margin: 0 2px; */
}

.dock-top .toolbox-resizer:hover,
.dock-bottom .toolbox-resizer:hover {
    background: var(--resizer-hover);
}

/* Optionally, tweak the icon size for horizontal resizer */
.dock-bottom .toolbox-resizer i {
    font-size: 8px;
    color: var(--text-color);
    opacity: 0.7;
}

/* Floating toolbox resize handles */
.toolbox[style*="position: fixed"] .floating-resize-handle {
    position: absolute;
    z-index: 3000;
    background: transparent;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: auto;
}

.toolbox[style*="position: fixed"] .floating-resize-handle:hover {
    opacity: 0;
}
/* Edge handles - thin lines */
.floating-resize-n { 
    top: 0; left: 0; right: 0; height: 2px; 
    cursor: ns-resize; 
}
.floating-resize-e { 
    top: 0; right: 0; bottom: 0; width: 2px; 
    cursor: ew-resize; 
}
.floating-resize-s { 
    bottom: 0; left: 0; right: 0; height: 2px; 
    cursor: ns-resize; 
}
.floating-resize-w { 
    top: 0; left: 0; bottom: 0; width: 2px; 
    cursor: ew-resize; 
}
/* Corner handles - small squares */
.floating-resize-ne { 
    top: 0; right: 0; width: 4px; height: 4px; 
    cursor: nesw-resize; 
}
.floating-resize-se { 
    bottom: 0; right: 0; width: 4px; height: 4px; 
    cursor: nwse-resize; 
}
.floating-resize-sw { 
    bottom: 0; left: 0; width: 4px; height: 4px; 
    cursor: nesw-resize; 
}
.floating-resize-nw { 
    top: 0; left: 0; width: 4px; height: 4px; 
    cursor: nwse-resize; 
}

/* Disable hover effects and cursor changes during drag/resize */
body.toolbox-dragging *,
body.toolbox-resizing * {
    cursor: inherit !important;
    pointer-events: none !important;
}

/* Allow pointer events on the active toolbox during drag/resize */
body.toolbox-dragging .toolbox.dragging,
body.toolbox-resizing .toolbox {
    pointer-events: auto !important;
}

/* Allow pointer events on docks during drag */
body.toolbox-dragging .dock {
    pointer-events: auto !important;
}

/* Separate drag outline element */
.toolbox-drag-outline {
    position: fixed;
    border: 6px solid white;
    border-radius: 8px;
    mix-blend-mode: difference;
    pointer-events: none;
    z-index: 3000; /* High z-index to be on top of everything */
}

/* Disable hover effects and cursor changes during drag/resize */
body.toolbox-dragging *,
body.toolbox-resizing * {
    cursor: inherit !important;
    pointer-events: none !important;
}

/* Allow pointer events on the active toolbox during drag/resize */
body.toolbox-dragging .toolbox.dragging,
body.toolbox-resizing .toolbox {
    pointer-events: auto !important;
}

/* Allow pointer events on docks during drag */
body.toolbox-dragging .dock {
    pointer-events: auto !important;
} 