/* ==================================================================
   custom-form.css
   Shared styles for CustomFormRenderer widgets.
   Loaded by pages that render custom forms via the shared module
   (currently MyCases.aspx; FillForm.aspx keeps its own fill-form.css).
   Widget rules are scoped under .custom-form-fields to avoid clashing
   with page-level classes (e.g. MyCases' attachment .file-upload-area).
   Global overlays (signature modal / toast) use cfr- prefixed classes.
   ================================================================== */

/* ---- Layout ---- */
.custom-form-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    align-items: flex-start;
}

.custom-form-fields .form-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
}

.custom-form-fields .form-group.half-width { width: calc(50% - 9px); }
.custom-form-fields .form-group.third-width { width: calc(33.33% - 12px); }
.custom-form-fields .form-group.quarter-width { width: calc(25% - 14px); }

@media (max-width: 640px) {
    .custom-form-fields .form-group.half-width,
    .custom-form-fields .form-group.third-width,
    .custom-form-fields .form-group.quarter-width { width: 100%; }
}

.custom-form-fields .form-group > label {
    font-weight: 600;
    font-size: 14px;
    color: #334155;
}

.custom-form-fields .required,
.custom-form-fields .required-mark { color: #e11d48; margin-inline-start: 2px; }

/* ---- Inputs ---- */
.custom-form-fields .form-control,
.custom-form-fields .form-input,
.custom-form-fields .form-textarea,
.custom-form-fields .form-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d0d7de;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    box-sizing: border-box;
}

.custom-form-fields .form-control:focus,
.custom-form-fields .form-input:focus,
.custom-form-fields .form-textarea:focus,
.custom-form-fields .form-select:focus {
    outline: none;
    border-color: var(--theme-color, #1a73e8);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-color, #1a73e8) 18%, transparent);
}

.custom-form-fields .form-textarea { resize: vertical; min-height: 96px; }

.custom-form-fields .form-control.error,
.custom-form-fields .form-control.is-invalid,
.custom-form-fields .is-invalid .form-control { border-color: #e11d48; }

.custom-form-fields .help-text { font-size: 12px; color: #64748b; }

.custom-form-fields .error-text { font-size: 12px; color: #e11d48; font-weight: 500; }

/* ---- Section / layout fields ---- */
.custom-form-fields .field-header,
.custom-form-fields .form-section-header-wrap { width: 100%; }
.custom-form-fields .form-section-header,
.custom-form-fields .field-header h3 {
    margin: 4px 0;
    font-size: 18px;
    color: var(--theme-color, #1a73e8);
    border-bottom: 2px solid var(--theme-color, #1a73e8);
    padding-bottom: 6px;
}
.custom-form-fields .field-paragraph,
.custom-form-fields .form-section-text { width: 100%; color: #475569; font-size: 14px; line-height: 1.7; }
.custom-form-fields .field-divider { width: 100%; border: none; border-top: 1px dashed #cbd5e1; margin: 4px 0; }

/* ---- Options (radio / checkbox) ---- */
.custom-form-fields .options-list { display: flex; flex-direction: column; gap: 8px; }
.custom-form-fields .option-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border: 1px solid #d0d7de; border-radius: 10px;
    cursor: pointer; transition: all .15s; font-size: 14px;
}
.custom-form-fields .option-item:hover { border-color: var(--theme-color, #1a73e8); background: #f8fafc; }
.custom-form-fields .option-item.selected {
    border-color: var(--theme-color, #1a73e8);
    background: color-mix(in srgb, var(--theme-color, #1a73e8) 8%, #fff);
}
.custom-form-fields .option-item input { accent-color: var(--theme-color, #1a73e8); width: 16px; height: 16px; }

/* ---- Rating ---- */
.custom-form-fields .rating-container { display: inline-flex; flex-direction: row-reverse; gap: 6px; font-size: 26px; }
.custom-form-fields .rating-star { color: #cbd5e1; cursor: pointer; transition: color .15s, transform .1s; }
.custom-form-fields .rating-star:hover { transform: scale(1.1); }
.custom-form-fields .rating-star.active { color: #f59e0b; }

/* ---- Signature field ---- */
.custom-form-fields .signature-area {
    border: 2px dashed #cbd5e1; border-radius: 12px; padding: 22px;
    text-align: center; color: #64748b; cursor: pointer; transition: all .15s;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.custom-form-fields .signature-area:hover { border-color: var(--theme-color, #1a73e8); background: #f8fafc; }
.custom-form-fields .signature-area i { font-size: 28px; }
.custom-form-fields .signature-preview { max-width: 100%; max-height: 150px; }
.custom-form-fields .signature-actions { margin-top: 8px; }
.custom-form-fields .btn-clear-signature {
    background: #f1f5f9; border: 1px solid #d0d7de; border-radius: 8px;
    padding: 6px 12px; cursor: pointer; font-size: 13px;
}

/* ---- File upload (scoped to custom form only) ---- */
.custom-form-fields .file-upload-area {
    border: 2px dashed #cbd5e1; border-radius: 12px; padding: 22px;
    text-align: center; color: #64748b; cursor: pointer; transition: all .15s;
}
.custom-form-fields .file-upload-area:hover,
.custom-form-fields .file-upload-area.dragover { border-color: var(--theme-color, #1a73e8); background: #f8fafc; }
.custom-form-fields .file-upload-area i { font-size: 26px; display: block; margin-bottom: 6px; }
.custom-form-fields .file-hint { display: block; font-size: 12px; color: #94a3b8; margin-top: 4px; }
.custom-form-fields .uploaded-files { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.custom-form-fields .uploaded-file {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px;
    border: 1px solid #e2e8f0; border-radius: 8px; font-size: 13px; position: relative;
}
.custom-form-fields .uploaded-file.upload-success { border-color: #86efac; background: #f0fdf4; }
.custom-form-fields .uploaded-file.upload-error { border-color: #fca5a5; background: #fef2f2; }
.custom-form-fields .uploaded-file .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-form-fields .uploaded-file .file-size { color: #94a3b8; font-size: 12px; }
.custom-form-fields .uploaded-file .file-error-msg { color: #e11d48; font-size: 12px; }
.custom-form-fields .uploaded-file .remove-file {
    background: none; border: none; color: #94a3b8; font-size: 18px; cursor: pointer; line-height: 1;
}
.custom-form-fields .uploaded-file .remove-file:hover { color: #e11d48; }
.custom-form-fields .file-progress-bar { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: #e2e8f0; border-radius: 0 0 8px 8px; overflow: hidden; }
.custom-form-fields .file-progress-fill { height: 100%; width: 0; background: var(--theme-color, #1a73e8); transition: width .2s; }

/* ---- Managed list autocomplete ---- */
.custom-form-fields .managed-list-autocomplete { position: relative; }
.custom-form-fields .ml-add-btn {
    margin-top: 6px; background: #f1f5f9; border: 1px solid #d0d7de;
    border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.ml-dropdown {
    position: fixed; z-index: 9999; background: #fff; border: 1px solid #d0d7de;
    border-radius: 10px; box-shadow: 0 12px 28px rgba(0,0,0,.12); max-height: 260px; overflow-y: auto;
}
.ml-dropdown .ml-item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.ml-dropdown .ml-item:hover { background: #f8fafc; }
.ml-dropdown .ml-item-contact { display: block; font-size: 12px; color: #94a3b8; }
.ml-dropdown .ml-no-results { padding: 12px; color: #94a3b8; text-align: center; }

/* ---- Inline text ---- */
.custom-form-fields .field-inline-text { line-height: 2.2; font-size: 15px; color: #334155; }
.custom-form-fields .inline-text-input {
    border: none; border-bottom: 2px solid #cbd5e1; padding: 2px 6px;
    min-width: 120px; font-size: 15px; font-family: inherit; background: transparent;
}
.custom-form-fields .inline-text-input:focus { outline: none; border-bottom-color: var(--theme-color, #1a73e8); }
.custom-form-fields .inline-text-input.error { border-bottom-color: #e11d48; }

/* ==================================================================
   Global overlays (not scoped) — signature modal, toasts, add-item modal
   ================================================================== */
.cfr-signature-modal {
    display: none; position: fixed; inset: 0; z-index: 10000;
    background: rgba(15,23,42,.55); align-items: center; justify-content: center;
}
.cfr-signature-modal.active { display: flex; }
.cfr-signature-box { background: #fff; border-radius: 16px; width: min(540px, 92vw); overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.cfr-signature-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid #eef2f7; }
.cfr-signature-header h3 { margin: 0; font-size: 16px; }
.cfr-signature-close { background: none; border: none; font-size: 26px; line-height: 1; cursor: pointer; color: #94a3b8; }
.cfr-signature-body { padding: 18px; }
.cfr-signature-body canvas { width: 100%; height: 200px; border: 1px solid #d0d7de; border-radius: 10px; touch-action: none; background: #fff; }
.cfr-signature-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid #eef2f7; }
.cfr-signature-footer button { padding: 8px 18px; border-radius: 8px; border: 1px solid #d0d7de; cursor: pointer; font-size: 14px; }
.cfr-signature-footer .btn-primary { background: var(--theme-color, #1a73e8); color: #fff; border-color: var(--theme-color, #1a73e8); }

#cfr-toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 10001; display: flex; flex-direction: column; gap: 10px; }
.cfr-toast {
    display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 10px;
    background: #1e293b; color: #fff; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.2);
    opacity: 0; transform: translateY(-10px); transition: opacity .3s, transform .3s;
}
.cfr-toast.cfr-toast-show { opacity: 1; transform: translateY(0); }
.cfr-toast-success { background: #16a34a; }
.cfr-toast-warning { background: #d97706; }
.cfr-toast-error { background: #dc2626; }

.ml-add-modal-overlay {
    position: fixed; inset: 0; z-index: 10000; background: rgba(15,23,42,.55);
    display: flex; align-items: center; justify-content: center;
}
.ml-add-modal { background: #fff; border-radius: 16px; width: min(460px, 92vw); padding: 22px; position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.ml-add-modal h3 { margin: 0 0 16px; font-size: 17px; }
.ml-add-close { position: absolute; top: 12px; left: 14px; background: none; border: none; font-size: 24px; cursor: pointer; color: #94a3b8; }
.ml-add-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.ml-add-field label { font-size: 13px; font-weight: 600; color: #475569; }
.ml-add-field .form-control { padding: 9px 11px; border: 1px solid #d0d7de; border-radius: 9px; font-size: 14px; }
.ml-add-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.ml-add-actions .btn { padding: 8px 18px; border-radius: 8px; border: 1px solid #d0d7de; cursor: pointer; font-size: 14px; }
.ml-add-actions .btn-primary { background: var(--theme-color, #1a73e8); color: #fff; border-color: var(--theme-color, #1a73e8); }

/* ---------------------------------------------------------------
   Read-only form view (identical rendering, locked)
   --------------------------------------------------------------- */
.cf-readonly .cf-ro-input,
.cf-readonly input:disabled,
.cf-readonly textarea:disabled,
.cf-readonly select:disabled {
    background: #f8fafc !important;
    color: #1e293b !important;
    -webkit-text-fill-color: #1e293b;
    opacity: 1 !important;
    cursor: default;
}

.cf-readonly .file-upload-area { display: none; }
.cf-readonly .remove-file { display: none !important; }
.cf-readonly .required-mark { display: none; }

.cf-readonly .signature-preview-img {
    max-width: 260px;
    max-height: 120px;
    border: 1px solid #e5e9f2;
    border-radius: 8px;
    background: #fff;
    display: block;
}

.cf-readonly .cf-ro-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    margin: 2px 6px 2px 0;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 13px;
    color: #334155;
    text-decoration: none;
}

.cf-readonly .cf-ro-file:hover { background: #e2e8f0; }

.cf-readonly .cf-ro-empty { color: #cbd5e1; font-size: 13px; }
