/* ===================================
   GRID BUILDER APP STYLES
   =================================== */

body {
    overflow: hidden;
}

.page-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-container {
    display: flex;
    flex: 1;
    background: var(--bg-dark);
    overflow: hidden;
}

/* ===================================
   SIDEBAR LEFT
   =================================== */

.sidebar-left {
    width: 280px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: var(--spacing-lg);
    overflow-y: auto;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xl);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.section {
    margin-bottom: var(--spacing-xl);
}

.section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: var(--spacing-md);
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.input-group {
    margin-bottom: var(--spacing-md);
}

.input-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
    display: block;
    font-weight: 500;
}

input[type="number"],
input[type="text"] {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition-fast);
}

input[type="number"]:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-darker);
}

.toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    padding: var(--spacing-sm);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.toggle:hover {
    background: rgba(129, 140, 248, 0.1);
}

.toggle input[type="checkbox"] {
    width: 44px;
    height: 24px;
    appearance: none;
    background: var(--bg-input);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background var(--transition-base);
    border: 2px solid var(--border);
}

.toggle input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle input[type="checkbox"]::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    top: 1px;
    left: 1px;
    transition: transform var(--transition-base);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle input[type="checkbox"]:checked::before {
    transform: translateX(20px);
}

.select-field {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.select-field:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-darker);
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.color-box {
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    border: 2px solid transparent;
}

.color-box:hover {
    transform: scale(1.1);
}

.color-box.selected {
    border-color: white;
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.3);
}

/* Opacity Slider */
.opacity-slider {
    width: 100%;
    height: 6px;
    background: linear-gradient(to right, 
        rgba(129, 140, 248, 0.3), 
        rgba(129, 140, 248, 1));
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: white;
    border: 2px solid var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.opacity-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: white;
    border: 2px solid var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.opacity-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.opacity-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
}

.opacity-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.tip-box {
    background: rgba(129, 140, 248, 0.05);
    border: 1px solid rgba(129, 140, 248, 0.2);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    font-size: 12px;
    line-height: 1.6;
}

.tip-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    color: var(--primary-light);
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
}

.tip-box p {
    color: var(--text-secondary);
    margin: 0;
}

/* ===================================
   CANVAS AREA
   =================================== */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-darker);
    overflow: hidden;
}

.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-darker);
}

.toolbar {
    background: var(--bg-card);
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-md);
}

.toolbar-left,
.toolbar-center,
.toolbar-buttons {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
}

.toolbar-center {
    flex: 1;
    justify-content: center;
}

/* Enhanced Icon Buttons */
.icon-btn {
    position: relative;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 18px;
}

.icon-btn:hover {
    background: rgba(129, 140, 248, 0.1);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(129, 140, 248, 0.3);
}

.icon-btn:active {
    transform: translateY(0);
}

/* Code Toggle Button - Default (inactive) */
.icon-btn.icon-btn-code {
    border-color: var(--border);
    color: var(--text-muted);
    background: var(--bg-card);
}

.icon-btn.icon-btn-code:hover {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.1), rgba(129, 140, 248, 0.1));
    border-color: #38bdf8;
    color: #38bdf8;
    box-shadow: 0 4px 16px rgba(56, 189, 248, 0.3);
}

.icon-btn.icon-btn-code.active {
    background: linear-gradient(135deg, #38bdf8, #0ea5e9) !important;
    border-color: #38bdf8 !important;
    color: white !important;
    box-shadow: 0 4px 16px rgba(56, 189, 248, 0.5), inset 0 2px 8px rgba(255, 255, 255, 0.2);
}

.icon-btn.icon-btn-code.active:hover {
    background: linear-gradient(135deg, #0ea5e9, #0284c7) !important;
    box-shadow: 0 6px 20px rgba(56, 189, 248, 0.6);
}

.icon-btn.icon-btn-code.active i {
    animation: pulse 2s infinite;
}

/* Delete Button */
.icon-btn-danger {
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

.icon-btn-danger:hover {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.1));
    border-color: #ef4444;
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4), 0 0 20px rgba(239, 68, 68, 0.2);
}

.icon-btn-danger:active {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

/* Button Tooltip */
.btn-tooltip {
    position: absolute;
    bottom: -32px;
    left: 50%;
    transform: translateX(-50%) scale(0);
    background: rgba(15, 23, 42, 0.95);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-tooltip::before {
    content: '';
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 4px solid rgba(15, 23, 42, 0.95);
}

.icon-btn:hover .btn-tooltip {
    transform: translateX(-50%) scale(1);
    opacity: 1;
}

/* Pulse Animation */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.toolbar-center {
    flex: 1;
    justify-content: center;
}

.canvas {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-2xl);
    overflow: auto;
}

.grid-container {
    display: grid;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    position: relative;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-xl);
    min-width: 400px;
    min-height: 300px;
}

.grid-container.show-lines {
    background-image: 
        repeating-linear-gradient(
            0deg, 
            transparent, 
            transparent calc(var(--cell-height) - 1px), 
            var(--border) calc(var(--cell-height) - 1px), 
            var(--border) var(--cell-height)
        ),
        repeating-linear-gradient(
            90deg, 
            transparent, 
            transparent calc(var(--cell-width) - 1px), 
            var(--border) calc(var(--cell-width) - 1px), 
            var(--border) var(--cell-width)
        );
}

.grid-item {
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: white;
    cursor: grab;
    position: relative;
    transition: all var(--transition-base);
    border: 3px solid transparent;
    overflow: hidden;
    user-select: none;
    /* Glassmorphism effect with border */
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.grid-item::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), transparent);
    pointer-events: none;
}

.grid-item:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.grid-item.selected {
    border-color: var(--secondary);
    border-width: 3px;
    box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
}

.grid-item.dragging {
    opacity: 0.7;
    cursor: grabbing !important;
    transform: scale(1.05);
    z-index: 100;
}

.grid-item.resizing {
    opacity: 0.8;
    z-index: 100;
}

.item-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    background: var(--danger);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-fast);
    font-size: 14px;
    color: white;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.item-delete i {
    pointer-events: none;
}

.grid-item:hover .item-delete,
.grid-item.selected .item-delete {
    opacity: 1;
}

.item-delete:hover {
    background: #dc2626;
    transform: scale(1.1);
}

.item-content {
    text-align: center;
    pointer-events: none;
    z-index: 1;
}

.item-icon {
    font-size: 24px;
    margin-bottom: var(--spacing-xs);
}

/* ===================================
   RESIZE HANDLES
   =================================== */

.resize-handle {
    position: absolute;
    background: white;
    border: 2px solid var(--primary);
    z-index: 20;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

/* Show handles on hover or when selected */
.grid-item:hover .resize-handle,
.grid-item.selected .resize-handle {
    opacity: 1;
}

/* Corner handles */
.resize-handle.resize-nw {
    top: -4px;
    left: -4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: nw-resize;
}

.resize-handle.resize-ne {
    top: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: ne-resize;
}

.resize-handle.resize-sw {
    bottom: -4px;
    left: -4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: sw-resize;
}

.resize-handle.resize-se {
    bottom: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: se-resize;
}

/* Side handles */
.resize-handle.resize-n {
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 8px;
    border-radius: 4px;
    cursor: n-resize;
}

.resize-handle.resize-s {
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 8px;
    border-radius: 4px;
    cursor: s-resize;
}

.resize-handle.resize-w {
    left: -4px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 24px;
    border-radius: 4px;
    cursor: w-resize;
}

.resize-handle.resize-e {
    right: -4px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 24px;
    border-radius: 4px;
    cursor: e-resize;
}

.resize-handle:hover {
    background: var(--primary);
    transform: scale(1.2);
}

.resize-handle.resize-n:hover,
.resize-handle.resize-s:hover {
    transform: translateX(-50%) scale(1.2);
}

.resize-handle.resize-w:hover,
.resize-handle.resize-e:hover {
    transform: translateY(-50%) scale(1.2);
}

/* ===================================
   SIDEBAR RIGHT
   =================================== */

.sidebar-right {
    width: 280px;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
}

.properties-panel {
    padding: var(--spacing-lg);
}

.empty-state {
    text-align: center;
    padding: var(--spacing-2xl) var(--spacing-lg);
    color: var(--text-muted);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing-lg);
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.125rem;
    margin-bottom: var(--spacing-sm);
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0;
}

/* ===================================
   CODE PANEL
   =================================== */

.code-panel {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    height: 300px;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: height var(--transition-base);
}

.code-panel.code-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100vh !important;
    z-index: 9999;
    border: none;
}

.code-tabs {
    display: flex;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border);
    padding: 0 var(--spacing-sm);
    align-items: center;
    flex-wrap: wrap;
}

.code-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: rgba(129, 140, 248, 0.1);
    border-radius: var(--radius-md);
    margin: var(--spacing-sm);
    font-size: 12px;
    color: var(--text-secondary);
    flex: 1;
    min-width: 250px;
}

.code-info i {
    color: var(--primary);
}

.code-tab {
    padding: var(--spacing-md) var(--spacing-lg);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all var(--transition-fast);
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.code-tab i {
    font-size: 16px;
}

.code-tab:hover {
    color: var(--text-primary);
    background: rgba(129, 140, 248, 0.05);
}

.code-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.code-content {
    flex: 1;
    overflow: auto;
    padding: var(--spacing-lg);
    background: #0a0f1e; /* Darker like VS Code */
}

.code-content pre {
    margin: 0;
    font-family: 'Fira Code', 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #e2e8f0; /* Lighter text */
}

.code-content code {
    display: block;
    white-space: pre;
}

/* Syntax Highlighting */
.hl-tag {
    color: #f472b6; /* pink */
}

.hl-attr {
    color: #fbbf24; /* amber */
}

.hl-string {
    color: #4ade80; /* green */
}

.hl-class {
    color: #2dd4bf; /* teal */
    font-weight: 600;
}

.hl-icon {
    color: #a78bfa; /* purple */
}

.hl-selector {
    color: #fbbf24; /* amber */
    font-weight: 600;
}

.hl-property {
    color: #38bdf8; /* sky */
}

.hl-value {
    color: #4ade80; /* green */
}

.hl-number {
    color: #c084fc; /* violet */
}

.hl-color {
    color: #f472b6; /* pink */
    font-weight: 600;
}

/* ===================================
   MODAL
   =================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    max-width: 400px;
    width: 90%;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal h3 {
    font-size: 1.25rem;
    margin-bottom: var(--spacing-md);
}

.modal p {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
}

.modal-buttons {
    display: flex;
    gap: var(--spacing-md);
    justify-content: flex-end;
}

/* Tutorial Modal */
.tutorial-modal {
    max-width: 600px;
    width: 90%;
}

.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.tutorial-step {
    display: flex;
    gap: var(--spacing-md);
    align-items: flex-start;
}

.step-number {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.step-content {
    flex: 1;
}

.step-content h4 {
    font-size: 1rem;
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.step-content h4 i {
    color: var(--primary);
}

.step-content p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

/* ===================================
   SCROLLBAR
   =================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-darker);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===================================
   ICON PICKER
   =================================== */

.icon-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px;
}

.icon-option {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-darker);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-muted);
    transition: all 0.2s;
}

.icon-option:hover {
    background: rgba(129, 140, 248, 0.1);
    border-color: var(--primary);
    color: var(--primary);
    transform: scale(1.1);
}

.icon-option.selected {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.2);
}

/* ===================================
   RESPONSIVE
   =================================== */

@media (max-width: 1024px) {
    .sidebar-left,
    .sidebar-right {
        width: 240px;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar-left {
        width: 100%;
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    .sidebar-right {
        width: 100%;
        max-height: 300px;
        border-left: none;
        border-top: 1px solid var(--border);
    }
    
    .canvas {
        padding: var(--spacing-lg);
    }
    
    .code-panel {
        height: 200px;
    }
}