/* Tharsol Connect: the image editor (js/image-editor.js) and the "✎ Edit" button on a picture waiting to be sent.
   Shared by Connect's pages (chat, mail; tokens.css: --surface, --text, --accent…) and the ticket screens
   (tms-tokens.css: --tms-*): every colour comes through the --ie-* variables below, which take whichever set the page
   has, so light, dark and the person's accent colour follow the page. Tinted controls: a tint fill, saturated text and
   a 1px border. No movement beyond colour changes, and none at all with reduced motion. */

.tc-ie,
.tc-ie-edit {
    --ie-bg: var(--surface, var(--tms-surface, #ffffff));
    --ie-bg2: var(--surface-2, var(--tms-surface-2, #f4f6f9));
    --ie-line: var(--border, var(--tms-border, #dde3ec));
    --ie-text: var(--text, var(--tms-text, #1a1922));
    --ie-mut: var(--muted, var(--tms-text-2, #5c6778));
    --ie-acc: var(--accent, var(--tms-accent, #1560d4));
    --ie-danger: var(--danger, var(--tms-danger, #c4461f));
    --ie-tint: color-mix(in srgb, var(--ie-acc) 15%, transparent);
    --ie-tint-line: color-mix(in srgb, var(--ie-acc) 50%, transparent);
}

.tc-ie [hidden] { display: none !important; }

.tc-ie {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(8, 10, 14, .58);
    color: var(--ie-text);
    font: 13px/1.35 var(--font-sans, var(--tms-font, "Segoe UI", system-ui, sans-serif));
}

.tc-ie *,
.tc-ie *::before,
.tc-ie *::after { box-sizing: border-box; }

.tc-ie-modal {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(1180px, 100%);
    min-width: 0;
    max-width: 100%;
    height: min(860px, 100%);
    background: var(--ie-bg);
    border: 1px solid var(--ie-line);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .35);
}

/* ---- header ---- */
.tc-ie-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px 9px 16px;
    border-bottom: 1px solid var(--ie-line);
    min-width: 0;
}
.tc-ie-head b { font-size: 14px; white-space: nowrap; }
.tc-ie-file { color: var(--ie-mut); font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc-ie-sp { flex: 1; min-width: 4px; }

/* ---- buttons ---- */
.tc-ie-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border: 1px solid var(--ie-line);
    border-radius: 8px;
    background: var(--ie-bg2);
    color: var(--ie-text);
    font: inherit;
    font-size: 12.5px;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .12s, border-color .12s, color .12s;
}
.tc-ie-btn:hover:not(:disabled) { border-color: var(--ie-tint-line); }
.tc-ie-btn:disabled { opacity: .45; cursor: default; }
.tc-ie-btn.tc-ie-pri {
    background: var(--ie-tint);
    color: var(--ie-acc);
    border-color: var(--ie-tint-line);
    font-weight: 600;
}
.tc-ie-btn.tc-ie-pri:hover:not(:disabled) { background: color-mix(in srgb, var(--ie-acc) 24%, transparent); }
.tc-ie-btn.tc-ie-danger {
    background: color-mix(in srgb, var(--ie-danger) 14%, transparent);
    color: var(--ie-danger);
    border-color: color-mix(in srgb, var(--ie-danger) 50%, transparent);
    font-weight: 600;
}
.tc-ie-btn.tc-ie-x { border-color: transparent; background: transparent; color: var(--ie-mut); padding: 0 8px; }
.tc-ie-btn.tc-ie-x:hover { color: var(--ie-text); }
.tc-ie-ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tc-ie-btn .tc-ie-ico { width: 16px; height: 16px; }

/* ---- options bar ---- */
.tc-ie-opts {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--ie-line);
    background: var(--ie-bg2);
    min-height: 50px;
    overflow-x: auto;
    scrollbar-width: thin;
}
.tc-ie-lbl { color: var(--ie-mut); font-size: 12px; white-space: nowrap; }
.tc-ie-lbl label { cursor: pointer; }
.tc-ie-group { display: flex; align-items: center; gap: 7px; }
.tc-ie-sep { flex: none; width: 1px; height: 22px; background: var(--ie-line); margin: 0 2px; }
.tc-ie-tip { color: var(--ie-mut); font-size: 12px; white-space: nowrap; }

.tc-ie-sw {
    position: relative;
    flex: none;
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid color-mix(in srgb, var(--ie-text) 28%, transparent);
    background: var(--sw, #888);
    cursor: pointer;
}
.tc-ie-sw.on { outline: 2px solid var(--ie-text); outline-offset: 2px; }
.tc-ie-custom { background: conic-gradient(#ff3b3b, #ffd23b, #45d46b, #3bd3ff, #4a6bff, #d34bff, #ff3b3b); overflow: hidden; display: inline-block; }
.tc-ie-custom.on { background: var(--sw); }
.tc-ie-cc { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.tc-ie-custom:focus-within { outline: 2px solid var(--ie-acc); outline-offset: 2px; }

.tc-ie-wd {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 26px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--ie-text);
    cursor: pointer;
}
.tc-ie-wd i { display: block; width: 22px; border-radius: 4px; background: currentColor; }
.tc-ie-wd .tc-ie-wd0 { height: 2px; }
.tc-ie-wd .tc-ie-wd1 { height: 4px; }
.tc-ie-wd .tc-ie-wd2 { height: 7px; }
.tc-ie-wd .tc-ie-wd3 { height: 11px; }
.tc-ie-wd.txt i { width: auto; height: auto; background: none; font-style: normal; font-weight: 700; line-height: 1; }
.tc-ie-wd.txt i::before { content: "A"; }
.tc-ie-wd.txt .tc-ie-wd0 { font-size: 10px; }
.tc-ie-wd.txt .tc-ie-wd1 { font-size: 13px; }
.tc-ie-wd.txt .tc-ie-wd2 { font-size: 16px; }
.tc-ie-wd.txt .tc-ie-wd3 { font-size: 19px; }
.tc-ie-wd.on { background: var(--ie-tint); border-color: var(--ie-tint-line); color: var(--ie-acc); }

.tc-ie-fill {
    height: 30px;
    padding: 0 8px;
    border: 1px solid var(--ie-line);
    border-radius: 8px;
    background: var(--ie-bg);
    color: var(--ie-text);
    font: inherit;
    font-size: 12.5px;
}
.tc-ie-fill:disabled { opacity: .5; }

.tc-ie-chip {
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--ie-line);
    border-radius: 999px;
    background: var(--ie-bg);
    color: var(--ie-text);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}
.tc-ie-chip.on { background: var(--ie-tint); border-color: var(--ie-tint-line); color: var(--ie-acc); font-weight: 600; }

/* ---- body: tool rail and stage ---- */
.tc-ie-body { flex: 1; display: flex; min-height: 0; min-width: 0; }
.tc-ie-tools {
    flex: none;
    width: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px 8px;
    border-right: 1px solid var(--ie-line);
    overflow-y: auto;
}
.tc-ie-tools .tc-ie-sep { width: 30px; height: 1px; margin: 3px 0; }
.tc-ie-t {
    flex: none;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: var(--ie-mut);
    cursor: pointer;
    transition: background-color .12s, color .12s, border-color .12s;
}
.tc-ie-t:hover { color: var(--ie-text); background: color-mix(in srgb, var(--ie-text) 6%, transparent); }
.tc-ie-t.on { background: var(--ie-tint); color: var(--ie-acc); border-color: var(--ie-tint-line); }
.tc-ie-t .tc-ie-ico { width: 20px; height: 20px; }

.tc-ie-stage {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background:
        repeating-conic-gradient(color-mix(in srgb, var(--ie-text) 5%, var(--ie-bg2)) 0 25%, color-mix(in srgb, var(--ie-text) 9%, var(--ie-bg2)) 0 50%) 0 0 / 18px 18px;
}
.tc-ie-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.tc-ie-canvas[data-tool="select"] { cursor: default; }
.tc-ie-canvas[data-tool="text"] { cursor: text; }
.tc-ie-canvas:focus-visible { outline: 2px solid var(--ie-acc); outline-offset: -2px; }
.tc-ie-textedit {
    position: absolute;
    z-index: 2;
    min-width: 40px;
    margin: -4px 0 0 -4px;
    padding: 2px 3px;
    border: 1px dashed var(--ie-acc);
    border-radius: 4px;
    background: rgba(0, 0, 0, .12);
    resize: none;
    overflow: hidden;
    line-height: 1.25;
    white-space: pre;
    outline: none;
}

/* ---- thumbnails ---- */
.tc-ie-thumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-top: 1px solid var(--ie-line);
    overflow-x: auto;
}
.tc-ie-th {
    flex: none;
    width: 58px;
    height: 42px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 8px;
    background: var(--ie-bg2);
    overflow: hidden;
    cursor: pointer;
}
.tc-ie-th.on { border-color: var(--ie-acc); }
.tc-ie-thc { width: 100%; height: 100%; display: block; }
.tc-ie-add {
    position: relative;
    flex: none;
    width: 58px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px dashed color-mix(in srgb, var(--ie-text) 35%, transparent);
    border-radius: 8px;
    color: var(--ie-mut);
    cursor: pointer;
}
.tc-ie-add:focus-within { outline: 2px solid var(--ie-acc); outline-offset: 2px; }
.tc-ie-thumbs > .tc-ie-lbl { margin-left: 6px; }

/* ---- footer and the discard prompt ---- */
.tc-ie-foot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-top: 1px solid var(--ie-line);
}
.tc-ie-cap {
    flex: 1;
    min-width: 0;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--ie-line);
    border-radius: 9px;
    background: var(--ie-bg2);
    color: var(--ie-text);
    font: inherit;
}
.tc-ie-msg { color: var(--ie-mut); font-size: 12px; }
.tc-ie-msg:empty { display: none; }
.tc-ie-confirm {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-top: 1px solid color-mix(in srgb, var(--ie-danger) 40%, transparent);
    background: color-mix(in srgb, var(--ie-danger) 10%, var(--ie-bg));
    color: var(--ie-text);
}

.tc-ie-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.tc-ie :focus-visible { outline: 2px solid var(--ie-acc); outline-offset: 2px; }

/* ---- phones: full screen, the tools in a bar under the picture (as the Android app) ---- */
@media (max-width: 600px) {
    .tc-ie { padding: 0; }
    .tc-ie-modal { width: 100%; height: 100%; border-radius: 0; border: 0; }
    .tc-ie-head { padding: 6px 6px 6px 12px; gap: 4px; }
    .tc-ie-head .tc-ie-btn { padding: 0 8px; }
    .tc-ie-head .tc-ie-l { display: none; }
    .tc-ie-head .tc-ie-btn[aria-label="Reset this picture"] .tc-ie-l { display: inline; }
    .tc-ie-file { display: none; }
    .tc-ie-opts { flex-wrap: wrap; gap: 6px 8px; padding: 6px 10px; min-height: 46px; overflow: visible; }
    .tc-ie-opts > .tc-ie-sp { display: none; }
    .tc-ie-copts .tc-ie-btn { padding: 0 9px; }
    .tc-ie-tip { display: none; }
    .tc-ie-body { flex-direction: column; }
    .tc-ie-stage { order: 1; }
    .tc-ie-tools {
        order: 2;
        width: auto;
        flex-direction: row;
        justify-content: flex-start;
        padding: 6px 8px;
        border-right: 0;
        border-top: 1px solid var(--ie-line);
        gap: 2px;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
    }
    .tc-ie-tools .tc-ie-sep { width: 1px; height: 26px; margin: 0 2px; }
    .tc-ie-t { width: 38px; height: 42px; }
    .tc-ie-thumbs > .tc-ie-lbl { display: none; }
    .tc-ie-foot { flex-wrap: wrap; gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)); }
    .tc-ie-cap { flex-basis: 100%; }
    .tc-ie-foot .tc-ie-btn { flex: 1; justify-content: center; }
}

/* ---- "✎ Edit" on a picture waiting to be sent (chat, mail, tickets) ---- */
.tc-ie-edit {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    padding: 0 8px;
    border: 1px solid var(--ie-tint-line);
    border-radius: 7px;
    background: var(--ie-tint);
    color: var(--ie-acc);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
}
.tc-ie-edit:hover { background: color-mix(in srgb, var(--ie-acc) 24%, transparent); }
.tc-ie-edit:focus-visible { outline: 2px solid var(--ie-acc); outline-offset: 2px; }
/* On a thumbnail tile: over its bottom edge, on a solid backing so it reads on any picture. */
.tc-ie-edit.on-tile {
    position: absolute;
    left: 4px;
    bottom: 4px;
    height: 22px;
    padding: 0 6px;
    background: color-mix(in srgb, var(--ie-acc) 22%, var(--ie-bg));
}

@media (prefers-reduced-motion: reduce) {
    .tc-ie *,
    .tc-ie-edit { transition-duration: 0s !important; animation-duration: 0s !important; }
}
