/**
 * WYSIWYG Form Builder Styles
 *
 * 3-panel layout: palette | canvas | properties
 * Shared by admin (WP Admin Settings) and vendor (Dokan Dashboard).
 *
 * @package WahraRentalsBookings
 * @since   2.3.0
 */

/* ==========================================================================
   Design Tokens (inherit from wahrb-admin.css / wahrb-vendor.css)
   ========================================================================== */
:root {
    --fb-palette-w: 230px;
    --fb-props-w: 300px;
    --fb-gap: 16px;
    --fb-radius: 8px;
    --fb-border: #e2e8f0;
    --fb-bg: #f8fafc;
    --fb-card-bg: #ffffff;
    --fb-accent: #2563eb;
    --fb-accent-hover: #1d4ed8;
    --fb-accent-light: #eff6ff;
    --fb-danger: #ef4444;
    --fb-danger-light: #fef2f2;
    --fb-success: #10b981;
    --fb-success-light: #ecfdf5;
    --fb-text: #1e293b;
    --fb-text-muted: #64748b;
    --fb-text-light: #94a3b8;
    --fb-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --fb-shadow-lg: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

/* ==========================================================================
   Template List View
   ========================================================================== */
.wahrb-fb-wrap {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--fb-text);
    line-height: 1.5;
}

/* ── Toolbar (shared top bar for list + builder) ── */
.wahrb-fb-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    background: var(--fb-card-bg);
    border: 1px solid var(--fb-border);
    border-radius: var(--fb-radius);
    margin-bottom: var(--fb-gap);
    flex-wrap: wrap;
}

.wahrb-fb-toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.wahrb-fb-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.wahrb-fb-toolbar h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--fb-text);
}

/* ── Template list table ── */
.wahrb-fb-table-wrap {
    background: var(--fb-card-bg);
    border: 1px solid var(--fb-border);
    border-radius: var(--fb-radius);
    overflow: hidden;
}

.wahrb-fb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.wahrb-fb-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--fb-bg);
    border-bottom: 1px solid var(--fb-border);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--fb-text-muted);
}

.wahrb-fb-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--fb-border);
    vertical-align: middle;
}

.wahrb-fb-table tr:last-child td {
    border-bottom: none;
}

.wahrb-fb-table tr:hover td {
    background: var(--fb-bg);
}

.wahrb-fb-empty-row td {
    text-align: center;
    padding: 40px 16px;
    color: var(--fb-text-light);
    font-size: 15px;
}

/* ── Badges ── */
.wahrb-fb-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
}

.wahrb-fb-badge-scope {
    background: var(--fb-accent-light);
    color: var(--fb-accent);
}

.wahrb-fb-badge-active {
    background: var(--fb-success-light);
    color: var(--fb-success);
}

.wahrb-fb-badge-inactive {
    background: var(--fb-danger-light);
    color: var(--fb-danger);
}

.wahrb-fb-badge-count {
    background: var(--fb-bg);
    color: var(--fb-text-muted);
}

/* ── Action links ── */
.wahrb-fb-actions {
    display: flex;
    gap: 12px;
}

.wahrb-fb-actions a,
.wahrb-fb-actions button {
    background: none;
    border: none;
    padding: 0;
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
}

.wahrb-fb-actions .wahrb-fb-action-edit {
    color: var(--fb-accent);
}

.wahrb-fb-actions .wahrb-fb-action-edit:hover {
    color: var(--fb-accent-hover);
    text-decoration: underline;
}

.wahrb-fb-actions .wahrb-fb-action-delete {
    color: var(--fb-danger);
}

.wahrb-fb-actions .wahrb-fb-action-delete:hover {
    color: #dc2626;
    text-decoration: underline;
}

/* ==========================================================================
   Builder – 3-panel layout
   ========================================================================== */
.wahrb-fb-builder {
    display: grid;
    grid-template-columns: var(--fb-palette-w) 1fr var(--fb-props-w);
    gap: var(--fb-gap);
    min-height: 500px;
    align-items: start;
}

/* ── Palette (left panel) ── */
.wahrb-fb-palette {
    background: var(--fb-card-bg);
    border: 1px solid var(--fb-border);
    border-radius: var(--fb-radius);
    padding: 14px;
    position: sticky;
    top: 40px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

.wahrb-fb-palette h3 {
    margin: 0 0 12px 0;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--fb-text-muted);
}

.wahrb-fb-palette-group {
    margin-bottom: 16px;
}

.wahrb-fb-palette-group:last-child {
    margin-bottom: 0;
}

.wahrb-fb-palette-group-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fb-text-light);
    margin: 0 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--fb-border);
}

.wahrb-fb-palette-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    margin-bottom: 4px;
    background: var(--fb-bg);
    border: 1px solid var(--fb-border);
    border-radius: 6px;
    cursor: grab;
    font-size: 13px;
    color: var(--fb-text);
    transition: all 0.15s ease;
    user-select: none;
}

.wahrb-fb-palette-item:hover {
    background: var(--fb-accent-light);
    border-color: var(--fb-accent);
    color: var(--fb-accent);
}

.wahrb-fb-palette-item:active {
    cursor: grabbing;
}

.wahrb-fb-palette-icon {
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    font-size: 14px;
}

.wahrb-fb-palette-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* SortableJS clone ghost in palette */
.wahrb-fb-palette-item.sortable-ghost {
    opacity: 0.4;
}

.wahrb-fb-palette-item.sortable-drag {
    background: var(--fb-accent-light);
    border-color: var(--fb-accent);
    box-shadow: var(--fb-shadow-lg);
}

/* ── Canvas (center panel) ── */
.wahrb-fb-canvas {
    background: var(--fb-card-bg);
    border: 1px solid var(--fb-border);
    border-radius: var(--fb-radius);
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.wahrb-fb-canvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--fb-border);
    background: var(--fb-bg);
    border-radius: var(--fb-radius) var(--fb-radius) 0 0;
}

.wahrb-fb-canvas-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--fb-text);
}

.wahrb-fb-canvas-count {
    font-size: 12px;
    color: var(--fb-text-light);
}

.wahrb-fb-canvas-body {
    flex: 1;
    padding: 12px;
    min-height: 200px;
}

/* Empty state */
.wahrb-fb-canvas-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    border: 2px dashed var(--fb-border);
    border-radius: 6px;
    margin: 4px;
    color: var(--fb-text-light);
    font-size: 14px;
    text-align: center;
    transition: all 0.2s ease;
}

.wahrb-fb-canvas-empty-icon {
    font-size: 32px;
    margin-bottom: 8px;
    opacity: 0.5;
}

.wahrb-fb-canvas-body.sortable-drag-over .wahrb-fb-canvas-empty {
    border-color: var(--fb-accent);
    background: var(--fb-accent-light);
    color: var(--fb-accent);
}

/* ── Field card (in canvas) ── */
.wahrb-fb-field {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin-bottom: 6px;
    background: var(--fb-card-bg);
    border: 1px solid var(--fb-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

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

.wahrb-fb-field:hover {
    border-color: var(--fb-accent);
    box-shadow: 0 0 0 1px var(--fb-accent);
}

.wahrb-fb-field.wahrb-fb-field-selected {
    border-color: var(--fb-accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
    background: var(--fb-accent-light);
}

.wahrb-fb-field.sortable-ghost {
    opacity: 0.4;
    background: var(--fb-accent-light);
}

.wahrb-fb-field.sortable-chosen {
    box-shadow: var(--fb-shadow-lg);
}

.wahrb-fb-field-handle {
    cursor: grab;
    color: var(--fb-text-light);
    font-size: 16px;
    flex-shrink: 0;
    padding: 2px;
    line-height: 1;
}

.wahrb-fb-field-handle:active {
    cursor: grabbing;
}

.wahrb-fb-field-icon {
    flex-shrink: 0;
    width: 22px;
    text-align: center;
    font-size: 14px;
}

.wahrb-fb-field-info {
    flex: 1;
    min-width: 0;
}

.wahrb-fb-field-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--fb-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wahrb-fb-field-type {
    font-size: 11px;
    color: var(--fb-text-light);
    margin-top: 1px;
}

.wahrb-fb-field-width-badge {
    flex-shrink: 0;
    background: var(--fb-accent);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    line-height: 1.4;
}

.wahrb-fb-field-required {
    color: var(--fb-danger);
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.wahrb-fb-field-delete {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 4px 6px;
    cursor: pointer;
    color: var(--fb-text-light);
    font-size: 14px;
    border-radius: 4px;
    transition: all 0.15s ease;
    line-height: 1;
}

.wahrb-fb-field-delete:hover {
    color: var(--fb-danger);
    background: var(--fb-danger-light);
}

/* ── Properties (right panel) ── */
.wahrb-fb-properties {
    background: var(--fb-card-bg);
    border: 1px solid var(--fb-border);
    border-radius: var(--fb-radius);
    position: sticky;
    top: 40px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

.wahrb-fb-properties-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--fb-border);
    background: var(--fb-bg);
    border-radius: var(--fb-radius) var(--fb-radius) 0 0;
}

.wahrb-fb-properties-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--fb-text);
}

.wahrb-fb-properties-body {
    padding: 14px 16px;
}

.wahrb-fb-properties-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 16px;
    color: var(--fb-text-light);
    font-size: 13px;
    text-align: center;
}

.wahrb-fb-properties-empty-icon {
    font-size: 28px;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* ── Form controls inside properties panel ── */
.wahrb-fb-prop-group {
    margin-bottom: 14px;
}

.wahrb-fb-prop-group:last-child {
    margin-bottom: 0;
}

.wahrb-fb-prop-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--fb-text-muted);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.wahrb-fb-prop-input,
.wahrb-fb-prop-textarea,
.wahrb-fb-prop-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--fb-border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--fb-text);
    background: var(--fb-card-bg);
    transition: border-color 0.15s ease;
    box-sizing: border-box;
    font-family: inherit;
}

.wahrb-fb-prop-input:focus,
.wahrb-fb-prop-textarea:focus,
.wahrb-fb-prop-select:focus {
    outline: none;
    border-color: var(--fb-accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.wahrb-fb-prop-textarea {
    resize: vertical;
    min-height: 60px;
}

.wahrb-fb-prop-input[readonly] {
    background: var(--fb-bg);
    color: var(--fb-text-muted);
}

.wahrb-fb-prop-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
}

.wahrb-fb-prop-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--fb-accent);
    cursor: pointer;
}

/* ── Options list (for select/radio/checkbox fields) ── */
.wahrb-fb-options-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wahrb-fb-option-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.wahrb-fb-option-row input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--fb-border);
    border-radius: 5px;
    font-size: 13px;
    color: var(--fb-text);
    box-sizing: border-box;
}

.wahrb-fb-option-row input:focus {
    outline: none;
    border-color: var(--fb-accent);
}

.wahrb-fb-option-remove {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--fb-text-light);
    font-size: 16px;
    padding: 2px 4px;
    border-radius: 4px;
    line-height: 1;
}

.wahrb-fb-option-remove:hover {
    color: var(--fb-danger);
    background: var(--fb-danger-light);
}

.wahrb-fb-option-add {
    align-self: flex-start;
    margin-top: 4px;
}

/* ── Template metadata form (in toolbar when editing) ── */
.wahrb-fb-meta {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px 20px;
    background: var(--fb-card-bg);
    border: 1px solid var(--fb-border);
    border-radius: var(--fb-radius);
    margin-bottom: var(--fb-gap);
    flex-wrap: wrap;
}

.wahrb-fb-meta-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.wahrb-fb-meta-field.wahrb-fb-meta-name {
    flex: 1;
    min-width: 200px;
}

.wahrb-fb-meta-field.wahrb-fb-meta-desc {
    flex: 1;
    min-width: 200px;
}

.wahrb-fb-meta-field label {
    font-size: 12px;
    font-weight: 600;
    color: var(--fb-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.wahrb-fb-meta-field input,
.wahrb-fb-meta-field select {
    padding: 7px 10px;
    border: 1px solid var(--fb-border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--fb-text);
    background: var(--fb-card-bg);
    box-sizing: border-box;
}

.wahrb-fb-meta-field input:focus,
.wahrb-fb-meta-field select:focus {
    outline: none;
    border-color: var(--fb-accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.wahrb-fb-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    line-height: 1.4;
    font-family: inherit;
    white-space: nowrap;
}

.wahrb-fb-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.wahrb-fb-btn-primary {
    background: var(--fb-accent);
    color: #ffffff;
    border-color: var(--fb-accent);
}

.wahrb-fb-btn-primary:hover {
    background: var(--fb-accent-hover);
    border-color: var(--fb-accent-hover);
}

.wahrb-fb-btn-secondary {
    background: var(--fb-card-bg);
    color: var(--fb-text);
    border-color: var(--fb-border);
}

.wahrb-fb-btn-secondary:hover {
    background: var(--fb-bg);
    border-color: var(--fb-text-light);
}

.wahrb-fb-btn-danger {
    background: var(--fb-card-bg);
    color: var(--fb-danger);
    border-color: var(--fb-danger);
}

.wahrb-fb-btn-danger:hover {
    background: var(--fb-danger-light);
}

.wahrb-fb-btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.wahrb-fb-btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ==========================================================================
   Alerts / Notices
   ========================================================================== */
.wahrb-fb-notice {
    padding: 12px 16px;
    border-radius: var(--fb-radius);
    font-size: 13px;
    margin-bottom: var(--fb-gap);
    display: flex;
    align-items: center;
    gap: 8px;
}

.wahrb-fb-notice-success {
    background: var(--fb-success-light);
    border: 1px solid #a7f3d0;
    color: #065f46;
}

.wahrb-fb-notice-error {
    background: var(--fb-danger-light);
    border: 1px solid #fecaca;
    color: #991b1b;
}

.wahrb-fb-notice-info {
    background: var(--fb-accent-light);
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

/* ==========================================================================
   Preview Mode
   ========================================================================== */
.wahrb-fb-preview {
    padding: 20px;
}

/* Multi-column grid layout for preview */
.wahrb-fb-preview-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.wahrb-fb-preview-field {
    flex: 0 0 100%;
    min-width: 0;
    box-sizing: border-box;
}

.wahrb-fb-preview-field-half {
    flex: 0 0 calc(50% - 8px);
}

.wahrb-fb-preview-field-third {
    flex: 0 0 calc(33.333% - 11px);
}

.wahrb-fb-preview-heading {
    flex: 0 0 100%;
}

.wahrb-fb-preview-heading.wahrb-fb-preview-field-half {
    flex: 0 0 calc(50% - 8px);
}

.wahrb-fb-preview-heading.wahrb-fb-preview-field-third {
    flex: 0 0 calc(33.333% - 11px);
}

.wahrb-fb-preview-field label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--fb-text);
    margin-bottom: 5px;
}

.wahrb-fb-preview-field .required {
    color: var(--fb-danger);
    margin-left: 2px;
}

.wahrb-fb-preview-field input,
.wahrb-fb-preview-field select,
.wahrb-fb-preview-field textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--fb-border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--fb-text);
    box-sizing: border-box;
    background: var(--fb-card-bg);
}

.wahrb-fb-preview-field textarea {
    resize: vertical;
    min-height: 60px;
}

/* Preview heading — base + grid override (full-width heading already handled above) */
.wahrb-fb-preview h4.wahrb-fb-preview-heading {
    font-size: 16px;
    font-weight: 600;
    color: var(--fb-text);
    margin: 4px 0 0 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--fb-border);
}

.wahrb-fb-preview-html {
    padding: 10px 0;
    color: var(--fb-text);
    font-size: 14px;
    line-height: 1.6;
}

.wahrb-fb-preview-consent {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 14px;
}

.wahrb-fb-preview-consent input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-top: 2px;
    flex-shrink: 0;
}

.wahrb-fb-preview-consent a {
    color: var(--fb-accent);
}

/* ==========================================================================
   Loading / Spinner
   ========================================================================== */
.wahrb-fb-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--fb-text-light);
    font-size: 14px;
    gap: 10px;
}

.wahrb-fb-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--fb-border);
    border-top-color: var(--fb-accent);
    border-radius: 50%;
    animation: wahrb-fb-spin 0.6s linear infinite;
}

@keyframes wahrb-fb-spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   Responsive — Stack panels below 960px
   ========================================================================== */
@media (max-width: 960px) {
    .wahrb-fb-builder {
        grid-template-columns: 1fr;
    }

    .wahrb-fb-palette,
    .wahrb-fb-properties {
        position: static;
        max-height: none;
    }

    .wahrb-fb-palette {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 8px;
    }

    .wahrb-fb-palette h3 {
        grid-column: 1 / -1;
    }

    .wahrb-fb-meta {
        flex-direction: column;
    }

    .wahrb-fb-meta-field.wahrb-fb-meta-name,
    .wahrb-fb-meta-field.wahrb-fb-meta-desc {
        min-width: unset;
    }

    /* Collapse multi-column to single column on small screens */
    .wahrb-fb-preview-field-half,
    .wahrb-fb-preview-field-third {
        flex: 0 0 100%;
    }
}

/* ==========================================================================
   WordPress Admin Overrides
   ========================================================================== */
.wahrb-admin-wrap .wahrb-fb-wrap {
    margin-top: 20px;
}

/* Dokan Dashboard Overrides */
.dokan-dashboard-content .wahrb-fb-wrap {
    margin-top: 0;
}
