/*
 * Mateen Labs text tools: diff checker, remove duplicates and sort, find and replace, lorem ipsum, slugs.
 * Builds on /tools/assets/tools.css and /tools/assets/file-tool.css and the site tokens (light and dark follow the site).
 * Mobile first: nothing here may be wider than a 320px screen.
 */

.tx-app { min-width: 0; }
.tx-app [hidden] { display: none !important; }

.tx-app .tool-editor { min-height: 240px; }
.tx-app .tool-actions { justify-content: flex-start; }
.tx-app .file-options { margin-top: 16px; }

@media (max-width: 720px) {
    .tx-app .tool-editor { min-height: 200px; }
}

/* Safari ignores min-height on native selects, so draw our own arrow (keeps the 44px target). */
.tx-app select {
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
    padding-right: 38px;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 20px) 52%, calc(100% - 14px) 52%;
    background-size: 6px 6px;
    background-repeat: no-repeat;
}

.tx-app .opt-row .opt-radio { margin-right: 6px; }
.tx-app .opt-row input[type="text"].tx-short { flex: 0 0 120px; min-width: 0; }

.tx-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    margin: 12px 0;
}

.tx-bar button,
.tx-btn {
    min-height: 44px;
    padding: 8px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 11px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    font-weight: 650;
    cursor: pointer;
}

.tx-bar button:hover:not(:disabled),
.tx-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--panel); }
.tx-bar button:disabled,
.tx-btn:disabled { opacity: .5; cursor: not-allowed; }
.tx-bar button.primary,
.tx-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tx-bar button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.tx-bar button:focus-visible,
.tx-btn:focus-visible,
.tx-app input:focus-visible,
.tx-app select:focus-visible,
.tx-app textarea:focus-visible,
.diff-gap:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---------- Progress and warnings ---------- */

.tx-progress {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    margin: 12px 0;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    font-size: 14px;
}

.tx-progress progress { flex: 1 1 160px; min-width: 0; height: 10px; accent-color: var(--accent); }

.tx-note {
    margin: 12px 0;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    border-radius: 10px;
    background: var(--panel);
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.tx-note.is-warning { border-color: var(--warn-line); border-left-color: var(--warn-text); background: var(--warn-bg); color: var(--warn-text); }
.tx-note.is-error { border-color: var(--err-line); border-left-color: var(--err-text); background: var(--err-bg); color: var(--err-text); }

.tx-field-error { margin: 0; color: var(--err-text); font-size: 14px; font-weight: 600; }

/* ---------- Statistics ---------- */

.tx-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(130px, 100%), 1fr));
    gap: 10px;
    margin: 14px 0;
    padding: 0;
}

.tx-stat {
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
}

.tx-stat dt { color: var(--muted); font-size: 13px; font-weight: 700; }
.tx-stat dd { margin: 2px 0 0; color: var(--text); font-size: 20px; font-weight: 800; overflow-wrap: anywhere; }
.tx-stat.is-added dd { color: var(--ok-text); }
.tx-stat.is-removed dd { color: var(--err-text); }

/* ---------- Diff ---------- */

.diff-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    margin: 8px 0;
    color: var(--muted);
    font-size: 13px;
}

.diff-legend span { display: inline-flex; align-items: center; gap: 6px; }

.diff-view {
    margin: 10px 0 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
    font: 13.5px/1.6 var(--mono);
}

.diff-sbs { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.diff-inline { display: block; }

.diff-head {
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    color: var(--muted);
    font: 700 13px var(--font);
}

.diff-line {
    display: flex;
    gap: 8px;
    min-width: 0;
    padding: 1px 10px 1px 6px;
    border-left: 4px solid transparent;
}

.diff-sbs .diff-line + .diff-line { }

.diff-no {
    flex: none;
    min-width: 3.2ch;
    color: var(--muted);
    text-align: right;
    user-select: none;
}

.diff-mark { flex: none; width: 1.5ch; font-weight: 800; user-select: none; }
.diff-text { flex: 1; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.diff-line.is-added { border-left-color: var(--ok-text); background: var(--ok-bg); color: var(--ok-text); }
.diff-line.is-removed { border-left-color: var(--err-text); background: var(--err-bg); color: var(--err-text); }
.diff-line.is-added .diff-text { text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; }
.diff-line.is-removed .diff-text { text-decoration: line-through; }
.diff-line.is-empty { background: var(--panel); min-height: 1.6em; }
.diff-line.is-current { outline: 3px solid var(--accent); outline-offset: -3px; }

.diff-gap {
    grid-column: 1 / -1;
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 6px 12px;
    border: 0;
    border-top: 1px dashed var(--line-strong);
    border-bottom: 1px dashed var(--line-strong);
    background: var(--panel);
    color: var(--accent-text);
    font: 650 13px var(--font);
    text-align: center;
    cursor: pointer;
}

.diff-gap:hover { background: var(--accent-soft); }

.diff-pre {
    margin: 0;
    padding: 10px 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: inherit;
    color: var(--text);
}

.diff-pre ins,
.diff-pre del { padding: 0 1px; border-radius: 3px; }
.diff-pre ins { background: var(--ok-bg); color: var(--ok-text); text-decoration: underline; text-underline-offset: 3px; }
.diff-pre del { background: var(--err-bg); color: var(--err-text); text-decoration: line-through; }
.diff-pre .is-current { outline: 3px solid var(--accent); outline-offset: 1px; }

.diff-more { margin: 0; padding: 10px 12px; color: var(--muted); font: 600 13px var(--font); }

@media (max-width: 720px) {
    .diff-sbs { grid-template-columns: minmax(0, 1fr); }
    .diff-sbs .diff-line.is-empty { display: none; }
}

/* ---------- Find and replace ---------- */

.fr-rules { display: grid; gap: 10px; margin: 0 0 10px; padding: 0; list-style: none; }

.fr-rule {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 8px 10px;
    align-items: end;
}

.fr-rule label { display: grid; gap: 4px; min-width: 0; color: var(--muted); font-size: 13px; font-weight: 700; }

.fr-rule input[type="text"] {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 6px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: 15px var(--mono);
}

.fr-rule input[aria-invalid="true"] { border-color: var(--err-text); }
.fr-rule .tx-btn { align-self: end; }

@media (max-width: 620px) {
    .fr-rule { grid-template-columns: minmax(0, 1fr); }
    .fr-rule .tx-btn { justify-self: start; }
}

.fr-preview {
    max-height: 340px;
    margin: 0;
    padding: 12px 14px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: 13.5px/1.7 var(--mono);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.fr-preview mark {
    padding: 0 1px;
    border-radius: 3px;
    background: var(--warn-bg);
    color: var(--warn-text);
    outline: 1px solid var(--warn-line);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.fr-preview mark.is-current { background: var(--accent); color: var(--on-accent); outline-color: var(--accent); }

/* ---------- Lorem ipsum and slugs ---------- */

.lorem-out { min-height: 280px; }

.slug-out {
    box-sizing: border-box;
    width: 100%;
    min-height: 48px;
    padding: 10px 14px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--panel);
    color: var(--text);
    font: 700 17px var(--mono);
    overflow-wrap: anywhere;
}

.slug-table { width: 100%; margin: 10px 0; border-collapse: collapse; font-size: 14px; }
.slug-table th,
.slug-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; overflow-wrap: anywhere; }
.slug-table th { color: var(--muted); font-size: 13px; }
.slug-table code { font-family: var(--mono); font-weight: 700; }
.slug-wrap { max-width: 100%; overflow-x: auto; }

.tx-h2 { margin: 22px 0 8px; font-size: 18px; }
