/* ===========================================================================
   Rich-text editor (WYSIWYG)  —  used by «ثبت درخواست» and ticket replies.
   Tokens follow the panel convention: var(--x-dark, var(--x, fallback)) so the
   same rules work for both the light theme and dark.css.
   =========================================================================== */

.rte {
    --rte-bg: var(--input-bg-dark, var(--surface, #fff));
    --rte-bar-bg: var(--card-bg-dark, var(--surface-2, #f4f6fa));
    --rte-border: var(--input-border-dark, var(--border, #e6e9f0));
    --rte-text: var(--text-color-dark, var(--text, #1f2937));
    --rte-muted: var(--text-secondary-dark, var(--text-secondary, var(--text-2, #64748b)));
    --rte-hover: var(--hover-bg-dark, var(--hover, var(--surface-3, #eef2f8)));
    --rte-primary: var(--primary-color, var(--primary, #2563eb));

    border: 1.5px solid var(--rte-border);
    border-radius: 12px;
    background: var(--rte-bg);
    overflow: hidden;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.rte.is-focused {
    border-color: var(--rte-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--rte-primary) 16%, transparent);
}

.rte.is-invalid {
    border-color: var(--danger-color, #dc2626);
}

/* ----- toolbar ----- */
.rte-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 6px;
    background: var(--rte-bar-bg);
    border-bottom: 1px solid var(--rte-border);
}

/* every control is scoped with an extra `.rte` so the panel-wide
   `.modal-box button / input / select` rules cannot resize them */
.rte .rte-btn,
.rte .rte-swatch,
.rte .rte-panel-reset,
.rte .rte-linkbar button {
    margin: 0;
    box-shadow: none;
    transform: none;
}

.rte .rte-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: auto;
    min-width: 29px;
    height: 29px;
    padding: 0 5px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--rte-text);
    font: inherit;
    font-size: .82rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.rte .rte-btn:hover {
    background: var(--rte-hover);
}

.rte .rte-btn.is-active {
    background: color-mix(in srgb, var(--rte-primary) 16%, transparent);
    color: var(--rte-primary);
}

.rte .rte-btn:disabled {
    opacity: .45;
    cursor: default;
}

.rte-btn svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.rte-btn svg.is-filled {
    fill: currentColor;
    stroke: none;
}

.rte-sep {
    width: 1px;
    height: 18px;
    margin: 0 4px;
    background: var(--rte-border);
}

/* the extra `.rte` beats the generic `.modal-box input/select` rules that would
   otherwise stretch these controls to 100% and add a 16px bottom margin */
.rte .rte-select {
    width: auto;
    min-width: 106px;
    height: 30px;
    margin: 0;
    padding: 0 9px 0 26px;
    border: 1px solid var(--rte-border);
    border-radius: 8px;
    background-color: var(--rte-bg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 8px center;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    color: var(--rte-text);
    font: inherit;
    font-size: .78rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: none;
}

.rte .rte-select:focus {
    border-color: var(--rte-primary);
    box-shadow: none;
}

/* ----- dropdowns (colors) ----- */
.rte-pop {
    position: relative;
}

.rte-panel {
    position: absolute;
    z-index: 40;
    top: calc(100% + 6px);
    inset-inline-start: 0;
    display: none;
    padding: 8px;
    border: 1px solid var(--rte-border);
    border-radius: 12px;
    background: var(--rte-bg);
    box-shadow: 0 10px 26px rgba(0, 0, 0, .16);
}

.rte-panel.is-open {
    display: block;
}

.rte-swatches {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
}

.rte .rte-swatch {
    width: 20px;
    min-width: 0;
    height: 20px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, .18);
    border-radius: 6px;
    cursor: pointer;
    transition: transform .12s ease;
}

.rte .rte-swatch:hover {
    transform: scale(1.14);
}

.rte .rte-panel-reset {
    width: 100%;
    margin-top: 8px;
    padding: 6px;
    border: 1px solid var(--rte-border);
    border-radius: 8px;
    background: transparent;
    color: var(--rte-muted);
    font: inherit;
    font-size: .74rem;
    cursor: pointer;
}

.rte .rte-panel-reset:hover {
    background: var(--rte-hover);
}

/* ----- link bar ----- */
.rte-linkbar {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 7px 8px;
    background: var(--rte-bar-bg);
    border-bottom: 1px solid var(--rte-border);
}

.rte-linkbar.is-open {
    display: flex;
}

.rte .rte-linkbar input {
    flex: 1;
    width: auto;
    min-width: 0;
    height: 30px;
    margin: 0;
    padding: 0 10px;
    border: 1px solid var(--rte-border);
    border-radius: 8px;
    background: var(--rte-bg);
    color: var(--rte-text);
    font: inherit;
    font-size: .8rem;
    line-height: 1;
    direction: ltr;
    box-shadow: none;
}

.rte .rte-linkbar button {
    width: auto;
    height: 30px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-size: .78rem;
    font-weight: 700;
    cursor: pointer;
}

.rte-linkbar .rte-link-ok {
    background: var(--rte-primary);
    color: #fff;
}

.rte-linkbar .rte-link-cancel {
    background: var(--rte-hover);
    color: var(--rte-muted);
}

/* ----- editing surface ----- */
.rte-editor {
    min-height: 150px;
    max-height: 46vh;
    padding: 12px 14px;
    overflow-y: auto;
    color: var(--rte-text);
    font: inherit;
    font-size: .9rem;
    line-height: 1.95;
    outline: none;
    word-break: break-word;
}

.rte-editor.is-empty::before {
    content: attr(data-placeholder);
    color: var(--rte-muted);
    pointer-events: none;
    display: block;
}

/* ----- footer ----- */
.rte-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 5px 10px;
    border-top: 1px solid var(--rte-border);
    background: var(--rte-bar-bg);
    color: var(--rte-muted);
    font-size: .7rem;
}

.rte.is-invalid .rte-hint {
    color: var(--danger-color, #dc2626);
    font-weight: 700;
}

/* ===========================================================================
   Shared typography for editor content and for rendering saved content
   (.rte-editor while typing, .rich-content once it is stored & displayed).
   =========================================================================== */

.rte-editor p,
.rich-content p {
    margin: 0 0 .55em;
}

.rte-editor p:last-child,
.rich-content p:last-child {
    margin-bottom: 0;
}

.rte-editor h2,
.rich-content h2 {
    margin: .5em 0 .35em;
    font-size: 1.12em;
    font-weight: 800;
}

.rte-editor h3,
.rich-content h3 {
    margin: .5em 0 .35em;
    font-size: 1.03em;
    font-weight: 800;
}

.rte-editor ul,
.rte-editor ol,
.rich-content ul,
.rich-content ol {
    margin: .35em 0;
    padding-inline-start: 1.6em;
}

.rte-editor li,
.rich-content li {
    margin: .15em 0;
}

.rte-editor blockquote,
.rich-content blockquote {
    margin: .5em 0;
    padding: .35em .9em;
    border-inline-start: 3px solid var(--primary-color, #2563eb);
    background: color-mix(in srgb, var(--primary-color, #2563eb) 7%, transparent);
    border-radius: 8px;
    color: inherit;
}

.rte-editor code,
.rich-content code {
    padding: .1em .4em;
    border-radius: 6px;
    background: color-mix(in srgb, currentColor 10%, transparent);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .88em;
    direction: ltr;
    display: inline-block;
}

.rte-editor pre,
.rich-content pre {
    margin: .5em 0;
    padding: .7em .9em;
    border-radius: 10px;
    background: color-mix(in srgb, currentColor 8%, transparent);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .85em;
    direction: ltr;
    text-align: left;
    overflow-x: auto;
    white-space: pre-wrap;
}

.rte-editor pre code,
.rich-content pre code {
    padding: 0;
    background: none;
}

/* highlighted text keeps a dark ink so it stays readable in the dark theme too;
   an explicit inline `color` still wins, because inline styles beat this rule.
   `transparent` is excluded — a cleared highlight is not a highlight, and forcing
   dark ink there would make the text vanish on a dark background. */
.rte-editor span[style*="background-color"]:not([style*="transparent"]),
.rich-content span[style*="background-color"]:not([style*="transparent"]) {
    color: #1f2937;
    border-radius: 3px;
}

.rte-editor a,
.rich-content a {
    color: var(--primary-color, #2563eb);
    text-decoration: underline;
    word-break: break-all;
}

.rte-editor hr,
.rich-content hr {
    margin: .8em 0;
    border: 0;
    border-top: 1px solid var(--input-border-dark, var(--border, #e6e9f0));
}

.rich-content {
    line-height: 1.95;
    word-break: break-word;
    /* the markup carries the formatting — ignore a pre-wrap container */
    white-space: normal;
}

.rich-content>*:first-child {
    margin-top: 0;
}

.rich-content>*:last-child {
    margin-bottom: 0;
}

@media (max-width: 480px) {
    .rte-editor {
        min-height: 130px;
    }

    .rte-btn {
        min-width: 28px;
        height: 28px;
    }
}
