/* ============================================================================
 * Ticket detail (breadcrumb, sidebar, activity, attachments)
 * ============================================================================ */
.breadcrumb {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 8px; font-size: .85rem; color: var(--text-muted);
}
.breadcrumb a {
    color: var(--primary); text-decoration: none;
    display: flex; align-items: center; gap: 4px;
}
.breadcrumb .sep { color: var(--text-muted); }
.breadcrumb i { font-size: 13px; }

.detail-grid { display: grid; grid-template-columns: 1fr 320px; gap: 16px; }
@media (max-width: 992px) { .detail-grid { grid-template-columns: 1fr; } }

.card-title { font-size: 1rem; font-weight: 600; margin: 0 0 12px; }
.sidebar-heading {
    font-size: .72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-muted); margin: 0 0 12px;
}

.detail-meta {
    display: grid; grid-template-columns: max-content 1fr;
    gap: 8px 16px; font-size: .88rem; margin: 0;
}
.detail-meta dt { color: var(--text-muted); font-weight: 500; }
.detail-meta dd { margin: 0; word-break: break-word; }

.activity-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.activity-header .card-title { display: flex; align-items: center; gap: 8px; margin: 0; }
.activity-header .card-title i { color: var(--primary); }
.msg-count {
    background: var(--surface-alt); color: var(--text-muted);
    border: 1px solid var(--border); border-radius: 999px;
    font-size: .72rem; font-weight: 600;
    padding: 1px 8px; margin-left: 4px;
}

.thread {
    display: flex; flex-direction: column; gap: 0;
    position: relative; padding-left: 4px; padding-right: 4px;
    max-height: 55vh; overflow-y: auto;
    scrollbar-gutter: stable;
    /* Query container so the chat left/right split (see the @container block
       below) reacts to the THREAD's own width, not the screen size. inline-size
       only — block size stays free so max-height + overflow-y keep scrolling. */
    container: ticket-thread / inline-size;
}
.thread::-webkit-scrollbar { width: 8px; }
.thread::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.thread::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.thread-msg {
    display: grid; grid-template-columns: 40px 1fr; gap: 12px;
    padding-bottom: 16px; position: relative;
}
.thread-msg:last-child { padding-bottom: 0; }

.msg-side { display: flex; flex-direction: column; align-items: center; }
.msg-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: .78rem;
    flex-shrink: 0; box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.msg-connector {
    flex: 1; width: 2px;
    background: linear-gradient(180deg, var(--border) 0%, transparent 100%);
    margin-top: 6px; min-height: 12px;
}
.thread-msg:last-child .msg-connector { display: none; }

.msg-bubble {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 10px 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
    position: relative;
}
.msg-bubble::before {
    content: ""; position: absolute;
    left: -6px; top: 12px;
    width: 10px; height: 10px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    transform: rotate(45deg);
}
/* Colour is org-based and identical on every width: VC4 / internal messages are
   tinted, customer messages keep the plain surface. The wide chat split below
   only adds left/right positioning — it does not change these colours. */
.thread-msg.from-internal .msg-bubble {
    background: var(--primary-subtle);
    border-color: var(--primary-tint);
}
.thread-msg.from-internal .msg-bubble::before {
    background: var(--primary-subtle);
    border-color: var(--primary-tint);
}

.msg-bubble-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.msg-author { font-weight: 600; color: var(--text); font-size: .88rem; }
.msg-role {
    font-size: .65rem; font-weight: 700;
    letter-spacing: .04em; text-transform: uppercase;
    padding: 2px 7px; border-radius: 999px;
}
.role-customer { background: #e1eef5; color: #114b6e; }
.role-internal { background: #d4f4dd; color: #15643a; }
.role-attachment { background: #fff3cc; color: #8a5e00; display: inline-flex; align-items: center; gap: 4px; }
.role-attachment i { font-size: 10px; }
[data-bs-theme="dark"] .role-customer { background: rgba(95,153,187,.22); color: #b8d4ec; }
[data-bs-theme="dark"] .role-internal { background: rgba(18,151,81,.22); color: #8ce0b3; }
[data-bs-theme="dark"] .role-attachment { background: rgba(238,173,0,.20); color: #f7d27a; }

/* Attachment-log entries use the muted surface (overrides the org tint above),
   whichever side they sit on. */
.thread-msg.is-attachment .msg-bubble { background: var(--surface-alt); }
.thread-msg.is-attachment .msg-bubble::before { background: var(--surface-alt); border-color: var(--border); }

/* ----------------------------------------------------------------------------
 * Chat-style left/right split — driven by the THREAD's own width (container
 * query), NOT the screen size. Narrow: the default grid above keeps every
 * message left-aligned (exactly as it was). Wide enough: a two-sided chat split
 * by ORGANISATION — customer messages (.from-customer) on the LEFT, VC4 /
 * internal (.from-internal) on the RIGHT. All customer users share the left
 * side, all VC4 users share the right, however many distinct people there are.
 * Colours come from the org rules above (VC4 tinted, customer plain); this block
 * only positions the two sides and flips the VC4 bubble's tail to the right.
 *
 * Container query → reacts to the ticket component's own width, so narrowing the
 * window collapses it back to all-left regardless of screen size. 560px tunable.
 * -------------------------------------------------------------------------- */
@container ticket-thread (min-width: 560px) {
    .thread-msg {
        display: flex;          /* override the all-left 40px / 1fr grid */
        align-items: stretch;   /* let .msg-side stretch so its connector fills */
    }
    .thread-msg.from-customer { flex-direction: row; }          /* customers → left  */
    .thread-msg.from-internal { flex-direction: row-reverse; }  /* VC4       → right */

    .msg-side { flex: 0 0 auto; }
    /* Content-sized bubbles so the left/right split is visible — a full-width
       bubble would touch both edges and hide the side. */
    .msg-bubble { max-width: 78%; }

    /* VC4 bubbles sit on the right, so flip their tail to point right. Customer
       bubbles keep the default left tail; both colours come from the base rules,
       so a bubble looks identical in the narrow all-left layout and here. */
    .thread-msg.from-internal .msg-bubble::before {
        left: auto; right: -6px; transform: rotate(-135deg);
    }
}

.msg-attach-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    margin-top: 4px;
}
.msg-attach-tile {
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    background: var(--surface);
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.msg-attach-tile:hover, .msg-attach-tile:focus-visible {
    border-color: var(--primary);
    box-shadow: 0 4px 12px -4px rgba(var(--s2c-primary-rgb),.30);
    outline: none;
    transform: translateY(-1px);
}
.msg-attach-tile.is-removed { cursor: default; opacity: .55; }
.msg-attach-tile.is-removed:hover { border-color: var(--border); box-shadow: none; transform: none; }
.msg-attach-tile.is-removed .msg-attach-name { text-decoration: line-through; }
.msg-attach-preview {
    aspect-ratio: 4 / 3;
    background: var(--surface-alt);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.msg-attach-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg-attach-preview .attach-icon { font-size: 1.8rem; }
.msg-attach-name {
    padding: 5px 8px; font-size: .78rem;
    color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-date { color: var(--text-muted); font-size: .75rem; margin-left: auto; }
.msg-body { white-space: pre-wrap; word-break: break-word; font-size: .9rem; line-height: 1.5; color: var(--text); }
.msg-body span { white-space: pre-wrap; }

.msg-inline-attach {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 8px; border-radius: 6px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--text); cursor: pointer;
    font-size: .82rem; line-height: 1.2;
    vertical-align: middle;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
    white-space: normal;
}
.msg-inline-attach:hover, .msg-inline-attach:focus-visible {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 2px 8px -3px rgba(var(--s2c-primary-rgb),.30);
    outline: none;
}
.msg-inline-attach i { color: var(--primary); font-size: 14px; }
.msg-inline-name { font-weight: 500; }
.msg-inline-attach.is-image {
    padding: 0; border-radius: 8px; background: transparent;
    max-width: 240px; overflow: hidden;
}
.msg-inline-attach.is-image:hover {
    background: transparent;
    box-shadow: 0 4px 12px -4px rgba(var(--s2c-primary-rgb),.40);
}
.msg-inline-attach.is-image img {
    display: block; max-width: 240px; max-height: 160px;
    width: auto; height: auto; object-fit: contain;
    border-radius: 8px;
}

/* ============================================================================
 * Message composer (new ticket + reply)
 * ============================================================================ */
/* WhatsApp-style pill: a single-line input that grows with content (JS
   auto-size, see imsApp.autoGrowTextarea) up to max-height, with a round
   send button hugging the right edge and staying bottom-aligned as it grows. */
.msg-composer {
    display: flex; align-items: flex-end; gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 4px 4px 4px 8px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.msg-composer:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(var(--s2c-primary-rgb),.15);
}
.msg-composer-input {
    flex: 1; min-width: 0;
    border: none; outline: none;
    background: transparent;
    resize: none;
    padding: 8px 6px;
    font: inherit; font-size: .92rem; line-height: 1.4;
    color: var(--text);
    min-height: 24px;     /* one line */
    max-height: 140px;    /* ~6 lines, then the textarea scrolls */
    overflow-y: hidden;   /* JS flips to auto once the max is hit */
}
.msg-composer-input::placeholder { color: var(--text-muted); }
.msg-composer-pending {
    margin: 0 12px 8px;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}
.msg-composer-toolbar {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px;
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
}
.msg-composer-icon-btn {
    width: 36px; height: 36px; border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-muted);
    border: 1px solid transparent;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.msg-composer-icon-btn:hover {
    background: var(--surface);
    color: var(--primary);
    border-color: var(--border);
}
.msg-composer-icon-btn input[type=file] { display: none; }
.msg-composer-cancel {
    margin-left: auto;
    background: transparent; border: none; cursor: pointer;
    padding: 6px 14px; border-radius: 6px;
    color: var(--text-muted);
    font: inherit; font-size: .88rem;
}
.msg-composer-cancel:hover { color: var(--text); background: var(--surface); }
.msg-composer-spacer { flex: 1; }
/* Round send button (WhatsApp-style), bottom-aligned next to the input. */
.msg-composer-send {
    flex: 0 0 auto;
    width: 40px; height: 40px; border-radius: 50%;
    border: none; cursor: pointer;
    background: var(--primary); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .95rem;
    transition: background .15s ease, opacity .15s ease, transform .1s ease;
}
.msg-composer-send:hover:not(:disabled) { background: color-mix(in srgb, var(--primary) 88%, black); }
.msg-composer-send:active:not(:disabled) { transform: scale(.94); }
.msg-composer-send:disabled { opacity: .45; cursor: default; }
/* Optical centering: the paper-plane glyph reads as right-leaning (its nose
   reaches the right edge), so nudge it left a touch. Spinner stays untouched
   (it's symmetric). */
.msg-composer-send .fa-paper-plane { transform: translateX(-1px); }

/* ============================================================================
 * Attachment chips + tiles
 * ============================================================================ */
/* Negative-margin row + per-chip margin combo: behaves like gap but is
   immune to any stray flex-children "margin: 0" rules that may shadow the
   gap property at this depth. */
.msg-attach-row {
    display: flex;
    flex-wrap: wrap;
    margin: 8px -6px 0;
}
.attach-chip {
    display: inline-flex; align-items: center;
    background: var(--surface-alt); color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 250px;
    height: 40px;
    margin: 6px;             /* gives the 12 px gutter via 2 × 6 px */
    font-size: .82rem;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.attach-chip:hover, .attach-chip:focus-within {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 2px 8px -3px rgba(var(--s2c-primary-rgb),.25);
}
.attach-chip.is-removed { opacity: .55; }
.attach-chip.is-removed .attach-chip-name { text-decoration: line-through; }

.attach-chip-main {
    display: inline-flex; align-items: center; gap: 10px;
    padding: 0 14px;
    height: 100%;
    border: none; background: transparent; color: inherit;
    cursor: pointer; font: inherit; font-size: inherit;
    flex: 1; min-width: 0;
    text-align: left;
}
.attach-chip-main:disabled { cursor: default; }
.attach-chip-main:focus-visible { outline: none; }
.attach-chip-main i { color: var(--primary); font-size: 14px; flex-shrink: 0; }
.attach-chip-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.attach-chip-delete {
    width: 22px; height: 22px;
    border: none; background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 11px;
    margin: 0 4px 0 -2px;
    opacity: 0;
    transition: opacity .15s ease, background .15s ease, color .15s ease;
}
.attach-chip:hover .attach-chip-delete,
.attach-chip:focus-within .attach-chip-delete { opacity: 1; }
.attach-chip-delete:hover {
    background: rgba(220, 53, 69, .12);
    color: var(--danger);
}

.attach-add-btn {
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; border-radius: 6px;
    background: var(--surface-alt); color: var(--text);
    border: 1px solid var(--border);
    font-size: .82rem; font-weight: 500;
}
.attach-add-btn:hover { background: var(--surface); border-color: var(--primary); color: var(--primary); }
.attach-add-btn input[type=file] { display: none; }
.attach-add-btn.inline { margin-top: 4px; }

.attach-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}
.attach-tile {
    display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    overflow: hidden; cursor: pointer;
    transition: box-shadow .15s ease, border-color .15s ease;
    position: relative;
}
.attach-tile:hover, .attach-tile:focus-visible {
    border-color: var(--primary);
    box-shadow: 0 4px 12px -4px rgba(var(--s2c-primary-rgb),.25);
    outline: none;
}
.attach-preview {
    aspect-ratio: 16 / 9;
    background: var(--surface-alt);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.attach-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-icon { font-size: 2.2rem; color: var(--text-muted); opacity: .8; }
.attach-meta { padding: 8px 10px; }
.attach-name {
    font-size: .85rem; font-weight: 500; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.attach-sub { font-size: .72rem; color: var(--text-muted); margin-top: 2px; }
.attach-del {
    position: absolute; top: 6px; right: 6px;
    width: 24px; height: 24px; border-radius: 50%;
    border: none; cursor: pointer;
    background: rgba(0,0,0,.55); color: #fff;
    font-size: 11px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity .15s ease;
}
.attach-tile:hover .attach-del, .attach-tile:focus-within .attach-del { opacity: 1; }
.attach-del:hover { background: var(--danger); }

.attach-empty {
    border: 1px dashed var(--border); border-radius: 8px;
    padding: 16px; text-align: center;
    color: var(--text-muted); font-size: .85rem;
    margin-bottom: 16px;
}

.attach-pending {
    list-style: none; padding: 0; margin: 8px 0 0;
    display: flex; flex-direction: column; gap: 4px;
    /* Cap the selected-files list and let it scroll on its own, so picking many
       attachments (e.g. 20) can't push the form's Create/Cancel actions off
       screen. ~6 rows visible; the rest scroll within this block. */
    max-height: 220px;
    overflow-y: auto;
    /* Room for the scrollbar so it doesn't overlap the × remove buttons. */
    padding-right: 4px;
}
.attach-pending li {
    display: flex; align-items: center; gap: 8px;
    background: var(--surface-alt); border: 1px solid var(--border);
    border-radius: 6px; padding: 6px 10px; font-size: .85rem;
}
.attach-pending li i { color: var(--text-muted); }
.attach-pending li .attach-name { flex: 1; }
.attach-pending li .attach-del { position: static; opacity: 1; background: transparent; color: var(--text-muted); }
.attach-pending li .attach-del:hover { color: var(--danger); background: transparent; }

.thread-empty {
    text-align: center; padding: 32px 16px;
    color: var(--text-muted);
    border: 1px dashed var(--border); border-radius: 10px;
    background: var(--surface-alt);
}
.thread-empty i { font-size: 2rem; opacity: .4; margin-bottom: 8px; display: block; }
.thread-empty p { margin: 0; }

/* ============================================================================
 * Composer (in-thread reply) — separate from the new-ticket .msg-composer
 * ============================================================================ */
.composer {
    margin-top: 16px;
    display: grid; grid-template-columns: 40px 1fr; gap: 12px;
    align-items: center;
    padding-top: 16px; border-top: 1px solid var(--border);
}
.composer-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: .78rem;
}
.composer-body { display: flex; flex-direction: column; gap: 10px; }
.composer-input textarea.e-input { min-height: 70px; max-height: 200px; resize: vertical; }
.composer-actions { display: flex; align-items: center; gap: 12px; justify-content: flex-end; }

.e-stepper .e-step-container .e-step-label-container { font-size: .82rem; }


/* ============================================================================
 * Lightbox (image preview)
 * ============================================================================ */
.lightbox {
    position: fixed; inset: 0; z-index: 1500;
    background: rgba(2,38,63,.82);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 24px;
    cursor: zoom-out;
    outline: none;
}
.lightbox-stage {
    flex: 1; width: 100%;
    display: flex; align-items: center; justify-content: center;
    overflow: auto;
    cursor: default;
}
.lightbox-stage img {
    max-width: min(92vw, 1400px);
    max-height: 78vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 50px -10px rgba(0,0,0,.5);
    background: #fff;
    transition: transform .15s ease;
    transform-origin: center center;
}
.lightbox-toolbar {
    display: inline-flex; align-items: center; gap: 8px;
    background: rgba(0,0,0,.45);
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 999px;
    padding: 6px 14px;
    margin-top: 14px;
    color: #fff;
    cursor: default;
}
.lightbox-btn {
    background: transparent; color: #fff;
    border: none; cursor: pointer;
    width: 36px; height: 36px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 14px;
    transition: background .15s ease;
}
.lightbox-btn:hover:not(:disabled) { background: rgba(255,255,255,.14); }
.lightbox-btn:disabled { opacity: .35; cursor: default; }
.lightbox-btn.primary { background: var(--primary); }
.lightbox-btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.lightbox-zoom {
    font-size: .8rem; font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    color: rgba(255,255,255,.9); min-width: 44px; text-align: center;
}
.lightbox-caption {
    color: rgba(255,255,255,.78);
    font-size: .82rem;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    margin: 0 10px;
    max-width: 320px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lightbox-close {
    position: absolute; top: 16px; right: 16px;
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,.12); color: #fff;
    border: 1px solid rgba(255,255,255,.25);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 18px;
    transition: background .15s ease;
}
.lightbox-close:hover { background: rgba(255,255,255,.22); }

