/* General Body and HTML structure */
html, body {
    height: 100%;
    margin: 0;
    overflow-x: hidden; /* Prevent horizontal scrollbar, allow vertical */
    font-family: 'Inter', sans-serif;
    background-color: #f5f5f5;
}

/* NEW: Top Horizontal Toolbar */
.top-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px; /* Fixed height for the toolbar */
    background-color: #2a70b8; /* Medium blue */
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000; /* Ensure it's on top */
}

.top-toolbar-left, .top-toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px; /* Spacing between buttons */
}

/* Styles for buttons within the top toolbar */
.btn-top-toolbar {
    background-color: #4d8ece; /* A lighter shade of the blue */
    color: white;
    border: none;
    padding: 8px 15px; /* Smaller padding */
    border-radius: 5px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    white-space: nowrap; /* Prevent text wrapping */
    font-size: 0.9em;
}

.btn-top-toolbar:hover {
    background-color: #386fa4; /* Darker blue on hover */
    transform: translateY(-1px);
}

.btn-top-toolbar:active {
    transform: translateY(0);
}

/* Specific style for "Enable Editing" */
.btn-enable-editing {
    background-color: #ADD8E6; /* Light blue */
    color: #333; /* Darker text */
    font-weight: 600;
}

.btn-enable-editing:hover {
    background-color: #9acfe1; /* Slightly darker light blue on hover */
    color: #000;
}

/* Badges in top toolbar */
.top-toolbar .badge {
    margin-left: 10px;
    font-size: 0.9em;
    padding: 5px 10px;
}

/* Main content area below the top toolbar */
.main-content-area {
    display: flex;
    /* height: calc(100% - 60px); - REMOVED: Now allows scrolling */
    min-height: calc(100vh - 60px); /* Ensure it takes at least viewport height minus toolbar */
    margin-top: 60px; /* Push content down below fixed top toolbar */
    background-color: #f5f5f5;
    position: relative; /* For collapsible sidebar offset */
}

/* REMOVED: .action-buttons-sidebar styles as it's no longer needed */
/* The h1 is now in the collapsible-sidebar */


/* Collapsible Left Sidebar for Contextual Controls */
.collapsible-sidebar {
    position: fixed; /* Fixed position */
    top: 60px; /* Below the top toolbar */
    left: 0;
    bottom: 0; /* Extends to the bottom of the viewport */
    width: 380px; /* Desired width when open */
    background: white;
    padding: 15px;
    box-shadow: 2px 0 15px rgba(0,0,0,0.2);
    overflow-y: auto; /* Enable scrolling for contents */
    z-index: 900; /* Below top-toolbar, above preview */
    transform: translateX(-100%); /* Hidden by default */
    transition: transform 0.3s ease-in-out; /* Smooth transition */
    display: flex; /* Flex container for its sections */
    flex-direction: column;
    gap: 15px; /* Spacing between main sections */
}

.collapsible-sidebar.open {
    transform: translateX(0); /* Shown */
}

.collapsible-sidebar h1 { /* NEW: Style for H1 inside the collapsible sidebar */
    font-size: 1.2em;
    margin-bottom: 15px;
    color: #333;
    text-align: center;
}

.collapsible-sidebar .close-sidebar-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: none;
    border: none;
    font-size: 20px;
    color: #666;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    z-index: 10;
}

.collapsible-sidebar .close-sidebar-btn:hover {
    color: #d9534f;
}

.sidebar-message {
    padding: 20px;
    text-align: center;
    color: #666;
    font-style: italic;
}


/* Adjust editor-toolbar (now residing within the collapsible sidebar) */
.editor-toolbar {
    position: static;
    width: 100%;
    max-width: none;
    transform: none;
    top: auto;
    left: auto;
    padding: 0;
    border: none;
    box-shadow: none;
    background-color: transparent;
    display: none;
    flex-direction: column;
    gap: 15px;
}

/* All other .editor-toolbar related styles remain the same, just ensure they apply within .collapsible-sidebar */
.editor-toolbar.dragging { cursor: auto; }
.editor-toolbar.mobile-edit-active { border: none; }
.editor-toolbar button, .editor-toolbar select, .editor-toolbar input[type="number"] { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; cursor: pointer; background-color: #f0f0f0; transition: background-color 0.2s ease; font-size: 13px; }
.editor-toolbar input[type="text"] { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; background-color: white; color: #333; font-size: 13px; cursor: text; flex-grow: 1; min-width: 120px; transition: border-color 0.2s ease; }
.editor-toolbar input[type="text"]:focus { border-color: #007bff; outline: none; box-shadow: 0 0 0 0.15rem rgba(0, 123, 255, 0.25); }
.editor-toolbar button:hover, .editor-toolbar select:hover, .editor-toolbar input[type="number"]:focus { background-color: #e0e0e0; border-color: #007bff; outline: none; }
.editor-toolbar input[type="color"] { width: 35px; height: 35px; padding: 2px; vertical-align: middle; width: 30px; height: 30px; }
.editor-toolbar label { margin: 0; display: flex; align-items: center; font-size: 13px; font-weight: 500; color: #333; }
.editor-toolbar input[type="number"] { width: 60px; text-align: center; }
.toolbar-section { display: flex; align-items: center; gap: 5px; margin-right: 0; flex-wrap: wrap; border: 1px solid #e0e0e0; padding: 10px; border-radius: 5px; background-color: #fafafa; width: 100%; box-sizing: border-box; }
.toolbar-section label { white-space: nowrap; }
#elementTagName { font-weight: bold; color: #2a70b8; margin-left: 10px; border: 1px solid #a3ccf1; padding: 3px 8px; border-radius: 4px; background-color: #eef7ff; }

/* Preview Area */
.preview-area-wrapper {
    flex-grow: 1; /* Takes all available horizontal space */
    display: flex;
    flex-direction: column;
    padding: 15px; /* Padding around the preview iframe */
    position: relative;
    margin-left: 0; /* REMOVED: No initial left offset from action-buttons-sidebar */
    transition: margin-left 0.3s ease-in-out; /* Smooth transition for sidebar open/close */
    /* NEW: ensure height fills available space and allows scrolling of its content */
    flex-shrink: 0; /* Prevent it from shrinking */
    min-height: calc(100% - 30px); /* Minimum height accounting for padding, allows content to push it */
}

.preview-area-wrapper.sidebar-open { /* Class added when collapsible sidebar is open */
    margin-left: 380px; /* Offset by collapsible sidebar width */
}

.preview-section {
    flex-grow: 1; /* Allow preview section to fill remaining height */
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.preview-header {
    background: linear-gradient(135deg, #2a70b8 0%, #4d8ece 100%);
    color: white;
    padding: 15px 20px;
    border-radius: 8px 8px 0 0;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.html-preview {
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 8px 8px;
    height: 100%;
    overflow: auto;
    background: white;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 10px;
}
iframe {
    width: 100%;
    height: 100%;
    border: none;
    transition: width 0.3s ease-in-out, height 0.3s ease-in-out, border-radius 0.3s ease-in-out;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    background-color: #fff;
}
iframe.mobile-view { width: 375px; height: 667px; border-radius: 10px; }
iframe.ipad-vertical-view { width: 834px; height: 1194px; border-radius: 15px; }
iframe.ipad-horizontal-view { width: 1194px; height: 834px; border-radius: 15px; }

/* Status message (fixed position maintained) */
#status { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 1001; width: 80%; max-width: 600px; padding: 20px 30px; border-radius: 10px; text-align: center; font-size: 1.4em; font-weight: 600; box-shadow: 0 5px 15px rgba(0,0,0,0.2); opacity: 0; visibility: hidden; transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out, visibility 0.3s; color: #333; }
#status.show { opacity: 1; visibility: visible; }
.status-success { background-color: rgba(232, 245, 232, 0.95); color: #2e7d32; border: 1px solid #4CAF50; }
.status-info { background-color: rgba(227, 242, 253, 0.95); color: #1565c0; border: 1px solid #2a70b8; }
.status-error { background-color: rgba(252, 232, 230, 0.95); color: #c0392b; border: 1px solid #e74c3c; }

/* Injected styles for iframe highlighting */
.editable-element-highlight { outline: 3px dashed #007bff !important; outline-offset: 2px; cursor: text !important; }
.editable-image-highlight { outline: 3px dashed #17a2b8 !important; outline-offset: 2px; cursor: pointer !important; }
.editable-container-highlight { outline: 3px dashed #28a745 !important; outline-offset: 2px; cursor: pointer !important; }
#previewFrame.editing-enabled iframe body *:hover { outline: 1px dashed #cccccc; outline-offset: 1px; cursor: pointer; }
#previewFrame.editing-enabled iframe body .editable-element-highlight:hover,
#previewFrame.editing-enabled iframe body .editable-image-highlight:hover,
#previewFrame.editing-enabled iframe body .editable-container-highlight:hover { outline: 3px dashed #007bff !important; }

.rich-text-active { background-color: #007bff !important; color: white !important; border-color: #007bff !important; }
#mobileEditStatus { margin-left: 15px; }
.badge-mobile-active { background-color: #0d6efd !important; }

/* Specific property group styles (already existing, verify fit in new sidebar) */
.gradient-inputs { display: flex; align-items: center; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.gradient-inputs label { min-width: 60px; }
.gradient-inputs input[type="color"] { width: 30px; height: 30px; }
.properties-group { display: flex; flex-direction: column; gap: 8px; padding: 5px; border: 1px solid #d0d0d0; border-radius: 5px; background-color: #fcfcfc; flex: 1 1 100%; min-width: auto; }
#imageControls { flex-direction: column; gap: 8px; flex: 1 1 100%; min-width: auto; padding: 5px; border: 1px solid #d0d0d0; border-radius: 5px; background-color: #fcfcfc; }
#imageControls .input-row { display: flex; align-items: center; gap: 5px; width: 100%; flex-wrap: wrap; }
#imageUrlInput { min-width: 150px; }
#sectionControls { flex-direction: column; gap: 8px; flex: 1 1 100%; padding: 5px; border: 1px solid #d0d0d0; border-radius: 5px; background-color: #fcfcfc; }
#sectionControls .input-row, #sectionControls .gradient-direction-row { display: flex; align-items: center; gap: 5px; width: 100%; flex-wrap: wrap; }
#sectionControls .input-row label, #sectionControls .gradient-direction-row label { min-width: 80px; }
#backgroundsControls { display: none; flex-direction: column; gap: 8px; padding: 5px; border: 1px solid #d0d0d0; border-radius: 5px; background-color: #fcfcfc; flex-basis: 100%; }
#backgroundsControls .input-row, #backgroundsControls .gradient-inputs, #backgroundsControls .gradient-direction-row { display: flex; align-items: center; gap: 5px; width: 100%; flex-wrap: wrap; }
#backgroundsControls .input-row label, #backgroundsControls .gradient-inputs label, #backgroundsControls .gradient-direction-row label { min-width: 80px; }
#elementSpecificControls { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 15px; width: 100%; border: none; padding: 0; background-color: transparent; margin-right: 0; flex-direction: column; }
#buttonLinkControls { display: none; flex-direction: column; gap: 8px; padding: 5px; border: 1px solid #d0d0d0; border-radius: 5px; background-color: #fcfcfc; flex: 1 1 100%; min-width: auto; }
#buttonLinkControls h3 { margin: 0 0 5px 0; font-size: 1.1em; color: #2a70b8; }
#buttonLinkControls .input-row { display: flex; align-items: center; gap: 5px; width: 100%; flex-wrap: wrap; }
#buttonLinkControls .input-row label { min-width: 60px; }
#buttonLinkControls input[type="text"] { flex-grow: 1; min-width: 80px; }
#buttonLinkControls .color-inputs-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 5px; }
#buttonLinkControls .color-inputs-row label { min-width: 60px; }
#buttonLinkControls .gradient-styling-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#buttonLinkControls .gradient-styling-row label { min-width: 60px; }


/* HTML Code Editor Section at the bottom (NO LONGER FIXED, will be below the fold) */
.html-code-editor-section {
    background-color: #f0f0f0;
    padding: 20px;
    border-top: 1px solid #ddd;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    height: 300px; /* Fixed height for the code editor area */
    display: flex;
    flex-direction: column;
    /* REMOVED: position: fixed; bottom: 0; left: 0; width: 100%; */
}

.html-code-editor-section h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #333;
}

.html-code-editor-section textarea {
    flex-grow: 1;
    min-height: 100px;
    font-size: 0.8em;
    font-family: monospace;
    resize: vertical;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

.html-editor-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
}

.html-editor-actions .btn-primary {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.html-editor-actions .btn-primary:hover {
    background-color: #0056b3;
}

.html-editor-actions .btn-secondary {
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.html-editor-actions .btn-secondary:hover {
    background-color: #5a6268;
}