:root {
    --editor-sidebar-width: 320px;
    --editor-border: #e2e8f0;
    --editor-border-dark: #313131;
    --editor-bg-light: #f8fafc;
    --editor-primary: #2271b1;
    --editor-success: #10b981;
    --editor-text-main: #1e293b;
    --editor-text-muted: #64748b;
    --editor-accent: #6d28d9;
    --editor-editing-text: #1a1a1a;
    /* Dark text for editing contrast */
}

@media (max-width: 1024px) {
    :root {
        --editor-sidebar-width: 260px;
    }
}

/* 1. Reset / Base */
* {
    box-sizing: border-box;
}

.is-editable:focus {
    outline: 2px solid var(--editor-accent);
    background: #fff !important;
    color: var(--editor-editing-text) !important;
    padding: 2px 4px;
    border-radius: 4px;
    z-index: 10;
}

img {
    max-width: 100%;
    height: auto;
    vertical-align: bottom;
    box-sizing: border-box;
}

.emarturii-editor-container {
    display: flex;
    height: calc(100vh - 100px);
    background: #fff;
    border: 1px solid var(--editor-border);
    overflow: hidden;
}

@media (max-width: 768px) {
    .emarturii-editor-container {
        flex-direction: column;
        height: 100vh;
    }
}

/* Sidebar Styling */
.emarturii-editor-sidebar {
    width: var(--editor-sidebar-width);
    flex-shrink: 0;
    border-right: 1px solid var(--editor-border);
    background: var(--editor-bg-light);
    display: flex;
    flex-direction: column;
    height: 100%;
}

@media (max-width: 768px) {
    .emarturii-editor-sidebar {
        width: 100%;
        height: 40%;
        order: 2;
        border-right: none;
        border-top: 1px solid var(--editor-border-dark);
        box-shadow: -1px -1px 14px 1px var(--editor-border-dark);
        position: relative;
        z-index: 10;
    }
}

.emarturii-editor-sidebar h3 {
    padding: 20px;
    margin: 0;
    font-size: 18px;
    border-bottom: 1px solid var(--editor-border);
    background: #fff;
}

#editable-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex-grow: 1;
}

#editable-list li {
    padding: 15px 20px;
    border-bottom: 1px solid var(--editor-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
}

#editable-list li:hover {
    background: #edf2f7;
}

#editable-list li.active {
    background: #fff;
    border-left: 4px solid var(--editor-primary);
}

#editable-list li.is-completed .status-icon {
    color: var(--editor-success);
}

.element-label {
    font-size: 14px;
    font-weight: 500;
}

.updated-value {
    font-size: 14px;
    color: #64748b;
    font-style: italic;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--editor-border);
    background: #fff;
}

/* Content Area Styling */
.emarturii-editor-content {
    width: calc(100% - var(--editor-sidebar-width));
    overflow-y: auto;
    background: #f1f5f9;
    display: flex;
    flex-direction: column;
}

@media (max-width: 768px) {
    .emarturii-editor-content {
        width: 100%;
        height: 60%;
        order: 1;
    }
}

.device-toolbar {
    background: #fff;
    border-bottom: 1px solid var(--editor-border);
    padding: 10px;
    display: flex;
    justify-content: center;
    gap: 15px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.device-btn {
    background: none;
    border: 1px solid var(--editor-border);
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    color: var(--editor-text-muted);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.device-btn:hover {
    background: #f8fafc;
    color: var(--editor-primary);
    border-color: var(--editor-primary);
}

.device-btn.active {
    background: var(--editor-primary);
    color: #fff;
    border-color: var(--editor-primary);
}

.device-btn .dashicons {
    font-size: 20px;
    width: 20px;
    height: 20px;
}

/* Positioning Modes */
.emarturii-editor-container.position-fixed {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99999;
    border-radius: 0;
}

.emarturii-editor-container.position-modal {
    position: fixed;
    top: 2rem;
    left: 2rem;
    right: 2rem;
    bottom: 2rem;
    width: calc(100vw - 4rem);
    height: calc(100vh - 4rem);
    z-index: 99999;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.editor-close-btn {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 3rem;
    height: 3rem;
    background: #fff;
    border: none;
    border-radius: 50%;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    z-index: 1000;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.editor-close-btn:hover {
    background: #ff5f5f;
    color: #fff;
    transform: scale(1.1);
}

.preview-container {
    background: #fff;
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    position: relative;
    /* Lock down non-editable clicks */
    pointer-events: auto;
    margin: 0 auto;
    transition: width 0.3s ease-in-out;
}

.preview-container.view-tablet {
    width: 768px;
    max-width: 90%;
    margin: 20px auto;
    height: auto;
    min-height: calc(100% - 40px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.preview-container.view-mobile {
    width: 375px;
    max-width: 90%;
    margin: 20px auto;
    height: auto;
    min-height: calc(100% - 40px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

/* Everything in preview is non-clickable except editable spans and sections themselves (for overlays) */
.preview-container *:not(.is-editable):not(.template-section) {
    pointer-events: none;
}

.section-edit-btn {
    pointer-events: auto !important;
}

.is-editable {
    pointer-events: auto !important;
    display: inline-block;
    padding: 2px 6px;
    background: rgba(34, 113, 177, 0.03);
    border: 1px dashed rgba(34, 113, 177, 0.4);
    border-radius: 4px;
    cursor: text;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 20px;
    position: relative;
}

.is-editable:hover {
    background: rgba(34, 113, 177, 0.08);
    border-color: var(--editor-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.1);
}

.image-edit-btn:hover {
    background: var(--editor-primary-dark);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.3);
}

.editable-bg-wrapper {
    position: relative;
    width: 100%;
}

.bg-edit-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 20;
    background: rgba(34, 113, 177, 0.9);
    backdrop-filter: blur(4px);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 30px;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: auto !important;
}

.bg-edit-btn:hover {
    background: var(--editor-primary);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(34, 113, 177, 0.4);
}

.bg-edit-btn span {
    display: inline-block;
}

.direct-editable::after {
    content: "Edit text";
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--editor-primary);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    white-space: nowrap;
    z-index: 10;
    pointer-events: none;
}

.direct-editable.date::after {
    content: "Edit date";
}

.direct-editable.editable-location::after {
    content: "Edit in Location & Date/Time";
    background: var(--editor-accent);
}

.editable-location {
    border-color: var(--editor-accent) !important;
    background: rgba(109, 40, 217, 0.05) !important;
    cursor: help !important;
}

.direct-editable:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-5px);
}

/* Ensure block elements stay block */
h1.is-editable,
h2.is-editable,
h3.is-editable,
h4.is-editable,
h5.is-editable,
h6.is-editable,
p.is-editable,
blockquote.is-editable {
    display: block;
}

.is-editable:focus {
    outline: none;
    background: #fff;
    border-style: solid;
    border-color: var(--editor-primary);
    box-shadow: 0 0 0 4px rgba(34, 113, 177, 0.15), 0 10px 20px rgba(0, 0, 0, 0.05);
    transform: scale(1.01);
}

.is-editable[contenteditable="false"] {
    border-style: solid;
    border-color: var(--editor-success);
    background: rgba(16, 185, 129, 0.05);
}

.editable-img {
    transition: all 0.3s ease;
    cursor: pointer !important;
    position: relative;
    border: 2px dashed var(--editor-primary);
}

.editable-img:hover {
    outline: 4px solid var(--editor-primary);
    outline-offset: -4px;
    opacity: 0.9;
    filter: brightness(0.8);
}

.editable-img.active {
    outline: 4px solid var(--editor-primary);
    outline-offset: -4px;
}

.editable-img-wrapper {
    position: relative;
    display: inline-block;
    line-height: 0;
    max-width: 100%;
}

.image-edit-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    background: var(--editor-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 16px;
    pointer-events: auto !important;
}

.image-edit-btn:hover {
    transform: scale(1.1);
    background: var(--editor-accent);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
}

.template-section.is-focused .image-edit-btn {
    display: flex;
}

.editable-date-wrapper {
    position: relative;
    display: inline-block;
}

.date-edit-btn {
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: var(--editor-primary);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto !important;
    white-space: nowrap;
}

.date-edit-btn:hover {
    background: var(--editor-accent);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
    transform: translateX(-50%) scale(1.05);
}

.template-section.is-focused .date-edit-btn {
    display: flex;
}

.editable-bg {
    transition: all 0.3s ease;
    cursor: pointer !important;
    position: relative;
    display: block;
    box-shadow: inset 0 0 0 2px var(--editor-primary);
}

.editable-bg:hover {
    box-shadow: inset 0 0 0 4px var(--editor-primary);
    opacity: 0.95;
}

.editable-bg.active {
    box-shadow: inset 0 0 0 4px var(--editor-primary);
}

/* Section Handling */
.template-section {
    position: relative;
    transition: all 0.3s ease;
    /* padding: clamp(15px, 3.75vw, 60px) clamp(20px, 5vw, 80px) !important;*/
}

.section-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: rgba(14, 14, 14, 0);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 5;
    backdrop-filter: none !important;
}

@media (min-width: 768px) {
    .template-section:hover .section-overlay {
        background: rgba(14, 14, 14, 0.4);
        pointer-events: auto;
    }

    .template-section.is-focused .section-overlay {
        background: transparent !important;
        pointer-events: none !important;
    }

    .template-section.is-focused .section-edit-btn {
        display: none !important;
    }

    .section-edit-btn {
        opacity: 0;
        transform: translateY(10px);
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding: 12px 24px;
        background: var(--editor-primary);
        color: white;
        border: none;
        border-radius: 50px;
        font-weight: 600;
        cursor: pointer;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
        display: flex;
        align-items: center;
        gap: 8px;
        pointer-events: auto !important;
    }

    .section-edit-btn span {
        pointer-events: none !important;
    }


    .template-section:hover .section-edit-btn {
        opacity: 1;
        transform: translateY(0);
    }
}

/*
.section-edit-btn {
    display: none;
}
*/

/* Sidebar States */
.sidebar-view {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
}

.sidebar-view.active {
    display: flex;
}

.view-header {
    padding: 20px;
    border-bottom: 1px solid var(--editor-border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.back-btn {
    background: none;
    border: 1px solid var(--editor-border);
    border-radius: 4px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.back-btn:hover {
    background: #fff;
    border-color: var(--editor-primary);
    color: var(--editor-primary);
}

.editor-hints {
    padding: 15px 20px;
    font-size: 13px;
    color: #64748b;
    background: #f8fafc;
    border-bottom: 1px solid var(--editor-border);
    line-height: 1.5;
}

/* Presets */
.preset-section {
    padding: 20px;
    border-top: 1px solid var(--editor-border);
}

.preset-group {
    margin-bottom: 20px;
}

.preset-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #475569;
}

.color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.color-swatch {
    width: 60px;
    height: 32px;
    border-radius: 8px;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #e2e8f0;
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    overflow: hidden;
}

.color-swatch-mini {
    flex: 1;
    height: 100%;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-swatch.active {
    box-shadow: 0 0 0 2px var(--editor-primary);
}

.typo-selects {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.typo-option {
    padding: 10px;
    background: #fff;
    border: 1px solid var(--editor-border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.typo-option:hover {
    border-color: var(--editor-primary);
}

.typo-option.active {
    background: var(--editor-primary);
    color: #fff;
    border-color: var(--editor-primary);
}

/* Utility Wizard Button (borrowed from builder if not available) */
.wizard-btn {
    display: block;
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.wizard-btn-primary {
    background: var(--editor-primary);
    color: #fff;
}

/* Sidebar Elements Listing */
.sidebar-elements-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-elements-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border: 1px solid var(--editor-border);
    margin: 0.5rem;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.sidebar-elements-list li:hover {
    background: #f8fafc;
}

.sidebar-elements-list li.active-element {
    background: #fff;
    border-color: var(--editor-primary);
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.1);
}

.sidebar-elements-list .element-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--editor-text-main);
}

.sidebar-edit-element-btn {
    margin-left: auto;
    padding: 6px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: #fff;
    border: 1px solid var(--editor-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-elements-list li:hover .sidebar-edit-element-btn {
    border-color: var(--editor-accent);
    color: var(--editor-accent);
}

/*Sidebar settings*/
.section-sidebar-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin: 0.5rem;
    padding: 12px;
}

.section-sidebar-group label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--editor-text-muted);
    width: 100%;
}

.em-dashboard-sidebar input,
.em-dashboard-sidebar select,
.em-dashboard-sidebar textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--editor-border);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    background: #fff;
    transition: all 0.2s;
}
input[type="color"]{
    padding:0;
    cursor:pointer;
}

/* Date Settings UI */
.date-settings-container {
    padding: 15px;
    background: #fff;
    border: 1px solid var(--editor-border);
    border-radius: 8px;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.date-settings-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.date-settings-group label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--editor-text-muted);
}

.date-settings-container input[type="date"],
.date-settings-container select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--editor-border);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    background: #fff;
    transition: all 0.2s;
}

.date-settings-container input[type="date"]:focus,
.date-settings-container select:focus {
    border-color: var(--editor-primary);
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.1);
}

.sidebar-elements-list li.date-active {
    background: #fff;
    border-color: var(--editor-primary);
    flex-direction: column;
    align-items: stretch;
}

.date-active .element-header {
    display: flex;
    align-items: center;
    width: 100%;
}

.date-active .date-settings-container {
    display: flex;
}

.date-settings-container {
    display: none;
}
