/* ══════════════════════════════════════
   CMS EDITOR PANEL (within Templates tab)
══════════════════════════════════════ */
.cms-editor {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--cream);
    flex-direction: column;
    animation: cmsSlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.cms-editor.open {
    display: flex;
}

@keyframes cmsSlideIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.cms-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    background: #fff;
    border-bottom: 1px solid var(--cream-d);
    flex-shrink: 0;
    gap: 16px;
}

.cms-editor-back {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid var(--cream-d);
    border-radius: var(--radius);
    padding: 8px 16px 8px 10px;
    font-family: "Jost", sans-serif;
    font-size: 0.72rem;
    font-weight: 400;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--txt-m);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}
.cms-editor-back:hover {
    border-color: var(--terra);
    color: var(--terra);
}
.cms-editor-back svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.cms-editor-title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}
.cms-editor-title h2 {
    font-family: "Cormorant Garamond", serif;
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--txt);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cms-editor-badge {
    display: inline-block;
    font-size: 0.52rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 10px;
    white-space: nowrap;
}
.cms-editor-badge.is-active {
    background: var(--terra-bg);
    color: var(--terra);
    border: 1px solid rgba(200, 88, 42, 0.2);
}
.cms-editor-badge.is-inactive {
    background: var(--cream-d);
    color: var(--txt-l);
    border: 1px solid var(--cream-dd);
}

.cms-editor-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Three-column layout: nav sidebar + live preview + content panel */
.cms-editor-layout {
    display: grid;
    grid-template-columns: 200px 1fr 440px;
    flex: 1;
    overflow: hidden;
}

/* CMS Nav Sidebar */
.cms-nav {
    background: #fff;
    border-right: 1px solid var(--cream-d);
    overflow-y: auto;
    padding: 16px 0;
}

.cms-nav-group {
    margin-bottom: 8px;
}

.cms-nav-group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px 6px;
    font-size: 0.52rem;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    font-weight: 500;
    color: var(--txt-l);
}
.cms-nav-group-title svg {
    width: 12px;
    height: 12px;
    opacity: 0.5;
}

.cms-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px 9px 24px;
    font-size: 0.78rem;
    font-weight: 300;
    color: var(--txt-m);
    cursor: pointer;
    transition: var(--transition);
    border-left: 2px solid transparent;
    position: relative;
}
.cms-nav-item:hover {
    background: rgba(200, 88, 42, 0.03);
    color: var(--txt);
}
.cms-nav-item.active {
    background: var(--terra-bg);
    color: var(--terra);
    font-weight: 400;
    border-left-color: var(--terra);
}
.cms-nav-item svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    opacity: 0.55;
}
.cms-nav-item.active svg {
    opacity: 1;
}

.cms-nav-sep {
    height: 1px;
    background: var(--cream-d);
    margin: 8px 20px;
}

/* ══════════════════════════════════════
   LIVE PREVIEW PANEL
══════════════════════════════════════ */
.cms-preview {
    display: flex;
    flex-direction: column;
    background: #e8e2da;
    border-right: 1px solid var(--cream-d);
    position: relative;
    overflow: hidden;
}
.cms-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #fff;
    border-bottom: 1px solid var(--cream-d);
    flex-shrink: 0;
}
.preview-device-toggle {
    display: flex;
    gap: 2px;
    background: var(--cream);
    border-radius: var(--radius);
    padding: 2px;
}
.preview-device-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--txt-l);
    transition: var(--transition);
}
.preview-device-btn:hover {
    color: var(--txt);
    background: rgba(0, 0, 0, 0.04);
}
.preview-device-btn.active {
    background: #fff;
    color: var(--terra);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.preview-open-btn {
    padding: 4px 8px !important;
    font-size: 0.6rem !important;
}
.cms-preview-frame-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    position: relative;
    overflow: hidden;
}
.cms-preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
    transition:
        width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.cms-preview-iframe.device-mobile {
    width: 375px;
    height: 100%;
    max-height: 100%;
}
.cms-preview-iframe.device-tablet {
    width: 768px;
    height: 100%;
    max-height: 100%;
}
.cms-preview-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: #e8e2da;
    z-index: 2;
    transition: opacity 0.3s ease;
}
.cms-preview-loading.hidden {
    opacity: 0;
    pointer-events: none;
}
.cms-preview-loading span {
    font-size: 0.7rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--txt-l);
    font-weight: 300;
}
.preview-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--cream-d);
    border-top-color: var(--terra);
    border-radius: 50%;
    animation: previewSpin 0.8s linear infinite;
}
@keyframes previewSpin {
    to {
        transform: rotate(360deg);
    }
}

/* CMS Content Panel */
.cms-panel {
    overflow-y: auto;
    padding: 16px;
    background: var(--cream);
    transition: opacity 0.12s ease;
    position: relative;
}
.cms-panel.switching {
    opacity: 0;
}

.cms-panel-section {
    display: none;
    animation: cmsFadeIn 0.2s ease;
}
.cms-panel-section.active {
    display: block;
    min-height: 60vh;
}

@keyframes cmsFadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Override CMS section styles inside the editor */
.cms-editor .cms-section {
    margin-bottom: 0;
    box-shadow: none;
    border-radius: 0;
    padding: 16px;
}
.cms-editor .cms-section:hover {
    box-shadow: none;
}
.cms-editor .cms-header {
    display: none;
}
.cms-editor .cms-body {
    display: block;
    padding: 0;
    border-top: none;
}
.cms-editor .cms-actions {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
}
.save-indicator {
    font-size: 0.72rem;
    color: var(--sage-d, #6E8A66);
    opacity: 0;
    transition: opacity .3s;
}
.save-indicator.visible {
    opacity: 1;
}

/* Section title shown above each section content */
.cms-section-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
.cms-section-title .cms-header-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.cms-section-title .cms-header-icon svg {
    width: 18px;
    height: 18px;
}
.cms-section-title h3 {
    font-family: "Cormorant Garamond", serif;
    font-weight: 500;
    font-size: 1.1rem;
    color: var(--txt);
}
.cms-section-title .scope-badge {
    margin-left: 0;
}

/* Section visibility toggle (inline in section header) */
.cms-section-toggle {
    margin-left: auto;
    position: relative;
    display: inline-block;
    width: 36px; height: 20px;
    cursor: pointer; flex-shrink: 0;
}
.cms-section-toggle input { display: none; }
.cms-toggle-slider {
    position: absolute; inset: 0;
    background: #ccc; border-radius: 20px;
    transition: .3s;
}
.cms-toggle-slider::before {
    content: ''; position: absolute;
    left: 2px; top: 2px;
    width: 16px; height: 16px;
    background: #fff; border-radius: 50%;
    transition: .3s;
}
.cms-section-toggle input:checked + .cms-toggle-slider {
    background: var(--sage-d, #6E8A66);
}
.cms-section-toggle input:checked + .cms-toggle-slider::before {
    transform: translateX(16px);
}

/* Responsive: medium screens — hide preview, two-column */
@media (max-width: 1100px) {
    .cms-editor-layout {
        grid-template-columns: 200px 1fr;
    }
    .cms-preview {
        display: none;
    }
}

/* Responsive: collapse nav on tablet */
@media (max-width: 900px) {
    .cms-editor-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        overflow: hidden;
    }
    .cms-preview {
        display: none;
    }
    .cms-nav {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        border-right: none;
        border-bottom: 1px solid var(--cream-d);
        padding: 0;
        white-space: nowrap;
        gap: 0;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 5;
        background: #fff;
    }
    .cms-nav::-webkit-scrollbar {
        display: none;
    }
    .cms-nav-group {
        margin: 0;
        display: flex;
        align-items: stretch;
    }
    .cms-nav-group-title {
        padding: 8px 10px;
        font-size: 0.42rem;
        writing-mode: horizontal-tb;
        background: var(--cream-d);
        color: var(--txt-l);
        display: flex;
        align-items: center;
        gap: 4px;
        border-right: 1px solid rgba(0, 0, 0, 0.06);
        font-weight: 600;
        letter-spacing: 2px;
        user-select: none;
        pointer-events: none;
    }
    .cms-nav-group-title svg {
        width: 10px;
        height: 10px;
    }
    .cms-nav-item {
        padding: 10px 14px;
        border-left: none;
        border-bottom: 2px solid transparent;
        font-size: 0.72rem;
        white-space: nowrap;
    }
    .cms-nav-item.active {
        border-left-color: transparent;
        border-bottom-color: var(--terra);
    }
    .cms-nav-sep {
        width: 0;
        height: auto;
        margin: 0;
        border-left: 1px solid var(--cream-d);
    }
    .cms-panel {
        padding: 20px 16px;
        overflow-y: auto;
    }
    .cms-editor-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 10px;
    }
    .cms-editor-title h2 {
        font-size: 1rem;
    }
}

/* Responsive: small mobile */
@media (max-width: 600px) {
    .cms-editor-header {
        padding: 10px 12px;
        gap: 8px;
        flex-direction: column;
        align-items: stretch;
    }
    .cms-editor-back {
        padding: 6px 12px 6px 8px;
        font-size: 0.65rem;
        align-self: flex-start;
    }
    .cms-editor-title {
        gap: 8px;
    }
    .cms-editor-title h2 {
        font-size: 0.9rem;
    }
    .cms-editor-badge {
        font-size: 0.48rem;
        padding: 2px 8px;
    }
    .cms-editor-actions {
        flex-wrap: wrap;
        gap: 6px;
        justify-content: stretch;
    }
    .cms-editor-actions .btn {
        flex: 1;
        min-width: 0;
        justify-content: center;
        font-size: 0.6rem;
        padding: 6px 8px;
    }
    .cms-nav-group-title {
        padding: 6px 8px;
        font-size: 0.38rem;
        letter-spacing: 1.5px;
    }
    .cms-nav-item {
        padding: 8px 10px;
        font-size: 0.65rem;
    }
    .cms-nav-item svg {
        width: 12px;
        height: 12px;
    }
    .cms-nav-sep {
        border-left-width: 1px;
    }
    .cms-panel {
        padding: 16px 12px;
    }
    .cms-section-title {
        gap: 8px;
        margin-bottom: 14px;
    }
    .cms-section-title .cms-header-icon {
        width: 30px;
        height: 30px;
    }
    .cms-section-title .cms-header-icon svg {
        width: 14px;
        height: 14px;
    }
    .cms-section-title h3 {
        font-size: 0.95rem;
    }
    .cms-row {
        flex-direction: column;
        gap: 0;
    }
    .cms-field {
        min-width: 100%;
    }
    .color-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    .slot-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .font-select-wrap {
        flex-direction: column;
        gap: 8px;
    }
    .font-select {
        width: 100%;
    }
    .font-select-preview {
        display: none;
    }
    .font-preview {
        padding: 14px;
    }
    .font-preview-title {
        font-size: 1.3rem;
    }
    .fs-header {
        flex-wrap: wrap;
    }
    .theme-subgroup {
        margin-top: 14px;
        padding-top: 12px;
    }
}

