/* ==========================================================================
   CraftX ERP — Catalog & Templates surfaces
   Domain CSS for content-management pages: CatalogManager, TemplateManager,
   EmailTemplateEditorDialog, TextSnippetEditorDialog, plus shared content
   dialogs (InsertablePickerDialog, ContentMetadataEditor, ContentComposeDialog).
   Token-only; layered on top of cx-widgets.css primitives (.card, .cx-card-*,
   .chip, .btn, .data-table).
   ========================================================================== */

/* ──────────────────────────────────────────────────────────────────────────
   Catalog page (CatalogManager)
   ────────────────────────────────────────────────────────────────────────── */

.cx-catalog-page {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: transparent;
    overflow: hidden;
}

/* Stat card icon tones — semantic, copper-leaning palette */
.cx-catalog-page .stat-total .cx-stat-icon    { background: var(--cx-primary-soft); color: var(--cx-primary); }
.cx-catalog-page .stat-material .cx-stat-icon { background: var(--warning-50);      color: var(--cx-warning); }
.cx-catalog-page .stat-labor .cx-stat-icon    { background: var(--success-50);      color: var(--cx-success); }
.cx-catalog-page .stat-product .cx-stat-icon  { background: var(--info-50);         color: var(--cx-info); }
.cx-catalog-page .stat-bundle .cx-stat-icon   { background: var(--ai-50);           color: var(--ai); }

/* Catalog Grid Shell — wraps SfGrid in a polished card surface.
   The card fills the page (flex: 1) and is the scroll container; the grid
   inside renders auto-height with a sticky header, so the quick-add line
   docks directly beneath the last row and the rest of the card stays empty. */
.cx-catalog-grid-shell {
    background: var(--cx-card-bg);
    border: 1px solid var(--cx-card-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xs);
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.cx-catalog-grid-shell .catalog-data-grid {
    border: 0;
}

.cx-catalog-grid-shell .catalog-data-grid .e-gridheader {
    border-bottom: 1px solid var(--cx-hairline-soft);
}

.cx-catalog-grid-shell .catalog-data-grid .e-headercell {
    background: var(--light-gray);
    color: var(--cx-text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 0.55rem 0.65rem;
}

.cx-catalog-grid-shell .catalog-data-grid .e-rowcell {
    padding: 0.35rem 0.65rem;
    vertical-align: middle;
}

.cx-catalog-grid-shell .catalog-data-grid .e-gridcontent .e-row:hover {
    background: var(--cx-primary-soft);
}

/* Type chip inside grid rows — uses .chip primitive tones from cx-widgets */
.cx-catalog-grid-shell .cx-catalog-type-chip {
    font-size: 0.66rem;
    font-weight: 600;
    padding: 0.18rem 0.5rem;
    border-radius: var(--radius-pill);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
}

.cx-catalog-type-chip.type-position { background: var(--success-50); color: var(--cx-success); }
.cx-catalog-type-chip.type-bundle   { background: var(--ai-50);      color: var(--ai); }

.cx-catalog-grid-link {
    border: 0;
    background: transparent;
    padding: 0;
    color: var(--cx-text-primary);
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: left;
    cursor: pointer;
}

.cx-catalog-grid-link:hover {
    color: var(--cx-primary);
}

.cx-catalog-grid-input {
    min-height: 32px;
    padding: 0.22rem 0.45rem;
    font-size: 0.82rem;
    line-height: 1.2;
}

.cx-catalog-grid-readonly {
    display: inline-block;
    color: var(--cx-text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
}

.cx-catalog-grid-actions {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
}

/* Tile (grid) view — used when ViewMode == "grid" */
.cx-catalog-tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1px;
}

.cx-catalog-tile {
    background: var(--cx-card-bg);
    border-radius: var(--radius-xl);
    padding: 1.25rem;
    cursor: pointer;
    transition: border-color 0.2s var(--ease, ease), box-shadow 0.2s var(--ease, ease), transform 0.2s var(--ease, ease);
    border: 1px solid var(--cx-card-border);
    box-shadow: var(--shadow-xs);
    display: flex;
    flex-direction: column;
    min-height: 160px;
}

.cx-catalog-tile:hover {
    border-color: rgba(184, 96, 31, 0.30);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.cx-catalog-tile.inactive {
    opacity: 0.7;
    background: var(--paper-2);
}

.cx-catalog-tile .tile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.cx-catalog-tile .tile-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    color: var(--cx-text-primary);
    line-height: 1.3;
}

.cx-catalog-tile .tile-description {
    color: var(--cx-text-muted);
    font-size: 0.85rem;
    margin: 0;
    flex: 1;
    line-height: 1.4;
}

.cx-catalog-tile .tile-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--cx-hairline-soft);
}

.cx-catalog-tile .tile-price {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--cx-success);
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
}

.cx-catalog-tile .tile-type {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    background: var(--light-gray);
    border-radius: var(--radius-sm);
    color: var(--cx-text-secondary);
}

/* Action buttons (edit / archive / restore) shared by Catalog + Templates */
.cx-action-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    border: 1px solid var(--cx-card-border);
    background: var(--cx-card-bg);
    color: var(--cx-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s var(--ease, ease), color 0.2s var(--ease, ease), border-color 0.2s var(--ease, ease);
}

.cx-action-btn:hover {
    background: var(--cx-primary);
    color: white;
    border-color: var(--cx-primary);
}

.cx-action-btn.action-archive:hover {
    background: var(--cx-danger);
    border-color: var(--cx-danger);
}

.cx-action-btn.action-restore:hover {
    background: var(--cx-success);
    border-color: var(--cx-success);
}

/* Empty state — layered on top of .card */
.cx-catalog-empty,
.cx-templates-empty {
    text-align: center;
    padding: 4rem 2rem;
    border: 2px dashed var(--cx-hairline);
    border-radius: var(--radius-xl);
    background: var(--cx-card-bg);
}

.cx-catalog-empty .empty-icon,
.cx-templates-empty .empty-icon {
    font-size: 4rem;
    color: var(--cx-text-muted);
    margin-bottom: 1rem;
}

.cx-catalog-empty h3,
.cx-templates-empty h3 {
    color: var(--cx-text-primary);
    margin: 0 0 0.5rem 0;
}

.cx-catalog-empty p,
.cx-templates-empty p {
    color: var(--cx-text-muted);
    margin: 0 0 1.5rem 0;
}

.cx-catalog-empty__actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.cx-catalog-result-info {
    text-align: center;
    padding: 1.5rem;
}

.cx-catalog-result-info .showing-text {
    color: var(--cx-text-muted);
    font-size: 0.9rem;
    margin: 0;
}

@media (max-width: 768px) {
    .cx-catalog-tile-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .cx-catalog-empty,
    .cx-templates-empty {
        padding: 2.5rem 1rem;
    }

    .cx-action-btn {
        width: 36px;
        height: 36px;
    }
}

/* ──────────────────────────────────────────────────────────────────────────
   Templates page (TemplateManager)
   ────────────────────────────────────────────────────────────────────────── */

.cx-templates-page {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: transparent;
    overflow: hidden;
}

.cx-templates-page .stat-total .cx-stat-icon   { background: var(--cx-primary-soft); color: var(--cx-primary); }
.cx-templates-page .stat-snippet .cx-stat-icon { background: var(--success-50);      color: var(--cx-success); }
.cx-templates-page .stat-email .cx-stat-icon   { background: var(--ai-50);           color: var(--ai); }

.cx-templates-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.cx-template-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border: 1px solid var(--cx-card-border);
    border-radius: var(--radius-xl);
    background: var(--cx-card-bg);
    box-shadow: var(--shadow-xs);
    transition: border-color 0.2s var(--ease, ease), box-shadow 0.2s var(--ease, ease);
}

.cx-template-row:hover {
    border-color: rgba(184, 96, 31, 0.30);
    box-shadow: var(--shadow-md);
}

.cx-template-row.inactive {
    opacity: 0.7;
    background: var(--paper-2);
}

.cx-template-row .row-main {
    flex: 1;
    min-width: 0;
}

.cx-template-row .row-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.35rem;
}

.cx-template-row .row-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--cx-text-primary);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cx-template-row .row-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.cx-template-row .row-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Type tag pills (Textbaustein / E-Mail) */
.cx-templates-page .type-tag {
    font-size: 0.66rem;
    font-weight: 600;
    padding: 0.18rem 0.5rem;
    border-radius: var(--radius-pill);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.cx-templates-page .type-tag.type-snippet { background: var(--success-50); color: var(--cx-success); }
.cx-templates-page .type-tag.type-email   { background: var(--ai-50);      color: var(--ai); }

/* Usage / scenario badges */
.cx-templates-page .usage-pill,
.cx-templates-page .scenario-pill {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-pill);
}

.cx-templates-page .usage-pill {
    background: var(--cx-primary-soft);
    color: var(--cx-primary);
}

.cx-templates-page .scenario-pill {
    background: var(--ai-50);
    color: var(--ai);
}

.cx-templates-page .tag-pill {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    background: var(--light-gray);
    border-radius: var(--radius-sm);
    color: var(--cx-text-secondary);
}

@media (max-width: 992px) {
    .cx-template-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .cx-template-row .row-actions {
        justify-content: flex-end;
    }
}

@media (max-width: 768px) {
    .cx-template-row .row-header {
        flex-wrap: wrap;
    }
}

@media (max-width: 640px) {
    .cx-template-row {
        padding: 0.875rem 1rem;
    }
}

/* ──────────────────────────────────────────────────────────────────────────
   Editor dialogs — EmailTemplateEditorDialog + TextSnippetEditorDialog
   ────────────────────────────────────────────────────────────────────────── */

.email-template-editor-dialog .e-dlg-content,
.snippet-editor-dialog .e-dlg-content {
    max-height: calc(80vh - 110px);
    overflow: hidden;
}

.email-template-editor-dialog .dialog-header,
.snippet-editor-dialog .dialog-header,
.variable-input-dialog .dialog-header {
    display: flex;
    align-items: center;
    font-weight: 600;
}

.email-template-editor-dialog .editor-column,
.snippet-editor-dialog .editor-column {
    max-height: calc(80vh - 140px);
    overflow-y: auto;
    padding-right: 0.5rem;
}

.email-template-editor-dialog .e-footer-content,
.snippet-editor-dialog .e-footer-content {
    border-top: 1px solid var(--cx-border);
}

.email-template-editor-dialog .loading-state,
.snippet-editor-dialog .loading-state {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.email-template-editor-dialog .editor-content,
.snippet-editor-dialog .editor-content {
    padding: 0.5rem 0;
}

/* Inputs / form chrome inside editor dialogs */
.email-template-editor-dialog .form-control,
.snippet-editor-dialog .form-control,
.variable-input-dialog .form-control {
    border-radius: var(--radius-md);
    border: 1px solid var(--cx-input-border);
    background: var(--cx-card-bg);
    transition: border-color 0.15s var(--ease, ease), box-shadow 0.15s var(--ease, ease);
}

.email-template-editor-dialog .form-control:focus,
.snippet-editor-dialog .form-control:focus,
.variable-input-dialog .form-control:focus {
    border-color: var(--cx-primary);
    box-shadow: var(--cx-focus-ring);
    outline: none;
}

.email-template-editor-dialog .form-label,
.snippet-editor-dialog .form-label,
.variable-input-dialog .form-label {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--cx-text-muted);
    margin-bottom: 0.3rem;
}

/* Preview area */
.email-template-editor-dialog .template-preview {
    padding: 1rem;
    border: 1px solid var(--cx-card-border);
    border-radius: var(--radius-md);
    background: var(--paper-2);
}

.email-template-editor-dialog .preview-title {
    font-weight: 600;
    color: var(--cx-text-primary);
}

.email-template-editor-dialog .preview-subtitle {
    font-size: 0.85rem;
    color: var(--cx-text-secondary);
}

.email-template-editor-dialog .subject-preview {
    margin: 0.75rem 0;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    background: var(--cx-card-bg);
    border: 1px solid var(--cx-card-border);
}

.email-template-editor-dialog .subject-label {
    font-weight: 600;
    margin-right: 0.5rem;
}

.email-template-editor-dialog .preview-body {
    padding: 1rem;
    border-radius: var(--radius-md);
    background: var(--cx-card-bg);
    border: 1px solid var(--cx-card-border);
}

.email-template-editor-dialog .preview-body h1 { font-size: 2em; font-weight: bold; margin: 0.67em 0; }
.email-template-editor-dialog .preview-body h2 { font-size: 1.5em; font-weight: bold; margin: 0.75em 0; }
.email-template-editor-dialog .preview-body h3 { font-size: 1.17em; font-weight: bold; margin: 0.83em 0; }
.email-template-editor-dialog .preview-body h4 { font-size: 1em; font-weight: bold; margin: 1em 0; }
.email-template-editor-dialog .preview-body ul { list-style-type: disc; padding-left: 1.5rem; margin: 0.5em 0; }
.email-template-editor-dialog .preview-body ol { list-style-type: decimal; padding-left: 1.5rem; margin: 0.5em 0; }
.email-template-editor-dialog .preview-body li { display: list-item; }
.email-template-editor-dialog .preview-body blockquote {
    border-left: 3px solid var(--cx-hairline);
    padding-left: 0.75rem;
    margin: 0.5em 0;
    color: var(--cx-text-secondary);
}
.email-template-editor-dialog .preview-body p { margin: 0.5em 0; }
.email-template-editor-dialog .preview-body a { color: var(--cx-primary); text-decoration: underline; }

/* Token reference / chips */
.email-template-editor-dialog .token-reference {
    padding: 0.75rem;
    border: 1px solid var(--cx-card-border);
    border-radius: var(--radius-md);
    background: var(--paper-2);
}

.email-template-editor-dialog .token-reference-header {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--cx-text-primary);
    margin-bottom: 0.25rem;
}

.email-template-editor-dialog .token-reference-hint {
    font-size: 0.75rem;
    color: var(--cx-text-muted);
    margin-bottom: 0.5rem;
}

.email-template-editor-dialog .token-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.email-template-editor-dialog .token-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--cx-hairline);
    border-radius: var(--radius-sm);
    background: var(--cx-card-bg);
    font-size: 0.78rem;
    color: var(--cx-text-secondary);
    cursor: pointer;
    transition: border-color 0.15s var(--ease, ease), background 0.15s var(--ease, ease), color 0.15s var(--ease, ease);
}

.email-template-editor-dialog .token-chip:hover {
    border-color: var(--ai);
    background: var(--ai-50);
    color: var(--ai);
}

.email-template-editor-dialog .token-chip.copied {
    border-color: var(--cx-success);
    background: var(--success-50);
    color: var(--cx-success);
}

/* Subject input with overlay rendering live token pills */
.email-template-editor-dialog .subject-input-wrapper {
    position: relative;
}

.email-template-editor-dialog .subject-input-wrapper.has-tokens .subject-input {
    color: transparent;
    caret-color: var(--cx-text-primary);
}

.email-template-editor-dialog .subject-input-wrapper .subject-input::placeholder {
    color: var(--cx-text-muted);
}

.email-template-editor-dialog .subject-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    white-space: nowrap;
    overflow: hidden;
    color: var(--cx-text-primary);
}

.email-template-editor-dialog .subject-pill {
    display: inline;
    background-color: var(--cx-primary-soft);
    color: var(--cx-primary);
    border-radius: var(--radius-sm);
    padding: 1px 5px;
    font-size: 0.9em;
    white-space: nowrap;
    border: 1px solid rgba(184, 96, 31, 0.3);
}

/* Collapsible config section */
.email-template-editor-dialog .config-collapsible {
    border: 1px solid var(--cx-card-border);
    border-radius: var(--radius-md);
    background: var(--paper-2);
}

.email-template-editor-dialog .config-summary {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--cx-text-secondary);
    cursor: pointer;
    user-select: none;
}

.email-template-editor-dialog .config-summary::-webkit-details-marker {
    margin-right: 0.25rem;
}

.email-template-editor-dialog .config-body {
    padding: 0 0.75rem 0.75rem;
}

/* Non-editable placeholder chips inside the RTE — covers both the template
   authoring dialogs and the document-send dialogs (V1 + V2 document send). */
.email-template-editor-dialog .e-richtexteditor .e-mention-chip,
.email-template-editor-dialog .e-richtexteditor [contenteditable="false"].e-mention-chip,
.snippet-editor-dialog .e-richtexteditor .e-mention-chip,
.snippet-editor-dialog .e-richtexteditor [contenteditable="false"].e-mention-chip,
.document-send-dialog .e-richtexteditor .e-mention-chip,
.document-send-dialog .e-richtexteditor [contenteditable="false"].e-mention-chip,
.cx-versenden .e-richtexteditor .e-mention-chip,
.cx-versenden .e-richtexteditor [contenteditable="false"].e-mention-chip {
    display: inline;
    background-color: var(--cx-primary-soft);
    color: var(--cx-primary);
    border-radius: var(--radius-sm);
    padding: 1px 6px;
    font-size: 0.9em;
    white-space: nowrap;
    cursor: default;
    border: 1px solid rgba(184, 96, 31, 0.3);
}

/* ──────────────────────────────────────────────────────────────────────────
   Shared Catalog dialogs
   ────────────────────────────────────────────────────────────────────────── */

/* InsertablePickerDialog */
.insertable-picker-dialog {
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-md) !important;
}

.insertable-picker-dialog .e-dlg-header {
    background: linear-gradient(135deg, var(--paper-2) 0%, var(--cx-border) 100%);
    border-bottom: 1px solid var(--cx-card-border);
}

.insertable-picker-dialog .e-dlg-header h5 {
    font-weight: 600;
    color: var(--cx-text-primary);
}

.insertable-picker-dialog .picker-result-item {
    cursor: pointer;
    transition: background-color 0.15s var(--ease, ease);
    border-bottom: 1px solid var(--cx-hairline-soft);
}

.insertable-picker-dialog .picker-result-item:last-child {
    border-bottom: none;
}

.insertable-picker-dialog .picker-result-item:hover {
    background-color: var(--cx-hover-bg) !important;
}

.insertable-picker-dialog .picker-result-item.is-selected,
.insertable-picker-dialog .picker-result-item.is-selected:hover {
    background-color: var(--cx-primary-soft) !important;
}

/* ContentMetadataEditor */
.content-metadata-editor {
    margin-top: 1rem;
    padding: 1rem;
    border: 1px solid var(--cx-hairline);
    border-radius: var(--radius-lg);
    background: var(--paper-2);
}

.content-metadata-editor .metadata-header {
    margin-bottom: 0.75rem;
}

.content-metadata-editor .metadata-title {
    font-weight: 600;
    color: var(--cx-text-primary);
}

.content-metadata-editor .metadata-subtitle {
    font-size: 0.85rem;
    color: var(--cx-text-muted);
}

.content-metadata-editor .metadata-empty {
    font-size: 0.9rem;
    color: var(--cx-text-muted);
}

.content-metadata-editor .metadata-section + .metadata-section {
    margin-top: 1rem;
}

.content-metadata-editor .section-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--cx-text-secondary);
}

.content-metadata-editor .variables-table {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.content-metadata-editor .variables-head,
.content-metadata-editor .variables-row {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(220px, 2fr) 80px;
    gap: 0.75rem;
    align-items: center;
}

.content-metadata-editor .variables-head {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--cx-text-muted);
}

.content-metadata-editor .variable-required {
    display: flex;
    justify-content: center;
}

.content-metadata-editor .block-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.content-metadata-editor .block-card {
    padding: 0.75rem;
    border: 1px solid var(--cx-hairline);
    border-radius: var(--radius-md);
    background: var(--cx-card-bg);
}

.content-metadata-editor .block-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.content-metadata-editor .default-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--cx-text-secondary);
}

@media (max-width: 768px) {
    .content-metadata-editor .variables-head,
    .content-metadata-editor .variables-row {
        grid-template-columns: 1fr;
    }

    .content-metadata-editor .variables-head {
        display: none;
    }

    .content-metadata-editor .variable-required {
        justify-content: flex-start;
    }
}

/* ContentComposeDialog */
.content-compose-dialog .e-dlg-header-content {
    border-bottom: 1px solid var(--cx-card-border);
    padding: 1rem 1.25rem;
}

.content-compose-dialog .e-dlg-content {
    padding: 0 !important;
    max-height: 65vh;
    overflow-y: auto;
}

.content-compose-dialog .e-footer-content {
    border-top: 1px solid var(--cx-card-border);
    padding: 0.875rem 1.25rem !important;
}

.content-compose-dialog .dialog-header {
    display: flex;
    align-items: center;
    font-weight: 600;
    font-size: 1.0625rem;
    color: var(--cx-text-primary);
}

.content-compose-dialog .dialog-header i {
    color: var(--cx-primary);
}

.content-compose-dialog .compose-form {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.content-compose-dialog .section {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.content-compose-dialog .section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--cx-text-primary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.content-compose-dialog .section-header i {
    color: var(--cx-primary);
}

.content-compose-dialog .variables-grid {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--cx-card-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.content-compose-dialog .grid-header {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 1rem;
    padding: 0.5rem 0.75rem;
    background: var(--paper-2);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--cx-text-secondary);
}

.content-compose-dialog .grid-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 1rem;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--cx-hairline-soft);
    align-items: start;
}

.content-compose-dialog .variable-key {
    display: flex;
    align-items: center;
    padding-top: 0.25rem;
}

.content-compose-dialog .variable-key code {
    background: var(--cx-primary-soft);
    color: var(--cx-primary);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 500;
}

.content-compose-dialog .variable-value .form-control {
    border-radius: var(--radius-md);
    border: 1px solid var(--cx-input-border);
    font-size: 0.875rem;
}

.content-compose-dialog .variable-value .form-control:focus {
    border-color: var(--cx-primary);
    box-shadow: var(--cx-focus-ring);
    outline: none;
}

.content-compose-dialog .blocks-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.content-compose-dialog .block-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--paper-2);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s var(--ease, ease);
}

.content-compose-dialog .block-item:hover {
    background: var(--cx-hover-bg);
}

.content-compose-dialog .block-item input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

.content-compose-dialog .block-label {
    font-size: 0.875rem;
    color: var(--cx-text-primary);
}

.content-compose-dialog .preview-section {
    border-top: 1px solid var(--cx-card-border);
    padding-top: 1rem;
}

.content-compose-dialog .subject-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: var(--paper-2);
    border: 1px solid var(--cx-card-border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border-bottom: none;
    font-size: 0.875rem;
}

.content-compose-dialog .subject-label {
    font-weight: 600;
    color: var(--cx-text-secondary);
    white-space: nowrap;
}

.content-compose-dialog .subject-text {
    color: var(--cx-text-primary);
}

.content-compose-dialog .preview-content {
    padding: 1rem;
    background: var(--paper-2);
    border: 1px solid var(--cx-card-border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--cx-text-primary);
    max-height: 200px;
    overflow-y: auto;
}

.content-compose-dialog .subject-preview + .preview-content {
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.content-compose-dialog .preview-content p {
    margin: 0 0 0.5rem 0;
}

.content-compose-dialog .preview-content p:last-child {
    margin-bottom: 0;
}

.content-compose-dialog .dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ──────────────────────────────────────────────────────────────────────────
   Templates polish — chrome alignment for TemplateManager + editor dialogs
   ────────────────────────────────────────────────────────────────────────── */

/* Spinner container in TemplateManager */
.cx-templates-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

/* Empty state CTA alignment — buttons render inline via .btn primary/outline */
.cx-templates-empty .btn.primary,
.cx-templates-empty .btn.outline,
.cx-templates-empty .btn.ghost {
    margin-inline: auto;
}

/* Dialog title chrome — let cx-card-header own the padding/border so the
   Syncfusion default header padding does not double up. */
.email-template-editor-dialog .e-dlg-header-content,
.snippet-editor-dialog .e-dlg-header-content,
.variable-input-dialog .e-dlg-header-content {
    padding: 0 !important;
    border-bottom: none !important;
}

.email-template-editor-dialog .cx-card-header.dialog-header,
.snippet-editor-dialog .cx-card-header.dialog-header,
.variable-input-dialog .cx-card-header.dialog-header {
    width: 100%;
    background: transparent;
}

/* Footer separator already provided by .e-footer-content rule above; keep
   the inner action row breathable. */
.email-template-editor-dialog .e-footer-content > .d-flex,
.snippet-editor-dialog .e-footer-content > .d-flex,
.variable-input-dialog .e-footer-content > .d-flex {
    padding: 0.5rem;
}

/* Editor body — cx-card-body adds the canonical card padding; trim the
   legacy inner spacing so vertical rhythm matches other polished dialogs. */
.email-template-editor-dialog .cx-card-body.editor-content,
.snippet-editor-dialog .cx-card-body.editor-content {
    padding: var(--cx-card-pad);
}

.variable-input-dialog .cx-card-body {
    padding: var(--cx-card-pad);
}

/* Inline alert inside the editor — soften Bootstrap's alert chrome onto
   the warm palette. */
.email-template-editor-dialog .alert-danger,
.snippet-editor-dialog .alert-danger {
    background: color-mix(in srgb, var(--cx-danger) 8%, white);
    color: var(--cx-danger);
    border: 1px solid color-mix(in srgb, var(--cx-danger) 30%, white);
    border-radius: var(--radius-md);
}

.email-template-editor-dialog .alert-danger code,
.snippet-editor-dialog .alert-danger code {
    color: var(--cx-danger);
    background: transparent;
}

/* Form-check chrome inside dialog — tone the checkbox to match the
   primary palette. */
.email-template-editor-dialog .form-check-input:checked,
.snippet-editor-dialog .form-check-input:checked {
    background-color: var(--cx-primary);
    border-color: var(--cx-primary);
}

.email-template-editor-dialog .form-check-input:focus,
.snippet-editor-dialog .form-check-input:focus,
.variable-input-dialog .form-check-input:focus {
    border-color: var(--cx-primary);
    box-shadow: var(--cx-focus-ring);
}

/* Inline editing in the catalog list: while a row's change is being persisted
   its inputs dim and ignore further input until the save round-trip finishes. */
.catalog-data-grid .cx-inline-saving {
    opacity: 0.55;
    pointer-events: none;
}

/* Split button "Neuer Eintrag": main segment opens the editor directly,
   the arrow opens a type-preselect popover (mirrors the positions tab). */
.cx-catalog-add-split {
    position: relative;
    display: inline-flex;
}

.cx-catalog-add-split .btn.cx-catalog-add-split__main {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.cx-catalog-add-split .btn.cx-catalog-add-split__arrow {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.35);
    padding-left: 10px;
    padding-right: 10px;
}

.cx-catalog-add-split__backdrop {
    position: fixed;
    inset: 0;
    z-index: 1050;
}

.cx-catalog-add-split__menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 1060;
    min-width: 210px;
    display: flex;
    flex-direction: column;
    padding: 6px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
}

.cx-catalog-add-split__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--cx-text-primary);
    cursor: pointer;
    text-align: left;
}

.cx-catalog-add-split__item:hover {
    background: var(--paper-2);
}

.cx-catalog-add-split__item i {
    color: var(--cx-primary);
    font-size: 1rem;
}

.cx-catalog-add-split__divider {
    height: 1px;
    margin: 4px 6px;
    background: rgba(0, 0, 0, 0.08);
}

/* Quick-add line inside the grid shell, directly beneath the last row (like the
   JobDetailsV2 positions editor). Sticky at the shell bottom so it stays reachable
   while a long list scrolls; bundles keep the full dialog. */
.cx-catalog-quickadd {
    position: sticky;
    bottom: 0;
    background: var(--cx-card-bg);
    border-top: 1px solid var(--cx-hairline-soft);
}

.cx-catalog-quickadd__trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--cx-text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.cx-catalog-quickadd__trigger:hover {
    color: var(--cx-primary);
    background: rgba(184, 96, 31, 0.04);
}

.cx-catalog-quickadd__row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--cx-card-bg);
}

.cx-catalog-quickadd__type { flex: 0 0 150px; }
.cx-catalog-quickadd__name { flex: 1; min-width: 0; }
.cx-catalog-quickadd__price { flex: 0 0 110px; }
.cx-catalog-quickadd__unit { flex: 0 0 100px; }

.cx-catalog-quickadd__eur {
    color: var(--cx-text-secondary);
    font-size: 0.875rem;
}

.cx-catalog-quickadd .btn.cx-catalog-quickadd__save {
    padding: 6px 14px;
    font-size: 0.85rem;
    white-space: nowrap;
}

.cx-catalog-quickadd__cancel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: var(--cx-text-secondary);
    border-radius: 8px;
    cursor: pointer;
}

.cx-catalog-quickadd__cancel:hover {
    background: var(--paper-2);
    color: var(--cx-text-primary);
}

.cx-catalog-quickadd__hint {
    display: block;
    padding: 0 14px 8px;
    font-size: 0.75rem;
    color: var(--cx-text-muted);
}

/* ──────────────────────────────────────────────────────────────────────────
   Catalog editor modal (CatalogEditorDialog) — leave-dialog design language.
   Own cxe- prefix and self-contained tokens: the dialog renders on /catalog
   AND inside job pages, so it cannot rely on a page-scoped wrapper class.
   z-band 5040/5050: above Syncfusion dialog containers (4999/5000 !important
   in cx-syncfusion-overrides.css), below the variable-input SfDialog (100000
   in CatalogOptionalDetails).
   ────────────────────────────────────────────────────────────────────────── */

.cxe-scrim {
    position: fixed;
    inset: 0;
    background: rgba(28, 25, 21, 0.34);
    backdrop-filter: blur(2px);
    z-index: 5040;
    animation: cxe-fade 0.18s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes cxe-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.cxe-modal {
    --cxe-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --cxe-sh-xl: 0 28px 56px rgba(28, 25, 21, 0.18), 0 10px 20px rgba(28, 25, 21, 0.10);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 680px;
    max-width: 94vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    border-radius: 18px;
    z-index: 5050;
    box-shadow: var(--cxe-sh-xl);
    animation: cxe-modalin 0.24s var(--cxe-ease);
    font-family: var(--font-sans);
    color: var(--ink);
}

@keyframes cxe-modalin {
    from { opacity: 0; transform: translate(-50%, -46%) scale(0.97); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Header: icon tile + title + live subtitle */
.cxe-h {
    padding: 22px 24px 16px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    border-bottom: 1px solid var(--hairline-soft);
    position: relative;
    flex-shrink: 0;
}

.cxe-hi {
    width: 42px;
    height: 42px;
    border-radius: 11px;
    background: var(--copper-50);
    color: var(--copper);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    font-size: 1.25rem;
}

.cxe-t {
    font-family: var(--font-display);
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.cxe-s {
    font-size: 13px;
    color: var(--walnut);
    margin-top: 3px;
    max-width: 56ch;
}

.cxe-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: var(--sand);
    display: grid;
    place-items: center;
    color: var(--walnut);
    cursor: pointer;
}

.cxe-close:hover {
    background: var(--sand-2);
}

/* Body: the scrollable form area (header + footer stay fixed) */
.cxe-b {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.cxe-b .loading-state {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 3rem;
}

/* Usage alert (edit mode) */
.cxe-b .usage-alert {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: rgba(31, 74, 130, 0.08);
    border: 1px solid rgba(31, 74, 130, 0.2);
    border-radius: 10px;
    margin-bottom: 1.5rem;
}

.cxe-b .usage-alert.warning {
    background: rgba(255, 193, 7, 0.1);
    border-color: rgba(255, 193, 7, 0.3);
}

.cxe-b .usage-icon {
    flex-shrink: 0;
    font-size: 1.125rem;
    color: var(--cx-info);
}

.cxe-b .usage-alert.warning .usage-icon {
    color: var(--cx-warning);
}

.cxe-b .usage-content { flex: 1; }

.cxe-b .usage-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--cx-text-primary);
}

.cxe-b .usage-details {
    font-size: 0.8125rem;
    color: var(--cx-text-secondary);
}

.cxe-b .usage-warning {
    font-size: 0.8125rem;
    color: var(--cx-danger);
    margin-top: 0.25rem;
}

/* Type badge (edit mode, bundles) */
.cxe-b .edit-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    background: var(--paper-2);
    border-radius: 8px;
    margin-bottom: 1.25rem;
}

.cxe-b .type-label {
    font-size: 0.8125rem;
    color: var(--cx-text-secondary);
}

.cxe-b .type-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--cx-text-primary);
}

/* Primary section: fields + image side by side */
.cxe-b .primary-section {
    display: flex;
    gap: 1.25rem;
    margin-bottom: 0.5rem;
}

.cxe-b .primary-fields {
    flex: 1;
    min-width: 0;
}

/* Label typography = leave dialog: small bold labels, quiet hints. This is the
   hierarchy backbone — labels recede, input values carry the weight. */
.cxe-b .field-label,
.cxe-b .type-selector-label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink);
}

.cxe-b .field-hint {
    font-size: 11.5px;
    color: var(--stone);
}

.cxe-b .field-label .required {
    color: var(--cx-danger);
}

/* Name is the anchor field — slightly larger than the rest of the form. */
.cxe-b .form-control.cxe-name {
    font-size: 1rem;
    font-weight: 500;
}

/* Section rhythm: hairline + header instead of nested tinted boxes ("box in box"
   killed the hierarchy). Used by the bundle components and optional details. */
.cxe-b .cxe-section {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--hairline-soft);
}

.cxe-b .cxe-section-title {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.cxe-b .cxe-section-hint {
    font-size: 11.5px;
    color: var(--stone);
}

.cxe-b .form-control {
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    transition: all 0.2s ease;
}

.cxe-b .form-control:focus {
    border-color: var(--cx-primary);
    box-shadow: 0 0 0 3px rgba(184, 96, 31, 0.12);
}

/* Inline error block (save errors + template validation) — leave .plan-errors style */
.cxe-errors {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: var(--cx-danger-soft, rgba(154, 59, 51, 0.08));
    border: 1px solid var(--cx-danger);
    border-radius: 10px;
    padding: 11px 13px;
    font-size: 12.5px;
    color: var(--cx-danger);
    line-height: 1.5;
    margin-top: 1rem;
}

.cxe-errors i {
    flex-shrink: 0;
    margin-top: 1px;
}

.cxe-errors b {
    color: var(--ink);
    display: block;
    margin-bottom: 2px;
}

.cxe-errors code {
    font-size: 11.5px;
}

/* Footer: live summary left, actions right */
.cxe-f {
    padding: 15px 24px;
    border-top: 1px solid var(--hairline-soft);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--cx-card-bg);
    border-radius: 0 0 18px 18px;
    flex-shrink: 0;
}

.cxe-sum {
    flex: 1;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--walnut);
}

.cxe-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: var(--sand);
    color: var(--walnut);
    white-space: nowrap;
}

.cxe-sum-val b {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.cxe-sum-val.computed i {
    color: var(--copper);
    margin-right: 4px;
}

.cxe-f-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cxe-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 38px;
    padding: 0 18px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 600;
    border: 1.5px solid transparent;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
}

.cxe-btn.ghost:hover {
    background: var(--sand);
}

.cxe-btn.primary {
    background: var(--copper);
    color: #fff;
    box-shadow: 0 8px 20px rgba(184, 96, 31, 0.28), 0 2px 6px rgba(184, 96, 31, 0.16);
}

.cxe-btn.primary:hover {
    background: var(--copper-dark);
}

.cxe-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.cxe-btn:active:not(:disabled) {
    transform: translateY(1px);
}

@media (max-width: 576px) {
    .cxe-modal {
        width: 96vw;
        max-height: 94vh;
    }

    .cxe-b .primary-section {
        flex-direction: column;
    }

    .cxe-f {
        flex-wrap: wrap;
    }

    .cxe-sum {
        flex-basis: 100%;
    }
}
