/* DesignerIA — Chat SaaS Core
   Conversation history, client context and post-generation workflow. */

:root {
  --dia-saas-panel: #101114;
  --dia-saas-panel-2: #15171b;
  --dia-saas-panel-3: #1a1c21;
  --dia-saas-border: rgba(255,255,255,.085);
  --dia-saas-border-strong: rgba(255,255,255,.14);
  --dia-saas-muted: #7f8591;
  --dia-saas-text: #f2f3f5;
  --dia-saas-yellow: var(--accent, #ffd60a);
  --dia-saas-success: #57d695;
  --dia-saas-shadow: 0 28px 80px rgba(0,0,0,.52), 0 2px 10px rgba(0,0,0,.24);
}

.dia-client-chip {
  appearance: none;
  cursor: pointer;
  font: inherit;
  max-width: 170px;
  transition: border-color .16s ease, background .16s ease, color .16s ease;
}
.dia-client-chip:hover {
  border-color: rgba(255,214,10,.28) !important;
  background: rgba(255,214,10,.045) !important;
  color: var(--txt) !important;
}
.dia-client-chip > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dia-client-chip .dia-context-dot { background: #8c93a0 !important; }
.dia-client-chip:not([title^="Selecionar"]) .dia-context-dot {
  background: var(--dia-saas-yellow) !important;
  box-shadow: 0 0 0 3px rgba(255,214,10,.07);
}

.dia-client-popover {
  position: fixed;
  z-index: 3400;
  width: 310px;
  max-height: min(430px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  padding: 10px;
  border: 1px solid var(--dia-saas-border-strong);
  border-radius: 14px;
  background: rgba(17,18,21,.98);
  box-shadow: var(--dia-saas-shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-5px) scale(.985);
  transform-origin: top left;
  transition: opacity .14s ease, transform .14s ease, visibility .14s;
  backdrop-filter: blur(18px);
}
.dia-client-popover.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.dia-client-popover-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 7px 11px;
  border-bottom: 1px solid var(--dia-saas-border);
}
.dia-client-popover-head > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.dia-client-popover-head strong { font-size: 12px; font-weight: 650; color: var(--dia-saas-text); }
.dia-client-popover-head span { font-size: 10.5px; line-height: 1.4; color: var(--dia-saas-muted); }
.dia-client-close,
.dia-history-close {
  width: 29px;
  height: 29px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  color: #777d88;
  background: transparent;
}
.dia-client-close:hover,
.dia-history-close:hover { color: #e7e8eb; background: rgba(255,255,255,.055); }
.dia-client-close svg,
.dia-history-close svg { width: 15px; height: 15px; }
.dia-client-list { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding-top: 8px; }
.dia-client-option {
  width: 100%;
  min-height: 52px;
  display: grid;
  grid-template-columns: 31px 1fr 18px;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #c8cbd1;
  text-align: left;
}
.dia-client-option:hover { background: rgba(255,255,255,.035); border-color: var(--dia-saas-border); }
.dia-client-option.is-active { background: rgba(255,214,10,.045); border-color: rgba(255,214,10,.18); }
.dia-client-option-mark {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border: 1px solid var(--dia-saas-border);
  border-radius: 9px;
  background: #17191d;
  color: #8e949f;
}
.dia-client-option.is-active .dia-client-option-mark { color: var(--dia-saas-yellow); border-color: rgba(255,214,10,.2); }
.dia-client-option-mark svg { width: 15px; height: 15px; }
.dia-client-option > span:nth-child(2) { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.dia-client-option strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; font-weight: 600; color: #e5e6e9; }
.dia-client-option small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9.5px; color: #747a84; }
.dia-client-option > svg { width: 15px; height: 15px; color: var(--dia-saas-yellow); }
.dia-client-empty { padding: 18px 10px; text-align: center; color: var(--dia-saas-muted); font-size: 11px; }

.dia-history-overlay {
  position: fixed;
  inset: 0;
  z-index: 3290;
  background: rgba(0,0,0,.34);
  opacity: 0;
  visibility: hidden;
  transition: opacity .18s ease, visibility .18s;
  backdrop-filter: blur(2px);
}
.dia-history-overlay.open { opacity: 1; visibility: visible; }

.dia-history-drawer {
  position: fixed;
  z-index: 3300;
  top: 0;
  right: 0;
  width: min(385px, calc(100vw - 24px));
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 15px;
  border-left: 1px solid var(--dia-saas-border-strong);
  background: rgba(13,14,17,.985);
  box-shadow: -22px 0 70px rgba(0,0,0,.34);
  transform: translateX(102%);
  visibility: hidden;
  transition: transform .2s cubic-bezier(.2,.8,.2,1), visibility .2s;
  backdrop-filter: blur(20px);
}
.dia-history-drawer.open { transform: translateX(0); visibility: visible; }
.dia-history-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 3px 2px 15px;
}
.dia-history-head > div { display: flex; flex-direction: column; gap: 3px; }
.dia-history-head strong { font-size: 14px; letter-spacing: -.01em; color: var(--dia-saas-text); }
.dia-history-head span { font-size: 10.5px; color: var(--dia-saas-muted); }
.dia-history-toolbar { display: flex; gap: 7px; margin-bottom: 9px; }
.dia-history-new {
  height: 36px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid rgba(255,214,10,.2);
  border-radius: 9px;
  background: rgba(255,214,10,.07);
  color: #f3d72d;
  font-size: 11px;
  font-weight: 600;
}
.dia-history-new:hover { background: rgba(255,214,10,.11); border-color: rgba(255,214,10,.3); }
.dia-history-new svg { width: 14px; height: 14px; }
.dia-history-images {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--dia-saas-border);
  border-radius: 9px;
  color: #858b96;
  background: #14161a;
}
.dia-history-images:hover { color: #dddfe3; border-color: var(--dia-saas-border-strong); }
.dia-history-images svg { width: 15px; height: 15px; }
.dia-history-search {
  height: 37px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  margin-bottom: 12px;
  border: 1px solid var(--dia-saas-border);
  border-radius: 9px;
  background: #111317;
  color: #676d78;
}
.dia-history-search:focus-within { border-color: rgba(255,255,255,.16); background: #131519; }
.dia-history-search svg { width: 14px; height: 14px; flex: 0 0 auto; }
.dia-history-search input {
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: #e4e5e8;
  font-size: 11px;
}
.dia-history-search input::placeholder { color: #626873; }
.dia-history-list { flex: 1; min-height: 0; overflow-y: auto; padding: 1px 2px 18px; }
.dia-history-group { display: flex; flex-direction: column; gap: 3px; margin-bottom: 15px; }
.dia-history-group-label {
  padding: 4px 7px 5px;
  color: #646a75;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.dia-history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 51px;
  border: 1px solid transparent;
  border-radius: 10px;
  transition: background .13s ease, border-color .13s ease;
}
.dia-history-item:hover { background: rgba(255,255,255,.032); border-color: rgba(255,255,255,.045); }
.dia-history-item.is-active { background: rgba(255,214,10,.037); border-color: rgba(255,214,10,.12); }
.dia-history-open {
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  padding: 7px 8px;
  text-align: left;
}
.dia-history-title {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #d8dade;
  font-size: 11.5px;
  font-weight: 550;
}
.dia-history-item.is-active .dia-history-title { color: #f0e7a2; }
.dia-history-meta { color: #696f79; font-size: 9.5px; }
.dia-history-item-actions {
  display: flex;
  align-items: center;
  gap: 1px;
  padding-right: 5px;
  opacity: 0;
  transition: opacity .13s ease;
}
.dia-history-item:hover .dia-history-item-actions,
.dia-history-fav.is-active { opacity: 1; }
.dia-history-fav,
.dia-history-delete {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: #686e79;
}
.dia-history-fav:hover { color: var(--dia-saas-yellow); background: rgba(255,214,10,.06); }
.dia-history-fav.is-active { color: var(--dia-saas-yellow); }
.dia-history-delete:hover { color: #ee8585; background: rgba(239,68,68,.07); }
.dia-history-fav svg,
.dia-history-delete svg { width: 13px; height: 13px; }
.dia-history-fav.is-active svg { fill: currentColor; }
.dia-history-empty {
  margin: 26px 8px;
  padding: 24px 18px;
  border: 1px dashed rgba(255,255,255,.07);
  border-radius: 11px;
  color: #6d737e;
  font-size: 10.5px;
  line-height: 1.55;
  text-align: center;
}

.dia-legacy-actions-hidden { display: none !important; }
.studio-chat-log .refine-msg--model:has(> img) { overflow: visible; }
.dia-creative-actions {
  width: fit-content;
  max-width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 8px;
  padding: 4px;
  border: 1px solid rgba(255,255,255,.075);
  border-radius: 10px;
  background: rgba(13,14,17,.9);
  box-shadow: 0 3px 14px rgba(0,0,0,.16);
}
.dia-creative-action {
  min-height: 29px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: #8b919c;
  font-size: 9.5px;
  font-weight: 550;
  white-space: nowrap;
  transition: color .12s ease, background .12s ease, border-color .12s ease;
}
.dia-creative-action:hover { color: #e3e4e7; background: rgba(255,255,255,.045); }
.dia-creative-action svg { width: 13px; height: 13px; flex: 0 0 auto; }
.dia-action-approve { border-color: rgba(87,214,149,.13); color: #9bb9aa; }
.dia-action-approve:hover { color: #bdebd3; background: rgba(87,214,149,.055); border-color: rgba(87,214,149,.2); }
.dia-action-approve.is-approved {
  color: var(--dia-saas-success);
  background: rgba(87,214,149,.065);
  border-color: rgba(87,214,149,.2);
}
.dia-action-more { width: 29px; padding: 0; }
.dia-action-more span { display: none; }
.dia-action-menu-wrap { position: relative; display: inline-flex; }
.dia-adapt-menu,
.dia-creative-more-menu {
  position: absolute;
  z-index: 400;
  left: 0;
  bottom: calc(100% + 7px);
  min-width: 205px;
  padding: 5px;
  border: 1px solid var(--dia-saas-border-strong);
  border-radius: 10px;
  background: #17191d;
  box-shadow: 0 18px 44px rgba(0,0,0,.48);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px) scale(.985);
  transform-origin: bottom left;
  transition: opacity .12s ease, transform .12s ease, visibility .12s;
}
.dia-creative-more-menu { left: auto; right: 0; min-width: 190px; }
.dia-adapt-menu.open,
.dia-creative-more-menu.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.dia-adapt-menu button,
.dia-creative-more-menu button {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 7px;
  color: #aeb2ba;
  text-align: left;
  font-size: 10.5px;
}
.dia-adapt-menu button:hover,
.dia-creative-more-menu button:hover { color: #f0f1f2; background: rgba(255,255,255,.05); }
.dia-adapt-menu button strong { min-width: 36px; color: #e1e3e6; font-size: 10.5px; }
.dia-adapt-menu button span { color: #717782; font-size: 9.5px; }
.dia-adapt-menu .dia-adapt-all {
  margin-top: 3px;
  border-top: 1px solid rgba(255,255,255,.06);
  border-radius: 4px 4px 7px 7px;
}
.studio-chat-log .refine-msg--model > img {
  border: 1px solid rgba(255,255,255,.07);
  box-shadow: 0 12px 36px rgba(0,0,0,.22);
}
#stripToggleBtn svg { width: 14px; height: 14px; }

@media (max-width: 900px) {
  .dia-client-chip { max-width: 116px; }
  .dia-client-chip > span:last-child { max-width: 88px; }
  .dia-creative-actions { gap: 2px; }
  .dia-creative-action { padding: 0 7px; }
}

@media (max-width: 680px) {
  .dia-history-drawer {
    top: auto;
    bottom: 0;
    width: 100%;
    height: min(82dvh, 680px);
    border-left: 0;
    border-top: 1px solid var(--dia-saas-border-strong);
    border-radius: 18px 18px 0 0;
    transform: translateY(102%);
  }
  .dia-history-drawer.open { transform: translateY(0); }
  .dia-client-popover { width: calc(100vw - 24px); left: 12px !important; }
  .dia-client-chip { display: none !important; }
  .dia-creative-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .dia-creative-action { width: 100%; padding: 0 5px; }
  .dia-action-menu-wrap { width: 100%; }
  .dia-action-menu-wrap > .dia-creative-action { width: 100%; }
  .dia-creative-more-menu { right: 0; left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .dia-history-drawer,
  .dia-history-overlay,
  .dia-client-popover,
  .dia-adapt-menu,
  .dia-creative-more-menu { transition: none !important; }
}


.dia-recovery-banner{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 16px;border:1px solid #65561d;border-radius:12px;background:#201c10;color:#e9dfb3;font-size:12px;margin:12px;flex-wrap:wrap}.dia-recovery-banner button{padding:8px 12px;border:1px solid #8d7827;border-radius:8px;background:#2f2815;color:#fff;cursor:pointer}
.dia-usage-chip{height:34px;display:inline-flex;align-items:center;background:rgba(255,255,255,.025);color:#b9bec6;border:1px solid var(--dia-border,#353535);border-radius:9px;padding:0 11px;font-size:11px;font-weight:600;white-space:nowrap;cursor:pointer;transition:all 150ms}
.dia-usage-chip:hover{background:rgba(255,255,255,.06);color:#f3f4f5}
/* chave Muse + consumo formam um bloco só: bordas coladas, sem a lacuna do flex */
.dia-muse-header-btn+.dia-usage-chip{margin-left:-6px;border-top-left-radius:0;border-bottom-left-radius:0}
.dia-muse-header-btn:has(+.dia-usage-chip){border-top-right-radius:0;border-bottom-right-radius:0}
.dia-usage-chip+.dia-muse-header-btn{margin-left:-6px;border-top-left-radius:0;border-bottom-left-radius:0}
.dia-usage-chip:has(+.dia-muse-header-btn){border-top-right-radius:0;border-bottom-right-radius:0}
body.dia-minimal-ui .dia-usage-chip{height:32px;border-radius:8px;background:transparent}
body.dia-minimal-ui .dia-muse-header-btn+.dia-usage-chip,body.dia-minimal-ui .dia-usage-chip+.dia-muse-header-btn{margin-left:-5px;border-top-left-radius:0;border-bottom-left-radius:0}
body.dia-minimal-ui .dia-muse-header-btn:has(+.dia-usage-chip),body.dia-minimal-ui .dia-usage-chip:has(+.dia-muse-header-btn){border-top-right-radius:0;border-bottom-right-radius:0}
.dia-usage-dialog{background:#141414;color:#eee;border:1px solid #3a3a3a;border-radius:14px;padding:24px;max-width:480px;width:calc(100% - 40px)}
.dia-usage-dialog::backdrop{background:rgba(0,0,0,.7)}
.dia-usage-dialog h2{font-size:18px;margin:0 0 18px}.dia-usage-dialog p{font-size:13px;line-height:1.6;margin:12px 0}
.dia-usage-dialog button{background:#252525;color:#eee;border:1px solid #444;border-radius:8px;padding:10px 15px;margin:8px 8px 0 0;cursor:pointer}
@media(max-width:600px){.dia-studio-actions{flex-wrap:wrap}.dia-usage-chip{max-width:100%;font-size:10px}}

/* Anexar imagem: o ícone vinha sem tamanho (0x0) e o botão aparecia vazio */
.studio-chat-attach-btn svg{width:18px;height:18px;flex:none;display:block}
body.dia-premium-ui .studio-chat-attach-btn{background:rgba(255,255,255,.04);border:1px solid var(--dia-border,rgba(255,255,255,.1));color:#b4bbc4;cursor:pointer}
body.dia-premium-ui .studio-chat-attach-btn:hover{background:rgba(255,224,51,.10);border-color:rgba(255,224,51,.35);color:#ffe033}
/* Marca do menu: com o menu recolhido é o único jeito de expandir */
.sb-brand{cursor:pointer;border-radius:9px}
.sb-brand:hover{background:rgba(255,255,255,.06)}
.sb-brand:focus-visible{outline:2px solid rgba(255,224,51,.5);outline-offset:2px}

/* Chip "Texto separado": botão com a mesma aparência dos outros chips do campo de criar */
.dia-text-mode-chip{appearance:none;font-family:inherit;cursor:pointer}
.dia-text-mode-chip:hover{color:#c8ccd2}
.dia-text-mode-chip.is-active{color:#aab0b9}

/* Referência do Explorar: imagem menor e botões fixos no rodapé, para nunca ficarem fora da tela */
.comm-lightbox--pin{padding-top:4vh;padding-bottom:4vh}
.comm-lightbox--pin img#commLightboxImg{max-height:min(52vh,620px)}
.comm-lightbox--pin .comm-lightbox-caption{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.comm-lightbox--pin .comm-lightbox-actions{position:sticky;bottom:14px;z-index:5;padding:8px 10px;border-radius:14px;background:rgba(12,12,14,.9);backdrop-filter:blur(8px);border:1px solid rgba(255,255,255,.1)}

/* Consumo Muse: campo para informar o valor do painel da Meta */
.dia-usage-form{margin:16px 0 4px;padding:12px;border:1px solid #333;border-radius:12px;background:#101012}
.dia-usage-form label{display:grid;gap:6px;font-size:12px;color:#9aa1ab}
.dia-usage-form input{background:#1a1b1e;color:#eee;border:1px solid #3a3d44;border-radius:8px;padding:10px;font-size:14px}
.dia-usage-form button{margin-top:10px}
.dia-usage-msg{font-size:12px!important;margin:8px 0 0!important;color:#ffb4b4}

/* Imagem ampliada: a barra de ações fica ABAIXO da foto (antes ficava por cima e cobria o rodapé da imagem) */
.refchat-img-lightbox{flex-direction:column;gap:14px;padding:3vh 4vw 2vh}
.refchat-img-lightbox>img{flex:0 1 auto;min-height:0;max-width:92vw;max-height:calc(100vh - 215px)}
.refchat-img-lightbox .dia-lightbox-actions{position:static;transform:none;flex:none;max-width:min(94vw,760px)}
/* Resultado no chat: a imagem inteira cabe na área visível (descontando campo de criar e referências) */
:root{--dia-log-h:560px}
body .studio-chat-log .refine-msg--model>img{max-height:clamp(220px,calc(var(--dia-log-h) - 130px),800px);width:auto;max-width:100%;object-fit:contain}
.studio-chat-log .refine-msg--model{scroll-margin-top:12px}
