/**
 * Cesivi Forms Designer — Editor CSS
 * PLAN-392: Visual form designer styles.
 */

/* =========================================================================
   Designer Shell
   ========================================================================= */
.fd-designer {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 130px);
    min-height: 500px;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    font-size: 13px;
    color: #323130;
}

/* =========================================================================
   Toolbar
   ========================================================================= */
.fd-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #f3f2f1;
    border-bottom: 1px solid #d0d0d0;
    flex-shrink: 0;
}
.fd-toolbar-title {
    font-size: 16px;
    font-weight: 600;
    color: #003082;
    margin: 0;
}
.fd-toolbar-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* =========================================================================
   Buttons
   ========================================================================= */
.fd-btn {
    display: inline-block;
    padding: 5px 12px;
    border: 1px solid #8a8886;
    border-radius: 3px;
    background: #fff;
    color: #323130;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}
.fd-btn:hover { background: #edebe9; }
.fd-btn-primary { background: #003082; color: #fff; border-color: #003082; }
.fd-btn-primary:hover { background: #004db3; }
.fd-btn-danger { color: #a80000; border-color: #a80000; }
.fd-btn-danger:hover { background: #fde7e9; }
.fd-btn-sm { padding: 3px 8px; font-size: 11px; }
.fd-btn-link { border: none; background: none; color: #003082; text-decoration: underline; }
.fd-btn-link:hover { color: #004db3; }

.fd-toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 4px 10px;
    border: 1px solid #8a8886;
    border-radius: 3px;
    background: #fff;
    color: #323130;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    line-height: 1.4;
}
.fd-toolbar-btn:hover:not(:disabled) { background: #edebe9; }
.fd-toolbar-btn:disabled {
    opacity: 0.4;
    cursor: default;
}
.fd-toolbar-btn span {
    font-size: 15px;
    line-height: 1;
}
.fd-toolbar-separator {
    display: inline-block;
    width: 1px;
    height: 24px;
    background: #d0d0d0;
    margin: 0 4px;
    vertical-align: middle;
}

.fd-select {
    padding: 4px 8px;
    border: 1px solid #8a8886;
    border-radius: 3px;
    font-size: 12px;
    font-family: inherit;
    background: #fff;
}

/* =========================================================================
   3-Column Layout
   ========================================================================= */
.fd-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left: Palette */
.fd-palette {
    width: 220px;
    min-width: 180px;
    border-right: 1px solid #d0d0d0;
    background: #faf9f8;
    overflow-y: auto;
    padding: 8px;
    flex-shrink: 0;
}
.fd-palette h2,
.fd-palette-section-title {
    font-size: 12px;
    font-weight: 600;
    color: #605e5c;
    text-transform: uppercase;
    margin: 0 0 6px 0;
    letter-spacing: 0.5px;
}
.fd-palette-header {
    margin-bottom: 8px;
}
.fd-search-input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid #c8c6c4;
    border-radius: 3px;
    font-size: 12px;
    box-sizing: border-box;
    margin-top: 4px;
}
.fd-separator { border: none; border-top: 1px solid #e1dfdd; margin: 10px 0; }

/* Palette field items */
.fd-field-list {
    min-height: 40px;
}
.fd-palette-field {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    margin-bottom: 2px;
    border: 1px solid transparent;
    border-radius: 3px;
    cursor: grab;
    background: #fff;
    transition: background 0.15s, border-color 0.15s;
}
.fd-palette-field:hover {
    border-color: #003082;
    background: #e8f0fe;
}
.fd-palette-field.fd-used {
    opacity: 0.4;
    cursor: default;
    text-decoration: line-through;
}
.fd-palette-field.fd-ghost {
    opacity: 0.4;
    background: #e8f0fe;
}
.fd-drag-handle {
    color: #8a8886;
    cursor: grab;
    font-size: 11px;
    flex-shrink: 0;
}
.fd-field-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fd-field-type-badge {
    font-size: 10px;
    color: #605e5c;
    background: #edebe9;
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
}
.fd-field-required-badge { color: #c00; font-weight: bold; font-size: 14px; }

/* Layout tools */
.fd-layout-tools,
.fd-form-events-tools {
    display: flex;
    gap: 4px;
    margin-bottom: 6px;
}

/* Center: Canvas */
.fd-canvas {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #fff;
}
.fd-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #605e5c;
}
.fd-empty-state p { margin: 4px 0; }

/* Tab bar */
.fd-tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #003082;
    margin-bottom: 12px;
}
.fd-tab {
    padding: 6px 14px;
    cursor: pointer;
    background: #f3f2f1;
    border: 1px solid #d0d0d0;
    border-bottom: none;
    border-radius: 3px 3px 0 0;
    margin-right: 2px;
    position: relative;
    font-size: 13px;
    color: #323130;
    user-select: none;
}
.fd-tab:hover { background: #e8f0fe; }
.fd-tab.fd-tab-active {
    background: #fff;
    border-color: #003082;
    color: #003082;
    font-weight: 600;
    border-bottom: 2px solid #fff;
    margin-bottom: -2px;
}
.fd-tab-remove {
    display: inline-block;
    margin-left: 6px;
    border: none;
    background: none;
    color: #a19f9d;
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
    vertical-align: middle;
}
.fd-tab-remove:hover { color: #a80000; }
.fd-tab-add {
    padding: 6px 12px;
    cursor: pointer;
    color: #003082;
    font-size: 16px;
    font-weight: bold;
    border: 1px dashed #c8c6c4;
    border-bottom: none;
    border-radius: 3px 3px 0 0;
    background: transparent;
    user-select: none;
}
.fd-tab-add:hover { background: #e8f0fe; }

/* Sections */
.fd-section {
    border: 1px solid #e1dfdd;
    border-radius: 4px;
    margin-bottom: 12px;
    transition: border-color 0.15s;
}
.fd-section.fd-selected { border-color: #003082; box-shadow: 0 0 0 1px #003082; }
.fd-section-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #f3f2f1;
    border-bottom: 1px solid #e1dfdd;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
}
.fd-section-header:hover { background: #edebe9; }
.fd-section-title { font-weight: 600; flex: 1; }
.fd-section-info { font-size: 11px; color: #605e5c; }
.fd-section-badge {
    font-size: 10px;
    background: #edebe9;
    color: #605e5c;
    padding: 1px 5px;
    border-radius: 3px;
}
.fd-badge-condition { background: #fff4ce; color: #8a6914; }
.fd-section-remove {
    border: none;
    background: none;
    color: #a19f9d;
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
}
.fd-section-remove:hover { color: #a80000; }
.fd-section-empty {
    padding: 20px;
    text-align: center;
    color: #a19f9d;
}

/* Section body with columns */
.fd-section-body {
    display: grid;
    gap: 8px;
    padding: 8px;
    min-height: 40px;
}
.fd-cols-1 { grid-template-columns: 1fr; }
.fd-cols-2 { grid-template-columns: 1fr 1fr; }
.fd-cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.fd-cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.fd-col {
    min-height: 36px;
    border: 1px dashed #e1dfdd;
    border-radius: 3px;
    padding: 4px;
}
.fd-col-placeholder {
    text-align: center;
    color: #c8c6c4;
    padding: 10px;
    font-size: 11px;
    transition: transform 120ms ease-in;
}
.fd-col.fd-drop-target {
    outline: 2px dashed var(--cesivi-accent, #0078d4);
    background-color: rgba(0, 120, 212, 0.08);
    transition: background-color 120ms ease-in, outline-color 120ms ease-in;
}
.fd-col.fd-drop-target .fd-col-placeholder {
    transform: scale(1.05);
}

/* Canvas field items */
.fd-canvas-field {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    margin-bottom: 3px;
    border: 1px solid #e1dfdd;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.fd-canvas-field:hover { border-color: #003082; }
.fd-canvas-field.fd-selected { border-color: #003082; box-shadow: 0 0 0 1px #003082; background: #e8f0fe; }
.fd-canvas-field.fd-ghost { opacity: 0.5; background: #e8f0fe; }
.fd-canvas-field-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.fd-field-badge-ro {
    font-size: 9px;
    background: #a0a0a0;
    color: #fff;
    padding: 1px 4px;
    border-radius: 2px;
}
.fd-field-badge-cond {
    font-size: 12px;
    color: #8a6914;
    font-weight: bold;
}
.fd-field-badge-event {
    font-size: 12px;
    color: #0078d4;
}
.fd-field-remove {
    border: none;
    background: none;
    color: #a19f9d;
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
}
.fd-field-remove:hover { color: #a80000; }

/* Right: Properties */
.fd-properties {
    width: 280px;
    min-width: 240px;
    border-left: 1px solid #d0d0d0;
    background: #faf9f8;
    overflow-y: auto;
    padding: 8px;
    flex-shrink: 0;
}
.fd-properties h2 {
    font-size: 12px;
    font-weight: 600;
    color: #605e5c;
    text-transform: uppercase;
    margin: 0 0 8px 0;
    letter-spacing: 0.5px;
}
.fd-hint { color: #a19f9d; font-style: italic; }

/* Property rows */
.fd-prop-group h3 {
    font-size: 14px;
    font-weight: 600;
    color: #003082;
    margin: 0 0 10px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid #003082;
}
.fd-prop-row {
    margin-bottom: 8px;
}
.fd-prop-row label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #605e5c;
    margin-bottom: 2px;
}
.fd-prop-row input[type="text"],
.fd-prop-row textarea,
.fd-prop-row select {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid #c8c6c4;
    border-radius: 3px;
    font-size: 12px;
    font-family: inherit;
    box-sizing: border-box;
}
.fd-prop-row textarea { resize: vertical; }
.fd-prop-row input[type="checkbox"] { margin-right: 4px; }
.fd-prop-readonly {
    font-size: 12px;
    color: #605e5c;
}
.fd-prop-condition-status {
    font-size: 11px;
    color: #605e5c;
}

/* Bulk selection styles */
.fd-bulk-header {
    font-size: 14px;
    font-weight: 600;
    color: #003082;
    margin: 0 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid #003082;
}
.fd-bulk-field-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}
.fd-bulk-field-chip {
    display: inline-block;
    padding: 2px 8px;
    background: #e8f0fe;
    border: 1px solid #a8c7fa;
    border-radius: 12px;
    font-size: 11px;
    color: #003082;
}

/* =========================================================================
   Event Handler Editor
   ========================================================================= */
.fd-event-handler {
    border: 1px solid #e1dfdd;
    border-radius: 3px;
    margin-bottom: 6px;
    background: #fff;
}
.fd-event-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    background: #f3f2f1;
    border-bottom: 1px solid #e1dfdd;
    font-size: 11px;
}
.fd-event-header select {
    padding: 2px 4px;
    font-size: 11px;
    border: 1px solid #c8c6c4;
    border-radius: 2px;
}
.fd-event-bp-label {
    font-size: 11px;
    color: #605e5c;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 2px;
}
.fd-event-remove {
    border: none;
    background: none;
    color: #a19f9d;
    cursor: pointer;
    font-size: 14px;
    margin-left: auto;
    padding: 0 2px;
}
.fd-event-remove:hover { color: #a80000; }
.fd-event-code {
    width: 100%;
    padding: 6px;
    border: none;
    font-family: "Cascadia Code", "Consolas", monospace;
    font-size: 11px;
    resize: vertical;
    box-sizing: border-box;
    min-height: 60px;
}
.fd-event-code-container {
    border-top: 1px solid #e1dfdd;
    min-height: 80px;
}
.fd-event-code-container .cm-editor {
    border: none;
    min-height: 80px;
}
.fd-event-code-container .cm-editor.cm-focused {
    outline: none;
}

/* Form events list in palette */
.fd-form-events-list {
    margin-top: 4px;
}

/* =========================================================================
   Condition Dialog
   ========================================================================= */
.fd-dialog {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.fd-dialog-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
}
.fd-dialog-content {
    position: relative;
    background: #fff;
    border-radius: 6px;
    padding: 20px;
    min-width: 500px;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.fd-dialog-content h3 {
    margin: 0 0 8px 0;
    color: #003082;
}
.fd-dialog-actions {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e1dfdd;
}
.fd-cond-logic {
    margin-top: 8px;
    font-size: 12px;
}
.fd-cond-logic label { font-weight: 600; margin-right: 6px; }
.fd-cond-logic select { font-size: 12px; padding: 2px 4px; }

/* Condition rule rows */
.fd-cond-rule {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
    align-items: center;
}
.fd-cond-rule select,
.fd-cond-rule input {
    padding: 4px 6px;
    border: 1px solid #c8c6c4;
    border-radius: 3px;
    font-size: 12px;
}
.fd-cond-rule .fd-cond-field { flex: 2; }
.fd-cond-rule .fd-cond-op { flex: 2; }
.fd-cond-rule .fd-cond-value { flex: 2; }
.fd-cond-remove-rule {
    border: none;
    background: none;
    color: #a19f9d;
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
}
.fd-cond-remove-rule:hover { color: #a80000; }

/* =========================================================================
   Toast Notification
   ========================================================================= */
.fd-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    padding: 10px 20px;
    background: #323130;
    color: #fff;
    border-radius: 4px;
    font-size: 13px;
    z-index: 10001;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
.fd-toast.fd-toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.fd-toast-error { background: #a80000; }

/* =========================================================================
   Dark Mode
   ========================================================================= */
@media (prefers-color-scheme: dark) {
    .fd-designer { color: #e0e0e0; }
    .fd-toolbar { background: #252525; border-bottom-color: #444; }
    .fd-toolbar-title { color: #88aaff; }
    .fd-palette,
    .fd-properties { background: #1e1e1e; border-color: #444; }
    .fd-palette h2,
    .fd-palette-section-title,
    .fd-properties h2 { color: #a0a0a0; }
    .fd-canvas { background: #1a1a1a; }
    .fd-empty-state { color: #888; }

    .fd-palette-field { background: #252525; }
    .fd-palette-field:hover { background: #2d3748; border-color: #88aaff; }
    .fd-search-input { background: #333; border-color: #555; color: #e0e0e0; }

    .fd-btn { background: #333; color: #e0e0e0; border-color: #555; }
    .fd-btn:hover { background: #444; }
    .fd-btn-primary { background: #003082; color: #fff; border-color: #003082; }
    .fd-btn-primary:hover { background: #004db3; }
    .fd-btn-danger { color: #ff6b6b; border-color: #ff6b6b; }
    .fd-btn-link { color: #88aaff; }
    .fd-toolbar-btn { background: #333; color: #e0e0e0; border-color: #555; }
    .fd-toolbar-btn:hover:not(:disabled) { background: #444; }
    .fd-toolbar-separator { background: #555; }
    .fd-select { background: #333; border-color: #555; color: #e0e0e0; }

    .fd-tab { background: #252525; border-color: #444; color: #ccc; }
    .fd-tab:hover { background: #2d3748; }
    .fd-tab.fd-tab-active { background: #1a1a1a; border-color: #88aaff; color: #88aaff; border-bottom-color: #1a1a1a; }
    .fd-tab-bar { border-bottom-color: #88aaff; }
    .fd-tab-add { border-color: #555; color: #88aaff; }

    .fd-section { border-color: #444; }
    .fd-section.fd-selected { border-color: #88aaff; box-shadow: 0 0 0 1px #88aaff; }
    .fd-section-header { background: #252525; border-bottom-color: #444; }
    .fd-section-header:hover { background: #2a2a2a; }
    .fd-section-title { color: #e0e0e0; }

    .fd-col { border-color: #444; }
    .fd-col-placeholder { color: #555; }

    .fd-canvas-field { background: #252525; border-color: #444; }
    .fd-canvas-field:hover { border-color: #88aaff; }
    .fd-canvas-field.fd-selected { border-color: #88aaff; box-shadow: 0 0 0 1px #88aaff; background: #2d3748; }
    .fd-field-type-badge { background: #333; color: #a0a0a0; }

    .fd-prop-group h3 { color: #88aaff; border-bottom-color: #88aaff; }
    .fd-prop-row label { color: #a0a0a0; }
    .fd-prop-row input[type="text"],
    .fd-prop-row textarea,
    .fd-prop-row select { background: #333; border-color: #555; color: #e0e0e0; }
    .fd-prop-readonly { color: #888; }
    .fd-bulk-header { color: #88aaff; border-bottom-color: #88aaff; }
    .fd-bulk-field-chip { background: #2d3748; border-color: #4a6fa5; color: #88aaff; }

    .fd-event-handler { border-color: #444; background: #252525; }
    .fd-event-header { background: #2a2a2a; border-bottom-color: #444; }
    .fd-event-header select { background: #333; border-color: #555; color: #e0e0e0; }
    .fd-event-code { background: #1e1e1e; color: #d4d4d4; }
    .fd-event-code-container { border-top-color: #444; }
    .fd-event-code-container .cm-editor { background: #1e1e1e; }

    .fd-dialog-content { background: #2a2a2a; color: #e0e0e0; }
    .fd-dialog-content h3 { color: #88aaff; }
    .fd-dialog-actions { border-top-color: #444; }
    .fd-cond-rule select,
    .fd-cond-rule input { background: #333; border-color: #555; color: #e0e0e0; }

    .fd-separator { border-top-color: #444; }
    .fd-toast { background: #444; }
    .fd-toast-error { background: #a80000; }
}

/* =========================================================================
   Print — hide designer UI
   ========================================================================= */
@media print {
    .fd-designer { display: none; }
}

/* =========================================================================
   Custom HTML/CSS Slot — preview pane (PLAN-1511 β-4)
   ========================================================================= */
.fd-htmlslot-preview {
    padding: 4px;
    border: 1px dashed var(--ms-borderColor, #ccc);
    background: #fafafa;
    min-height: 90px;
}
.fd-htmlslot-preview-frame {
    width: 100%;
    min-height: 80px;
    max-height: 240px;
    border: 1px solid var(--ms-borderColor, #ccc);
    background: #fff;
    display: block;
}
