/* App-specific additions on top of the Velzon theme */

.filter-bar.row { margin: 0; gap: .5rem; }
.filter-bar > [class*="col-"] {
    flex: 1 1 180px;
    width: auto;
    min-width: 0;
    max-width: 100%;
    margin-top: 0;
    padding: 0;
}
.filter-bar > .col-auto { flex: 0 0 auto; }
.filter-bar .form-control,
.filter-bar .form-select { width: 100%; min-width: 0; max-width: 100%; }

@media (max-width: 575.98px) {
    .filter-bar > [class*="col-"] { flex-basis: 100%; }
    .filter-bar > .col-auto { flex: 1 1 0; }
    .filter-bar > .col-auto .btn { width: 100%; }
}

.table-report td.num,
.table-report th.num { text-align: right; font-variant-numeric: tabular-nums; }

.msg-content, .table-nowrap td.msg-content { max-width: 420px; white-space: normal; word-break: break-word; }
/* Cells ignore max-width, so the template list wraps its text in a sized block */
.msg-content-box { width: 360px; max-width: 60vw; white-space: pre-line; word-break: break-word; overflow-wrap: anywhere; }

/* WhatsApp-style template preview (legacy compose page) */
.wh-card { border: 0; border-radius: 1rem; box-shadow: 0 10px 30px rgba(15, 23, 42, .08); overflow: hidden; background: #fff; max-width: 420px; }
.wh-card .media-wrap { padding: .75rem; }
.wh-card .media-wrap img, .wh-card .media-wrap video { width: 100%; border-radius: .75rem; display: block; }
.wh-msg { margin: .75rem; background: #fff; border-radius: .9rem; padding: 1rem 1rem .5rem; border: 1px solid #eef2f7; white-space: pre-line; }
.wh-footer { margin: 0 .75rem .75rem; color: #94a3b8; font-size: .8rem; }
.wh-carousel { display: flex; gap: .75rem; overflow-x: auto; padding-bottom: .5rem; scroll-snap-type: x mandatory; }
.wh-carousel .wh-card { flex: 0 0 220px; scroll-snap-align: start; }
.wh-carousel .wh-msg { padding: .6rem .75rem; font-size: .85rem; }
/* Emoji picker under the template editor toolbar */
.emoji-popover { position: absolute; top: 100%; right: 0; margin-top: .25rem; z-index: 1056; }
.emoji-popover em-emoji-picker { height: 380px; max-width: calc(100vw - 2rem); }

/* Template popup on the list: chat-coloured backdrop behind the bubble */
.tpl-view-body { background: #efeae2; }
.tpl-view-body .wh-card { margin: 0 auto; }
.tpl-view-body .wh-carousel .wh-card { margin: 0; }
.wh-action { display: flex; align-items: center; justify-content: center; gap: .5rem; padding: .8rem 1rem; color: #0d6efd; border-top: 1px solid #eef2f7; font-weight: 500; }

/* Campaigns & contacts */
.group-picker { max-height: 220px; overflow-y: auto; }
.stat-tile { height: 100%; }
.stat-tile .stat-value { font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.stat-tile .stat-sub { font-size: .8rem; color: var(--vz-secondary-color); }
/* Stacked delivery bar: each segment is a status, separated by a 2px surface gap */
.delivery-bar { display: flex; gap: 2px; height: 10px; min-width: 140px; border-radius: 5px; overflow: hidden; background: var(--vz-light); }
.delivery-bar > span { display: block; min-width: 2px; }
.delivery-bar.lg { height: 16px; border-radius: 8px; }
.seg-read { background: #0ab39c; }
.seg-delivered { background: #6ad3c3; }
.seg-sent { background: #b4c7e7; }
.seg-pending { background: #f7b84b; }
.seg-failed { background: #f06548; }
.seg-skipped { background: #ced4da; }
.legend-dot { display: inline-block; width: .65rem; height: .65rem; border-radius: 2px; margin-right: .3rem; vertical-align: baseline; }

/* Inbox */
.inbox { display: grid; grid-template-columns: 360px minmax(0, 1fr); height: calc(100vh - 210px); min-height: 520px; overflow: hidden; }
.inbox-side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--vz-border-color); }
.inbox-tools { padding: .75rem; border-bottom: 1px solid var(--vz-border-color); display: grid; gap: .5rem; }
.inbox-filters .btn { flex: 1; }
.inbox-list { flex: 1; overflow-y: auto; }
.inbox-list .list-state { padding: 1.5rem 1rem; text-align: center; color: var(--vz-secondary-color); }

.conv { display: flex; gap: .75rem; align-items: center; padding: .7rem .9rem; color: inherit; border-bottom: 1px solid var(--vz-border-color-translucent, #f1f3f5); }
.conv:hover { background: var(--vz-light); color: inherit; }
.conv.active { background: var(--vz-primary-bg-subtle, #e8f0fe); }
.conv-avatar { flex: 0 0 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: .85rem;
    color: hsl(var(--hue, 200) 45% 30%); background: hsl(var(--hue, 200) 60% 88%); }
.conv-body { flex: 1; min-width: 0; display: grid; gap: .15rem; }
.conv-line { display: flex; align-items: center; gap: .4rem; min-width: 0; }
.conv-name { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { flex-shrink: 0; font-size: .75rem; color: var(--vz-secondary-color); }
.conv-preview { flex: 1; min-width: 0; font-size: .85rem; color: var(--vz-secondary-color); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .conv-name, .conv.unread .conv-preview { font-weight: 600; color: var(--vz-body-color); }
.conv.unread .conv-time { color: #1fa855; font-weight: 600; }
.conv-badge { flex-shrink: 0; min-width: 1.35rem; padding: 0 .4rem; border-radius: 1rem; background: #25d366; color: #fff; font-size: .72rem; font-weight: 600; text-align: center; line-height: 1.35rem; }
.conv-live { flex-shrink: 0; width: .5rem; height: .5rem; border-radius: 50%; background: #25d366; }

.inbox-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.inbox-empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--vz-secondary-color); background: #f7f5f2; }
.thread-head { display: flex; align-items: center; gap: .75rem; padding: .6rem .9rem; border-bottom: 1px solid var(--vz-border-color); }
.thread-title { min-width: 0; }
.thread-back { display: none; }
.thread { position: relative; flex: 1; overflow-y: auto; padding: 1rem 1.25rem; background: #efeae2; }
.thread-loading { text-align: center; padding: .5rem; color: #667781; font-size: .8rem; }
.day-sep { display: flex; justify-content: center; margin: .75rem 0; }
.day-sep span { background: #fff; color: #54656f; font-size: .75rem; padding: .2rem .7rem; border-radius: .5rem; box-shadow: 0 1px .5px rgba(11, 20, 26, .13); }
.chat-msg { display: flex; margin-bottom: .35rem; }
.chat-msg.out { justify-content: flex-end; }
.bubble { position: relative; max-width: min(75%, 560px); padding: .4rem .6rem .3rem; border-radius: .5rem; background: #fff; box-shadow: 0 1px .5px rgba(11, 20, 26, .13); word-break: break-word; }
.chat-msg.out .bubble { background: #d9fdd3; }
.bubble.failed { background: #fdecea !important; }
.bubble.pending { opacity: .7; }
.bubble-text { white-space: pre-wrap; }
.bubble-text code { white-space: pre-wrap; }
.bubble-media { display: block; margin: -.15rem -.35rem .3rem; }
.bubble-media img { display: block; max-width: 100%; max-height: 320px; border-radius: .35rem; }
.bubble-media.sticker img { max-width: 140px; }
.bubble-file { display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem; margin-bottom: .3rem; border-radius: .35rem; background: rgba(0, 0, 0, .05); color: inherit; max-width: 320px; }
.bubble-template { font-style: italic; }
.bubble-video { display: block; width: 100%; max-width: 320px; max-height: 320px; margin-bottom: .3rem; border-radius: .35rem; background: #000; }
.bubble-audio { display: block; width: 260px; max-width: 100%; margin-bottom: .3rem; }
.bubble-tpl-header { font-weight: 600; margin-bottom: .2rem; }
.bubble-tpl-footer { font-size: .78rem; color: #667781; margin-top: .2rem; }
.bubble-tpl-buttons { margin: .35rem -.6rem -.1rem; border-top: 1px solid rgba(0, 0, 0, .08); }
.bubble-tpl-button { padding: .35rem .6rem; text-align: center; color: #027eb5; font-size: .85rem; }
.bubble-tpl-button + .bubble-tpl-button { border-top: 1px solid rgba(0, 0, 0, .08); }
.bubble-tpl-cards { display: flex; gap: .5rem; overflow-x: auto; margin-top: .4rem; padding-bottom: .25rem; }
.bubble-tpl-card { flex: 0 0 220px; padding: .4rem .6rem .2rem; border-radius: .4rem; background: rgba(255, 255, 255, .7); }
.bubble-tpl-card .bubble-media { margin: 0 0 .3rem; }
.bubble-meta { float: right; margin: .35rem 0 -.15rem .6rem; font-size: .68rem; color: #667781; white-space: nowrap; }
.bubble-meta .tick-read { color: #53bdeb; }
.bubble-error { clear: both; font-size: .75rem; color: #b42318; }
.new-pill { position: sticky; bottom: .5rem; display: block; margin: 0 auto; border-radius: 1rem; box-shadow: 0 2px 6px rgba(0, 0, 0, .15); }

.composer { border-top: 1px solid var(--vz-border-color); padding: .6rem .75rem; background: var(--vz-card-bg, #fff); }
.composer-row { display: flex; align-items: flex-end; gap: .5rem; }
.composer textarea { resize: none; max-height: 140px; }
.composer-file { display: inline-flex; align-items: center; gap: .4rem; margin-bottom: .5rem; padding: .25rem .5rem; border-radius: .4rem; background: var(--vz-light); font-size: .85rem; max-width: 100%; }
.composer-closed { border-top: 1px solid var(--vz-border-color); padding: .75rem; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; background: #fffbea; }

@media (max-width: 991.98px) {
    .inbox { grid-template-columns: 1fr; height: calc(100vh - 190px); }
    .inbox .inbox-main { display: none; }
    .inbox.show-thread .inbox-side { display: none; }
    .inbox.show-thread .inbox-main { display: flex; }
    .thread-back { display: inline-flex; }
    .bubble { max-width: 88%; }
}

/* Inbox "Send Template" popup */
.tpl-modal-preview { background: #efeae2; max-height: 60vh; overflow: auto; }
.tpl-modal-preview .wh-card { max-width: 100%; }
@media (max-width: 767.98px) { .tpl-modal-preview { max-height: none; } }

/* Searchable select (components/SearchSelect) */
.search-select { position: relative; }
.search-select > .form-select { cursor: pointer; }
.search-select-panel { position: absolute; z-index: 1060; top: calc(100% + 4px); left: 0; right: 0; background: var(--bs-body-bg, #fff); border: 1px solid var(--bs-border-color, #e9ebec); border-radius: .4rem; overflow: hidden; }
.search-select-search { position: relative; padding: .5rem; border-bottom: 1px solid var(--bs-border-color, #e9ebec); }
.search-select-search i { position: absolute; left: 1.05rem; top: 50%; transform: translateY(-50%); color: var(--bs-secondary-color, #878a99); pointer-events: none; }
.search-select-search .form-control { padding-left: 2rem; }
.search-select-list { list-style: none; margin: 0; padding: .25rem 0; max-height: 240px; overflow-y: auto; }
.search-select-list li { display: flex; align-items: center; gap: .5rem; padding: .45rem .9rem; cursor: pointer; }
.search-select-list li.active { background: var(--bs-tertiary-bg, #f3f6f9); }
.search-select-list li.selected { font-weight: 600; color: var(--bs-success, #0ab39c); }
.search-select-list .search-select-empty { color: var(--bs-secondary-color, #878a99); cursor: default; }
/* Reply quote: the message a customer replied to / the template whose button they tapped */
.bubble-quote { display: block; width: 100%; text-align: left; border: 0; margin: -.1rem 0 .35rem; padding: .3rem .5rem; border-radius: .4rem; background: rgba(0, 0, 0, .05); border-left: 4px solid #06cf9c; font-size: .8rem; line-height: 1.3; cursor: pointer; }
.bubble-quote.quote-in { border-left-color: #53bdeb; }
.bubble-quote .quote-who { display: block; font-weight: 600; color: #06a37d; }
.bubble-quote.quote-in .quote-who { color: #3a9fd1; }
.bubble-quote .quote-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; color: #54656f; }
.quote-button-label { font-size: .7rem; color: #667781; margin-bottom: .1rem; }
.chat-msg.flash .bubble { animation: msg-flash 1.2s ease-out; }
@keyframes msg-flash { 0%, 40% { box-shadow: 0 0 0 3px rgba(6, 207, 156, .55); } 100% { box-shadow: 0 0 0 0 rgba(6, 207, 156, 0); } }

/* Server-side DataTables (components/DataTable.tsx) */
.datatable-search { width: 260px; max-width: 100%; }
.datatable-search i { pointer-events: none; }
th .sort-th { white-space: nowrap; cursor: pointer; }
th .sort-th:hover { color: var(--vz-primary, #405189) !important; }
th.num .sort-th { justify-content: flex-end; width: 100%; }
