:root {
    --primary-color: #4facfe;
    --secondary-color: #00f2fe;
    --accent-color: #ff9a9e;
    --bg-color: #f0f4f8;
    --panel-bg: #ffffff;
    --text-color: #2c3e50;
    --border-radius: 12px;
    --header-height: 60px;
    --sidebar-width: 250px;
    /* Lebar default panel */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.main-header {
    height: var(--header-height);
    background: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 10;
}

.logo {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
    background: -webkit-linear-gradient(45deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.actions {
    display: flex;
    gap: 10px;
}

/* ... lines skipped ... */
/* Properties Panel */
/* .settings-panel.hidden { opacity: 0; pointer-events: none; } - Removed for now as we just clear content */

/* Properties Controls */

.btn-action {
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
    background: #e2e8f0;
    color: #475569;
}

.btn-action:hover {
    transform: scale(1.05);
}

.btn-action.success {
    background: #10b981;
    color: white;
}

.btn-action.danger {
    background: #ef4444;
    color: white;
}

/* Workspace */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar & Palette */
.sidebar-palette,
.settings-panel {
    width: var(--sidebar-width);
    background: var(--panel-bg);
    padding: 20px;
    border-right: 1px solid #e2e8f0;
    border-left: 1px solid #e2e8f0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

h3 {
    font-family: 'Fredoka', sans-serif;
    color: #334155;
    margin-bottom: 10px;
    text-align: center;
}

.component-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.draggable-item {
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: var(--border-radius);
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: grab;
    transition: all 0.2s;
}

.draggable-item:hover {
    border-color: var(--primary-color);
    background: #e0f2fe;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.draggable-item .icon {
    font-size: 2rem;
}

.draggable-item .label {
    font-size: 0.9rem;
    font-weight: 600;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    background-color: var(--bg-color);
    /* Matches body bg */
    display: flex;
    justify-content: center;
    /* align-items: center;  Allow scrolling slightly better */
    padding: 40px 20px;
    overflow-y: auto;
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 20px 20px;
}

.mobile-frame {
    width: 375px;
    /* Standard mobile width */
    min-height: 667px;
    background: white;
    border-radius: 30px;
    border: 8px solid #334155;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.mobile-notch {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 25px;
    background: #334155;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    z-index: 20;
}

.canvas-content {
    flex: 1;
    padding: 20px 10px;
    /* Top padding clears notch visually */
    padding-top: 35px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.canvas-content::-webkit-scrollbar {
    width: 6px;
}

.canvas-content::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 3px;
}

.empty-state {
    text-align: center;
    color: #94a3b8;
    margin-top: 50%;
    padding: 0 20px;
    pointer-events: none;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    padding: 20px;
}

/* Dropped Elements on Canvas */
.canvas-element {
    position: relative;
    border: 2px solid transparent;
    padding: 5px;
    border-radius: 4px;
    cursor: pointer;
}

.canvas-element:hover {
    border-color: #93c5fd;
    background-color: rgba(239, 246, 255, 0.5);
}

.canvas-element.selected {
    border-color: var(--primary-color);
    outline: 2px solid rgba(79, 172, 254, 0.2);
}

/* Properties Panel */
.settings-panel.hidden {
    /* Optional: hide it if nothing is selected, generally better to show empty state */
}

/* Properties Controls */
.prop-group {
    margin-bottom: 15px;
}

.prop-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 5px;
    color: #64748b;
}

.prop-input {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    transition: 0.2s;
}

.prop-input:focus {
    border-color: var(--primary-color);
    outline: none;
}

input[type="color"] {
    height: 40px;
    padding: 2px;
    cursor: pointer;
}

input[type="range"] {
    width: 100%;
    cursor: pointer;
}

/* Button Component Styles (Preview) */
.comp-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    text-align: center;
    display: inline-block;
}

/* Default Image Placeholder */
.comp-img-placeholder {
    width: 100%;
    height: 150px;
    background-color: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    border-radius: 8px;
    overflow: hidden;
}

.comp-img-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Helper for dragging */
.dragging {
    opacity: 0.5;
}

.drag-over-nested {
    background-color: rgba(79, 172, 254, 0.3) !important;
    border: 2px dashed var(--primary-color) !important;
}

/* Preview Mode Styles */
body.preview-mode .sidebar-palette,
body.preview-mode .settings-panel,
body.preview-mode .main-header .actions #btn-reset,
body.preview-mode .main-header .actions #btn-export {
    display: none;
}

body.preview-mode .canvas-area {
    padding: 0;
    align-items: center;
    height: 100vh;
}

body.preview-mode .mobile-frame {
    border: none;
    border-radius: 0;
    width: 100%;
    height: 100%;
    max-width: 480px;
    /* Limit width on desktop preview for realism */
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

body.preview-mode .mobile-notch {
    display: none;
}

body.preview-mode .canvas-content {
    padding-top: 20px;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .main-header {
        padding: 0 10px;
    }

    .logo {
        font-size: 1.2rem;
    }

    .desktop-only {
        display: none !important;
    }

    /* Hide text in buttons to save space */
    .btn-action {
        font-size: 0.8rem;
        padding: 8px;
    }

    .workspace {
        position: relative;
    }

    /* Turn Sidebars into Bottom Sheets */
    .sidebar-palette,
    .settings-panel {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: auto;
        min-height: 30vh;
        max-height: 50vh;
        /* Don't take too much space */
        z-index: 100;
        border-right: none;
        border-top: 2px solid #e2e8f0;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.1);
        transform: translateY(110%);
        /* Hidden by default */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding-top: 10px;
        padding-bottom: 90px;
        /* Space for mobile toggles */
    }

    /* Panel Header for Mobile */
    .panel-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 10px;
        padding: 0 5px;
    }

    .panel-header h3 {
        margin: 0;
        font-size: 1.1rem;
    }

    .btn-close-panel {
        background: #f1f5f9;
        border: none;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        font-size: 1.2rem;
        color: #64748b;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Hide Close button on desktop */
    @media (min-width: 769px) {
        .mobile-only {
            display: none;
        }

        .panel-header {
            display: block;
            /* Normal flow for desktop */
            text-align: center;
        }
    }

    .sidebar-palette.active,
    .settings-panel.active {
        transform: translateY(0);
    }

    /* Adjust Grid for Palette */
    .component-list {
        grid-template-columns: repeat(4, 1fr);
        /* More columns on horizontal sheet */
    }

    /* Canvas Adaptations */
    .canvas-area {
        padding: 10px;
        align-items: flex-start;
        height: 100%;
        padding-bottom: 80px;
        /* Space for mobile toggles */
    }

    .mobile-frame {
        width: 100%;
        height: 100%;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    .mobile-notch {
        display: none;
        /* No notch on actual mobile usage */
    }

    .canvas-content {
        padding-top: 10px;
    }

    /* Mobile Toggles */
    .mobile-toggles {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        gap: 15px;
        /* Reduced gap */
        z-index: 101;
        /* Above panels */
        background: rgba(255, 255, 255, 0.95);
        padding: 10px 20px;
        border-radius: 30px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
        backdrop-filter: blur(5px);
        width: 90%;
        /* Fit screen */
        justify-content: center;
        max-width: 400px;
    }

    .mobile-toggles button {
        flex: 1;
        min-width: 0;
        /* Allow shrinking */
        white-space: nowrap;
        font-size: 0.8rem;
        padding: 10px 5px;
    }

    /* Pages Panel Mobile Styles - Fixed */
    .sidebar-pages {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 60vh;
        z-index: 100;
        background: white;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.1);
        transform: translateY(110%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        padding-top: 10px;
    }

    .sidebar-pages.active {
        transform: translateY(0);
    }

    /* Header Adjustments for Mobile */
    .main-header {
        padding: 0 10px;
        height: 50px;
        /* Smaller header */
    }

    .logo {
        font-size: 1rem;
        /* Smaller logo */
    }

    .header-right {
        gap: 5px;
    }

    .header-right .btn-action {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    /* Hide specific texts on very small screens if needed, or rely on flex wrapping behavior (which we want to avoid) */
    .header-right .btn-action span.icon {
        margin-right: 0;
    }
}

@media (min-width: 769px) {
    .mobile-toggles {
        display: none;
    }

    /* Desktop Sidebar Pages */
    .sidebar-pages {
        position: fixed;
        top: 80px;
        left: 360px;
        /* Clear the palette */
        width: 250px;
        background: white;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
        display: none;
        flex-direction: column;
        z-index: 90;
        max-height: 80vh;
    }

    .sidebar-pages.active {
        display: flex;
    }
}