/*
Summary
- Layout/visual styles for the customer SMS inbox (issue #782, Wave 4).
- Mirrors docs/feat-issue-3068/mockups/messaging-inbox-refresh.html: thread list, conversation, Context pane.
- Portal.NS must reference this file: <link href="_content/TIP.App.Sms.UI/sms-inbox.css" rel="stylesheet" />
*/

/* Call Center cards: each pane is its own rounded card with the page showing in the gaps (the .cc-card look). */
.sms-inbox-grid {
    position: relative;
    display: grid;
    grid-template-columns: 384px minmax(0, 1fr);
    grid-template-rows: 100%;
    gap: 12px;
}

.sms-inbox-grid > .sms-pane {
    background-color: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 10px;
    overflow: hidden;
}

/* The thread side pane (True Context) as a third column. The host div is a size container, so the cascade follows the
   inbox's own width, with the left nav and the phone dock already counted. The conversation never drops under 420px.
   The pane is always the grid's last child. */
.sms-inbox-host {
    container-type: inline-size;
    container-name: smsinbox;
}

.sms-inbox-grid-ctx-open {
    /* Context takes 25% + 135px, never under 340px. Its cap keeps 900px for the list and the conversation together,
       so the 96px the list gave up (480 to 384) goes to the conversation, not to the context. */
    grid-template-columns: 384px minmax(420px, 1fr) max(340px, min(calc(25% + 135px), calc(100% - 900px - 24px)));
}

.sms-inbox-grid-ctx-rail {
    grid-template-columns: 384px minmax(420px, 1fr) 44px;
}

/* Each line is the sum of the columns it replaces plus the two 12px gaps: 384 + 420 + 340 + 24 = 1168, then 56 + 420 + 340 + 24 = 840. */
@container smsinbox (max-width: 1167px) {
    .sms-inbox-grid-ctx-open {
        grid-template-columns: 56px minmax(420px, 1fr) 340px;
    }
}

/* Under 840px with the pane open the thread list leaves the grid; the Threads button in the conversation header brings
   it back as an overlay. */
@media (min-width: 961px) {
    @container smsinbox (max-width: 839px) {
        .sms-inbox-grid-ctx-open {
            grid-template-columns: minmax(0, 1fr) 340px;
        }

        .sms-inbox-grid-ctx-open > :nth-child(1) {
            display: none;
        }
    }
}

/* The rail is 44px, so its lines are 384 + 420 + 44 + 24 = 872 and 56 + 420 + 44 + 24 = 544. */
@container smsinbox (max-width: 871px) {
    .sms-inbox-grid-ctx-rail {
        grid-template-columns: 56px minmax(420px, 1fr) 44px;
    }
}

@media (min-width: 961px) {
    @container smsinbox (max-width: 543px) {
        .sms-inbox-grid-ctx-rail {
            grid-template-columns: minmax(0, 1fr) 44px;
        }

        .sms-inbox-grid-ctx-rail > :nth-child(1) {
            display: none;
        }
    }
}

.sms-newmsg-panel {
    background-color: var(--mud-palette-surface);
}

.sms-newmsg-to {
    border-bottom: 1px solid var(--mud-palette-lines-default);
    flex-shrink: 0;
}

.sms-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--mud-palette-lines-default);
}

.sms-inbox-grid > .sms-pane:last-child {
    border-right: 1px solid var(--mud-palette-lines-default);
}

.sms-pane-header {
    border-bottom: 1px solid var(--mud-palette-lines-default);
    flex-shrink: 0;
}

.sms-pane-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
}

/* Number picker rows (NumberPicker): native buttons with the sharing menu beside each. The current row
   mirrors the selected list row rule in mud-blazor-overrides.css (tint, left bar, bold label). */
.sms-number-list {
    list-style: none;
    margin: 0;
    padding: 8px 0;
}

.sms-number-row {
    display: flex;
    align-items: center;
    padding-right: 8px;
    box-shadow: inset 3px 0 0 transparent;
}

.sms-number-row-all {
    border-bottom: 1px solid var(--mud-palette-divider);
    margin-bottom: 4px;
}

.sms-number-row:not(.sms-number-row-current):hover {
    background-color: var(--tip-neutral-tile);
}

.sms-number-row:has(> button.sms-number-pick:disabled):hover {
    background-color: transparent;
}

.sms-number-row.sms-number-row-current {
    background-color: var(--tip-nav-active);
    box-shadow: inset 3px 0 0 var(--tip-nav-indicator);
}

.sms-number-row-current .sms-number-label {
    font-weight: 700;
}

button.sms-number-pick {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px 6px 16px;
    margin: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: inherit;
    cursor: pointer;
}

button.sms-number-pick:disabled {
    cursor: default;
    color: var(--mud-palette-text-secondary);
}

button.sms-number-pick:focus-visible {
    outline: 2px solid var(--tip-focus-ring);
    outline-offset: -2px;
}

.sms-number-text {
    min-width: 0;
    overflow-wrap: anywhere;
}

.sms-number-label {
    display: block;
    font-size: var(--mud-typography-body1-size);
    line-height: var(--mud-typography-body1-lineheight);
}

.sms-number-unread {
    flex-shrink: 0;
}

.sms-number-menu {
    flex-shrink: 0;
}

.sms-pane-thread {
    flex: 1 1 auto;
}

.sms-pane-composer {
    border-top: 1px solid var(--mud-palette-lines-default);
    flex-shrink: 0;
}

.sms-message-row {
    display: flex;
    margin-bottom: 8px;
}

.sms-message-row.sms-message-inbound {
    justify-content: flex-start;
}

.sms-message-row.sms-message-outbound {
    justify-content: flex-end;
}

.sms-message-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 12px;
}

.sms-message-inbound .sms-message-bubble {
    background-color: var(--mud-palette-background-gray);
}

.sms-message-outbound .sms-message-bubble {
    background-color: color-mix(in srgb, var(--tip-link) 14%, var(--mud-palette-surface));
}

.sms-message-media {
    display: block;
    max-width: 260px;
    max-height: 260px;
    border-radius: 8px;
    object-fit: contain;
}

.sms-delivery-status {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    vertical-align: middle;
}

.sms-backfill-btn {
    border-style: dashed;
}

@media (max-width: 960px) {
    .sms-inbox-grid,
    .sms-inbox-grid-ctx-open,
    .sms-inbox-grid-ctx-rail {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    /* Issue #2267 (item 11): below the existing collapse point the pane opens as a full sheet, the New Message rule,
       and the rail is not shown; the Context button opens the sheet. */
    .sms-inbox-grid-ctx-open > :last-child {
        position: absolute;
        inset: 0;
        z-index: 10;
    }

    .sms-inbox-grid-ctx-rail > :last-child {
        display: none;
    }

    .sms-pane {
        border-right: none;
        border-bottom: 1px solid var(--mud-palette-lines-default);
    }

    /* Issue #1233, mockup Frame 4: below the existing collapse point the panel takes the full
       column as a sheet, matching how ThreadView itself already takes over the screen here. */
    .sms-newmsg-panel {
        border-left: none;
        position: absolute;
        inset: 0;
        z-index: 10;
    }
}

/* Issue #1853. MudFileUpload always renders an empty file-list div with a 4px top margin, which
   made the attach button's box 4px taller than the canned-replies control beside it and pushed
   the two off one center line. The composer shows the attached file as its own chip instead. */
.sms-composer-tools .mud-file-upload-files:empty {
    display: none;
}

/* Thread filter toggle group: MudToggleGroup sets equal columns inline, and "Unassigned" needs a little
   more than a quarter of the narrow thread list. Columns sized to their labels still fill the row. */
.sms-thread-filter.mud-toggle-group {
    grid-template-columns: repeat(4, auto) !important;
}

/* The thread strip and the Threads button. ThreadList renders both its list and its strip; the container rules below
   pick one, so no component knows the width. */
.sms-thread-strip,
.sms-thread-show {
    display: none;
}

.sms-thread-strip {
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    overflow-y: auto;
    min-height: 0;
}

.sms-thread-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: var(--mud-palette-action-default-hover);
    color: var(--mud-palette-text-primary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.sms-thread-dot-current {
    border-color: var(--mud-palette-primary);
}

/* Strips only above the 960px collapse point; under it the inbox stacks its panes as before. */
@media (min-width: 961px) {
    @container smsinbox (max-width: 1167px) {
        .sms-inbox-grid-ctx-open .sms-thread-strip {
            display: flex;
        }

        .sms-inbox-grid-ctx-open .sms-pane-threads > :not(.sms-thread-strip) {
            display: none;
        }
    }

    @container smsinbox (max-width: 871px) {
        .sms-inbox-grid-ctx-rail .sms-thread-strip {
            display: flex;
        }

        .sms-inbox-grid-ctx-rail .sms-pane-threads > :not(.sms-thread-strip) {
            display: none;
        }
    }
}

@media (min-width: 961px) {
    @container smsinbox (max-width: 839px) {
        .sms-inbox-grid-ctx-open .sms-thread-show {
            display: inline-flex;
        }
    }

    @container smsinbox (max-width: 543px) {
        .sms-inbox-grid-ctx-rail .sms-thread-show {
            display: inline-flex;
        }
    }
}

/* The full thread list as an overlay over the conversation column, from the Threads button or the strip's chevron. A
   pick or Esc closes it. Only in the layouts the pane makes, so a stale flag can never pull the list out of the plain
   grid. */
@media (min-width: 961px) {
    .sms-inbox-grid-ctx-open.sms-threads-overlay-open > :nth-child(1),
    .sms-inbox-grid-ctx-rail.sms-threads-overlay-open > :nth-child(1) {
        display: flex !important;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        width: 384px;
        max-width: 100%;
        z-index: 9;
        background: var(--mud-palette-surface);
        box-shadow: var(--mud-elevation-8);
    }

    .sms-inbox-grid-ctx-open.sms-threads-overlay-open .sms-thread-strip,
    .sms-inbox-grid-ctx-rail.sms-threads-overlay-open .sms-thread-strip {
        display: none !important;
    }

    .sms-inbox-grid-ctx-open.sms-threads-overlay-open .sms-pane-threads > :not(.sms-thread-strip),
    .sms-inbox-grid-ctx-rail.sms-threads-overlay-open .sms-pane-threads > :not(.sms-thread-strip) {
        display: revert !important;
    }
}

/* The DID a thread came in on, as a small outlined tag so it reads apart from the message preview. */
.sms-thread-via {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    margin-top: 4px;
    padding: 1px 8px 1px 6px;
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: 999px;
    font-size: var(--mud-typography-caption-size);
    color: var(--mud-palette-text-primary);
}

.sms-thread-via .mud-icon-root {
    font-size: 14px;
    color: var(--mud-palette-text-secondary);
}

.sms-thread-via-label {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Number picker: a full-width button over a dropdown of numbers, beside the New message button. */
.sms-num-picker-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 8px;
}

.sms-num-picker {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

button.sms-num-picker-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 6px 6px 10px;
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: var(--mud-default-borderradius);
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

button.sms-num-picker-btn:hover {
    border-color: var(--mud-palette-text-secondary);
}

button.sms-num-picker-btn:focus-visible {
    outline: 2px solid var(--tip-focus-ring);
    outline-offset: 1px;
}

.sms-num-picker-text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.sms-num-picker-label {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sms-num-picker-sub {
    font-size: var(--mud-typography-caption-size);
    font-variant-numeric: tabular-nums;
}

.sms-num-picker-section {
    padding: 8px 16px 4px;
    font-size: var(--mud-typography-overline-size);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary);
}

/* Wider than the button and tall enough for a long list; capped by the viewport. */
.sms-num-picker-popover.mud-popover {
    min-width: 320px;
    max-height: min(630px, calc(100vh - 14rem));
    overflow-y: auto;
}

.sms-num-picker-new-host {
    display: flex;
    flex-shrink: 0;
}

.sms-num-picker-check {
    display: inline-flex;
    flex: 0 0 20px;
    color: var(--mud-palette-text-secondary);
}

.sms-number-pick > .sms-number-text {
    flex: 1 1 auto;
}

/* Empty conversation: faint placeholder bubbles under one prompt. */
.sms-empty-conv {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.sms-empty-ghosts {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    height: 100%;
    padding: 28px 40px;
}

.sms-empty-ghost {
    height: 38px;
    border-radius: 16px;
    background-color: var(--mud-palette-background-gray);
    align-self: flex-start;
}

.sms-empty-ghost:nth-child(1) { width: 46%; }
.sms-empty-ghost:nth-child(2) { width: 30%; }
.sms-empty-ghost:nth-child(3) { width: 52%; align-self: flex-end; }
.sms-empty-ghost:nth-child(4) { width: 38%; }
.sms-empty-ghost:nth-child(5) { width: 28%; align-self: flex-end; }
.sms-empty-ghost:nth-child(6) { width: 44%; align-self: flex-end; }
.sms-empty-ghost:nth-child(7) { width: 34%; }

.sms-empty-prompt {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    pointer-events: none;
}

.sms-empty-card {
    pointer-events: auto;
    text-align: center;
}

/* Composer: the message field on top, then one bar with the tools, the counter, Send from and Send. */
.sms-composer-box {
    min-width: 0;
}

.sms-composer-box textarea {
    resize: vertical;
}

.sms-composer-nowrap {
    flex-shrink: 0;
    white-space: nowrap;
}

/* Hidden while New message holds the column, so an unsent reply and the scroll position survive the compose. */
.sms-pane-thread.sms-pane-hidden {
    display: none;
}

.sms-composer-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 8px;
    margin-top: 6px;
}

.sms-composer-counter {
    white-space: nowrap;
}

.sms-composer-send {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.sms-composer-from {
    width: 200px;
    max-width: 100%;
}

/* Conversation rows: one fixed height and three lines (name and time, preview, tags), so content never grows a row. */
.mud-list-item.sms-thread-row {
    padding: 0 14px;
}

.sms-thread-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 78px;
    min-width: 0;
    overflow: hidden;
}

.sms-thread-avatar {
    position: relative;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 14px;
    font-weight: 600;
    background-color: var(--mud-palette-action-default-hover);
    color: var(--mud-palette-text-secondary);
}

/* Unread is a status, so the dot takes the info color; a ring in the surface color keeps it apart from the avatar. */
.sms-thread-dot-unread {
    position: absolute;
    top: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--mud-palette-info);
    box-shadow: 0 0 0 2px var(--mud-palette-surface);
}

.sms-thread-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sms-thread-line1 {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.sms-thread-name {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--mud-palette-text-primary);
}

.sms-thread-when {
    flex-shrink: 0;
    font-size: var(--mud-typography-caption-size);
    color: var(--mud-palette-text-secondary);
}

.sms-thread-preview {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: var(--mud-typography-caption-size);
    color: var(--mud-palette-text-secondary);
}

.sms-thread-unread .sms-thread-name {
    font-weight: 650;
}

.sms-thread-unread .sms-thread-when,
.sms-thread-unread .sms-thread-preview {
    color: var(--mud-palette-text-primary);
}

.sms-thread-tags {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 20px;
    min-width: 0;
    overflow: hidden;
}

/* The DID tag's tooltip wrapper (TipTooltip's root; its Class lands on the popover, not here). As a block it made a
   24px line box and set the tag on its baseline, 1px above the clipped tag line, so it is a 20px flex box instead. */
.sms-thread-tags > .mud-tooltip-root {
    display: flex;
    align-items: center;
    flex: 0 1 auto;
    height: 20px;
    min-width: 0;
}

/* The tag line is 20px tall and clips, so the DID tag is sized to fit it exactly (border included); at 22px its top
   edge was cut off. */
.sms-thread-tags .sms-thread-via {
    box-sizing: border-box;
    height: 20px;
    margin-top: 0;
    padding-block: 0;
}

.sms-thread-status {
    flex-shrink: 0;
    padding: 0 7px;
    border-radius: 999px;
    font-size: var(--mud-typography-caption-size);
    font-weight: 600;
    white-space: nowrap;
}

.sms-thread-status-blocked {
    background-color: var(--mud-palette-error);
    color: var(--mud-palette-error-text);
}

.sms-thread-status-optedout {
    border: 1px solid var(--mud-palette-error);
    color: var(--tip-status-fail-fg);
}

.sms-thread-assignee {
    flex-shrink: 0;
    font-size: var(--mud-typography-caption-size);
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
}

/* Issue #3510 (group text Wave 3, mockup G1 to G4). Neutral marks only: the badge carries a count, a data point, so it never
   takes the accent (branding standard, accent default deny). */
.sms-group-badge {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    gap: 3px;
    box-sizing: border-box;
    height: 20px;
    padding: 0 7px;
    border-radius: 999px;
    border: 1px solid var(--mud-palette-lines-default);
    background-color: var(--mud-palette-action-default-hover);
    color: var(--mud-palette-text-secondary);
    font-size: var(--mud-typography-caption-size);
    font-weight: 600;
    white-space: nowrap;
}

.sms-group-badge .mud-icon-root {
    font-size: 14px;
}

.sms-thread-avatar.sms-thread-avatar-group {
    border-radius: 10px;
}

.sms-thread-dot.sms-thread-dot-group {
    position: relative;
    border-radius: 9px;
    display: grid;
    place-items: center;
}

.sms-thread-dot-group .mud-icon-root {
    font-size: 16px;
}

.sms-thread-dot-count {
    position: absolute;
    right: -6px;
    bottom: -5px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: 8px;
    border: 1px solid var(--mud-palette-lines-default);
    background-color: var(--mud-palette-surface);
    color: var(--mud-palette-text-secondary);
    font-size: 10px;
    line-height: 14px;
}

.sms-group-head {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.sms-group-head-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.sms-group-title,
.sms-group-members {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sms-message-row.sms-message-has-sender {
    flex-direction: column;
    align-items: flex-start;
}

.sms-message-sender {
    margin: 0 0 2px 4px;
    font-size: var(--mud-typography-caption-size);
    font-weight: 600;
    color: var(--mud-palette-text-secondary);
}

/* Issue #3510: the header's title side may shrink, so a long group title or member line ends in an ellipsis instead of
   pushing the actions off the row. */
.sms-thread-head-main {
    flex: 1 1 auto;
    min-width: 0;
}
