/* ============================================================
   Chat — Teams-style layout
   ------------------------------------------------------------
   Prefixed .tm- so it collides with neither Filament nor .of-.
   Loaded after office-modern.css.

   The shape borrowed from Teams: a left rail of conversations,
   left-aligned messages with a name/time header, consecutive
   messages from one person grouped under a single avatar, day
   dividers, and a composer with an attach control.
   ============================================================ */

:root {
    --tm-accent:      #5b5fc7;   /* Teams violet */
    --tm-accent-soft: #e8ebfa;
    --tm-rail-bg:     #f5f5f7;
    --tm-mine:        #e8ebfa;
    --tm-theirs:      #ffffff;
    --tm-radius:      10px;
}

.dark {
    --tm-accent-soft: #23264a;
    --tm-rail-bg:     #12161e;
    --tm-mine:        #262a52;
    --tm-theirs:      #1a2029;
}

/* ---------- frame ---------- */
.tm {
    display: flex;
    height: calc(100dvh - 210px);
    min-height: 480px;
    border: 1px solid var(--of-border);
    border-radius: var(--of-radius);
    overflow: hidden;
    background: var(--of-surface);
    box-shadow: var(--of-shadow);
}

/* ---------- left rail ---------- */
.tm-rail {
    width: 300px;
    flex-shrink: 0;
    background: var(--tm-rail-bg);
    border-right: 1px solid var(--of-border);
    display: flex;
    flex-direction: column;
}

.tm-rail-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 16px 10px;
}
.tm-rail-title { margin: 0; font-size: 17px; font-weight: 700; color: var(--of-text); letter-spacing: -.02em; }
.tm-rail-count { font-size: 12px; font-weight: 600; color: var(--of-faint); }

.tm-search { padding: 0 12px 10px; }
.tm-search input {
    width: 100%; font-size: 13px; padding: 9px 12px;
    border: 1px solid transparent; border-radius: var(--of-radius-pill, 999px);
    background: var(--of-surface); color: var(--of-text);
    transition: box-shadow .15s, border-color .15s;
}
.tm-search input:focus {
    outline: none; border-color: var(--tm-accent);
    box-shadow: 0 0 0 3px rgba(91,95,199,.16);
}

.tm-rail-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; scrollbar-width: thin; }
.tm-rail-label {
    font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
    color: var(--of-faint); padding: 10px 8px 6px; margin: 0;
}

.tm-item {
    width: 100%; display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; margin-bottom: 2px;
    border: 0; border-radius: var(--tm-radius);
    background: transparent; cursor: pointer; text-align: left;
    transition: background .13s;
    position: relative;
}
.tm-item:hover { background: rgba(0,0,0,.045); }
.dark .tm-item:hover { background: rgba(255,255,255,.05); }

/* Active thread gets the accent rail, matching the sidebar pattern. */
.tm-item.is-active { background: var(--of-surface); box-shadow: var(--of-shadow); }
.tm-item.is-active::before {
    content: ''; position: absolute; left: 0; top: 50%;
    width: 3px; height: 22px; transform: translateY(-50%);
    background: var(--tm-accent); border-radius: 0 3px 3px 0;
}

.tm-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.tm-item-name {
    font-size: 13.5px; font-weight: 600; color: var(--of-text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tm-item-sub {
    font-size: 11.5px; color: var(--of-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tm-item.is-unread .tm-item-name { font-weight: 750; }

.tm-pill {
    min-width: 20px; height: 20px; padding: 0 6px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--tm-accent); color: #fff;
    font-size: 11px; font-weight: 700; border-radius: 999px;
    font-variant-numeric: tabular-nums;
}

/* ---------- avatars ---------- */
.tm-avatar {
    width: 34px; height: 34px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 999px; font-size: 13px; font-weight: 700;
    background: var(--tm-accent); color: #fff;
    background-size: cover; background-position: center;
}
.tm-avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.tm-avatar.is-group { border-radius: 8px; background: var(--of-muted); }

/* Deterministic colour per person so faces stay recognisable. */
.tm-avatar.c0 { background: #5b5fc7; }
.tm-avatar.c1 { background: #0e9f6e; }
.tm-avatar.c2 { background: #b54708; }
.tm-avatar.c3 { background: #b42318; }
.tm-avatar.c4 { background: #2563eb; }
.tm-avatar.c5 { background: #7e22ce; }
.tm-avatar.c6 { background: #0f766e; }
.tm-avatar.c7 { background: #a16207; }

/* ---------- thread ---------- */
.tm-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.tm-head {
    display: flex; align-items: center; gap: 11px;
    padding: 13px 18px;
    border-bottom: 1px solid var(--of-border);
    background: var(--of-surface);
}
.tm-head-text { display: flex; flex-direction: column; min-width: 0; }
.tm-head-name {
    font-size: 15px; font-weight: 700; color: var(--of-text); letter-spacing: -.01em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tm-head-sub { font-size: 11.5px; color: var(--of-muted); }

.tm-back {
    display: none; border: 0; background: transparent;
    font-size: 20px; line-height: 1; color: var(--of-text);
    cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.tm-back:hover { background: var(--of-bg); }

.tm-scroll {
    flex: 1; overflow-y: auto; padding: 18px 18px 8px;
    display: flex; flex-direction: column; gap: 2px;
    scrollbar-width: thin;
}

/* ---------- day divider ---------- */
.tm-day { display: flex; align-items: center; gap: 12px; margin: 16px 0 12px; }
.tm-day::before, .tm-day::after { content: ''; flex: 1; height: 1px; background: var(--of-border); }
.tm-day span {
    font-size: 11px; font-weight: 650; color: var(--of-faint);
    text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
}

/* ---------- messages ---------- */
.tm-msg { display: flex; gap: 10px; padding: 3px 0; }
.tm-msg.is-grouped { padding-top: 0; }
.tm-msg-gutter { width: 28px; flex-shrink: 0; }
.tm-msg-body { min-width: 0; max-width: 74%; }

.tm-msg-meta { display: flex; align-items: baseline; gap: 8px; margin: 0 0 3px; }
.tm-msg-author { font-size: 13px; font-weight: 700; color: var(--of-text); }
.tm-msg-time   { font-size: 11px; color: var(--of-faint); font-variant-numeric: tabular-nums; }

.tm-bubble {
    background: var(--tm-theirs);
    border: 1px solid var(--of-border);
    border-radius: var(--tm-radius);
    padding: 9px 13px;
    display: inline-block;
    max-width: 100%;
}
/* Own messages keep the same left alignment Teams uses — only the
   tint changes. Right-aligned bubbles make grouped threads hard to
   scan once more than two people are talking. */
.tm-msg.is-mine .tm-bubble { background: var(--tm-mine); border-color: transparent; }

.tm-text {
    margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--of-text);
    white-space: pre-wrap; word-break: break-word;
}

/* ---------- attachments ---------- */
.tm-image { display: block; margin-top: 6px; border-radius: 8px; overflow: hidden; max-width: 320px; }
.tm-image img { display: block; width: 100%; height: auto; max-height: 300px; object-fit: cover; }

.tm-file {
    display: flex; align-items: center; gap: 10px;
    margin-top: 6px; padding: 9px 11px;
    background: var(--of-bg); border: 1px solid var(--of-border);
    border-radius: 8px; text-decoration: none; transition: border-color .14s;
    max-width: 300px;
}
.tm-file:hover { border-color: var(--tm-accent); }
.tm-file-icon { font-size: 20px; flex-shrink: 0; }
.tm-file-text { min-width: 0; display: flex; flex-direction: column; }
.tm-file-name {
    font-size: 12.5px; font-weight: 600; color: var(--of-text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tm-file-size { font-size: 11px; color: var(--of-muted); }

/* ---------- composer ---------- */
.tm-composer {
    border-top: 1px solid var(--of-border);
    padding: 12px 16px 10px;
    background: var(--of-surface);
    transition: background .15s;
}
.tm-composer.is-dragging { background: var(--tm-accent-soft); }

.tm-composer-row {
    display: flex; align-items: flex-end; gap: 8px;
    border: 1px solid var(--of-border-2);
    border-radius: var(--of-radius-sm, 12px);
    padding: 6px 6px 6px 10px;
    transition: border-color .15s, box-shadow .15s;
}
.tm-composer-row:focus-within {
    border-color: var(--tm-accent);
    box-shadow: 0 0 0 3px rgba(91,95,199,.14);
}

.tm-attach {
    cursor: pointer; font-size: 17px; line-height: 1;
    padding: 8px; border-radius: 8px; flex-shrink: 0;
    transition: background .13s;
}
.tm-attach:hover { background: var(--of-bg); }
.tm-attach-input { display: none; }

.tm-input {
    flex: 1; border: 0; background: transparent; resize: none;
    font: inherit; font-size: 13.5px; line-height: 1.5;
    color: var(--of-text); padding: 8px 0; max-height: 140px;
    font-family: inherit;
}
.tm-input:focus { outline: none; }

.tm-send {
    flex-shrink: 0; width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 0; border-radius: 9px;
    background: var(--tm-accent); color: #fff;
    font-size: 15px; cursor: pointer; transition: background .14s, transform .1s;
}
.tm-send:hover:not(:disabled) { background: #4a4eb5; }
.tm-send:active:not(:disabled) { transform: translateY(1px); }
.tm-send:disabled { opacity: .55; cursor: not-allowed; }

.tm-pending {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 10px; margin-bottom: 8px;
    background: var(--tm-accent-soft); border-radius: 8px;
    font-size: 12px; color: var(--of-text); max-width: 100%;
}
.tm-pending-x {
    border: 0; background: transparent; cursor: pointer;
    font-size: 17px; line-height: 1; color: var(--of-muted); padding: 0 2px;
}
.tm-pending-x:hover { color: var(--of-danger); }

.tm-uploading { font-size: 11.5px; color: var(--of-muted); margin-bottom: 6px; }
.tm-error     { font-size: 11.5px; color: var(--of-danger); margin: 0 0 6px; font-weight: 600; }
.tm-hint      { font-size: 10.5px; color: var(--of-faint); margin: 7px 2px 0; }

/* ---------- empty states ---------- */
.tm-empty { text-align: center; padding: 30px 16px; font-size: 13px; color: var(--of-faint); line-height: 1.6; }
.tm-empty-lg { margin: auto; }

.tm-blank {
    margin: auto; text-align: center; padding: 40px 20px;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.tm-blank-icon  { font-size: 40px; opacity: .5; }
.tm-blank-title { font-size: 15px; font-weight: 650; color: var(--of-text); margin: 6px 0 0; }
.tm-blank-sub   { font-size: 13px; color: var(--of-muted); margin: 0; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
    .tm-rail { width: 260px; }
    .tm-msg-body { max-width: 84%; }
}

@media (max-width: 720px) {
    .tm { height: calc(100dvh - 170px); border-radius: var(--of-radius); }

    /* One pane at a time: the rail, or the open thread. */
    .tm-rail { width: 100%; border-right: 0; }
    .tm-rail.is-hidden-sm { display: none; }
    .tm-back { display: inline-flex; }
    .tm-msg-body { max-width: 88%; }
    .tm-scroll { padding: 14px 12px 6px; }
    .tm-composer { padding: 10px 12px; }
    .tm-image { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .tm-item, .tm-send, .tm-composer, .tm-composer-row { transition: none !important; }
}
