/* ============================================================
   MegaForm — Base Stylesheet
   CSS Variables-based theming system (inspired by JotForm Designer)
   ============================================================ */

/* ============================================================
   CSS CUSTOM PROPERTIES (Theme Variables)
   Override these per-theme via .mf-theme-{name} class
   ============================================================ */
:root,
.mf-form-wrapper {
    /* --- Page / Background --- */
    --mf-page-bg:               #f5f5f5;
    --mf-page-bg-image:         none;

    /* --- Form Container --- */
    --mf-form-bg:               #ffffff;
    --mf-form-shadow:           0 1px 6px rgba(0,0,0,0.1);
    --mf-form-radius:           8px;
    --mf-form-padding:          32px 40px;
    --mf-form-max-width:        960px;
    --mf-form-border:           none;

    /* --- Typography --- */
    --mf-font-family:           'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mf-font-size-base:        15px;
    --mf-line-height:           1.5;
    --mf-color-text:            #333333;
    --mf-color-text-light:      #666666;
    --mf-color-text-muted:      #999999;

    /* --- Title & Description --- */
    --mf-title-font-size:       24px;
    --mf-title-font-weight:     700;
    --mf-title-color:           #1a1a2e;
    --mf-title-align:           left;
    --mf-desc-font-size:        14px;
    --mf-desc-color:            #666666;

    /* --- Labels --- */
    --mf-label-font-size:       14px;
    --mf-label-font-weight:     600;
    --mf-label-color:           #333333;
    --mf-label-margin-bottom:   6px;
    --mf-sublabel-font-size:    12px;
    --mf-sublabel-color:        #888888;

    /* --- Inputs --- */
    --mf-input-bg:              #ffffff;
    --mf-input-border:          1px solid #d0d5dd;
    --mf-input-radius:          6px;
    --mf-input-padding:         10px 14px;
    --mf-input-font-size:       15px;
    --mf-input-color:           #333333;
    --mf-input-placeholder:     #aaaaaa;
    --mf-input-focus-border:    #4a90d9;
    --mf-input-focus-shadow:    0 0 0 3px rgba(74, 144, 217, 0.15);
    --mf-input-error-border:    #e74c3c;
    --mf-input-disabled-bg:     #f5f5f5;

    /* --- Primary Color (buttons, accents) --- */
    --mf-primary:               #4a90d9;
    --mf-primary-hover:         #3a7bc8;
    --mf-primary-text:          #ffffff;

    /* --- Submit Button --- */
    --mf-btn-bg:                var(--mf-primary);
    --mf-btn-bg-hover:          var(--mf-primary-hover);
    --mf-btn-color:             var(--mf-primary-text);
    --mf-btn-radius:            6px;
    --mf-btn-padding:           12px 32px;
    --mf-btn-font-size:         16px;
    --mf-btn-font-weight:       600;
    --mf-btn-shadow:            0 2px 4px rgba(0,0,0,0.1);
    --mf-btn-width:             auto;

    /* --- Section / Headings --- */
    --mf-section-border-color:  #e0e0e0;
    --mf-section-title-size:    18px;
    --mf-section-title-color:   #1a1a2e;
    --mf-section-bg:            transparent;
    --mf-section-padding:       16px 0;

    /* --- Progress Bar --- */
    --mf-progress-bg:           #e9ecef;
    --mf-progress-fill:         var(--mf-primary);
    --mf-progress-height:       6px;
    --mf-progress-radius:       3px;

    /* --- Required Star --- */
    --mf-required-color:        #e74c3c;

    /* --- Help Text --- */
    --mf-help-color:            #888888;
    --mf-help-font-size:        12px;

    /* --- Checkbox / Radio --- */
    --mf-check-size:            20px;
    --mf-check-color:           var(--mf-primary);
    --mf-check-radius:          4px;
    --mf-radio-radius:          50%;

    /* --- File Upload --- */
    --mf-file-border:           2px dashed #d0d5dd;
    --mf-file-bg:               #fafafa;
    --mf-file-hover-bg:         #f0f4ff;

    /* --- Field Spacing --- */
    --mf-field-gap:             20px;
}

/* ============================================================
   BASE LAYOUT
   ============================================================ */
.mf-form-wrapper {
    font-family: var(--mf-font-family);
    font-size: var(--mf-font-size-base);
    line-height: var(--mf-line-height);
    color: var(--mf-color-text);
    background: var(--mf-page-bg);
    background-image: var(--mf-page-bg-image);
    background-size: cover;
    background-position: center;
    padding: 24px 16px;
    display: flex;
    justify-content: center;
}

.mf-form-wrapper * { box-sizing: border-box; }

/* Inner container — constrains header + progress + form to same width */
.mf-form-inner {
    width: 100%;
    max-width: var(--mf-form-max-width);
}

.mf-form {
    background: var(--mf-form-bg);
    box-shadow: var(--mf-form-shadow);
    border-radius: var(--mf-form-radius);
    border: var(--mf-form-border);
    padding: var(--mf-form-padding);
    width: 100%;
}

/* ============================================================
   HEADER
   ============================================================ */
.mf-progress-bar {
    margin: 0 28px;
    width: calc(100% - 56px);
}
.mf-standard-body {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 24px 28px 28px;
    min-width: 0;
}
.mf-standard-body > .mf-fields-container {
    min-width: 0;
}
.mf-standard-actions {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
}
.mf-standard-actions > .mf-form-actions {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.mf-form-header {
    margin-bottom: 24px;
}
.mf-form-title {
    font-size: var(--mf-title-font-size);
    font-weight: var(--mf-title-font-weight);
    color: var(--mf-title-color);
    text-align: var(--mf-title-align);
    margin: 0 0 8px 0;
}
.mf-form-description {
    font-size: var(--mf-desc-font-size);
    color: var(--mf-desc-color);
    text-align: var(--mf-title-align);
    margin: 0;
}

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.mf-progress-bar { margin-bottom: 24px; }

/* Step Indicator — Circles with labels */
.mf-steps {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
    padding: 0 16px;
}
.mf-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 70px;
    flex-shrink: 0;
}
.mf-step-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid #d1d5db;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #9ca3af;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}
.mf-step-label {
    font-size: 11px;
    color: #9ca3af;
    text-align: center;
    max-width: 100px;
    line-height: 1.3;
    transition: color 0.3s ease;
}
.mf-step-line {
    flex: 1;
    height: 2px;
    background: #e5e7eb;
    margin-top: 18px;
    min-width: 24px;
    transition: background 0.3s ease;
}

/* Active step */
.mf-step.active .mf-step-circle {
    border-color: var(--mf-primary, #4f46e5);
    background: var(--mf-primary, #4f46e5);
    color: #fff;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
}
.mf-step.active .mf-step-label {
    color: var(--mf-primary, #4f46e5);
    font-weight: 600;
}

/* Done step */
.mf-step.done .mf-step-circle {
    border-color: #10b981;
    background: #10b981;
    color: #fff;
}
.mf-step.done .mf-step-circle::after {
    content: '✓';
    font-size: 16px;
}
.mf-step.done .mf-step-circle { font-size: 0; } /* hide number, show checkmark */
.mf-step.done .mf-step-label {
    color: #10b981;
}
.mf-step-line.done {
    background: #10b981;
}

/* Responsive */
@media (max-width: 480px) {
    .mf-step-label { display: none; }
    .mf-step { min-width: 40px; }
    .mf-step-circle { width: 30px; height: 30px; font-size: 12px; }
    .mf-step-line { margin-top: 15px; }
}

/* Legacy fallback (hidden, replaced by .mf-steps) */
.mf-progress-track, .mf-progress-fill, .mf-progress-text { display: none; }

/* ============================================================
   FIELDS — Shared
   ============================================================ */
.mf-field-group {
    margin-bottom: var(--mf-field-gap);
    position: relative;
}
.mf-field-group.mf-hidden { display: none; }

.mf-field-label {
    display: block;
    font-size: var(--mf-label-font-size);
    font-weight: var(--mf-label-font-weight);
    color: var(--mf-label-color);
    margin-bottom: var(--mf-label-margin-bottom);
}
.mf-field-label .mf-required {
    color: var(--mf-required-color);
    margin-left: 2px;
}
.mf-field-sublabel {
    display: block;
    font-size: var(--mf-sublabel-font-size);
    color: var(--mf-sublabel-color);
    margin-top: 4px;
}
.mf-field-help {
    font-size: var(--mf-help-font-size);
    color: var(--mf-help-color);
    margin-top: 4px;
}
.mf-field-error {
    color: var(--mf-input-error-border);
    font-size: 12px;
    margin-top: 4px;
}

/* ============================================================
   INPUTS
   ============================================================ */
.mf-input,
.mf-select,
.mf-textarea {
    width: 100%;
    background: var(--mf-input-bg);
    border: var(--mf-input-border);
    border-radius: var(--mf-input-radius);
    padding: var(--mf-input-padding);
    font-family: var(--mf-font-family);
    font-size: var(--mf-input-font-size);
    color: var(--mf-input-color);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
.mf-input::placeholder,
.mf-textarea::placeholder {
    color: var(--mf-input-placeholder);
}
.mf-input:focus,
.mf-select:focus,
.mf-textarea:focus {
    border-color: var(--mf-input-focus-border);
    box-shadow: var(--mf-input-focus-shadow);
}
.mf-input.mf-error,
.mf-select.mf-error,
.mf-textarea.mf-error {
    border-color: var(--mf-input-error-border);
}
.mf-input:disabled, .mf-textarea:disabled {
    background: var(--mf-input-disabled-bg);
    cursor: not-allowed;
}
.mf-textarea { min-height: 100px; resize: vertical; }
.mf-select { appearance: none; cursor: pointer; }

/* ============================================================
   CHECKBOX & RADIO
   ============================================================ */
.mf-option-group { display: flex; flex-direction: column; gap: 8px; }
.mf-option-group.mf-inline { flex-direction: row; flex-wrap: wrap; gap: 16px; }
.mf-option-group.mf-option-group--cols {
    display: grid;
    align-items: start;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 14px;
    row-gap: 10px;
}
.mf-option-group.mf-cols-1 { grid-template-columns: 1fr; }
.mf-option-group.mf-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mf-option-group.mf-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mf-option-group.mf-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.mf-option-item {
    display: grid;
    grid-template-columns: var(--mf-check-size) minmax(0, 1fr);
    align-items: start;
    column-gap: 10px;
    cursor: pointer;
    font-size: var(--mf-font-size-base);
    color: var(--mf-color-text);
    line-height: 1.4;
} 
@media (max-width: 980px) {
    .mf-option-group.mf-cols-4,
    .mf-option-group.mf-cols-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 640px) {
    .mf-option-group.mf-option-group--cols {
        grid-template-columns: 1fr;
    }
}
.mf-option-item input[type="checkbox"],
.mf-option-item input[type="radio"] {
    width: var(--mf-check-size);
    height: var(--mf-check-size);
    accent-color: var(--mf-check-color);
    cursor: pointer;
    margin: 0;
    align-self: start;
    transform: translateY(2px);
}
.mf-option-ui {
    min-width: 0;
    display: block;
}
.mf-option-label {
    display: block;
    min-width: 0;
    line-height: 1.4;
    white-space: normal;
}

/* ============================================================
   FILE UPLOAD
   ============================================================ */
.mf-file-dropzone {
    border: var(--mf-file-border);
    border-radius: var(--mf-input-radius);
    background: var(--mf-file-bg);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.mf-file-dropzone:hover { background: var(--mf-file-hover-bg); }
.mf-file-dropzone.mf-file-dragover { background: var(--mf-file-hover-bg); border-color: var(--mf-primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.mf-file-dropzone .mf-file-icon { font-size: 32px; color: var(--mf-primary); margin-bottom: 8px; }
.mf-file-dropzone .mf-file-text { color: var(--mf-color-text-muted); font-size: 14px; }
.mf-file-list { margin-top: 8px; }
.mf-file-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px; background: #f8f9fa; border-radius: 4px; margin-top: 4px; font-size: 13px;
}
.mf-file-item .mf-file-remove { color: #e74c3c; cursor: pointer; border: none; background: none; }

/* ============================================================
   SECTION / HTML
   ============================================================ */
.mf-section-break {
    border-top: 1px solid var(--mf-section-border-color);
    background: var(--mf-section-bg);
    padding: var(--mf-section-padding);
    margin: 8px 0;
}
.mf-section-title {
    font-size: var(--mf-section-title-size);
    font-weight: 600;
    color: var(--mf-section-title-color);
    margin: 0 0 4px 0;
}
.mf-html-block { padding: 8px 0; color: var(--mf-color-text); }

/* ============================================================
   ROW / COLUMNS — Grid Layout (form view)
   ============================================================ */
.mf-row {
    display: grid;
    gap: var(--mf-field-gap, 20px);
    margin-bottom: var(--mf-field-gap, 20px);
}
.mf-row-column { display: flex; flex-direction: column; gap: var(--mf-field-gap, 16px); }
.mf-row-column .mf-field-group { margin-bottom: 0; }
/* Ensure fields inside row columns expand to fill width */
.mf-row-column .mf-field-group input,
.mf-row-column .mf-field-group select,
.mf-row-column .mf-field-group textarea {
    width: 100%;
    box-sizing: border-box;
}
@media (max-width: 600px) {
    .mf-row { grid-template-columns: 1fr !important; }
}

/* ============================================================
   BUTTONS
   ============================================================ */
.mf-form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
    flex-wrap: wrap;
}
.mf-btn-submit {
    background: var(--mf-btn-bg);
    color: var(--mf-btn-color);
    border: none;
    border-radius: var(--mf-btn-radius);
    padding: var(--mf-btn-padding);
    font-family: var(--mf-font-family);
    font-size: var(--mf-btn-font-size);
    font-weight: var(--mf-btn-font-weight);
    box-shadow: var(--mf-btn-shadow);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    width: var(--mf-btn-width);
}
.mf-btn-submit:hover { background: var(--mf-btn-bg-hover); }
.mf-btn-submit:active { transform: translateY(1px); }
.mf-btn-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.mf-btn-prev {
    background: transparent;
    border: 1px solid #d1d5db;
    color: #6b7280;
    border-radius: var(--mf-btn-radius);
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.mf-btn-prev:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
    color: #374151;
}
.mf-btn-next {
    background: var(--mf-primary, #4f46e5);
    border: none;
    color: #fff;
    border-radius: var(--mf-btn-radius);
    padding: 10px 28px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: auto;
}
.mf-btn-next:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.mf-btn-save {
    background: transparent;
    border: 1px solid #aaa;
    color: #666;
    border-radius: var(--mf-btn-radius);
    padding: 10px 20px;
    font-size: 14px;
    cursor: pointer;
}
.mf-btn-save:hover { border-color: #666; color: #333; }

/* ============================================================
   SUCCESS / ERROR / LOADING
   ============================================================ */
.mf-success-message { text-align: center; padding: 40px 20px; }
.mf-success-message .fa-check-circle { color: #27ae60; }
.mf-error-message { margin-top: 16px; }
.mf-loading { text-align: center; padding: 20px; color: var(--mf-primary); }

/* ============================================================
   INLINE MULTI-COLUMN SUPPORT
   ============================================================ */
.mf-fields-container {
    display: flex;
    flex-wrap: wrap;
    gap: var(--mf-field-gap);
}
/* BUG FIX: mf-page is a direct flex child of mf-fields-container.
   Without explicit width/flex, it shrinks to content width instead of
   filling the container — causing all field groups inside to be ~2/3 wide.  */
.mf-fields-container > .mf-page {
    width: 100%;
    flex: 0 0 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.mf-field-group { flex: 0 0 100%; }
/* Standard renderer pages stack direct child field groups vertically.
   Keep auto height there so blank/standard templates do not create giant gaps. */
.mf-fields-container > .mf-page > .mf-field-group:not([data-width]) {
    flex: 0 0 auto;
    width: 100%;
}
.mf-field-group[data-width="50%"] { flex: 0 0 calc(50% - var(--mf-field-gap) / 2); }
.mf-field-group[data-width="33%"] { flex: 0 0 calc(33.33% - var(--mf-field-gap) * 2 / 3); }
.mf-field-group[data-width="66%"] { flex: 0 0 calc(66.66% - var(--mf-field-gap) / 3); }
.mf-field-group[data-width="25%"] { flex: 0 0 calc(25% - var(--mf-field-gap) * 3 / 4); }

@media (max-width: 600px) {
    .mf-field-group[data-width] { flex: 0 0 100% !important; }
    .mf-form { padding: 20px 16px; }
    .mf-form-actions { flex-direction: column; }
    .mf-btn-submit { width: 100%; }
    .mf-standard-body { padding: 20px 20px 24px; }
}

/* ============================================================
   LABEL POSITION VARIANTS
   ============================================================ */
.mf-labels-left .mf-field-group {
    display: flex; align-items: flex-start; gap: 12px;
}
.mf-labels-left .mf-field-label {
    flex: 0 0 140px; text-align: right; padding-top: 10px;
}
.mf-labels-left .mf-field-body { flex: 1; }

.mf-labels-floating .mf-field-group { position: relative; }
.mf-labels-floating .mf-field-label {
    position: absolute; top: 12px; left: 14px;
    font-size: 15px; font-weight: 400; color: var(--mf-input-placeholder);
    transition: all 0.2s; pointer-events: none; z-index: 1;
}
.mf-labels-floating .mf-input:focus ~ .mf-field-label,
.mf-labels-floating .mf-input:not(:placeholder-shown) ~ .mf-field-label,
.mf-labels-floating .mf-field-group.mf-has-value .mf-field-label {
    top: -8px; left: 10px; font-size: 11px;
    background: var(--mf-form-bg); padding: 0 4px;
    color: var(--mf-primary); font-weight: 600;
}

/* ============================================================
   HONEYPOT — Never visible
   ============================================================ */
.mf-hp-field {
    position: absolute !important;
    left: -9999px !important; top: -9999px !important;
    width: 0 !important; height: 0 !important;
    overflow: hidden !important;
    opacity: 0 !important;
}

/* ============================================================
   Field Validation Error Styles
   ============================================================ */
.mf-field-group.mf-field-error input,
.mf-field-group.mf-field-error textarea,
.mf-field-group.mf-field-error select {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}
.mf-field-group.mf-field-error label {
    color: #dc2626;
}
.mf-field-error-msg {
    color: #dc2626;
    font-size: 12px;
    margin-top: 4px;
    padding: 4px 8px;
    background: #fef2f2;
    border-radius: 4px;
    border-left: 3px solid #ef4444;
}

/* Better error banner */
.mf-error-message .alert-danger {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left: 4px solid #ef4444;
    color: #991b1b;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
}
.mf-error-message .alert-danger i {
    color: #ef4444;
    margin-right: 8px;
}

/* Better success banner */
.mf-success-message .alert-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-left: 4px solid #22c55e;
    color: #166534;
    padding: 24px;
    border-radius: 8px;
    text-align: center;
}
.mf-success-message .alert-success i {
    color: #22c55e;
    display: block;
    margin-bottom: 12px;
}
.mf-success-message .alert-success h3 {
    margin: 0 0 8px 0;
    font-size: 20px;
}

/* Multi-page — see step indicator styles above */

/* ============================================================
   CONFIGURATION PANEL
   ============================================================ */
.mf-config-panel { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; width: 100%; margin: 0; background: #fff; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.1), 0 4px 20px rgba(0,0,0,.06); overflow: hidden; box-sizing: border-box; }
.mf-config-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: linear-gradient(135deg, #4f46e5, #6366f1); color: #fff; flex-wrap: wrap; gap: 12px; }
.mf-config-title { font-size: 18px; font-weight: 700; }
.mf-config-title i { margin-right: 8px; opacity: .85; }
.mf-config-actions { display: flex; gap: 8px; }
.mf-cfg-btn { padding: 8px 18px; border: 1px solid rgba(255,255,255,.3); border-radius: 8px; background: rgba(255,255,255,.15); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s; }
.mf-cfg-btn:hover { background: rgba(255,255,255,.25); }
.mf-cfg-btn-primary { background: #fff !important; color: #4f46e5 !important; border-color: #fff !important; }
.mf-cfg-btn-primary:hover { background: #f0f0ff !important; }
.mf-cfg-btn-danger { background: transparent !important; color: #dc2626 !important; border-color: rgba(220,38,38,.3) !important; font-size: 12px !important; }
.mf-cfg-btn-danger:hover { background: rgba(220,38,38,.1) !important; border-color: #dc2626 !important; }

.mf-config-body { padding: 0; }
.mf-config-tabs { display: flex; border-bottom: 2px solid #e2e8f0; background: #f8fafc; }
.mf-cfg-tab { flex: 1; padding: 12px 16px; border: none; background: none; font-size: 13px; font-weight: 600; color: #64748b; cursor: pointer; transition: all .15s; text-align: center; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.mf-cfg-tab:hover { color: #334155; background: #f1f5f9; }
.mf-cfg-tab.active { color: #4f46e5; border-bottom-color: #4f46e5; background: #fff; }
.mf-cfg-tab i { margin-right: 6px; }

.mf-cfg-content { display: none; padding: 24px; }
.mf-cfg-content.active { display: block; }

.mf-cfg-notice { padding: 12px 16px; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px; color: #1e40af; font-size: 13px; margin-bottom: 20px; }
.mf-cfg-notice i { margin-right: 6px; }

.mf-cfg-form-select { max-width: 400px; }
.mf-cfg-form-select label { display: block; font-weight: 600; color: #334155; margin-bottom: 6px; font-size: 13px; }
.mf-cfg-input { width: 100%; padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 13px; background: #fff; transition: border-color .15s; box-sizing: border-box; }
.mf-cfg-input:focus { border-color: #6366f1; outline: none; box-shadow: 0 0 0 3px rgba(99,102,241,.15); }

.mf-cfg-section { margin-bottom: 20px; }
.mf-cfg-section > label { display: block; font-weight: 600; color: #334155; margin-bottom: 12px; font-size: 14px; }

.mf-cfg-view-types { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.mf-cfg-vt-card { padding: 14px 12px; border: 2px solid #e2e8f0; border-radius: 10px; text-align: center; cursor: pointer; transition: all .15s; background: #fff; }
.mf-cfg-vt-card:hover { border-color: #a5b4fc; background: #f5f3ff; }
.mf-cfg-vt-card.active { border-color: #6366f1; background: #eef2ff; box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.mf-cfg-vt-card i { display: block; font-size: 24px; color: #6366f1; margin-bottom: 8px; }
.mf-cfg-vt-card strong { display: block; font-size: 13px; color: #1e293b; margin-bottom: 2px; }
.mf-cfg-vt-card span { font-size: 11px; color: #94a3b8; }

.mf-cfg-view-opts { margin-top: 20px; padding-top: 20px; border-top: 1px solid #e2e8f0; }
.mf-cfg-view-opts h4 { font-size: 14px; color: #334155; margin: 0 0 16px; }
.mf-cfg-view-opts h4 i { margin-right: 6px; color: #6366f1; }

.mf-cfg-row { margin-bottom: 14px; }
.mf-cfg-row > label { display: block; font-weight: 500; color: #475569; margin-bottom: 6px; font-size: 13px; }
.mf-cfg-row-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 14px; }
.mf-cfg-row-grid label { display: block; font-weight: 500; color: #475569; margin-bottom: 6px; font-size: 13px; }

.mf-cfg-checklist { max-height: 200px; overflow-y: auto; border: 1px solid #e2e8f0; border-radius: 8px; padding: 8px; }
.mf-cfg-check-item { display: block; padding: 4px 8px; font-size: 13px; cursor: pointer; border-radius: 4px; }
.mf-cfg-check-item:hover { background: #f1f5f9; }
.mf-cfg-check-item input { margin-right: 6px; }
.mf-cfg-check-item small { color: #94a3b8; }

.mf-cfg-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }

/* Admin Edit View button */
.mf-cfg-edit-btn { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; font-size: 12px; color: #6366f1; background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 6px; text-decoration: none; transition: all .15s; }
.mf-cfg-edit-btn:hover { background: #e0e7ff; color: #4f46e5; text-decoration: none; }

/* ── Template Gallery ── */
.mf-tpl-categories { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid #e2e8f0; }
.mf-tpl-cat-btn { display: inline-flex; align-items: center; gap: 5px; padding: 6px 14px; font-size: 13px; border: 1px solid #e2e8f0; border-radius: 20px; background: #fff; color: #64748b; cursor: pointer; transition: all .15s; }
.mf-tpl-cat-btn:hover { border-color: #a5b4fc; color: #4f46e5; background: #eef2ff; }
.mf-tpl-cat-btn.active { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.mf-tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 20px; }
.mf-tpl-card { position: relative; border: 1px solid #e2e8f0; border-radius: 12px; padding: 20px; background: #fff; transition: all .2s; cursor: default; display: flex; flex-direction: column; }
.mf-tpl-card:hover { border-color: #a5b4fc; box-shadow: 0 4px 16px rgba(79,70,229,.1); transform: translateY(-2px); }
.mf-tpl-card-icon { font-size: 32px; margin-bottom: 10px; }
.mf-tpl-card-body h4 { margin: 0 0 6px; font-size: 16px; font-weight: 600; color: #1e293b; }
.mf-tpl-card-body p { margin: 0 0 8px; font-size: 13px; color: #64748b; line-height: 1.4; }
.mf-tpl-card-meta { font-size: 11px; color: #94a3b8; text-transform: uppercase; letter-spacing: .5px; }
.mf-tpl-use-btn { display: inline-flex; align-items: center; gap: 5px; margin-top: 12px; padding: 8px 16px; font-size: 13px; font-weight: 500; color: #4f46e5; background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 8px; cursor: pointer; transition: all .15s; align-self: flex-start; }
.mf-tpl-use-btn:hover { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.mf-tpl-use-btn:disabled { opacity: .6; cursor: not-allowed; }
.mf-tpl-use-btn.applied { background: #dcfce7; color: #16a34a; border-color: #86efac; cursor: default; }
.mf-tpl-use-btn.applied:hover { background: #dcfce7; color: #16a34a; border-color: #86efac; }
.mf-tpl-card.applied { border-color: #86efac; background: #f0fdf4; }
.mf-tpl-pagination { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 12px 0; }
.mf-tpl-page-btn { padding: 6px 14px; font-size: 13px; border: 1px solid #e2e8f0; border-radius: 6px; background: #fff; cursor: pointer; color: #475569; transition: all .15s; }
.mf-tpl-page-btn:hover:not(:disabled) { border-color: #4f46e5; color: #4f46e5; }
.mf-tpl-page-btn:disabled { opacity: .4; cursor: not-allowed; }
.mf-tpl-page-info { font-size: 13px; color: #94a3b8; }

/* ── Config Panel TS overrides ── */
.mf-cfg-section { margin-bottom: 20px; }
.mf-cfg-section > label { display: block; font-weight: 600; font-size: 14px; color: #1e293b; margin-bottom: 10px; }
.mf-cfg-form-select { max-width: 400px; }
.mf-cfg-form-select label { display: block; font-weight: 500; color: #475569; margin-bottom: 6px; font-size: 13px; }
.mf-cfg-notice { padding: 12px 16px; background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 8px; color: #0369a1; font-size: 13px; line-height: 1.5; }
.mf-cfg-notice i { margin-right: 4px; }
.mf-cfg-view-opts h4 { font-size: 14px; color: #334155; margin: 0 0 14px; padding-bottom: 8px; border-bottom: 1px solid #f1f5f9; }
.mf-cfg-view-opts h4 i { color: #6366f1; margin-right: 6px; }
.mf-cfg-row { margin-bottom: 14px; }
.mf-cfg-row > label { display: block; font-weight: 500; color: #475569; margin-bottom: 6px; font-size: 13px; }
.mf-cfg-preview-frame { border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.mf-cfg-preview-header { padding: 8px 16px; background: #f8fafc; border-bottom: 1px solid #e2e8f0; font-size: 12px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: .5px; }
.mf-cfg-preview-header i { color: #6366f1; margin-right: 4px; }

/* Toast notifications */
.mf-toast { position: fixed; top: 20px; right: 20px; z-index: 100000; padding: 12px 20px; border-radius: 8px; font-size: 14px; font-weight: 500; color: #fff; animation: mf-toast-in .3s ease; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.mf-toast-success { background: #059669; }
.mf-toast-error { background: #dc2626; }
.mf-toast-info { background: #4f46e5; }
@keyframes mf-toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }


/* ── Custom Template (mfp-) width fix ─────────────────────────────────
   Template HTML inject CSS riêng (mfp-event v.v.) với max-width cứng.
   Dùng --mf-form-max-width và buộc width:100% để Live Editor win.
   -------------------------------------------------------------------- */
.mf-fields-container { align-items: stretch; }

/* mfp-* width override removed — all forms use customHtml which manages its own layout */

/* ── Hosted page context (mfp-card wraps the form)
   When renderer is inside a platform card/wrapper,
   strip double background, shadow, radius, padding from .mf-form
   so the platform card provides the visual chrome.
   ---------------------------------------------------------------- */
.mfp-body .mf-form-wrapper,
.mf-form-host .mf-form-wrapper {
  margin: 0;
}
.mfp-body .mf-form-inner,
.mf-form-host .mf-form-inner {
  max-width: none;
  margin: 0;
}
.mfp-body .mf-form,
.mf-form-host .mf-form {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  border: none;
  padding: 0;
}
/* Alert styles (success/error) — used by renderer */
.alert { padding: 16px 20px; border-radius: 8px; font-size: 14px; line-height: 1.6; }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.alert-success .fa-check-circle { color: #16a34a; font-size: 28px; display: block; margin-bottom: 10px; }
.alert-success h3 { margin: 0 0 6px; font-size: 18px; color: #15803d; }
.alert-success p { margin: 4px 0 0; }
.alert-success .mf-ref-number { margin-top: 8px; color: #4ade80; font-size: 12px; }
.alert-danger { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.alert-danger .fa-exclamation-triangle { color: #ef4444; margin-right: 6px; }

/* ── Default generated layout (mfp-default) ────────────────────── */
/* Used when schema has no customHtml — generateDefaultCustomHtml() creates this. */
.mfp.mfp-default,
.mfp.mfp-default *, .mfp.mfp-default *::before, .mfp.mfp-default *::after { box-sizing: border-box; }
.mfp.mfp-default { max-width: 680px; margin: 0 auto; padding: 20px; font-family: var(--mf-font-family, 'Inter', system-ui, sans-serif); }
.mfp-default .mfp-default-header { padding: 28px 32px 20px; border-bottom: 1px solid var(--mf-section-border-color, #f1f5f9); margin-bottom: 8px; }
.mfp-default .mfp-default-header h1 { margin: 0 0 6px; font-size: 22px; font-weight: 700; color: var(--mf-title-color, #0f172a); }
.mfp-default .mfp-default-header p { margin: 0; font-size: 14px; color: var(--mf-color-text-muted, #64748b); line-height: 1.6; }
.mfp-default .mfp-default-body { padding: 20px 32px 32px; background: var(--mf-form-bg, #fff); }
.mfp-default .mfp-actions { padding-top: 12px; }
.mfp-default .mfp-actions button[type=submit] { width: 100%; background: var(--mf-primary, #6366f1); color: var(--mf-primary-text, #fff); border: none; border-radius: var(--mf-btn-radius, 8px); padding: var(--mf-btn-padding, 14px 32px); font-size: var(--mf-btn-font-size, 15px); font-weight: var(--mf-btn-font-weight, 600); cursor: pointer; transition: opacity .15s; }
.mfp-default .mfp-actions button[type=submit]:hover { opacity: .88; }


/* ============================================================
   MULTI-STEP + CUSTOM HTML SHELL
   Keeps stepper, body, and actions inside one renderer shell.
   ============================================================ */
.mf-form-wrapper.mf-has-multistep-shell .mf-form {
    display: block;
    width: 100%;
}
.mf-form-wrapper.mf-has-multistep-shell .mf-fields-container {
    display: block;
    width: 100%;
    min-width: 0;
}
.mf-multistep-shell {
    width: 100%;
    min-width: 0;
}
.mf-multistep-frame {
    --mf-multistep-effective-max-width: var(--mf-multistep-max-width, var(--mf-form-max-width, 1100px));
    width: min(100%, var(--mf-multistep-effective-max-width));
    min-width: 0;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.mf-multistep-header,
.mf-multistep-body,
.mf-multistep-footer {
    width: 100%;
    min-width: 0;
}
.mf-multistep-header .mf-progress-bar {
    margin-bottom: 0;
}
.mf-multistep-body > .mfp,
.mf-multistep-body > .mf-page,
.mf-multistep-body .mf-page {
    width: 100%;
    min-width: 0;
}
.mf-multistep-footer .mf-form-actions {
    margin-top: 0;
}
