/* Form designer, tab "Designermodus" (Helpdesk service catalog forms, Admin Center).
   Look of the object layout designer, CSS only and scoped to #grid-stack-formular-designer: the designer saves the innerHTML
   of each cell (propFieldLabel stays in the stored form), so markup and attributes must stay exactly as they are.
   Overrides site.css (.grid-stack-item-content, .prop-id-container, ...) and #template-formular-tab rules there. */

#grid-stack-formular-designer {
    --fdm-accent: #2d6a9f;
    --fdm-accent-soft: #e8f1f9;
    --fdm-border: #dfe3e8;
    --fdm-border-strong: #c5ccd6;
    --fdm-muted: #6b7380;
    --fdm-text: #1f2a37;
    --fdm-surface: #ffffff;
    --fdm-canvas: #f4f6f8;
    --fdm-standard: #4a5360;
    --fdm-standard-soft: #eef0f2;
    --fdm-component: #006941;
    --fdm-component-soft: #e6f4ee;
    --fdm-danger: #c0392b;
    background: var(--fdm-canvas);
    border-color: var(--fdm-border);
}

/* Cell: white card, content as flowing rows instead of absolutely placed badges (no overlap, no scrollbar) */
#template-formular-tab #grid-stack-formular-designer .grid-stack-item-content {
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    align-items: center;
    column-gap: 6px;
    row-gap: 2px;
    padding: 5px 28px 5px 10px !important;
    line-height: 16px !important;
    overflow: hidden !important;
    background: var(--fdm-surface);
    border: 1px solid var(--fdm-border);
    border-left: 3px solid var(--fdm-border-strong);
    border-radius: 6px;
    color: var(--fdm-text);
    box-shadow: 0 1px 2px rgba(31, 42, 55, 0.05);
    transition: border-color 120ms, box-shadow 120ms;
}

#template-formular-tab #grid-stack-formular-designer .grid-stack-item:hover > .grid-stack-item-content {
    border-color: var(--fdm-border-strong);
    box-shadow: 0 2px 6px rgba(31, 42, 55, 0.10);
}

#template-formular-tab #grid-stack-formular-designer .grid-stack-item-content.selected {
    background: var(--fdm-accent-soft);
    border-color: var(--fdm-accent);
    box-shadow: 0 0 0 1px var(--fdm-accent);
}

/* Type accent on the left edge (same specificity as the cell rule above) */
#template-formular-tab #grid-stack-formular-designer .grid-stack-item-content:has(> .prop-id-container) { border-left-color: var(--fdm-accent); }
#template-formular-tab #grid-stack-formular-designer .grid-stack-item-content:has(> .fixprop-id-container) { border-left-color: var(--fdm-standard); }
#template-formular-tab #grid-stack-formular-designer .grid-stack-item-content:has(> .component-id-container) { border-left-color: var(--fdm-component); }

/* Row 1: label (what the user sees) + DB-ID, row 2: key chip. The label takes the row except the DB-ID's room, so the
   key always wraps to row 2 (a <br> cannot break a flex line). */
#grid-stack-formular-designer .grid-stack-item-content > br {
    display: none;
}

#grid-stack-formular-designer .propFieldLabel,
#grid-stack-formular-designer .componentFieldLabel {
    position: static;
    order: 1;
    flex: 1 0 calc(100% - 72px);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
    color: var(--fdm-text);
}

#grid-stack-formular-designer .prop-id-container,
#grid-stack-formular-designer .fixprop-id-container,
#grid-stack-formular-designer .component-id-container {
    position: static;
    order: 4;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 6px;
    border-radius: 3px;
    font-family: Consolas, "Courier New", monospace;
    font-size: 11px;
    line-height: 16px;
    background: var(--fdm-accent-soft);
    color: var(--fdm-accent);
}

#grid-stack-formular-designer .fixprop-id-container {
    background: var(--fdm-standard-soft);
    color: var(--fdm-standard);
}

#grid-stack-formular-designer .component-id-container {
    background: var(--fdm-component-soft);
    color: var(--fdm-component);
}

#grid-stack-formular-designer .grid-stack-item-content:not(:has(> .prop-dbid-container)) > .propFieldLabel,
#grid-stack-formular-designer .componentFieldLabel {
    flex-basis: 100%;
}

/* inline style margin-left:8px / color #888 from template.js */
#grid-stack-formular-designer .prop-dbid-container {
    order: 2;
    flex: 0 1 auto;
    max-width: 72px;
    overflow: hidden;
    margin-left: 0 !important;
    font-size: 11px !important;
    color: var(--fdm-muted) !important;
    white-space: nowrap;
}

/* Narrow cells: hover shows the full key and label instead of cutting them off */
#template-formular-tab #grid-stack-formular-designer .grid-stack-item:hover > .grid-stack-item-content {
    z-index: 5;
}

#grid-stack-formular-designer .grid-stack-item:hover .propFieldLabel,
#grid-stack-formular-designer .grid-stack-item:hover .componentFieldLabel,
#grid-stack-formular-designer .grid-stack-item:hover .prop-id-container,
#grid-stack-formular-designer .grid-stack-item:hover .fixprop-id-container,
#grid-stack-formular-designer .grid-stack-item:hover .component-id-container {
    white-space: normal;
    word-break: break-all;
}

#template-formular-tab #grid-stack-formular-designer .grid-stack-item:hover > .grid-stack-item-content:has(> .prop-id-container, > .fixprop-id-container, > .component-id-container) {
    bottom: auto !important;
    min-height: calc(100% - 10px);
}

/* Actions: drag handle top left (shown on hover by template.js), delete and edit top right */
#grid-stack-formular-designer .delete-container,
#grid-stack-formular-designer .edit-container,
#grid-stack-formular-designer .drag-container {
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    border-radius: 4px;
    font-size: 12px;
    color: #9aa3ad;
    transition: color 120ms, background-color 120ms;
}

#grid-stack-formular-designer .delete-container { top: 4px; right: 4px; }
#grid-stack-formular-designer .edit-container { top: 4px; right: 26px; }
/* Drag handle in the top row next to the actions: below the x it sat on the resize handle (bottom right) */
#grid-stack-formular-designer .drag-container {
    top: 4px;
    left: auto;
    right: 26px;
    cursor: move;
}

#grid-stack-formular-designer .grid-stack-item-content:has(> .edit-container) > .drag-container { right: 48px; }

/* One column (gs-w 1 or none, ~37px): drag left and x right in one row of smaller buttons */
#grid-stack-formular-designer .grid-stack-item:is([gs-w="1"], :not([gs-w])) > .grid-stack-item-content > .delete-container,
#grid-stack-formular-designer .grid-stack-item:is([gs-w="1"], :not([gs-w])) > .grid-stack-item-content > .drag-container {
    top: 2px;
    width: 16px;
    height: 16px;
    line-height: 16px;
    font-size: 10px;
}

#grid-stack-formular-designer .grid-stack-item:is([gs-w="1"], :not([gs-w])) > .grid-stack-item-content > .delete-container { right: 2px; }
#grid-stack-formular-designer .grid-stack-item:is([gs-w="1"], :not([gs-w])) > .grid-stack-item-content > .drag-container { right: auto; left: 2px; }

/* Resize handle into the corner of the card, clear of the action row also for one-row fields */
#grid-stack-formular-designer .grid-stack-item > .ui-resizable-se { right: 4px; bottom: 4px; }

#template-formular-tab #grid-stack-formular-designer .grid-stack-item-content:has(> .drag-container) {
    padding-right: 50px !important;
}

#template-formular-tab #grid-stack-formular-designer .grid-stack-item-content:has(> .drag-container):has(> .edit-container) {
    padding-right: 72px !important;
}

#grid-stack-formular-designer .delete-container:hover {
    color: var(--fdm-danger);
    background: #fdf3f2;
}

#grid-stack-formular-designer .edit-container:hover,
#grid-stack-formular-designer .drag-container:hover {
    color: var(--fdm-accent);
    background: var(--fdm-accent-soft);
}

/* Section: accent line with its title */
/* a new section is <div><hr/></div>, an edited one <hr data-title=...> */
#grid-stack-formular-designer .grid-stack-item-content > div:has(> hr) {
    flex: 1 1 100%;
}

#grid-stack-formular-designer .grid-stack-item-content hr {
    flex: 1 1 100%;
    overflow: visible;
    margin: 0;
    border: 0;
    border-top: 2px solid rgba(45, 106, 159, 0.6);
}

#template-formular-tab #grid-stack-formular-designer .grid-stack-item-content:has(hr) {
    border-left-color: var(--fdm-accent);
    background: var(--fdm-accent-soft);
}

#grid-stack-formular-designer .grid-stack-item-content hr[data-title]:not([data-title=""])::after {
    content: attr(data-title);
    display: inline-block;
    position: relative;
    top: -10px;
    padding: 0 8px 0 0;
    background: var(--fdm-accent-soft);
    color: var(--fdm-accent);
    font-size: 12px;
    font-weight: 600;
}

/* File drop zone */
#grid-stack-formular-designer .dropzone-area {
    flex: 1 1 100%;
    border: 1px dashed var(--fdm-border-strong);
    border-radius: 4px;
    color: var(--fdm-muted);
    background: var(--fdm-canvas);
}
