/* ============================================================
   OmniToolkit — Text Category Styles
   ============================================================ */

/* ============================================================
   Textarea (input/output)
   ============================================================ */
.text-area {
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.6;
    resize: vertical;
}

/* Code-like textareas (base64, regex, diff, find/replace) → monospace */
.text-area[spellcheck="false"] {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85rem;
    line-height: 1.55;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
}

/* RTL handling */
[dir="rtl"] .text-area {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] .text-area[spellcheck="false"] {
    direction: ltr;
    text-align: left;
}

/* ============================================================
   Action buttons row
   ============================================================ */
.text-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.text-actions .btn {
    border-radius: 50px;
    font-size: 0.8rem;
    padding: 0.35rem 0.85rem;
}

/* ============================================================
   Word Counter — stats grid
   ============================================================ */
.text-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.text-stat {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.75rem 0.5rem;
    text-align: center;
    transition: border-color 0.15s ease;
}

.text-stat:hover {
    border-color: var(--accent);
}

.text-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 0.35rem;
    word-break: break-word;
    font-variant-numeric: tabular-nums;
}

.text-stat-label {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
}

/* ============================================================
   Notice box (script-aware warnings)
   ============================================================ */
.tool-notice {
    display: none;
    padding: 0.75rem 1rem;
    background: var(--amber-light);
    border-left: 3px solid var(--amber);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.65;
    margin-top: 0.85rem;
    animation: textNoticeAppear 0.25s ease;
}

.tool-notice.visible {
    display: block;
}

@keyframes textNoticeAppear {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

[data-theme="dark"] .tool-notice {
    background: #2b2013;
    color: #fcd34d;
    border-left-color: #f59e0b;
}

[dir="rtl"] .tool-notice {
    border-left: none;
    border-right: 3px solid var(--amber);
}

/* ============================================================
   Regex Tester
   ============================================================ */
.regex-pattern-row {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.regex-pattern-wrap {
    flex: 1 1 260px;
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0 0.65rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.regex-slash {
    color: var(--text-secondary, #6c757d);
    user-select: none;
    font-size: 1.05rem;
    line-height: 1;
}

.regex-pattern-wrap input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    padding: 0.55rem 0.25rem;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);
    min-width: 0;
}

.regex-flags {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary, #6c757d);
}

.regex-flag-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.65rem;
    height: 1.65rem;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, color 0.15s;
}

.regex-flag-label:hover {
    background: var(--border-color);
}

.regex-flag-label input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.regex-flag-label:has(input:checked) {
    background: var(--amber-light, #fef3c7);
    color: var(--amber, #d97706);
    font-weight: 700;
}

.regex-preview {
    min-height: 8rem;
    max-height: 22rem;
    overflow-y: auto;
    padding: 0.75rem 0.9rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-primary);
    direction: ltr;
    text-align: left;
}

.regex-match {
    background: #fde68a;
    color: #78350f;
    border-radius: 2px;
    padding: 0 1px;
}

.regex-match-group0 { background: #fde68a; color: #78350f; }
.regex-match-group1 { background: #a7f3d0; color: #065f46; }
.regex-match-group2 { background: #bfdbfe; color: #1e40af; }
.regex-match-group3 { background: #fbcfe8; color: #9d174d; }

.regex-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    font-size: 0.82rem;
    color: var(--text-secondary, #6c757d);
    margin-top: 0.65rem;
}

.regex-stats strong {
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.regex-error {
    color: var(--red, #ef4444);
    font-size: 0.85rem;
    padding: 0.55rem 0.85rem;
    background: var(--red-light, #fef2f2);
    border-left: 3px solid var(--red, #ef4444);
    border-radius: var(--radius-sm);
    margin-top: 0.65rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    word-break: break-word;
}

.regex-match-list {
    margin-top: 0.9rem;
    max-height: 20rem;
    overflow-y: auto;
}

.regex-match-item {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 0.4rem;
    font-size: 0.82rem;
    background: var(--bg-secondary);
}

.regex-match-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

.regex-match-index {
    font-weight: 700;
    color: var(--amber, #d97706);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.regex-match-pos {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.72rem;
    color: var(--text-secondary, #6c757d);
}

.regex-match-value {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    color: var(--text-primary);
    word-break: break-all;
    direction: ltr;
    text-align: left;
}

.regex-group {
    padding-left: 0.9rem;
    margin-top: 0.25rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.78rem;
    color: var(--text-secondary, #6c757d);
    direction: ltr;
    text-align: left;
}

.regex-group-name {
    color: var(--amber, #d97706);
    font-weight: 600;
    margin-right: 0.4rem;
}

[data-theme="dark"] .regex-match  { background: #78350f; color: #fde68a; }
[data-theme="dark"] .regex-preview { background: #1a1a1a; }
[data-theme="dark"] .regex-pattern-wrap,
[data-theme="dark"] .regex-match-item { background: #1a1a1a; border-color: #2e2e2e; }
[data-theme="dark"] .regex-flag-label:has(input:checked) { background: #2b2013; color: #fcd34d; }
[data-theme="dark"] .regex-error { background: #2b1010; color: #fca5a5; }

/* ============================================================
   Diff Checker
   ============================================================ */
.diff-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

@media (max-width: 767.98px) {
    .diff-inputs { grid-template-columns: 1fr; }
}

.diff-input-panel {
    display: flex;
    flex-direction: column;
}

.diff-input-panel label {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-secondary, #6c757d);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.4rem;
}

.diff-input-panel textarea {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    min-height: 14rem;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
    resize: vertical;
}

.diff-result {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.82rem;
    line-height: 1.65;
    margin-top: 1rem;
    direction: ltr;
    text-align: left;
}

.diff-result:empty {
    display: none;
}

.diff-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    padding: 0.7rem 0.9rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-family: inherit;
    font-size: 0.82rem;
}

.diff-stat {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.diff-stat-add    { color: #10b981; }
.diff-stat-remove { color: #ef4444; }
.diff-stat-same   { color: var(--text-secondary, #6c757d); }

.diff-stat-dot {
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: currentColor;
}

.diff-body {
    max-height: 40rem;
    overflow: auto;
}

.diff-row {
    display: grid;
    grid-template-columns: 3.5rem 1fr 3.5rem 1fr;
    align-items: stretch;
    min-height: 1.4em;
}

.diff-num {
    padding: 0 0.5rem;
    text-align: right;
    color: var(--text-secondary, #6c757d);
    background: var(--bg-secondary);
    font-size: 0.72rem;
    user-select: none;
    border-right: 1px solid var(--border-color);
    font-variant-numeric: tabular-nums;
}

.diff-cell {
    padding: 0 0.65rem;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-primary);
}

.diff-row-same .diff-cell {
    background: transparent;
}

.diff-row-remove .diff-num,
.diff-row-remove .diff-cell {
    background: #fee2e2;
    color: #7f1d1d;
}

.diff-row-add .diff-num,
.diff-row-add .diff-cell {
    background: #d1fae5;
    color: #064e3b;
}

.diff-row-remove .diff-cell::before { content: '−'; margin-right: 0.35rem; opacity: 0.55; }
.diff-row-add    .diff-cell::before { content: '+'; margin-right: 0.35rem; opacity: 0.55; }

.diff-row-empty .diff-cell {
    background: var(--bg-secondary);
    opacity: 0.6;
}

[data-theme="dark"] .diff-row-remove .diff-num,
[data-theme="dark"] .diff-row-remove .diff-cell { background: #2b1010; color: #fca5a5; }
[data-theme="dark"] .diff-row-add .diff-num,
[data-theme="dark"] .diff-row-add .diff-cell { background: #0a2218; color: #6ee7b7; }

/* Word-level diff highlight (within changed lines) */
.diff-word-add    { background: #86efac; color: #064e3b; border-radius: 2px; padding: 0 1px; }
.diff-word-remove { background: #fca5a5; color: #7f1d1d; border-radius: 2px; padding: 0 1px; }

/* Empty-state message */
.diff-empty {
    text-align: center;
    padding: 1.5rem 1rem;
    color: var(--text-secondary, #6c757d);
    font-size: 0.85rem;
}

/* View toggle */
.diff-view-toggle {
    display: inline-flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.diff-view-toggle button {
    background: transparent;
    border: none;
    padding: 0.35rem 0.85rem;
    font-size: 0.78rem;
    color: var(--text-secondary, #6c757d);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.diff-view-toggle button:hover {
    background: var(--bg-secondary);
}

.diff-view-toggle button.active {
    background: var(--amber-light, #fef3c7);
    color: var(--amber, #d97706);
    font-weight: 600;
}

/* ============================================================
   Mobile
   ============================================================ */
@media (max-width: 575.98px) {
    .text-stat-value { font-size: 1.25rem; }
    .regex-pattern-row { flex-direction: column; }
    .regex-flags { justify-content: flex-start; }
    .text-stats-grid { grid-template-columns: repeat(2, 1fr); }
}