/* Rich dialogs, tabs, WhatsApp template preview, media library, and pro inbox */

dialog.dlg.wide { width: min(940px, 96vw); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.dlg-head h2 { margin: 0; }
.dlg-close { background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 8px; width: 32px; height: 32px; font-size: 18px; line-height: 1; cursor: pointer; display: grid; place-items: center; flex: none; }
.dlg-close:hover { background: var(--blush); color: var(--ink); }

/* Accessible scrollable table region (responsive-table guide) */
.tablewrap { position: relative; max-inline-size: 100%; }
.tablewrap thead { position: sticky; inset-block-start: 0; z-index: 1; }

/* Accessible Tabs (tabs guide: single scrolling row, ::after border underline, hidden=until-found wrapper) */
.tabs { margin: 0 0 16px; }
.tablist { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); gap: 4px; scrollbar-width: thin; scroll-snap-type: inline proximity; }
.tablist [role="tab"] {
  position: relative; flex: none; scroll-snap-align: start;
  font: inherit; background: transparent; border: 0; color: var(--muted);
  padding: 9px 14px; cursor: pointer; border-radius: 8px 8px 0 0; white-space: nowrap;
}
.tablist [role="tab"]:hover { background: var(--blush); color: var(--ink); }
.tablist [role="tab"][aria-selected="true"] { color: var(--plum); }
.tablist [role="tab"][aria-selected="true"]::after {
  content: ""; position: absolute; inset: auto 0 0; border-block-end: 3px solid var(--plum);
}
.tabpanel-inner { padding-top: 14px; }

/* Search bars */
search.filterbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; }
search.filterbar input[type="search"] { min-width: 210px; flex: 1 1 210px; }

/* Studio split (form left, WhatsApp preview right) */
.studio { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(260px, 320px); gap: 18px; align-items: start; }
@media (max-width: 780px) { .studio { grid-template-columns: 1fr; } }
.studio-preview { position: sticky; top: 8px; }

/* Realistic WhatsApp card preview */
.wa-phone { background: var(--blush); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.wa-phone-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.wa-card { background: var(--card); color: var(--ink); border-radius: 10px; border: 1px solid var(--line); overflow: hidden; box-shadow: 0 2px 6px rgba(0, 0, 0, .06); font-size: 14px; }
.wa-hdr-media { background: var(--code); min-height: 120px; max-height: 190px; display: grid; place-items: center; color: var(--muted); font-size: 13px; overflow: hidden; }
.wa-hdr-media img, .wa-hdr-media video { width: 100%; max-height: 190px; object-fit: cover; display: block; }
.wa-hdr-text { font-weight: 700; padding: 10px 12px 0; font-size: 14.5px; }
.wa-body { padding: 8px 12px; white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.wa-footer { padding: 0 12px 8px; font-size: 12px; color: var(--muted); }
.wa-btns { border-top: 1px solid var(--line); display: flex; flex-direction: column; }
.wa-btn { padding: 8px 10px; text-align: center; color: var(--info); font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.wa-btn:last-child { border-bottom: 0; }

/* Media library grid */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.media-item { border: 1px solid var(--line); border-radius: 10px; background: var(--card); overflow: hidden; display: flex; flex-direction: column; }
.media-item.sel { outline: 2px solid var(--plum); border-color: var(--plum); }
.media-thumb { height: 105px; background: var(--code); display: grid; place-items: center; overflow: hidden; font-size: 12px; color: var(--muted); }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-meta { padding: 7px 9px; font-size: 12px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.media-meta b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* Pro 3-pane Inbox (Desktop 3-pane, Mobile WhatsApp-style single-pane drill-down!) */
.inbox-pro { display: grid; grid-template-columns: 290px minmax(0, 1fr) 290px; gap: 12px; align-items: start; }
@media (max-width: 1080px) { .inbox-pro { grid-template-columns: 260px minmax(0, 1fr); } .inbox-crm { grid-column: 1 / -1; } }
.mob-only { display: none !important; }
@media (max-width: 760px) {
  .inbox-pro { grid-template-columns: 1fr; }
  .mob-only { display: inline-flex !important; }
  /* When NO chat is open, hide empty thread & CRM panel on phones */
  .inbox-pro.mob-list-view .thread,
  .inbox-pro.mob-list-view .inbox-crm { display: none; }
  /* When a chat IS open, hide the chat list so the thread fills the screen cleanly */
  .inbox-pro.mob-chat-view .convs { display: none; }
  .inbox-pro.mob-chat-view:not(.show-crm) .inbox-crm { display: none; }
  .inbox-pro.mob-chat-view.show-crm .thread { display: none; }
  .msgs { max-height: 54dvh; }
}
.inbox-crm { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.bubble.whisper {
  align-self: stretch; max-width: 100%;
  background: var(--warn-bg); color: var(--ink); border: 1px dashed var(--warn);
  font-size: 13.5px;
}
.conv .top { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.unread-dot { background: var(--plum); color: var(--on-plum); border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; }
.bubble img, .bubble video { max-width: 100%; max-height: 240px; border-radius: 8px; display: block; margin-bottom: 6px; }
.bubble audio { max-width: 100%; display: block; margin-bottom: 4px; }
.bubble .tpl-hdr { font-weight: 700; margin-bottom: 4px; }
.bubble .tpl-ftr { font-size: 12px; opacity: .8; margin-top: 4px; }
.bubble .tpl-btns { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(128,128,128,.28); display: flex; flex-wrap: wrap; gap: 5px; }
.bubble .tpl-btn-pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; opacity: .9; }
.bubble .tap-tag { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 6px; background: var(--gold); color: #1b0f1a; margin-bottom: 4px; }
.composer-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.pill-tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.pill-tabs::-webkit-scrollbar { display: none; }
.pill-tabs button { font: inherit; font-size: 13px; border: 0; background: transparent; color: var(--muted); padding: 6px 11px; cursor: pointer; white-space: nowrap; flex: none; }
.pill-tabs button.on { background: var(--plum); color: var(--on-plum); font-weight: 600; }
