/* Messages page: a phone-sized texting screen for the Cloud Softphone web tab, two panes
   side by side when the tab is wide (the desktop softphone). Builds on app.css tokens. */

.page.page-flush { max-width: none; padding: 0; }

.msgs {
    --nav-h: calc(57px + env(safe-area-inset-bottom));
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: var(--nav-h);
    display: flex;
    background: var(--card);
    color: var(--text);
    overflow: hidden;
}

.msgs-list,
.msgs-detail {
    min-width: 0;
    min-height: 0;
    flex-direction: column;
}

.msgs-list { display: flex; flex: 1 1 auto; }
.msgs-detail { display: none; position: relative; background: var(--bg); }

/* On a phone an open conversation takes the whole screen, navigation included, and is
   sized to what is visible so the message box sits on top of the on-screen keyboard. */
.msgs.has-detail {
    z-index: 30;
    top: var(--sp-vtop, 0px);
    bottom: auto;
    height: var(--sp-vh, 100dvh);
}

.msgs.has-detail .msgs-list { display: none; }
.msgs.has-detail .msgs-detail { display: flex; flex: 1 1 auto; }

@media (min-width: 860px) {
    .msgs,
    .msgs.has-detail {
        z-index: auto;
        top: 0;
        bottom: var(--nav-h);
        height: auto;
    }

    .msgs-list,
    .msgs.has-detail .msgs-list {
        display: flex;
        flex: 0 0 360px;
        border-right: 1px solid var(--line);
    }

    .msgs-detail,
    .msgs.has-detail .msgs-detail { display: flex; flex: 1 1 auto; }
}

/* The number picker and the picture viewer sit above the bottom navigation. */
.msgs.has-overlay { z-index: 45; }

/* ---- list header ---- */

.msgs-head,
.thread-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 56px;
    padding: 6px 8px 6px 12px;
    padding-top: calc(6px + env(safe-area-inset-top));
    background: var(--card);
    border-bottom: 1px solid var(--line);
}

.thread-head { padding-left: 4px; }

.num-pick {
    flex: 1 1 auto;
    min-width: 0;
    min-height: var(--tap);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.num-pick.is-static { border-color: transparent; background: transparent; cursor: default; padding-left: 2px; }

.num-pick-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.num-pick-label { font-size: 1.05rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.num-pick-sub { font-size: .72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.num-pick .caret { color: var(--text-muted); font-size: .9rem; }

.count {
    flex: 0 0 auto;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: .75rem;
    font-weight: 700;
}

.head-btn {
    flex: 0 0 auto;
    width: var(--tap);
    height: var(--tap);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
}

.head-btn:active { background: var(--bg); }
.head-btn:disabled { opacity: .4; }

.msgs-search { flex: 0 0 auto; padding: 8px 12px; background: var(--card); }

.msgs-search input {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid transparent;
    border-radius: 10px;
    appearance: none;
    -webkit-appearance: none;
}

.msgs-search input:focus { outline: none; border-color: var(--primary); background: #fff; }

.msgs-toast {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0 12px 8px;
    padding: 10px 12px;
    border: none;
    border-radius: 12px;
    background: #1e3a8a;
    color: #fff;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.toast-title { font-size: .75rem; font-weight: 700; opacity: .85; }
.toast-body { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.msgs-scroll,
.thread-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.msgs-state {
    min-height: 40%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 28px 24px;
    text-align: center;
}

.msgs-state .big-icon { font-size: 2.6rem; }
.msgs-note { padding: 12px 16px 20px; text-align: center; }
.msgs-more { margin: 4px 0 12px; }

.msgs-divider {
    padding: 14px 16px 6px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-top: 1px solid var(--line);
}

/* ---- conversation rows ---- */

.conv {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 64px;
    padding: 10px 14px 10px 12px;
    border: none;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.conv:active { background: var(--bg); }
.conv.selected { background: #eff6ff; }

.avatar {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: hsl(var(--hue, 210) 55% 90%);
    color: hsl(var(--hue, 210) 45% 30%);
    font-size: .9rem;
    font-weight: 700;
}

.conv-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.conv-top { display: flex; align-items: baseline; gap: 8px; }
.conv-name { flex: 1 1 auto; min-width: 0; font-size: .98rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-when { flex: 0 0 auto; font-size: .75rem; color: var(--text-muted); }
.conv-preview { font-size: .86rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-prefix { color: #94a3b8; }
.conv-number { font-size: .72rem; color: var(--primary); font-weight: 600; }

.conv.unread .conv-name { font-weight: 800; }
.conv.unread .conv-preview { color: var(--text); font-weight: 600; }
.conv.unread .conv-when { color: var(--primary); font-weight: 700; }

.dot { flex: 0 0 auto; width: 11px; height: 11px; border-radius: 50%; background: var(--primary); }

/* ---- conversation ---- */

.thread-title { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.thread-name { font-size: 1.02rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-sub { font-size: .74rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* The Call button is a link the page script hands to the phone app; no link menu, no underline. */
.call-btn {
    color: var(--success);
    text-decoration: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
/* Set by the page script for a few seconds after a tap: a second tap could dial twice. */
.call-btn.is-busy { opacity: .4; pointer-events: none; }
/* Staff only, temporary: the link to the call test page. */
.call-test-btn { color: var(--text-muted); text-decoration: none; -webkit-touch-callout: none; }

.thread-note {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 4px 4px 4px 14px;
    background: #dcfce7;
    color: #166534;
    font-size: .88rem;
    border-bottom: 1px solid var(--line);
}

.thread-note.is-error { background: #fee2e2; color: #991b1b; }
.thread-note.is-wait { background: #e0f2fe; color: #075985; }
.thread-note-text { flex: 1 1 auto; min-width: 0; padding: 9px 0; }
.thread-note-detail { display: block; margin-top: 3px; font-size: .74rem; opacity: .8; overflow-wrap: anywhere; }
.thread-note .composer-icon { color: inherit; }

.thread-scroll { padding: 10px 12px 6px; display: flex; flex-direction: column; }
.thread-fill { flex: 1 1 auto; }

.thread-older, .thread-start { text-align: center; padding: 2px 0 10px; }
.thread-start { font-size: .75rem; color: var(--text-muted); }
.thread-older .btn { min-height: 36px; padding: 6px 14px; font-size: .88rem; }

.msg-day { display: flex; justify-content: center; margin: 10px 0 8px; }

.msg-day span {
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(100, 116, 139, .14);
    color: var(--text-muted);
    font-size: .72rem;
    font-weight: 600;
}

.msg { display: flex; flex-direction: column; max-width: 82%; margin-bottom: 2px; }
.msg.grp-end { margin-bottom: 9px; }
.msg-in { align-self: flex-start; align-items: flex-start; }
.msg-out { align-self: flex-end; align-items: flex-end; }

.msg-bubble {
    padding: 8px 12px;
    border-radius: 18px;
    font-size: .95rem;
    line-height: 1.35;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.msg-in .msg-bubble { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg-out .msg-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 6px; }

/* Texts an integration sent look different from the ones a person typed. */
.msg-out.msg-auto .msg-bubble { background: #e2e8f0; color: #334155; }
.msg-pending .msg-bubble { opacity: .6; }

.msg-bubble-media { padding: 4px; white-space: normal; }

.msg-media img {
    display: block;
    max-width: min(240px, 62vw);
    max-height: 300px;
    min-width: 96px;
    min-height: 72px;
    border-radius: 14px;
    object-fit: cover;
    background: rgba(100, 116, 139, .15);
    cursor: zoom-in;
}

.msg-file, .msg-missing { display: none; padding: 6px 8px; font-size: .9rem; }
.msg-file { color: inherit; font-weight: 600; text-decoration: underline; }
.msg-missing, .msg-missing-inline { font-style: italic; opacity: .8; }
.msg-media.media-file img, .msg-media.media-failed img { display: none; }
.msg-media.media-file .msg-file { display: inline-block; }
.msg-media.media-failed .msg-missing { display: inline-block; }

.msg-meta { margin: 3px 6px 0; font-size: .7rem; color: var(--text-muted); }

.auto-tag {
    display: inline-block;
    margin-right: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    background: #fde68a;
    color: #78350f;
    font-weight: 700;
}

.thread-pill {
    position: absolute;
    left: 50%;
    bottom: 76px;
    transform: translateX(-50%);
    z-index: 5;
    padding: 8px 16px;
    border: none;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-family: inherit;
    font-size: .85rem;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .25);
    cursor: pointer;
}

.detail-empty { flex: 1 1 auto; }

/* ---- message box ---- */

.composer {
    flex: 0 0 auto;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--card);
    border-top: 1px solid var(--line);
}

@media (min-width: 860px) {
    .composer { padding-bottom: 8px; }
}

.composer-bar { display: flex; align-items: flex-end; gap: 6px; }

.composer-file { display: none; }

.composer-icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
}

.composer-attach { color: var(--primary); }
.composer-icon.is-disabled { opacity: .4; pointer-events: none; }

.composer-input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 40px;
    max-height: 132px;
    padding: 9px 14px;
    font-size: 1rem;           /* 16px: no focus zoom on iOS */
    line-height: 1.3;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 20px;
    resize: none;
    appearance: none;
    -webkit-appearance: none;
}

.composer-input:focus { outline: none; border-color: var(--primary); background: #fff; }
.composer-input:disabled { opacity: .6; }

.composer-send {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
}

.composer-send:disabled { background: #cbd5e1; cursor: default; }

.spinner-sm { width: 18px; height: 18px; border-width: 2px; border-color: rgba(255, 255, 255, .5); border-top-color: #fff; }

.composer-attachment {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg);
}

.composer-thumb { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; }
.composer-fileicon { width: 48px; text-align: center; font-size: 1.6rem; }
.composer-attachment-info { flex: 1 1 auto; min-width: 0; }
.composer-attachment-name { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-attachment-size { font-size: .75rem; color: var(--text-muted); }

.composer-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 8px;
    padding: 8px 4px 8px 12px;
    border-radius: 10px;
    background: #fee2e2;
    color: #991b1b;
    font-size: .88rem;
}

.composer-error span { flex: 1 1 auto; padding-top: 9px; padding-bottom: 9px; }
.composer-error .composer-icon { color: #991b1b; }

/* ---- new message ---- */

.compose-form { flex: 0 0 auto; padding: 14px 14px 0; background: var(--card); border-bottom: 1px solid var(--line); }

.to-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 2px 4px 2px 12px;
    border: 1px solid var(--primary);
    border-radius: 10px;
    background: #eff6ff;
    font-weight: 600;
}

.to-chip span:first-child { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.to-chip-sub { flex: 0 0 auto; font-size: .8rem; font-weight: 400; color: var(--text-muted); }

.to-suggest { margin: -6px 0 12px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; max-height: 40vh; overflow-y: auto; }

.to-option {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: var(--tap);
    padding: 8px 12px;
    border: none;
    border-bottom: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    font-family: inherit;
    font-size: .95rem;
    text-align: left;
    cursor: pointer;
}

.to-option:last-child { border-bottom: none; }
.to-option-name { min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.to-option-sub { flex: 0 0 auto; font-size: .82rem; color: var(--text-muted); }

/* ---- number picker ---- */

.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .45); }

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 41;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    padding: 14px 12px calc(10px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
    background: var(--card);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
}

@media (min-width: 860px) {
    .sheet { left: 12px; right: auto; bottom: auto; top: 64px; width: 340px; border-radius: 14px; max-height: 70vh; padding-bottom: 10px; }
}

.sheet-title { padding: 0 6px 10px; font-size: 1.05rem; font-weight: 700; }
.sheet-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-note { padding: 10px 6px 0; }

.sheet-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 54px;
    padding: 8px 10px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.sheet-row.selected { background: #eff6ff; }
.sheet-row.selected .sheet-label { color: var(--primary); }
.sheet-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.sheet-label { font-size: 1rem; font-weight: 600; }
.sheet-sub { font-size: .76rem; color: var(--text-muted); }

/* A number's row with its alert bell beside it (the bell is its own button). */
.sheet-item { display: flex; align-items: center; gap: 4px; }
.sheet-item .sheet-row { flex: 1 1 auto; min-width: 0; width: auto; }

.sheet-bell {
    flex: 0 0 auto;
    width: var(--tap);
    height: var(--tap);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.sheet-bell.on { background: #eff6ff; color: var(--primary); }
.sheet-bell:disabled { opacity: .5; cursor: default; }
.sheet-bell svg { width: 22px; height: 22px; }

/* ---- picture viewer ---- */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .92);
    touch-action: pinch-zoom;
}

.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

.lightbox-close {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top));
    right: 12px;
    width: var(--tap);
    height: var(--tap);
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
}
