body {
    margin: 0;
    overflow: hidden;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    color: var(--editor-text);
    background:
        linear-gradient(180deg, #f3f6fa 0%, #e9edf3 100%);
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(460px, var(--editor-panel-width, 460px)) 10px minmax(0, 1fr);
    height: 100vh;
}

.editor-panel,
.preview-panel {
    min-height: 0;
}

.editor-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background:
        linear-gradient(180deg, #f8fafc 0%, #f2f5f9 100%);
    border-right: 1px solid var(--editor-border-strong);
}

.editor-panel-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 24px 24px 16px;
}

.editor-topbar {
}

.editor-topbar-actions {
    min-width: 0;
}

.editor-topbar .toolbar {
    position: relative;
}

.editor-topbar .primary-action,
.editor-topbar .secondary-button {
    width: auto;
    min-width: 0;
}

.preview-panel {
    display: flex;
    flex-direction: column;
    overflow: auto;
    padding: 0;
    background-color: #dfe6ee;
}

.preview-panel.is-resizing {
    pointer-events: none;
}

.editor-section {
    margin-bottom: 16px;
    padding: 14px;
}

.editor-section:last-child {
    margin-bottom: 0;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--editor-primary-dark);
}

.editor-section h2 {
    margin: 0;
    font-size: 18px;
}

.section-header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px;
}

.section-header > div,
.section-header > .section-head {
    flex: 1 1 auto;
}

.section-header:not(:last-child) {
    margin-bottom: 12px;
}

.section-header > .section-head {
    margin-bottom: 0;
}

.section-body > :last-child {
    margin-bottom: 0;
}

.section-toggle {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    color: var(--editor-primary-dark);
    cursor: pointer;
    background: #fff;
    border: 1px solid var(--editor-border-strong);
    border-radius: var(--editor-radius-sm);
}

.section-toggle:hover {
    background-color: #f3f6fa;
}

.section-toggle:active {
    transform: translateY(1px);
}

.editor-section.is-collapsed .section-header {
    margin-bottom: 0;
}

.editor-section.is-collapsed .section-body {
    display: none;
}

.panel-lead,
.section-note {
    margin: 0;
    color: var(--editor-muted);
    line-height: 1.55;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 14px;
}

.field:last-child {
    margin-bottom: 0;
}

.toggle-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.switch-field {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.switch-field input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.switch-ui {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    width: 68px;
    height: 38px;
    padding: 3px;
    color: var(--editor-muted);
    background-color: #fff;
    border: 1px solid var(--editor-border-strong);
    border-radius: var(--editor-radius-sm);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
    overflow: hidden;
}

.switch-ui::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 4px;
    width: 28px;
    height: 28px;
    background: linear-gradient(180deg, #ffffff 0%, #eef2f7 100%);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: calc(var(--editor-radius-sm) - 1px);
    box-shadow: 0 2px 4px rgba(24, 33, 43, 0.12);
    transform: translateY(-50%);
}

.switch-ui::after {
    content: "NE";
    position: absolute;
    z-index: 2;
    top: 50%;
    left: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    color: var(--editor-muted);
    transform: translate(-50%, -50%);
    user-select: none;
}

.switch-label {
    position: relative;
    z-index: 0;
    width: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

.switch-field input:checked + .switch-ui {
    color: #dbeafe;
    background: linear-gradient(180deg, var(--editor-primary) 0%, var(--editor-primary-dark) 100%);
    border-color: rgba(0, 0, 0, 0.08);
}

.switch-field input:checked + .switch-ui::before {
    left: 34px;
    background: linear-gradient(180deg, #7fb0ff 0%, #4f8df7 100%);
    border-color: rgba(255, 255, 255, 0.28);
    box-shadow: 0 2px 4px rgba(15, 23, 42, 0.22);
}

.switch-field input:checked + .switch-ui::after {
    content: "DA";
    left: 48px;
    color: #eff6ff;
}

.field-label {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.field input,
.field select,
.block-card textarea,
.block-card input {
    width: 100%;
}

.field input[type="color"] {
    width: 100%;
    height: 40px;
    padding: 4px;
    cursor: pointer;
    overflow: hidden;
    appearance: none;
    -webkit-appearance: none;
}

.field input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.field input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: var(--editor-radius-sm);
}

.field input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: var(--editor-radius-sm);
}

.field input::placeholder,
.field select::placeholder,
.block-card textarea::placeholder,
.block-card input::placeholder {
    color: #7a8794;
}

.field input:focus,
.field select:focus,
.block-card textarea:focus,
.block-card input:focus {
    outline: none;
    border-color: var(--editor-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.file-picker-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.file-name {
    font-size: 13px;
    color: var(--editor-muted);
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 16px;
    margin-bottom: 16px;
}

.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.add-element-toolbar {
    position: relative;
    width: 100%;
}

.element-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    min-width: 220px;
    padding: 8px;
    background-color: #f8fafc;
    border: 1px solid var(--editor-border-strong);
    border-radius: var(--editor-radius-md);
    box-shadow: 0 12px 26px rgba(24, 33, 43, 0.14);
}

.element-menu-up {
    top: auto;
    right: auto;
    bottom: calc(100% + 8px);
    left: 0;
}

.element-menu-right {
    right: 0;
    left: auto;
}

.element-menu[hidden] {
    display: none;
}

.element-menu button {
    display: flex;
    justify-content: flex-start;
    width: 100%;
    padding: 10px 12px;
    text-align: left;
    color: var(--editor-text);
    background: transparent;
    border: none;
    border-radius: var(--editor-radius-sm);
}

.element-menu button:hover {
    background-color: #e8eef7;
}

.toolbar button:hover,
.primary-action:hover,
.block-actions button:hover {
    filter: brightness(0.98);
}

.toolbar button:active,
.primary-action:active,
.block-actions button:active {
    transform: translateY(1px);
}

.block-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.block-card {
    padding: 15px;
    background-color: var(--editor-surface-strong);
    border: 1px solid var(--editor-border);
    border-radius: var(--editor-radius-md);
}

.block-card h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.nested-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

.nested-list:first-of-type {
    margin-top: 0;
}

.nested-card {
    padding: 12px;
    background-color: #f8fafc;
    border: 1px solid var(--editor-border);
    border-radius: var(--editor-radius-md);
}

.nested-card .field:last-of-type {
    margin-bottom: 0;
}

.nested-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

.nested-list + .secondary-button {
    margin-top: 10px;
}

.block-hint {
    margin: 0;
    font-size: 13px;
    color: var(--editor-muted);
}

.block-preview-chip {
    display: inline-block;
    margin-bottom: 10px;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--editor-primary-dark);
    background-color: #dbe8ff;
    border-radius: var(--editor-radius-sm);
}

.block-card textarea {
    min-height: 120px;
    resize: vertical;
}

.block-card input {
    margin-bottom: 10px;
}

.block-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.block-actions .secondary {
    color: var(--editor-text);
    background: #fff;
    border: 1px solid var(--editor-border-strong);
}

.block-actions .secondary:hover {
    background-color: #f3f6fa;
}

.block-actions .danger {
    background: linear-gradient(180deg, var(--editor-danger) 0%, var(--editor-danger-dark) 100%);
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 20px 24px;
    border: none;
    border-radius: 0;
    border-top: 1px solid rgba(154, 169, 184, 0.35);
    background:
        linear-gradient(180deg, #f8fafc 0%, #f2f5f9 100%);
    box-shadow: none;
}

.panel-resizer {
    position: relative;
    cursor: col-resize;
    user-select: none;
    touch-action: none;
    background:
        linear-gradient(
            to right,
            transparent 0,
            transparent 4px,
            rgba(90, 107, 124, 0.28) 4px,
            rgba(90, 107, 124, 0.28) 6px,
            transparent 6px,
            transparent 100%
        );
}

.panel-resizer::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4px;
    height: 64px;
    background-color: rgba(94, 107, 120, 0.5);
    transform: translate(-50%, -50%);
}

.panel-resizer.is-active::before {
    background-color: rgba(37, 99, 235, 0.72);
}

.primary-action {
    width: 100%;
}

.secondary-export {
    background: linear-gradient(180deg, #32455a 0%, #223244 100%);
}

.publish-action {
    background: linear-gradient(180deg, #0f766e 0%, #115e59 100%);
}

.editor-topbar .secondary-button {
    color: #fff;
    background: linear-gradient(180deg, var(--editor-primary) 0%, var(--editor-primary-dark) 100%);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.editor-topbar .secondary-button:hover {
    background: linear-gradient(180deg, var(--editor-primary) 0%, var(--editor-primary-dark) 100%);
    filter: brightness(0.98);
}

.validation-message {
    z-index: 50;
    max-width: min(520px, calc(100vw - 32px));
}

.modal-shell {
    z-index: 30;
}

.modal-panel {
    width: min(1100px, calc(100vw - 48px));
    max-height: calc(100vh - 48px);
    margin: 24px auto;
    overflow: hidden;
}

.modal-panel-narrow {
    width: min(720px, calc(100vw - 48px));
}

.modal-header h2 {
    margin: 0;
}

.modal-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: auto;
}

.request-preview {
    margin: 0;
    padding: 14px;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--editor-text);
    background-color: var(--editor-surface-strong);
    border: 1px solid var(--editor-border);
    border-radius: var(--editor-radius-md);
}

.publish-result {
    display: block;
    padding: 14px;
    background-color: var(--editor-surface-strong);
    border: 1px solid var(--editor-border);
    border-radius: var(--editor-radius-md);
}

.publish-result[hidden] {
    display: none;
}

.publish-result.is-error {
    border-color: #c7776f;
    background-color: #fff4f2;
}

.publish-result.is-success {
    border-color: #8fb691;
    background-color: #f4fbf4;
}

.publish-result-message {
    display: inline;
    margin: 0;
    color: var(--editor-text);
    font: inherit;
    line-height: 1.5;
}

.publish-result-link {
    display: inline;
    margin-left: 0;
    font: inherit;
    line-height: 1.5;
    color: #2f67c7;
    text-decoration: none;
}

.publish-result-link:hover {
    text-decoration: underline;
}

.publish-debug {
    border-top: 1px solid var(--editor-border);
    padding-top: 10px;
}

.publish-debug summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--editor-text-soft);
    list-style: none;
    user-select: none;
}

.publish-debug summary::-webkit-details-marker {
    display: none;
}

.publish-debug summary::before {
    content: "\2014";
    display: inline-block;
    margin-right: 8px;
    color: var(--editor-text-soft);
}

.publish-debug[open] summary::before {
    content: "\2212";
}

.publish-debug[open] .request-preview {
    margin-top: 10px;
}

.table-editor-grid {
    display: grid;
    gap: 8px;
    align-content: start;
    min-width: max-content;
}

.table-editor-grid input {
    width: 180px;
    padding: 8px 10px;
    color: var(--editor-text);
    background-color: #fff;
    border: 1px solid var(--editor-border-strong);
    border-radius: var(--editor-radius-sm);
}

.inline-rich-text-editor {
    min-height: 160px;
    padding: 10px 12px;
    line-height: 1.65;
    color: var(--editor-text);
    background-color: #fff;
    border: 1px solid var(--editor-border-strong);
    border-radius: var(--editor-radius-sm);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.inline-rich-text-editor:focus {
    outline: none;
    border-color: var(--editor-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.inline-rich-text-editor a {
    color: var(--editor-primary-dark);
    text-decoration: underline;
}

.inline-rich-text-toolbar {
    position: fixed;
    z-index: 80;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(248, 250, 252, 0.98);
    border: 1px solid var(--editor-border-strong);
    border-radius: var(--editor-radius-md);
    box-shadow: 0 12px 26px rgba(24, 33, 43, 0.18);
}

.inline-rich-text-button {
    min-height: 36px;
    min-width: 34px;
    padding: 6px 10px;
    font-size: 13px;
    justify-content: center;
}

.inline-rich-text-button-strong {
    font-weight: 800;
}

.inline-rich-text-button-em {
    font-style: italic;
}

.inline-rich-text-button-u {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.inline-rich-text-button-s {
    text-decoration: line-through;
    text-decoration-thickness: 1.5px;
}

#preview-frame {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 100%;
    background-color: #fff;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 1fr;
        height: auto;
    }

    body {
        overflow: auto;
    }

    .editor-panel {
        overflow: visible;
        border-right: none;
        border-bottom: 1px solid var(--editor-border-strong);
    }

    .editor-panel-scroll {
        overflow: visible;
        padding: 24px 24px 0;
    }

    .preview-panel {
        overflow: visible;
        min-height: 900px;
    }

    .panel-resizer {
        display: none;
    }
}

@media (max-width: 720px) {
    .editor-panel {
        padding: 0;
    }

    .editor-panel-scroll {
        padding: 16px 16px 0;
    }

    .actions {
        padding: 16px;
    }

    .field-grid {
        grid-template-columns: 1fr;
    }

    .section-head {
        flex-direction: column;
    }

    .modal-panel {
        width: calc(100vw - 24px);
        max-height: calc(100vh - 24px);
        margin: 12px auto;
        padding: 16px;
    }
}
