/* Regex tester - a pattern field with flag toggles, a test string with a live
   highlight overlay, a match/groups list, a replace preview, and a cheatsheet.
   Reuses base .btn / .btn-outline / .seg / .field; all colors come from theme
   tokens so it tracks the light/dark theme. */

.rt-intro { color: var(--muted); max-width: 64ch; margin: 8px 0 20px; }

/* Pattern row: a /.../ delimiter wrapper around the pattern input. */
.rt-pattern-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.rt-pattern-label { font-size: 14px; color: var(--muted); font-weight: 600; }
.rt-pattern-box {
    display: flex; align-items: center; gap: 4px;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface); padding: 0 12px;
}
.rt-pattern-box:focus-within { outline: 2px solid var(--accent); border-color: var(--accent); }
.rt-slash {
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
    font-size: 18px; color: var(--muted); user-select: none;
}
.rt-flags-readout {
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
    font-size: 14px; color: var(--accent-strong); min-width: 1ch;
}
.rt-pattern-input {
    flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
    color: var(--text); padding: 12px 0;
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
    font-size: 15px;
}

/* Controls toolbar: flag toggles on the left, mode switch on the right. */
.rt-toolbar {
    display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end;
    justify-content: space-between; margin-bottom: 16px;
}
.rt-control { display: flex; flex-direction: column; gap: 6px; }
.rt-control-label { font-size: 14px; color: var(--muted); font-weight: 600; }

/* Flag toggles: independent on/off chips (not a single-choice segment). */
.rt-flags { display: flex; flex-wrap: wrap; gap: 6px; }
.rt-flag {
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
    width: 34px; height: 34px; border-radius: 8px;
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted);
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
    transition: border-color .15s, background .15s, color .15s;
}
.rt-flag:hover { border-color: var(--accent); }
.rt-flag[aria-pressed="true"] {
    background: color-mix(in srgb, var(--accent) 16%, var(--surface));
    border-color: var(--accent); color: var(--accent-strong);
}

/* Test-string editor: a highlight backdrop and a transparent-text textarea share
   identical box metrics so the marks line up exactly under the typed characters. */
.rt-editor-label { font-size: 14px; color: var(--muted); font-weight: 600; display: block; margin-bottom: 6px; }
.rt-editor { position: relative; }
.rt-editor-shared {
    margin: 0; box-sizing: border-box; min-height: 220px;
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
    font-size: 14px; line-height: 1.6; tab-size: 4; padding: 12px;
    border: 1px solid var(--border); border-radius: 12px;
    white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
}
.rt-highlights {
    position: absolute; inset: 0; overflow: hidden;
    color: var(--text); background: var(--surface); pointer-events: none;
}
.rt-subject {
    position: relative; width: 100%; resize: vertical; overflow: auto;
    color: transparent; background: transparent; caret-color: var(--text);
    border-color: var(--border);
}
.rt-subject:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

/* Match highlights: a tinted wash, alternating shades so adjacent matches read apart. */
.rt-hl { border-radius: 3px; color: inherit; }
.rt-hl-odd { background: color-mix(in srgb, var(--accent) 32%, transparent); }
.rt-hl-even { background: color-mix(in srgb, var(--accent) 18%, transparent); }

.rt-error {
    margin: 14px 0 0; padding: 10px 14px; border-radius: 10px;
    color: var(--bad); background: var(--surface); border: 1px solid var(--bad);
    font-size: 14px;
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
}
.rt-status {
    margin: 12px 0 0; color: var(--muted); font-size: 14px;
    font-variant-numeric: tabular-nums; min-height: 1.2em;
}

/* Replace tab: replacement field + read-only result, shown only in replace mode. */
.rt-replace { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.rt-replace-head { display: flex; align-items: center; justify-content: space-between; min-height: 28px; }
.rt-replace-label { font-size: 14px; color: var(--muted); font-weight: 600; }
.rt-replace-input {
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
    font-size: 14px;
}
.rt-result {
    width: 100%; box-sizing: border-box; min-height: 160px; resize: vertical;
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
    font-size: 14px; line-height: 1.6; tab-size: 4; padding: 12px;
    color: var(--text); background: var(--bg);
    border: 1px solid var(--border); border-radius: 12px;
    white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
}
.rt-copy {
    font: inherit; font-size: 13px; padding: 4px 12px; cursor: pointer;
    border: 1px solid var(--border-strong); border-radius: 8px;
    background: var(--surface); color: var(--text);
    transition: border-color .15s, background .15s, color .15s;
}
.rt-copy:hover { border-color: var(--accent); color: var(--accent-strong); }

/* Match list: shown only in match mode. */
.rt-matchwrap { margin-top: 16px; }
.rt-matchwrap-title { font-size: 14px; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
.rt-matches { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rt-match {
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); padding: 10px 12px;
}
.rt-match-head {
    display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px;
    font-size: 13px;
}
.rt-match-no { font-weight: 600; color: var(--text); }
.rt-match-pos { color: var(--muted); font-variant-numeric: tabular-nums; }
.rt-match-value {
    display: block; font-size: 14px; color: var(--accent-strong);
    background: var(--bg); border-radius: 6px; padding: 4px 8px;
    white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
}
.rt-groups {
    display: grid; grid-template-columns: auto 1fr; gap: 2px 12px;
    margin: 8px 0 0; font-size: 13px;
}
.rt-groups dt {
    color: var(--muted); font-weight: 600; text-align: right;
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
}
.rt-groups dd {
    margin: 0; color: var(--text);
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
    white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
}
.rt-group-empty { color: var(--muted); font-style: italic; }

/* Mode-driven visibility: hide the panel that does not belong to the active tab. */
.rt[data-mode="match"] .rt-replace { display: none; }
.rt[data-mode="replace"] .rt-matchwrap { display: none; }

/* Cheatsheet: a crawlable token reference in collapsible sections. */
.rt-cheatsheet { margin-top: 28px; }
.rt-cheatsheet > summary {
    cursor: pointer; font-weight: 600; font-size: 16px; color: var(--text);
    padding: 8px 0;
}
.rt-cheat-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px; margin-top: 8px;
}
.rt-cheat-group h3 { font-size: 14px; margin: 0 0 8px; color: var(--accent-strong); }
.rt-cheat-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.rt-cheat-list dt {
    font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
    color: var(--accent-strong); white-space: nowrap;
}
.rt-cheat-list dd { margin: 0; color: var(--muted); }

@media (max-width: 640px) {
    .rt-toolbar { flex-direction: column; align-items: flex-start; }
}
