/* Central Telegram — layout de mensageiro responsivo. */
.main-content-area.tg-chat-host {
    min-height: 0;
    overflow: hidden !important;
    padding: 18px 24px 20px !important;
}

.tg-chat-host #tg-chat-tab-container,
.tg-chat-stage { width: 100%; height: 100%; min-width: 0; min-height: 0; }
.tg-chat-stage { container: telegram-chat / inline-size; }

.tg-chat-layout {
    --tg-blue: #2aabee;
    --tg-blue-strong: #168acd;
    --tg-navy: #07111d;
    --tg-panel: #0d1724;
    --tg-line: rgba(148, 163, 184, .15);
    --tg-muted: #91a2b7;
    --tg-text: #edf6ff;
    --tg-bubble-out: #1e6d98;
    --tg-bubble-in: #172534;
    display: grid;
    grid-template-columns: clamp(280px, 29%, 348px) minmax(0, 1fr);
    width: 100%; height: 100%; min-width: 0; min-height: 0;
    overflow: hidden;
    color: var(--tg-text);
    background: var(--tg-navy);
    border: 1px solid rgba(148, 163, 184, .18);
    border-radius: 18px;
    box-shadow: 0 20px 55px rgba(0, 0, 0, .34);
}

/* Lista de conversas */
.tg-sidebar {
    display: flex; flex-direction: column; min-width: 0; min-height: 0;
    overflow: hidden;
    background: linear-gradient(180deg, #101b29 0%, #0b1521 100%);
    border-right: 1px solid var(--tg-line);
}
.tg-sidebar-header {
    display: flex; align-items: center; gap: 11px; min-height: 66px;
    padding: 13px 16px;
    background: linear-gradient(135deg, rgba(42, 171, 238, .22), rgba(22, 138, 205, .06));
    border-bottom: 1px solid rgba(42, 171, 238, .16);
}
.tg-brand-icon {
    width: 40px; height: 40px; display: grid; place-items: center; flex: 0 0 auto;
    border-radius: 13px; background: linear-gradient(145deg, #35b8f5, #168acd);
    box-shadow: 0 8px 22px rgba(42, 171, 238, .24);
}
.tg-brand-icon .material-icons { font-size: 22px; color: #fff; }
.tg-brand-copy { min-width: 0; flex: 1; }
.tg-brand-title { font-size: 15px; font-weight: 800; line-height: 1.2; letter-spacing: .1px; }
.tg-brand-sub { margin-top: 3px; color: #b7c5d6; font-size: 11.5px; line-height: 1.25; }
.tg-channel-status {
    display: inline-flex; align-items: center; gap: 6px; max-width: 112px;
    padding: 5px 8px; overflow: hidden; color: #b7c5d6;
    background: rgba(2, 6, 12, .25); border: 1px solid rgba(148, 163, 184, .14);
    border-radius: 999px; font-size: 10px; font-weight: 700;
    white-space: nowrap; text-overflow: ellipsis;
}
.tg-status-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: #77879a; box-shadow: 0 0 0 3px rgba(119, 135, 154, .12); }
.tg-channel-status.online { color: #b9f6d0; border-color: rgba(52, 211, 153, .2); }
.tg-channel-status.online .tg-status-dot { background: #34d399; box-shadow: 0 0 0 3px rgba(52, 211, 153, .13); }
.tg-channel-status.offline { color: #fda4af; }
.tg-channel-status.offline .tg-status-dot { background: #fb7185; box-shadow: 0 0 0 3px rgba(251, 113, 133, .12); }

.tg-search-area { padding: 12px 12px 8px; }
.tg-search-box { position: relative; display: flex; align-items: center; }
.tg-search-box > .material-icons { position: absolute; left: 12px; z-index: 1; color: #7f91a6; font-size: 19px; pointer-events: none; }
.tg-search-box input {
    width: 100%; height: 40px; padding: 0 38px; color: var(--tg-text);
    background: rgba(3, 10, 18, .62); border: 1px solid rgba(148, 163, 184, .16);
    border-radius: 12px; outline: none; font-size: 13px;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.tg-search-box input::placeholder { color: #718196; }
.tg-search-box input:focus { background: rgba(3, 10, 18, .82); border-color: rgba(42, 171, 238, .65); box-shadow: 0 0 0 3px rgba(42, 171, 238, .11); }
.tg-search-clear {
    position: absolute; right: 7px; width: 28px; height: 28px; display: none;
    place-items: center; padding: 0; color: #8fa0b3; background: transparent;
    border: 0; border-radius: 50%; cursor: pointer;
}
.tg-search-clear.visible { display: grid; }
.tg-search-clear:hover { color: #fff; background: rgba(255,255,255,.07); }
.tg-search-clear .material-icons { font-size: 17px; }
.tg-list-meta { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px 5px; color: var(--tg-muted); font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.tg-conv-list {
    flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    padding: 4px 8px 14px; scrollbar-width: thin;
    scrollbar-color: rgba(148,163,184,.24) transparent;
}
.tg-conv-item {
    display: flex; align-items: center; gap: 11px; min-height: 66px;
    margin-bottom: 3px; padding: 9px 10px; border: 1px solid transparent;
    border-radius: 13px; cursor: pointer;
    transition: background .14s, border-color .14s, transform .14s;
}
.tg-conv-item:hover { background: rgba(255, 255, 255, .045); }
.tg-conv-item:active { transform: scale(.99); }
.tg-conv-item.active { background: linear-gradient(135deg, rgba(42, 171, 238, .17), rgba(42, 171, 238, .07)); border-color: rgba(42, 171, 238, .2); }
.tg-avatar {
    width: 46px; height: 46px; display: grid; place-items: center; flex: 0 0 auto;
    overflow: hidden; color: #fff; background: linear-gradient(145deg, #37baf6, #177fb8);
    border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
    font-size: 15px; font-weight: 800;
}
.tg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.tg-conv-details { min-width: 0; flex: 1; }
.tg-conv-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.tg-conv-name { min-width: 0; overflow: hidden; color: var(--tg-text); font-size: 13.5px; font-weight: 700; white-space: nowrap; text-overflow: ellipsis; }
.tg-conv-time { flex: 0 0 auto; color: #77899f; font-size: 10.5px; }
.tg-conv-snippet { margin-top: 3px; overflow: hidden; color: #8ea0b5; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }

/* Janela da conversa */
.tg-main {
    position: relative; display: flex; flex-direction: column;
    min-width: 0; min-height: 0; overflow: hidden; background-color: #07111d;
    background-image: radial-gradient(circle at 15% 8%, rgba(42,171,238,.09), transparent 27%), radial-gradient(circle at 83% 92%, rgba(22,138,205,.07), transparent 30%), radial-gradient(rgba(148,163,184,.055) .7px, transparent .7px);
    background-size: auto, auto, 18px 18px;
}
.tg-main-empty, .tg-empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; padding: 28px; color: var(--tg-muted); text-align: center; }
.tg-empty-visual { width: 72px; height: 72px; display: grid; place-items: center; margin-bottom: 16px; color: #8dd7fa; background: linear-gradient(145deg, rgba(42,171,238,.18), rgba(42,171,238,.07)); border: 1px solid rgba(42,171,238,.2); border-radius: 24px; box-shadow: 0 18px 45px rgba(0,0,0,.2); }
.tg-empty-visual .material-icons { font-size: 38px; }
.tg-main-empty h2, .tg-empty-state h3 { margin: 0; color: #dce9f6; font-size: 18px; }
.tg-main-empty p, .tg-empty-state p { max-width: 390px; margin: 7px 0 0; color: #8799ae; font-size: 12.5px; }
.tg-empty-state .material-icons { margin-bottom: 8px; color: #63c4ef; font-size: 38px; opacity: .82; }
.tg-empty-state.compact { min-height: 240px; height: auto; }
.tg-secondary-action { margin-top: 16px; padding: 8px 13px; color: #a8dcf5; background: rgba(42,171,238,.08); border: 1px solid rgba(42,171,238,.22); border-radius: 10px; cursor: pointer; font-size: 11.5px; font-weight: 700; }
.tg-secondary-action:hover { background: rgba(42,171,238,.15); }

.tg-chat-header { display: flex; align-items: center; gap: 11px; min-height: 66px; padding: 10px 16px; flex: 0 0 auto; background: rgba(13, 23, 36, .93); border-bottom: 1px solid var(--tg-line); backdrop-filter: blur(14px); }
.tg-chat-header .tg-avatar { width: 42px; height: 42px; font-size: 13px; }
.tg-chat-header-info { display: flex; flex-direction: column; min-width: 0; }
.tg-chat-header-name { overflow: hidden; color: var(--tg-text); font-size: 14px; font-weight: 800; white-space: nowrap; text-overflow: ellipsis; }
.tg-chat-header-status { display: flex; align-items: center; gap: 5px; margin-top: 2px; color: #6dcaf4; font-size: 11.5px; }
.tg-chat-header-status .material-icons { font-size: 13px; }
.tg-chat-header-actions { display: flex; gap: 4px; margin-left: auto; }
.tg-icon-btn, .tg-chat-header-back { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; padding: 0; color: #91a2b7; background: transparent; border: 0; border-radius: 50%; cursor: pointer; transition: color .14s, background .14s, transform .12s; }
.tg-chat-header-back { display: none; }
.tg-icon-btn:hover, .tg-chat-header-back:hover { color: #7ed3fa; background: rgba(255,255,255,.06); }
.tg-icon-btn:active, .tg-chat-header-back:active { transform: scale(.93); }
.tg-icon-btn .material-icons, .tg-chat-header-back .material-icons { font-size: 21px; }

.tg-messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px clamp(16px, 4vw, 52px) 14px; scrollbar-width: thin; scrollbar-color: rgba(148,163,184,.22) transparent; }
.tg-msg-row { display: flex; margin: 3px 0; }
.tg-msg-row.out { justify-content: flex-end; }
.tg-msg-row.in { justify-content: flex-start; }
.tg-bubble { position: relative; max-width: min(72%, 620px); padding: 8px 11px 6px; overflow: hidden; color: #eef7ff; background: var(--tg-bubble-in); border: 1px solid rgba(255,255,255,.045); border-radius: 15px 15px 15px 5px; box-shadow: 0 2px 7px rgba(0,0,0,.17); font-size: 13.2px; line-height: 1.42; overflow-wrap: anywhere; }
.tg-msg-row.out .tg-bubble { background: linear-gradient(145deg, #236f99, #1b5d82); border-color: rgba(97,199,246,.12); border-radius: 15px 15px 5px 15px; }
.tg-msg-row.pending .tg-bubble { opacity: .76; }
.tg-msg-row.failed .tg-bubble { border-color: rgba(251,113,133,.75); }
.tg-bubble-text { white-space: pre-wrap; }
.tg-bubble-meta { display: flex; align-items: center; justify-content: flex-end; gap: 3px; float: right; margin: 5px 0 0 11px; color: rgba(232,245,255,.65); font-size: 9.5px; }
.tg-delivery-icon { font-size: 13px !important; color: #9fe0ff; }
.tg-msg-row.pending .tg-delivery-icon { color: rgba(232,245,255,.48); }
.tg-msg-row.failed .tg-delivery-icon { color: #fda4af; }
.tg-bubble-media img, .tg-bubble-media video { display: block; width: min(300px, 100%); max-height: 320px; object-fit: cover; border-radius: 11px; cursor: pointer; }
.tg-bubble-media audio { width: min(270px, 65vw); height: 38px; }
.tg-bubble-doc { display: flex; align-items: center; gap: 10px; min-width: min(230px, 62vw); padding: 4px 2px; }
.tg-bubble-doc .material-icons { font-size: 32px; }
.tg-bubble-doc-info { display: flex; flex-direction: column; min-width: 0; }
.tg-bubble-doc-name { overflow: hidden; font-size: 12.5px; font-weight: 700; white-space: nowrap; text-overflow: ellipsis; }
.tg-bubble-doc-action { margin-top: 2px; color: #b8e8ff; font-size: 10.5px; text-decoration: none; }
.tg-day-divider { display: flex; align-items: center; justify-content: center; margin: 12px 0; }
.tg-day-divider span { padding: 5px 10px; color: #9eb0c3; background: rgba(8,17,28,.82); border: 1px solid rgba(148,163,184,.13); border-radius: 999px; box-shadow: 0 2px 8px rgba(0,0,0,.16); font-size: 10.5px; font-weight: 700; }

/* Campo de mensagem sempre visível */
.tg-composer { position: relative; z-index: 5; flex: 0 0 auto; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: rgba(10, 20, 31, .96); border-top: 1px solid var(--tg-line); box-shadow: 0 -12px 28px rgba(2,7,13,.13); backdrop-filter: blur(15px); }
.tg-composer-wrap { position: relative; }
.tg-composer-row { display: flex; align-items: flex-end; gap: 5px; }
.tg-input-or-recording { flex: 1; min-width: 0; }
.tg-composer textarea { display: block; width: 100%; min-height: 42px; max-height: 112px; padding: 10px 15px; resize: none; overflow-y: auto; color: var(--tg-text); background: #172534; border: 1px solid rgba(148,163,184,.12); border-radius: 18px; outline: none; font-family: inherit; font-size: 13px; line-height: 1.45; transition: border-color .15s, box-shadow .15s; }
.tg-composer textarea::placeholder { color: #7f90a4; }
.tg-composer textarea:focus { border-color: rgba(42,171,238,.5); box-shadow: 0 0 0 3px rgba(42,171,238,.08); }
.tg-mic-btn { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; padding: 0; touch-action: none; color: #fff; background: linear-gradient(145deg, #36b9f5, #168acd); border: 0; border-radius: 50%; box-shadow: 0 7px 18px rgba(42,171,238,.2); cursor: pointer; user-select: none; transition: filter .15s, transform .12s, opacity .15s; }
.tg-mic-btn:hover { filter: brightness(1.08); }
.tg-mic-btn:active { transform: scale(.92); }
.tg-mic-btn:disabled { cursor: wait; opacity: .55; }
.tg-mic-btn.recording { background: #e5484d; animation: tg-pulse 1.2s infinite; transform: scale(1.07); }
@keyframes tg-pulse { 0% { box-shadow: 0 0 0 0 rgba(229,72,77,.45); } 70% { box-shadow: 0 0 0 11px rgba(229,72,77,0); } 100% { box-shadow: 0 0 0 0 rgba(229,72,77,0); } }
.tg-recording-inline { display: flex; align-items: center; gap: 9px; min-height: 42px; padding: 9px 13px; color: var(--tg-text); background: #172534; border: 1px solid rgba(148,163,184,.12); border-radius: 18px; font-size: 12px; user-select: none; }
.tg-recording-dot { width: 9px; height: 9px; flex: 0 0 auto; background: #ef5350; border-radius: 50%; animation: tg-pulse 1.2s infinite; }
.tg-recording-hint { margin-left: auto; color: var(--tg-muted); white-space: nowrap; }
.tg-recording-hint.cancel-armed { color: #fda4af; font-weight: 800; }
.tg-uploading-toast { padding: 0 4px 7px; color: #8dd7fa; font-size: 11px; font-weight: 700; }
.tg-emoji-pop { position: absolute; left: 36px; bottom: calc(100% + 9px); z-index: 20; display: none; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 8px; background: #172534; border: 1px solid rgba(148,163,184,.17); border-radius: 14px; box-shadow: 0 14px 40px rgba(0,0,0,.38); }
.tg-emoji-pop.open { display: grid; }
.tg-emoji-pop button { padding: 5px; background: transparent; border: 0; border-radius: 7px; cursor: pointer; font-size: 19px; }
.tg-emoji-pop button:hover { background: rgba(255,255,255,.07); }

/* Compactação guiada pelo espaço do painel, não pelo zoom do navegador. */
@container telegram-chat (max-width: 680px) {
    .tg-chat-layout { grid-template-columns: minmax(0, 1fr); border-radius: 14px; }
    .tg-sidebar { display: flex; border-right: 0; }
    .tg-main { display: none; }
    .tg-chat-layout.tg-open-conv .tg-sidebar { display: none; }
    .tg-chat-layout.tg-open-conv .tg-main { display: flex; }
    .tg-chat-header-back { display: grid; }
    .tg-bubble { max-width: 87%; }
    .tg-messages { padding-inline: 12px; }
}
@container telegram-chat (max-width: 420px) {
    .tg-brand-sub { display: none; }
    .tg-channel-status { max-width: 92px; }
    .tg-composer { padding-inline: 7px; }
    .tg-composer-row { gap: 2px; }
    .tg-icon-btn { width: 34px; height: 40px; }
    .tg-emoji-pop { left: 4px; grid-template-columns: repeat(4, 1fr); }
    .tg-recording-hint { max-width: 115px; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 600px) { .main-content-area.tg-chat-host { padding: 8px !important; } }
@media (prefers-reduced-motion: reduce) { .tg-mic-btn.recording, .tg-recording-dot { animation: none; } .tg-conv-item, .tg-icon-btn, .tg-mic-btn { transition: none; } }
