
/* ===== Messages final layout stabilization ===== */
.messages-shell{
  min-width:0;
  min-height:560px;
  display:grid;
  grid-template-columns:minmax(250px,300px) minmax(0,1fr);
  overflow:hidden;
}
.messages-shell > *{min-width:0;min-height:0;}
.conv-list{min-width:0;overflow-x:hidden;overflow-y:auto;}
.conv-list-item{
  display:grid;
  grid-template-columns:42px minmax(0,1fr);
  align-items:center;
  min-width:0;
  gap:10px;
}
.conv-list-item > .avatar-frame-wrap,.conv-list-item > .avatar-wrap{min-width:0;}
.conv-list-item > div{min-width:0;}
.conv-title-row,.conv-preview{min-width:0;}
.conv-username,.conv-preview-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.conv-chat{min-width:0;display:flex;flex-direction:column;overflow:hidden;}
.conv-chat-header{
  display:flex;
  align-items:center;
  flex-wrap:nowrap;
  min-width:0;
  gap:8px;
  padding:10px 14px;
}
.conv-chat-header .chat-back-btn{flex:0 0 34px;}
.conv-chat-user{
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  justify-content:center;
  gap:2px;
  min-width:0;
  flex:1 1 auto;
  overflow:hidden;
}
.wianova-heading{
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:6px;
  min-width:0;
  line-height:1.15;
}
.wianova-heading > span:first-child{
  white-space:nowrap;
}
.wianova-subtitle{
  display:block;
  max-width:100%;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  line-height:1.25;
  margin-top:0;
}
.conv-chat-user > a{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.dm-header-actions{
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:6px;
  flex:0 0 auto;
}
.dm-header-action{margin:0!important;flex:0 0 auto;}
.dm-mini-action{
  display:inline-flex;align-items:center;justify-content:center;
  min-height:34px;white-space:nowrap;
}
.conv-chat-body{
  min-width:0;min-height:0;overflow:auto;
}
.msg-row{
  min-width:0;
  max-width:min(78%,760px);
}
.msg-row > div{min-width:0;max-width:100%;}
.msg-bubble{
  max-width:100%;
  overflow-wrap:anywhere;
  word-break:break-word;
}
.msg-actions{
  display:flex;align-items:center;justify-content:flex-end;
  flex-wrap:nowrap;gap:4px;
  min-width:0;
  white-space:nowrap;
}
.msg-action-btn{
  flex:0 0 auto;white-space:nowrap;
  padding:3px 5px;
}
.conv-chat-input{
  display:grid;
  grid-template-columns:38px 38px minmax(0,1fr) 38px;
  align-items:center;gap:7px;
  min-width:0;
}
.conv-chat-input > *{min-width:0;}
.conv-chat-input .msg-voice,.conv-chat-input .msg-attach,.conv-chat-input .msg-send{
  width:38px;height:38px;min-width:38px;
  display:inline-flex;align-items:center;justify-content:center;
  box-sizing:border-box;
}
.msg-attach{cursor:pointer;}
.msg-composer-wrap{min-width:0;width:100%;}
.conv-chat-input .msg-composer{
  display:block;width:100%;min-width:0;max-width:100%;
  height:40px;min-height:40px;max-height:96px;
  resize:none;box-sizing:border-box;
}
@media (max-width:900px){
  .messages-shell{grid-template-columns:1fr;min-height:0;max-height:none;border-radius:14px;}
  body.chat-list .conv-chat{display:none;}
  body.chat-open .conv-list{display:none;}
  body.chat-open .conv-chat{display:flex;min-height:0;height:100dvh;}
  body.chat-open .messages-shell{position:fixed;inset:0;z-index:60;width:100%;height:100dvh;margin:0;border-radius:0;}
  body.chat-open .content-wrap{padding:0!important;}
  body.chat-open .navbar,body.chat-open .bottom-nav,body.chat-open .footer,body.chat-open .hamburger{display:none!important;}
  .conv-chat-header{padding:9px 10px;gap:6px;flex-wrap:nowrap;}
  .conv-chat-user{flex:1 1 auto;min-width:0;}
  .conv-chat-user .avatar-frame-wrap{flex:0 0 auto;}
  .dm-header-actions{gap:4px;}
  .dm-mini-action{width:34px;min-width:34px;height:34px;padding:0;border-radius:9px;}
  .dm-mini-action span{display:none;}
  .conv-chat-body{padding:12px 10px 8px!important;}
  .msg-row{max-width:92%;}
  .msg-actions{gap:3px;}
  .msg-action-btn{font-size:10px;padding:3px 4px;}
  body.chat-open .conv-chat-input{
    position:fixed;left:0;right:0;bottom:0;
    display:grid;grid-template-columns:34px 34px minmax(0,1fr) 34px;
    gap:5px;padding:7px 8px calc(7px + env(safe-area-inset-bottom));
    background:rgba(8,11,24,.96);z-index:65;
  }
  .conv-chat-input > *{margin:0;}
  .conv-chat-input .msg-voice,.conv-chat-input .msg-attach,.conv-chat-input .msg-send{width:34px;height:34px;min-width:34px;}
  .conv-chat-input .msg-composer{height:34px;min-height:34px;max-height:72px;padding:6px 10px;border-radius:11px;}
}
@media (max-width:520px){
  .conv-chat-header{padding-left:8px;padding-right:8px;}
  .conv-chat-user > a{font-size:13px!important;}
  .dm-header-actions{gap:3px;}
  .dm-mini-action{width:32px;min-width:32px;height:32px;}
  body.chat-open .conv-chat-input{grid-template-columns:32px 32px minmax(0,1fr) 32px;gap:4px;padding-left:7px;padding-right:7px;}
  .conv-chat-input .msg-voice,.conv-chat-input .msg-attach,.conv-chat-input .msg-send{width:32px;height:32px;min-width:32px;}
  .conv-chat-input .msg-composer{height:32px;min-height:32px;padding:5px 9px;font-size:13px;}
  .msg-row{max-width:94%;} .msg-actions .msg-action-btn{font-size:9.5px;}
}

/* ===== FINAL MESSAGE OVERFLOW / ACTION BUTTON FIX ===== */
.messages-shell,
.messages-shell .conv-chat,
.messages-shell .conv-chat-body,
.messages-shell .conv-list{box-sizing:border-box;}

.messages-shell{overflow:hidden!important;}
.conv-chat{min-height:0!important;}
.conv-chat-body{
  flex:1 1 auto!important;
  min-height:0!important;
  overflow-x:hidden!important;
  overflow-y:auto!important;
  scrollbar-gutter:stable;
}
.msg-row{min-width:0!important;}
.msg-row > div{min-width:0!important;max-width:calc(100% - 0px)!important;}
.msg-bubble{min-width:0!important;max-width:100%!important;overflow:hidden!important;overflow-wrap:anywhere!important;word-break:break-word!important;}
.msg-text{overflow-wrap:anywhere!important;word-break:break-word!important;white-space:pre-wrap!important;}
.msg-media,.msg-media-image,.msg-media-video,.msg-media-audio{max-width:100%!important;}
.msg-media-image,.msg-media-video{height:auto!important;}
.msg-media-audio{width:min(260px,100%)!important;}

.msg-actions{
  display:flex!important;
  align-items:center!important;
  justify-content:flex-end!important;
  flex-wrap:wrap!important;
  gap:5px!important;
  margin-top:5px!important;
  width:100%!important;
  max-width:100%!important;
  overflow:visible!important;
}
.msg-action-btn{
  box-sizing:border-box!important;
  flex:0 0 auto!important;
  min-width:0!important;
  max-width:100%!important;
  height:25px!important;
  padding:0 8px!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  gap:4px!important;
  white-space:nowrap!important;
  line-height:1!important;
  overflow:visible!important;
}

.dm-header-actions{min-width:0!important;max-width:100%!important;}
.dm-header-action{min-width:0!important;}
.dm-mini-action{box-sizing:border-box!important;overflow:hidden!important;}

.conv-chat-input{box-sizing:border-box!important;min-width:0!important;}
.msg-composer-wrap{min-width:0!important;max-width:100%!important;}
.msg-composer{overflow-y:auto!important;overflow-x:hidden!important;}

@media (max-width:900px){
  body.chat-open .conv-chat-body{
    padding:12px 10px calc(12px + 58px + env(safe-area-inset-bottom))!important;
    overflow-x:hidden!important;
    overflow-y:auto!important;
    -webkit-overflow-scrolling:touch!important;
    overscroll-behavior-y:contain!important;
  }
  body.chat-open .conv-chat-input{
    height:auto!important;
    min-height:50px!important;
    box-sizing:border-box!important;
  }
  body.chat-open .msg-actions{
    padding-right:0!important;
  }
  body.chat-open .msg-row{max-width:94%!important;}
  body.chat-open .msg-row.mine{margin-left:auto!important;}
}

@media (max-width:520px){
  .conv-chat-header{min-width:0!important;}
  .conv-chat-user{min-width:0!important;}
  .dm-header-actions{flex:0 0 auto!important;}
  .msg-actions{gap:4px!important;}
  .msg-action-btn{height:24px!important;padding:0 7px!important;font-size:9px!important;}
  body.chat-open .conv-chat-body{
    padding-left:8px!important;
    padding-right:8px!important;
    padding-bottom:calc(12px + 56px + env(safe-area-inset-bottom))!important;
  }
}

@media (max-width:380px){
  .msg-action-btn{height:22px!important;padding:0 6px!important;font-size:8.5px!important;}
  body.chat-open .conv-chat-body{padding-bottom:calc(10px + 54px + env(safe-area-inset-bottom))!important;}
}

/* ===== WiaNova AI assistant ===== */
.wianova-avatar{
  width:42px;height:42px;min-width:42px;border-radius:14px;position:relative;
  display:block;object-fit:cover;object-position:center;
  border:1px solid rgba(255,255,255,.2);
  box-shadow:0 10px 28px rgba(34,100,255,.28),0 0 0 1px rgba(112,95,255,.12);
  background:#0b1020;
  overflow:hidden;isolation:isolate;
}
.wianova-avatar-sm{width:30px;height:30px;min-width:30px;border-radius:10px;}
.wianova-ai-badge{
  display:inline-flex;
  align-items:center;
  gap:4px;
  padding:3px 7px;
  border-radius:999px;
  color:#eaf7ff;
  background:linear-gradient(135deg,rgba(108,76,255,.24),rgba(25,182,255,.18));
  border:1px solid rgba(94,185,255,.34);
  font:700 9px/1 Inter,system-ui,sans-serif;
  letter-spacing:.15px;
  vertical-align:middle;
  white-space:nowrap;
}
.wianova-name{display:flex;align-items:center;gap:6px;min-width:0}
.wianova-conv-item{position:relative}
.wianova-conv-item.active{box-shadow:inset 0 0 0 1px rgba(91,145,255,.3),0 10px 28px rgba(48,58,140,.14)}
.wianova-heading{display:flex;align-items:center;gap:7px;font-size:14px;font-weight:800;min-width:0}
.wianova-subtitle{font-size:10px;color:var(--text-3,#8f96a8);margin-top:2px}
.wianova-send-btn{position:relative}
.wianova-send-btn::after{content:'';display:none}
[data-wianova="1"] .conv-chat-input{position:relative;z-index:100001;}
[data-wianova="1"] .msg-composer-wrap{position:relative;z-index:100002;pointer-events:auto!important;}
[data-wianova="1"] .msg-composer{position:relative;z-index:100003;display:block!important;pointer-events:auto!important;user-select:text!important;-webkit-user-select:text!important;cursor:text!important;opacity:1!important;}
[data-wianova="1"] .msg-composer{border-color:rgba(101,121,255,.34)}
[data-wianova="1"] .msg-composer:focus{border-color:rgba(112,146,255,.62);box-shadow:0 0 0 3px rgba(102,115,255,.12)}

@media (max-width:600px){
  .wianova-ai-badge{font-size:8px;padding:3px 6px}
  .wianova-heading{font-size:13px;gap:5px;line-height:1.15}
  .wianova-subtitle{font-size:9px;line-height:1.2}
}

.conv-chat-header .wianova-avatar{width:34px;height:34px;min-width:34px;border-radius:11px;font-size:11px}


/* WiaNova larger composer */
[data-wianova="1"] .msg-composer-wrap{flex:1 1 auto!important;min-width:0!important;}
[data-wianova="1"] .msg-composer{width:100%!important;min-height:58px!important;height:58px!important;max-height:140px!important;padding:14px 16px!important;line-height:1.5!important;resize:vertical!important;font-size:14px!important;border-radius:16px!important;box-sizing:border-box!important;}
[data-wianova="1"] .conv-chat-input{align-items:flex-end!important;gap:10px!important;padding:12px!important;}
[data-wianova="1"] .wianova-send-btn{width:44px!important;height:44px!important;min-width:44px!important;border-radius:13px!important;}
@media (max-width:600px){
  [data-wianova="1"] .msg-composer{min-height:54px!important;height:54px!important;max-height:120px!important;font-size:13px!important;}
  [data-wianova="1"] .conv-chat-input{padding:9px!important;gap:8px!important;}
}

/* ===== WiaNova composer FINAL layout fix =====
   The CSRF field is hidden, so WiaNova has only two visible grid items:
   composer + send button. The old 4-column DM grid left the composer in a
   38px column, making it appear as a tiny input. */
[data-wianova="1"].conv-chat-input{
  display:grid!important;
  grid-template-columns:minmax(0,1fr) 46px!important;
  align-items:end!important;
  gap:10px!important;
  padding:12px!important;
}
[data-wianova="1"] .msg-composer-wrap{
  grid-column:1!important;
  width:100%!important;
  min-width:0!important;
  max-width:none!important;
}
[data-wianova="1"] .msg-composer{
  display:block!important;
  width:100%!important;
  min-width:0!important;
  max-width:none!important;
  min-height:72px!important;
  height:72px!important;
  max-height:180px!important;
  resize:vertical!important;
  box-sizing:border-box!important;
}
[data-wianova="1"] .wianova-send-btn{
  grid-column:2!important;
  width:46px!important;
  min-width:46px!important;
  height:46px!important;
  align-self:end!important;
}
@media (max-width:900px){
  body.chat-open [data-wianova="1"].conv-chat-input{
    grid-template-columns:minmax(0,1fr) 42px!important;
    gap:8px!important;
    padding:8px!important;
  }
  [data-wianova="1"] .msg-composer{
    min-height:62px!important;
    height:62px!important;
    max-height:140px!important;
  }
  [data-wianova="1"] .wianova-send-btn{
    width:42px!important;
    min-width:42px!important;
    height:42px!important;
  }
}
@media (max-width:520px){
  body.chat-open [data-wianova="1"].conv-chat-input{
    grid-template-columns:minmax(0,1fr) 40px!important;
    gap:6px!important;
  }
  [data-wianova="1"] .msg-composer{
    min-height:58px!important;
    height:58px!important;
    font-size:13px!important;
  }
  [data-wianova="1"] .wianova-send-btn{
    width:40px!important;
    min-width:40px!important;
    height:40px!important;
  }
}


/* ===== WiaNova mobile UI v14: isolated to WiaNova chat ===== */
[data-wianova="1"] .msg-composer-wrap{flex:1 1 auto!important;min-width:0!important;}
.wianova-typing{display:inline-flex!important;align-items:center;gap:5px!important;padding:12px 14px!important;min-width:58px!important;}
.wianova-typing span{width:6px;height:6px;border-radius:50%;background:currentColor;opacity:.45;animation:wianovaDot 1s infinite ease-in-out;}
.wianova-typing span:nth-child(2){animation-delay:.14s}.wianova-typing span:nth-child(3){animation-delay:.28s}
@keyframes wianovaDot{0%,70%,100%{transform:translateY(0);opacity:.35}35%{transform:translateY(-4px);opacity:1}}
@media(max-width:900px){
  body.chat-open .conv-chat-header:has(.wianova-heading){padding:11px 12px!important;min-height:62px!important;background:linear-gradient(180deg,rgba(13,20,42,.98),rgba(8,12,27,.96))!important;}
  body.chat-open .conv-chat-header:has(.wianova-heading) .conv-chat-user{padding-left:2px!important;}
  body.chat-open .conv-chat-header:has(.wianova-heading) .wianova-avatar{width:40px!important;height:40px!important;min-width:40px!important;border-radius:13px!important;box-shadow:0 5px 20px rgba(45,110,255,.32)!important;}
  body.chat-open .conv-chat-body{padding:14px 10px 96px!important;background:linear-gradient(180deg,rgba(7,10,22,.18),rgba(8,10,20,.02))!important;}
  body.chat-open [data-wianova="1"].conv-chat-input{display:grid!important;grid-template-columns:minmax(0,1fr) 48px!important;gap:8px!important;padding:10px 10px calc(10px + env(safe-area-inset-bottom))!important;background:rgba(7,10,22,.98)!important;border-top:1px solid rgba(101,121,255,.16)!important;backdrop-filter:blur(16px)!important;}
  body.chat-open [data-wianova="1"] .msg-composer{min-height:56px!important;height:56px!important;max-height:132px!important;font-size:15px!important;line-height:1.45!important;padding:13px 14px!important;border-radius:16px!important;}
  body.chat-open [data-wianova="1"] .wianova-send-btn{width:48px!important;min-width:48px!important;height:48px!important;border-radius:15px!important;align-self:end!important;}
  body.chat-open [data-wianova="1"] .msg-composer:focus{box-shadow:0 0 0 3px rgba(102,115,255,.14)!important;}
}
@media(max-width:520px){
  body.chat-open [data-wianova="1"].conv-chat-input{grid-template-columns:minmax(0,1fr) 46px!important;padding:8px 8px calc(8px + env(safe-area-inset-bottom))!important;}
  body.chat-open [data-wianova="1"] .msg-composer{min-height:54px!important;height:54px!important;font-size:14px!important;}
  body.chat-open [data-wianova="1"] .wianova-send-btn{width:46px!important;min-width:46px!important;height:46px!important;border-radius:14px!important;}
}
