:root {
    --bg-dark: #0f111a;
    --bg-panel: rgba(30, 32, 45, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.4);
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --accent: #10b981;
    --danger: #ef4444;

    --glass-border: 1px solid rgba(255, 255, 255, 0.05);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Tajawal', 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.15) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.1) 0%, transparent 20%);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: var(--glass-border);
    border-left: var(--glass-border);
}

/* Sidebar */
.sidebar {
    width: 280px;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    border-left: var(--glass-border);
    z-index: 10;
    height: 100vh;
    overflow-y: auto;
    /* Fallback scroll */
}


.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 2rem;
    color: var(--primary);
    font-size: 1.2rem;
}

.toolbox h3,
.properties-panel h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: auto;
}

.tool-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 1rem;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.tool-btn i {
    font-size: 1.5rem;
    color: var(--text-muted);
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.tool-btn:hover i {
    color: var(--primary);
}

/* Actions */
.primary-btn {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: none;
    background: var(--primary);
    color: white;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    transition: all 0.3s;
}

.glow-effect {
    box-shadow: 0 0 15px var(--primary-glow);
}

.primary-btn:hover {
    filter: brightness(1.1);
    box-shadow: 0 0 25px var(--primary-glow);
}

.danger-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: 0.3s;
}

.danger-btn:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Workspace */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    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;
}

.canvas-header {
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    border-bottom: var(--glass-border);
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
}

.canvas-actions {
    display: flex;
    align-items: center;
    gap: 5px;
}

.action-divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 10px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    width: 35px;
    height: 35px;
    border-radius: 6px;
    transition: 0.2s;
}

.icon-btn.active,
.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary);
    transform: translateY(-1px);
}

.viewport-container {
    flex: 1;
    display: flex;
    justify-content: center;
    overflow: auto;
    padding: 2rem;
}

/* Canvas Area */
.canvas-area {
    width: 100%;
    max-width: 1200px;
    background: #0f111a;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    min-height: 100%;
    position: relative;
    transition: width 0.3s ease;
    border: 1px dashed rgba(255, 255, 255, 0.1);
    overflow: auto;
    /* Contain all designs */
}


.mobile-view {
    width: 375px;
    max-width: 375px;
}

.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    pointer-events: none;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Design Elements in Canvas */
.design-element {
    position: relative;
    min-height: 20px;
    padding: 10px;
    border: 1px dashed transparent;
    transition: all 0.2s;
    box-sizing: border-box;
    /* Ensure padding doesn't increase size */
    max-width: 100%;
    /* Prevent escaping parent width */
    word-break: break-word;
    /* Prevent long text from breaking layout */
}


.design-element:hover {
    border-color: rgba(99, 102, 241, 0.3);
}

.design-element.selected {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--primary);
}

.design-element.selected::after {
    content: attr(data-label);
    position: absolute;
    top: -20px;
    right: 0;
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px 4px 0 0;
}

.el-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 50px;
    background: rgba(255, 255, 255, 0.02);
    overflow: visible;
    /* Changed from default to allow absolute children, but check parent */
}


.el-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    background: rgba(255, 255, 255, 0.02);
}

/* Properties Panel */
.properties-panel {
    width: 300px;
    padding: 0;
    /* Remove padding to handle scroll better */
    border-right: var(--glass-border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.properties-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    scrollbar-width: thin;
}

.panel-header {
    padding: 1.5rem 1.5rem 0.5rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}


.prop-group {
    margin-bottom: 1.5rem;
}

.prop-group label {
    display: block;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.prop-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px;
    border-radius: 6px;
    color: white;
}

.prop-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 100;
    display: none;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    width: 600px;
    max-width: 90%;
    background: #1e202d;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: flex-end;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
}

textarea#aiPromptOutput {
    width: 100%;
    height: 200px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 1rem;
    color: var(--text-main);
    resize: none;
    font-size: 0.9rem;
    line-height: 1.6;
}

.secondary-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    display: flex;
    gap: 8px;
    align-items: center;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 1.5rem;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
}

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
}

/* Layers View */
.layers-view {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: 0.2s;
    border: 1px solid transparent;
}

.layer-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.layer-item.selected {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

.layer-indent {
    width: 16px;
    height: 100%;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

/* Layers View Actions */
.layer-item {
    position: relative;
    overflow: hidden;
}

.layer-actions {
    display: none;
    gap: 8px;
    margin-right: auto;
}

.layer-item:hover .layer-actions {
    display: flex;
}

.layer-actions i {
    cursor: pointer;
    font-size: 0.75rem;
    opacity: 0.6;
    transition: 0.2s;
}

.layer-actions i:hover {
    opacity: 1;
    color: var(--primary);
    transform: scale(1.2);
}

/* Premium Selection Pulse */
@keyframes selection-pulse {
    0% {
        outline: 2px solid rgba(99, 102, 241, 0.4);
        outline-offset: 0px;
    }

    50% {
        outline: 2px solid rgba(99, 102, 241, 1);
        outline-offset: 2px;
    }

    100% {
        outline: 2px solid rgba(99, 102, 241, 0.4);
        outline-offset: 0px;
    }
}

.design-element.selected {
    animation: selection-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    z-index: 5;
}

/* Glass Details */
.glass-panel {
    background: rgba(30, 32, 45, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: var(--glass-border);
}

.modal-content.glass-panel {
    background: rgba(15, 17, 26, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Properties Panel Improvements */
.panel-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

.prop-section {
    margin-bottom: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.prop-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.prop-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.prop-input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.prop-input-group label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
}

.prop-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 10px;
    border-radius: 8px;
    color: white;
    font-size: 0.8rem;
    transition: 0.2s;
}

.prop-input:hover {
    border-color: rgba(99, 102, 241, 0.3);
}

.prop-input:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.5);
    outline: none;
}

input[type="color"].prop-input {
    height: 38px;
    padding: 4px;
    cursor: pointer;
}

/* Element Hover Hint */
.design-element:not(.selected):hover::before {
    content: attr(data-label);
    position: absolute;
    top: -18px;
    right: 0;
    font-size: 10px;
    background: rgba(99, 102, 241, 0.5);
    padding: 2px 6px;
    border-radius: 4px;
    color: white;
    z-index: 10;
}

/* Smooth Scrolling */
.tab-content {
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

/* Action Tooltips */
[title] {
    position: relative;
}

/* Grid Background Update */
.workspace {
    background-image:
        radial-gradient(var(--border-color) 1px, transparent 1px);
    background-size: 30px 30px;
}

/* Controls */
select.prop-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='Length19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 12px;
    padding-right: 28px;
}

/* Special Element Styles in Canvas */
.el-navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.el-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.el-input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 15px;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* AI Modal Styling */
.ai-badge {
    display: inline-block;
    background: linear-gradient(90deg, #6366f1, #10b981);
    color: white;
    font-size: 0.7rem;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 20px;
    margin-bottom: 10px;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Responsive UI fixes */
@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
    }

    .properties-panel {
        width: 260px;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: var(--glass-border);
        order: 2;
        /* Put sidebar below canvas on mobile */
    }

    .workspace {
        height: 60vh;
        /* Fixed height for canvas area on mobile */
        min-height: 400px;
        order: 1;
    }

    .properties-panel {
        width: 100%;
        height: auto;
        border-left: none;
        border-top: var(--glass-border);
        order: 3;
    }

    .tool-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .logo-area {
        justify-content: center;
    }

    .modal-content {
        width: 95%;
        margin: 10px;
    }
}

/* Modal Scroll Fixes */
.modal-content {
    max-height: 90vh;
    /* Prevent overflowing viewport height */
    display: flex;
    flex-direction: column;
}

.modal-body {
    overflow-y: auto;
    /* Allow scrolling within modal body */
    flex: 1;
    /* Take remaining space */
    scrollbar-width: thin;
}

/* Adjust Textarea heights in modals */
textarea#aiPromptOutput,
#exportOutput,
#htmlImportInput {
    height: auto;
    min-height: 150px;
    max-height: 400px;
}

/* Export Options Styling */
.export-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.export-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1.25rem;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: right;
    position: relative;
    overflow: hidden;
}

.export-btn i {
    font-size: 1.5rem;
    margin-bottom: 8px;
    color: var(--primary);
    transition: transform 0.3s ease;
}

.export-btn span {
    font-weight: 700;
    font-size: 1rem;
    display: block;
}

.export-btn small {
    color: var(--text-muted);
    font-size: 0.75rem;
    display: block;
    line-height: 1.4;
}

.export-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2), 0 0 15px var(--primary-glow);
}

.export-btn:hover i {
    transform: scale(1.1);
}

.export-btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, transparent, rgba(99, 102, 241, 0.05));
    pointer-events: none;
}

@media (max-width: 480px) {
    .export-options {
        grid-template-columns: 1fr;
    }
}