/* Rich-text editor for long answers on /register — richtext-editor.js (toolbar + auto-growing textarea + preview).
   Uses register.css tokens (light + dark via [data-theme]) with light fallbacks; defines every class it uses. */

/* toolbar: sits on top of the field and shares its frame. Lists + preview only ("เหลือเฉพาะรายการ"), one row down to 320px */
.rte-bar{display:flex;flex-wrap:nowrap;align-items:center;gap:2px;padding:3px;min-width:0;
  background:var(--tint-2,#F4F8FF);border:1.5px solid var(--line,#E6E8EC);border-bottom-color:var(--tint-line,#D4E4FE);
  border-radius:10px 10px 0 0;transition:border-color .15s}
.rte-bar:has(+ .rte-input:focus){border-color:var(--blue,#2563EB);border-bottom-color:var(--tint-line,#D4E4FE)}
/* auto-grows (richtext-editor.js), so no manual resize; specific enough to beat ".fg textarea" */
.rte-bar + textarea.rte-input{display:block;resize:none;border-top-left-radius:0;border-top-right-radius:0;border-top-width:0}
.rte-input[hidden]{display:none!important}

.rte-btn{flex:none;display:inline-flex;align-items:center;justify-content:center;gap:6px;min-width:40px;min-height:40px;padding:0 10px;margin:0;
  font:inherit;font-size:13.5px;font-weight:600;line-height:1;color:var(--ink-2,#1F242B);background:transparent;
  border:1px solid transparent;border-radius:8px;cursor:pointer;
  transition:background-color .15s,border-color .15s,color .15s,transform .1s}
.rte-btn:hover:not(:disabled){background:var(--paper,#FFFFFF);border-color:var(--line,#E6E8EC);color:var(--blue-deep,#1D4ED8)}
.rte-btn:active:not(:disabled){transform:translateY(1px)}
.rte-btn:focus-visible{outline:2px solid var(--blue,#2563EB);outline-offset:1px}
.rte-btn:disabled{opacity:.38;cursor:not-allowed}
/* drawn icons (richtext-editor.js), one stroke weight */
.rte-ico{flex:none;display:block;width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.rte-ico .rte-dot{fill:currentColor;stroke:none}
.rte-grow{flex:1 1 auto;min-width:0}

/* preview toggle: the one state button, reads as "on" while previewing */
.rte-toggle{color:var(--blue-deep,#1D4ED8)}
.rte-bar.is-preview .rte-toggle{background:var(--paper,#FFFFFF);border-color:var(--tint-line,#D4E4FE)}

/* maxlength hint (role=status) */
.rte-hint{flex:1 1 0;min-width:0;padding:0 6px;font-size:12.5px;line-height:1.35;color:var(--err,#DC2626);
  opacity:0;transition:opacity .2s}
.rte-hint.is-on{opacity:1}
.rte-hint:empty{flex:0 0 0;padding:0}

/* preview: same frame as the textarea it replaces */
.rte-preview{box-sizing:border-box;max-height:60vh;overflow:auto;padding:11px 13px;color:var(--ink,#0B0C0E);
  background:var(--paper,#FFFFFF);border:1.5px solid var(--line,#E6E8EC);border-top-width:0;border-radius:0 0 10px 10px}
.rte-preview[hidden]{display:none}
.rte-preview:focus-visible{outline:none;border-color:var(--blue,#2563EB);box-shadow:0 0 0 3px var(--focus-soft,rgba(37,99,235,.14))}
.rte-empty{margin:0;color:var(--gray,#5B6470)}

/* rendered text (same rules as .rich in app.css — /register does not load app.css) */
.rte-preview .rich{overflow-wrap:anywhere;line-height:1.7}
.rte-preview .rich > :is(p,ul,ol){margin:0}
.rte-preview .rich > :is(p,ul,ol) + :is(p,ul,ol){margin-top:.6em}
.rte-preview .rich :is(ul,ol){padding-left:1.4em}
.rte-preview .rich li{margin:.15em 0}
.rte-preview .rich li::marker{color:var(--gray,#5B6470)}
.rte-preview .rich strong{font-weight:700;color:var(--ink,#0B0C0E)}
.rte-preview .rich em{font-style:italic}
.rte-preview .muted{color:var(--gray,#5B6470)}

/* phones: list buttons show their icon only (names stay in aria-label + title); compact padding keeps one row */
@media (max-width:520px){.rte-txt{display:none}.rte-btn{padding:0 8px}.rte-ul,.rte-ol{padding:0}}
@media (pointer:coarse){.rte-btn{min-width:44px;min-height:44px}}
@media (prefers-reduced-motion:reduce){.rte-bar,.rte-btn,.rte-hint{transition:none}.rte-btn:active:not(:disabled){transform:none}}
