function s = tdcs_model_summary(model, label)
%TDCS_MODEL_SUMMARY Full native fitlme/fitglme model summary as plain text.
%   S = TDCS_MODEL_SUMMARY(MODEL) captures DISP(MODEL) -- the complete summary
%   MATLAB prints for a fitted LinearMixedModel / GeneralizedLinearMixedModel
%   (model information and fit statistics, the formula, the fixed-effects
%   coefficient table with 95% CIs, and the random-effects covariance) -- and
%   strips the Command-Window-only <strong>...</strong> bold markup that EVALC
%   would otherwise emit as literal text, so the result is plain text suitable
%   for the console and the results/*.txt files.
%
%   S = TDCS_MODEL_SUMMARY(MODEL, LABEL) prefixes a titled banner naming the
%   model (typically its formula), so each scenario's output carries a
%   self-describing copy of the raw GLM/LME summary.
%
%   This is the single place that renders a fitted model verbatim; every report
%   (tdcs_report, tdcs_lme_report, tdcs_paper_lme, tdcs_phase_lme) routes
%   through it so that ALL scenarios print the full summary generated by the
%   MATLAB model-fitting functions.

raw = evalc('disp(model)');
s = regexprep(raw, '</?strong>', '');

if nargin > 1 && ~isempty(label)
    bar = repmat('=', 1, 78);
    s = sprintf('%s\nFULL MODEL SUMMARY -- %s\n%s\n%s', bar, label, bar, s);
end

end
