.chat-shell{
  display:grid;
  grid-template-columns:320px 1fr;
  gap:18px;
  min-height:72vh;
}
.chat-sidebar,.chat-main{min-width:0;}
.chat-card,.chat-panel-header,.chat-message-list,.chat-composer,.chat-call-card{
  background:var(--white);
  border:1px solid var(--gray);
  border-radius:16px;
  box-shadow:var(--shadow-sm, 0 6px 24px rgba(15,23,42,.06));
}
.chat-card{padding:14px;margin-bottom:14px;}
.chat-card-title{font-weight:800;margin-bottom:10px;color:var(--text);}
.chat-search input,.chat-composer textarea{
  width:100%;
  border:1px solid var(--gray);
  border-radius:12px;
  padding:12px 14px;
  background:var(--light);
  color:var(--text);
  font:inherit;
}
.chat-search input:focus,.chat-composer textarea:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px rgba(37,99,235,.12);}
.chat-list{display:flex;flex-direction:column;gap:8px;max-height:280px;overflow:auto;}
.chat-contact-item,.chat-conversation-item{
  width:100%;
  border:1px solid var(--gray);
  background:var(--light);
  border-radius:12px;
  padding:10px 12px;
  display:flex;
  align-items:center;
  gap:10px;
  text-align:right;
  cursor:pointer;
  transition:.18s ease;
}
.chat-contact-item:hover,.chat-conversation-item:hover,.chat-conversation-item.active{
  background:rgba(37,99,235,.08);
  border-color:rgba(37,99,235,.28);
}
.chat-contact-main,.chat-conversation-main{display:flex;flex-direction:column;min-width:0;flex:1;}
.chat-contact-main strong,.chat-conversation-main strong{font-size:14px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.chat-contact-main small,.chat-conversation-main small{font-size:12px;color:var(--text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.chat-user-status{
  width:10px;
  height:10px;
  border-radius:50%;
  background:#cbd5e1;
  flex-shrink:0;
  box-shadow:0 0 0 2px rgba(255,255,255,.85);
}
.chat-user-status.online{background:#10b981;}
.chat-unread-pill,.chat-nav-badge{
  min-width:20px;
  height:20px;
  border-radius:999px;
  padding:0 6px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  background:#ef4444;
  color:#fff;
  font-size:11px;
  font-weight:800;
}
.chat-nav-badge{margin-inline-start:auto;}
.chat-main{
  display:grid;
  grid-template-rows:auto 1fr auto;
  gap:14px;
}
.chat-panel-header{
  padding:16px 18px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
}
.chat-head-user{display:flex;align-items:center;gap:10px;}
.chat-head-name{font-weight:800;color:var(--text);}
.chat-head-meta,.chat-empty-sub{font-size:12px;color:var(--text-muted);}
.chat-empty-title{font-weight:800;color:var(--text);}
.chat-head-actions{display:flex;gap:8px;flex-wrap:wrap;}
.chat-message-list{
  padding:16px;
  overflow:auto;
  display:flex;
  flex-direction:column;
  gap:12px;
  min-height:420px;
  max-height:calc(72vh - 180px);
  background:
    radial-gradient(circle at top left, rgba(37,99,235,.05), transparent 34%),
    linear-gradient(180deg, rgba(248,250,252,.96), rgba(255,255,255,.95));
}
.chat-empty-state,.chat-empty-mini{
  text-align:center;
  color:var(--text-muted);
  padding:28px 16px;
}
.chat-empty-state .icon{font-size:30px;margin-bottom:8px;}
.chat-bubble-row{display:flex;}
.chat-bubble-row.mine{justify-content:flex-start;}
.chat-bubble{
  max-width:min(72%, 640px);
  padding:12px 14px;
  border-radius:16px;
  background:#fff;
  border:1px solid var(--gray);
  box-shadow:0 4px 18px rgba(15,23,42,.05);
}
.chat-bubble-row.mine .chat-bubble{
  background:linear-gradient(135deg, rgba(37,99,235,.1), rgba(37,99,235,.05));
  border-color:rgba(37,99,235,.16);
}
.chat-bubble-author{font-size:11px;font-weight:800;color:var(--text-muted);margin-bottom:6px;}
.chat-bubble-text{color:var(--text);line-height:1.7;word-break:break-word;}
.chat-bubble-time{margin-top:8px;font-size:11px;color:var(--text-muted);}
.chat-system-line{
  align-self:center;
  padding:7px 12px;
  border-radius:999px;
  background:rgba(15,23,42,.06);
  color:var(--text-muted);
  font-size:12px;
}
.chat-file-link,.chat-image-link{
  display:flex;
  flex-direction:column;
  gap:4px;
  text-decoration:none;
  color:inherit;
  border:1px solid var(--gray);
  background:rgba(248,250,252,.75);
  padding:10px;
  border-radius:12px;
  margin-top:10px;
}
.chat-image-link img{
  width:100%;
  max-height:240px;
  object-fit:cover;
  border-radius:10px;
  border:1px solid rgba(0,0,0,.06);
}
.chat-file-link small,.chat-image-link span{font-size:12px;color:var(--text-muted);}
.chat-composer{padding:12px 14px;}
.chat-attachment-row{
  margin-bottom:10px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  font-size:12px;
  color:var(--text-muted);
}
.chat-composer-controls{display:grid;grid-template-columns:1fr auto;gap:10px;align-items:end;}
.chat-composer-actions{display:flex;gap:8px;flex-wrap:wrap;}
.chat-float-card{
  position:fixed;
  left:22px;
  bottom:22px;
  width:min(360px, calc(100vw - 44px));
  z-index:1200;
  background:var(--white);
  border:1px solid var(--gray);
  border-radius:16px;
  box-shadow:0 24px 70px rgba(15,23,42,.25);
  padding:16px;
}
.chat-float-title{font-weight:800;color:var(--text);margin-bottom:8px;}
.chat-float-text{font-size:13px;color:var(--text-muted);line-height:1.6;}
.chat-float-actions{display:flex;gap:10px;margin-top:14px;}
.chat-call-modal{
  position:fixed;
  inset:0;
  background:rgba(2,6,23,.62);
  z-index:1250;
  display:none;
  align-items:center;
  justify-content:center;
  padding:20px;
}
.chat-call-card{
  width:min(980px, 96vw);
  padding:18px;
  background:#0f172a;
  color:#fff;
  border-color:rgba(255,255,255,.08);
}
.chat-call-top{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;margin-bottom:14px;}
.chat-call-title{font-size:20px;font-weight:800;}
.chat-call-status{font-size:13px;color:rgba(255,255,255,.72);}
.chat-call-videos{
  display:grid;
  grid-template-columns:1fr 280px;
  gap:14px;
}
.chat-video-box{
  border-radius:16px;
  overflow:hidden;
  background:#020617;
  min-height:260px;
  position:relative;
  border:1px solid rgba(255,255,255,.08);
}
.chat-video-box-local{min-height:180px;}
.chat-video-box video{
  width:100%;
  height:100%;
  object-fit:cover;
  background:#020617;
}
.chat-video-label{
  position:absolute;
  top:10px;
  right:10px;
  z-index:2;
  padding:5px 10px;
  border-radius:999px;
  background:rgba(15,23,42,.72);
  font-size:12px;
}
.chat-call-actions{display:flex;justify-content:center;margin-top:16px;}

body.dark #page-chat .chat-card,
body.dark #page-chat .chat-panel-header,
body.dark #page-chat .chat-message-list,
body.dark #page-chat .chat-composer{
  background:rgba(15,23,42,.84);
  border-color:rgba(148,163,184,.16);
}
body.dark #page-chat .chat-contact-item,
body.dark #page-chat .chat-conversation-item,
body.dark #page-chat .chat-search input,
body.dark #page-chat .chat-composer textarea,
body.dark #page-chat .chat-bubble,
body.dark #page-chat .chat-file-link,
body.dark #page-chat .chat-image-link{
  background:rgba(15,23,42,.72);
  border-color:rgba(148,163,184,.16);
  color:#e2e8f0;
}
body.dark #page-chat .chat-contact-main strong,
body.dark #page-chat .chat-conversation-main strong,
body.dark #page-chat .chat-head-name,
body.dark #page-chat .chat-empty-title,
body.dark #page-chat .chat-bubble-text{
  color:#f8fafc;
}
body.dark #page-chat .chat-contact-main small,
body.dark #page-chat .chat-conversation-main small,
body.dark #page-chat .chat-head-meta,
body.dark #page-chat .chat-empty-sub,
body.dark #page-chat .chat-bubble-author,
body.dark #page-chat .chat-bubble-time,
body.dark #page-chat .chat-file-link small,
body.dark #page-chat .chat-image-link span{
  color:#94a3b8;
}
body.dark #page-chat .chat-system-line{background:rgba(148,163,184,.12);color:#cbd5e1;}

@media (max-width: 980px){
  .chat-shell{grid-template-columns:1fr;}
  .chat-call-videos{grid-template-columns:1fr;}
  .chat-message-list{max-height:none;min-height:360px;}
}

/* Modern chat refresh */
#page-chat .chat-card,
#page-chat .chat-panel-header,
#page-chat .chat-message-list,
#page-chat .chat-composer{
  border-radius:22px;
  border-color:rgba(148,163,184,.18);
  box-shadow:0 14px 40px rgba(15,23,42,.08);
}

#page-chat .chat-card{
  padding:16px;
  background:linear-gradient(180deg, rgba(255,255,255,.98), rgba(248,250,252,.98));
}

#page-chat .chat-contact-item,
#page-chat .chat-conversation-item{
  border:none;
  border-radius:18px;
  padding:12px 14px;
  background:linear-gradient(180deg, rgba(248,250,252,.9), rgba(241,245,249,.92));
  box-shadow:inset 0 0 0 1px rgba(148,163,184,.14);
}

#page-chat .chat-contact-item:hover,
#page-chat .chat-conversation-item:hover,
#page-chat .chat-conversation-item.active{
  background:linear-gradient(180deg, rgba(220,252,231,.96), rgba(209,250,229,.96));
  box-shadow:
    inset 0 0 0 1px rgba(16,185,129,.18),
    0 10px 22px rgba(16,185,129,.12);
  transform:translateY(-1px);
}

#page-chat .chat-avatar{
  width:44px;
  height:44px;
  border-radius:50%;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  position:relative;
  flex-shrink:0;
  font-weight:800;
  font-size:14px;
  color:#fff;
  background:linear-gradient(135deg, #0f766e, #14b8a6);
  box-shadow:0 8px 22px rgba(20,184,166,.22);
}

#page-chat .chat-avatar.lg{
  width:52px;
  height:52px;
  font-size:16px;
}

#page-chat .chat-avatar-status{
  position:absolute;
  left:1px;
  bottom:1px;
  width:11px;
  height:11px;
  border-radius:50%;
  background:#94a3b8;
  box-shadow:0 0 0 3px rgba(255,255,255,.95);
}

#page-chat .chat-avatar.online .chat-avatar-status{
  background:#22c55e;
}

#page-chat .chat-user-status{
  display:none;
}

#page-chat .chat-conversation-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}

#page-chat .chat-conversation-stamp{
  flex-shrink:0;
  font-size:11px;
}

#page-chat .chat-panel-header{
  padding:16px 20px;
  background:linear-gradient(180deg, rgba(255,255,255,.98), rgba(248,250,252,.98));
}

#page-chat .chat-message-list{
  padding:18px;
  background:
    radial-gradient(circle at top right, rgba(16,185,129,.08), transparent 22%),
    radial-gradient(circle at bottom left, rgba(59,130,246,.08), transparent 24%),
    linear-gradient(180deg, #f8fafc, #f1f5f9);
}

#page-chat .chat-bubble-row{
  display:flex !important;
  justify-content:flex-start !important;
}

#page-chat .chat-bubble-row.mine{
  justify-content:flex-end !important;
}

#page-chat .chat-bubble-row:not(.mine){
  justify-content:flex-start !important;
}

#page-chat .chat-bubble{
  max-width:min(72%, 640px);
  padding:10px 12px 8px;
  border-radius:20px;
  box-shadow:0 10px 24px rgba(15,23,42,.08);
}

#page-chat .chat-bubble.theirs{
  background:linear-gradient(180deg, #f1f5f9, #e2e8f0) !important;
  border:1px solid rgba(148,163,184,.22) !important;
  border-top-right-radius:20px !important;
  border-top-left-radius:8px !important;
  color:#0f172a !important;
}

#page-chat .chat-bubble.mine{
  background:linear-gradient(180deg, #dcfce7, #bbf7d0) !important;
  border:1px solid rgba(34,197,94,.18) !important;
  border-top-left-radius:20px !important;
  border-top-right-radius:8px !important;
  color:#14532d !important;
}

#page-chat .chat-bubble-author{
  margin-bottom:4px;
}

#page-chat .chat-bubble-time{
  margin-top:6px;
  text-align:left;
  opacity:.8;
}

#page-chat .chat-file-link,
#page-chat .chat-image-link{
  border-radius:16px;
  background:rgba(255,255,255,.62);
  border:1px solid rgba(148,163,184,.16);
}

#page-chat .chat-bubble.mine .chat-file-link,
#page-chat .chat-bubble.mine .chat-image-link{
  background:rgba(255,255,255,.42);
  border-color:rgba(34,197,94,.16);
}

#page-chat .chat-composer{
  padding:12px;
  background:linear-gradient(180deg, rgba(255,255,255,.98), rgba(248,250,252,.98));
}

#page-chat .chat-composer textarea{
  border:none;
  background:#f8fafc;
  box-shadow:inset 0 0 0 1px rgba(148,163,184,.18);
}

#page-chat .chat-composer-controls{
  grid-template-columns:1fr auto;
  gap:12px;
}

#page-chat .chat-composer-actions{
  gap:10px;
  align-items:center;
}

#page-chat .chat-voice-player{
  display:flex;
  align-items:center;
  gap:10px;
  margin-top:8px;
  padding:10px 12px;
  border-radius:18px;
  background:rgba(255,255,255,.62);
  border:1px solid rgba(148,163,184,.14);
}

#page-chat .chat-voice-player.mine{
  background:rgba(255,255,255,.48);
  border-color:rgba(34,197,94,.16);
}

#page-chat .chat-voice-toggle{
  width:42px;
  height:42px;
  border:none;
  border-radius:50%;
  background:linear-gradient(135deg, #10b981, #14b8a6);
  color:#fff;
  font-size:16px;
  font-weight:800;
  cursor:pointer;
  flex-shrink:0;
  box-shadow:0 8px 20px rgba(16,185,129,.24);
}

#page-chat .chat-voice-player.theirs .chat-voice-toggle{
  background:linear-gradient(135deg, #0f172a, #334155);
  box-shadow:0 8px 20px rgba(15,23,42,.18);
}

#page-chat .chat-voice-body{
  min-width:0;
  flex:1;
  display:flex;
  flex-direction:column;
  gap:8px;
}

#page-chat .chat-voice-wave{
  height:22px;
  border-radius:999px;
  background:
    radial-gradient(circle, rgba(15,23,42,.18) 30%, transparent 31%) 0 50%/12px 12px repeat-x,
    linear-gradient(90deg, rgba(15,23,42,.06), rgba(15,23,42,.02));
  opacity:.95;
}

#page-chat .chat-voice-player.mine .chat-voice-wave{
  background:
    radial-gradient(circle, rgba(22,101,52,.26) 30%, transparent 31%) 0 50%/12px 12px repeat-x,
    linear-gradient(90deg, rgba(22,163,74,.08), rgba(22,163,74,.03));
}

#page-chat .chat-voice-progress{
  width:100%;
  margin:0;
  appearance:none;
  background:transparent;
  cursor:pointer;
}

#page-chat .chat-voice-progress::-webkit-slider-runnable-track{
  height:4px;
  border-radius:999px;
  background:rgba(148,163,184,.35);
}

#page-chat .chat-voice-progress::-webkit-slider-thumb{
  -webkit-appearance:none;
  width:14px;
  height:14px;
  margin-top:-5px;
  border:none;
  border-radius:50%;
  background:#10b981;
  box-shadow:0 2px 8px rgba(16,185,129,.35);
}

#page-chat .chat-voice-progress::-moz-range-track{
  height:4px;
  border-radius:999px;
  background:rgba(148,163,184,.35);
}

#page-chat .chat-voice-progress::-moz-range-thumb{
  width:14px;
  height:14px;
  border:none;
  border-radius:50%;
  background:#10b981;
  box-shadow:0 2px 8px rgba(16,185,129,.35);
}

#page-chat .chat-voice-meta{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  font-size:12px;
  color:var(--text-muted);
}

#page-chat .chat-voice-label{
  font-weight:700;
  color:var(--text);
}

#page-chat .chat-voice-audio{
  display:none;
}

body.dark #page-chat .chat-card,
body.dark #page-chat .chat-panel-header,
body.dark #page-chat .chat-message-list,
body.dark #page-chat .chat-composer{
  background:linear-gradient(180deg, rgba(15,23,42,.92), rgba(15,23,42,.88));
}

body.dark #page-chat .chat-contact-item,
body.dark #page-chat .chat-conversation-item{
  background:linear-gradient(180deg, rgba(15,23,42,.72), rgba(15,23,42,.84));
  box-shadow:inset 0 0 0 1px rgba(148,163,184,.12);
}

body.dark #page-chat .chat-contact-item:hover,
body.dark #page-chat .chat-conversation-item:hover,
body.dark #page-chat .chat-conversation-item.active{
  background:linear-gradient(180deg, rgba(6,95,70,.88), rgba(4,120,87,.92));
}

body.dark #page-chat .chat-message-list{
  background:
    radial-gradient(circle at top right, rgba(16,185,129,.12), transparent 22%),
    radial-gradient(circle at bottom left, rgba(59,130,246,.12), transparent 24%),
    linear-gradient(180deg, rgba(2,6,23,.96), rgba(15,23,42,.96));
}

body.dark #page-chat .chat-bubble.theirs{
  background:linear-gradient(180deg, rgba(15,23,42,.92), rgba(30,41,59,.92)) !important;
  border-color:rgba(148,163,184,.14) !important;
}

body.dark #page-chat .chat-bubble.mine{
  background:linear-gradient(180deg, rgba(5,150,105,.9), rgba(6,95,70,.94)) !important;
  border-color:rgba(16,185,129,.18) !important;
}

body.dark #page-chat .chat-file-link,
body.dark #page-chat .chat-image-link,
body.dark #page-chat .chat-voice-player{
  background:rgba(15,23,42,.55);
  border-color:rgba(148,163,184,.14);
}

body.dark #page-chat .chat-bubble.mine .chat-file-link,
body.dark #page-chat .chat-bubble.mine .chat-image-link,
body.dark #page-chat .chat-bubble.mine .chat-voice-player{
  background:rgba(255,255,255,.08);
}

body.dark #page-chat .chat-voice-label{
  color:#f8fafc;
}

@media (max-width: 980px){
  #page-chat .chat-bubble{
    max-width:88%;
  }

  #page-chat .chat-conversation-row{
    flex-direction:column;
    align-items:flex-start;
  }
}

/* Final fixes: dark mode text + correct conversation sides */
#page-chat .chat-message-list{
  direction:ltr !important;
}

#page-chat .chat-bubble-row{
  width:100%;
  direction:ltr !important;
}

#page-chat .chat-bubble-row.mine{
  justify-content:flex-end !important;
}

#page-chat .chat-bubble-row:not(.mine){
  justify-content:flex-start !important;
}

#page-chat .chat-bubble{
  direction:rtl;
  text-align:right;
}

#page-chat .chat-bubble.mine{
  margin-left:auto;
  margin-right:0;
}

#page-chat .chat-bubble.theirs{
  margin-right:auto;
  margin-left:0;
}

#page-chat .chat-bubble-text{
  color:inherit;
  unicode-bidi:plaintext;
}

#page-chat .chat-bubble-author{
  color:inherit;
}

#page-chat .chat-bubble-time{
  direction:ltr;
  text-align:left;
}

#page-chat .chat-composer textarea,
#page-chat .chat-search input{
  color:var(--text);
  caret-color:var(--text);
}

#page-chat .chat-composer textarea::placeholder,
#page-chat .chat-search input::placeholder{
  color:var(--text-muted);
}

body.dark #page-chat .chat-card,
body.dark #page-chat .chat-panel-header,
body.dark #page-chat .chat-message-list,
body.dark #page-chat .chat-composer,
html[data-theme="dark"] #page-chat .chat-card,
html[data-theme="dark"] #page-chat .chat-panel-header,
html[data-theme="dark"] #page-chat .chat-message-list,
html[data-theme="dark"] #page-chat .chat-composer{
  background:linear-gradient(180deg, rgba(15,23,42,.92), rgba(15,23,42,.88)) !important;
  border-color:rgba(148,163,184,.16) !important;
}

body.dark #page-chat .chat-contact-item,
body.dark #page-chat .chat-conversation-item,
body.dark #page-chat .chat-search input,
body.dark #page-chat .chat-composer textarea,
body.dark #page-chat .chat-file-link,
body.dark #page-chat .chat-image-link,
body.dark #page-chat .chat-voice-player,
html[data-theme="dark"] #page-chat .chat-contact-item,
html[data-theme="dark"] #page-chat .chat-conversation-item,
html[data-theme="dark"] #page-chat .chat-search input,
html[data-theme="dark"] #page-chat .chat-composer textarea,
html[data-theme="dark"] #page-chat .chat-file-link,
html[data-theme="dark"] #page-chat .chat-image-link,
html[data-theme="dark"] #page-chat .chat-voice-player{
  background:rgba(15,23,42,.72) !important;
  border-color:rgba(148,163,184,.16) !important;
  color:#e2e8f0 !important;
}

body.dark #page-chat .chat-contact-main strong,
body.dark #page-chat .chat-conversation-main strong,
body.dark #page-chat .chat-head-name,
body.dark #page-chat .chat-empty-title,
html[data-theme="dark"] #page-chat .chat-contact-main strong,
html[data-theme="dark"] #page-chat .chat-conversation-main strong,
html[data-theme="dark"] #page-chat .chat-head-name,
html[data-theme="dark"] #page-chat .chat-empty-title{
  color:#f8fafc !important;
}

body.dark #page-chat .chat-contact-main small,
body.dark #page-chat .chat-conversation-main small,
body.dark #page-chat .chat-head-meta,
body.dark #page-chat .chat-empty-sub,
body.dark #page-chat .chat-file-link small,
body.dark #page-chat .chat-image-link span,
body.dark #page-chat .chat-composer textarea::placeholder,
body.dark #page-chat .chat-search input::placeholder,
html[data-theme="dark"] #page-chat .chat-contact-main small,
html[data-theme="dark"] #page-chat .chat-conversation-main small,
html[data-theme="dark"] #page-chat .chat-head-meta,
html[data-theme="dark"] #page-chat .chat-empty-sub,
html[data-theme="dark"] #page-chat .chat-file-link small,
html[data-theme="dark"] #page-chat .chat-image-link span,
html[data-theme="dark"] #page-chat .chat-composer textarea::placeholder,
html[data-theme="dark"] #page-chat .chat-search input::placeholder{
  color:#94a3b8 !important;
}

body.dark #page-chat .chat-bubble.theirs,
html[data-theme="dark"] #page-chat .chat-bubble.theirs{
  background:linear-gradient(180deg, rgba(31,41,55,.96), rgba(17,24,39,.96)) !important;
  border-color:rgba(148,163,184,.18) !important;
  color:#f8fafc !important;
}

body.dark #page-chat .chat-bubble.mine,
html[data-theme="dark"] #page-chat .chat-bubble.mine{
  background:linear-gradient(180deg, rgba(5,150,105,.9), rgba(6,95,70,.94)) !important;
  border-color:rgba(16,185,129,.18) !important;
  color:#ecfdf5 !important;
}

body.dark #page-chat .chat-bubble.theirs .chat-bubble-text,
body.dark #page-chat .chat-bubble.theirs .chat-bubble-author,
body.dark #page-chat .chat-bubble.theirs .chat-bubble-time,
html[data-theme="dark"] #page-chat .chat-bubble.theirs .chat-bubble-text,
html[data-theme="dark"] #page-chat .chat-bubble.theirs .chat-bubble-author,
html[data-theme="dark"] #page-chat .chat-bubble.theirs .chat-bubble-time{
  color:#f8fafc !important;
}

body.dark #page-chat .chat-bubble.mine .chat-bubble-text,
body.dark #page-chat .chat-bubble.mine .chat-bubble-author,
body.dark #page-chat .chat-bubble.mine .chat-bubble-time,
html[data-theme="dark"] #page-chat .chat-bubble.mine .chat-bubble-text,
html[data-theme="dark"] #page-chat .chat-bubble.mine .chat-bubble-author,
html[data-theme="dark"] #page-chat .chat-bubble.mine .chat-bubble-time{
  color:#ecfdf5 !important;
}

#page-chat .chat-bubble-meta{
  margin-top:8px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  flex-wrap:wrap;
}

#page-chat .chat-bubble-edited{
  font-size:11px;
  color:var(--text-muted);
  opacity:.9;
}

#page-chat .chat-editing-row{
  margin-bottom:10px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid rgba(245,158,11,.22);
  background:rgba(254,243,199,.62);
  color:#92400e;
  font-size:12px;
  font-weight:700;
}

#chat-fab{
  position:fixed;
  left:18px;
  bottom:18px;
  z-index:1180;
  display:inline-flex;
  align-items:center;
  gap:10px;
  border:none;
  border-radius:999px;
  padding:14px 18px;
  background:linear-gradient(135deg, #10b981, #0f766e);
  color:#fff;
  font:inherit;
  font-weight:800;
  cursor:pointer;
  box-shadow:0 18px 44px rgba(15,118,110,.28);
}

#chat-fab.active{
  background:linear-gradient(135deg, #0f172a, #1e293b);
}

.chat-fab-icon{
  font-size:20px;
  line-height:1;
}

.chat-fab-label{
  font-size:13px;
}

.chat-fab-badge{
  min-width:22px;
  height:22px;
  padding:0 7px;
  border-radius:999px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  background:#ef4444;
  color:#fff;
  font-size:11px;
  font-weight:800;
}

#chat-float-backdrop{
  position:fixed;
  inset:0;
  z-index:1170;
  background:rgba(15,23,42,.42);
  backdrop-filter:blur(2px);
}

#page-chat.chat-floating-open{
  display:block !important;
  position:fixed;
  top:16px;
  right:16px;
  left:16px;
  bottom:16px;
  z-index:1175;
  margin:0;
  padding:18px;
  border-radius:26px;
  background:linear-gradient(180deg, rgba(255,255,255,.88), rgba(248,250,252,.94));
  border:1px solid rgba(148,163,184,.18);
  box-shadow:0 28px 90px rgba(15,23,42,.22);
  overflow:hidden;
}

body.dark #page-chat.chat-floating-open,
html[data-theme="dark"] #page-chat.chat-floating-open{
  background:linear-gradient(180deg, rgba(2,6,23,.84), rgba(15,23,42,.95));
  border-color:rgba(148,163,184,.18);
}

#page-chat.chat-floating-open .page-header{
  margin-bottom:14px;
}

#page-chat.chat-floating-open .chat-shell{
  min-height:calc(100% - 72px);
  max-height:calc(100% - 72px);
}

#page-chat .chat-floating-only{
  display:none;
}

#page-chat.chat-floating-open .chat-floating-only{
  display:inline-flex;
}

#chat-message-menu{
  position:fixed;
  z-index:1300;
  min-width:190px;
  padding:8px;
  border-radius:16px;
  border:1px solid rgba(148,163,184,.22);
  background:rgba(255,255,255,.98);
  box-shadow:0 18px 40px rgba(15,23,42,.18);
}

#chat-message-menu button{
  width:100%;
  border:none;
  background:transparent;
  color:var(--text);
  text-align:right;
  padding:11px 12px;
  border-radius:12px;
  font:inherit;
  font-size:13px;
  font-weight:700;
  cursor:pointer;
}

#chat-message-menu button:hover{
  background:rgba(15,23,42,.05);
}

#chat-message-menu button.danger{
  color:#dc2626;
}

body.dark #chat-message-menu,
html[data-theme="dark"] #chat-message-menu{
  background:rgba(15,23,42,.98);
  border-color:rgba(148,163,184,.18);
}

body.dark #chat-message-menu button,
html[data-theme="dark"] #chat-message-menu button{
  color:#f8fafc;
}

body.dark #chat-message-menu button:hover,
html[data-theme="dark"] #chat-message-menu button:hover{
  background:rgba(148,163,184,.12);
}

body.dark #page-chat .chat-editing-row,
html[data-theme="dark"] #page-chat .chat-editing-row{
  background:rgba(146,64,14,.16);
  border-color:rgba(245,158,11,.24);
  color:#fde68a;
}

@media (max-width: 768px){
  #chat-fab{
    left:12px;
    right:12px;
    bottom:82px;
    justify-content:center;
    padding:14px 16px;
    border-radius:18px;
  }

  #page-chat.chat-floating-open{
    inset:0;
    padding:10px 10px 86px;
    border-radius:0;
    max-height:100dvh;
  }

  #page-chat.chat-floating-open .page-header{
    margin-bottom:10px;
  }

  #page-chat.chat-floating-open .page-title{
    font-size:18px;
  }

  #page-chat.chat-floating-open .page-subtitle{
    font-size:12px;
  }

  #page-chat.chat-floating-open .chat-shell{
    grid-template-columns:1fr;
    gap:10px;
    min-height:calc(100dvh - 180px);
    max-height:calc(100dvh - 180px);
  }

  #page-chat.chat-floating-open .chat-sidebar{
    display:grid;
    grid-template-columns:1fr;
    gap:10px;
    max-height:38vh;
    overflow:auto;
    padding-inline-end:2px;
  }

  #page-chat.chat-floating-open .chat-card{
    margin-bottom:0;
  }

  #page-chat.chat-floating-open .chat-list{
    max-height:150px;
  }

  #page-chat.chat-floating-open .chat-main{
    min-height:0;
  }

  #page-chat.chat-floating-open .chat-message-list{
    min-height:220px;
    max-height:none;
    padding:12px;
  }

  #page-chat.chat-floating-open .chat-bubble{
    max-width:92%;
  }

  #page-chat.chat-floating-open .chat-composer{
    padding:10px;
  }

  #page-chat.chat-floating-open .chat-composer-controls{
    grid-template-columns:1fr;
    gap:8px;
  }

  #page-chat.chat-floating-open .chat-composer-actions{
    width:100%;
    justify-content:space-between;
  }

  #page-chat.chat-floating-open .chat-composer-actions .btn{
    flex:1;
    justify-content:center;
  }
}

/* WhatsApp-like status + mobile flow */
#page-chat .chat-conversation-preview-line{
  display:flex;
  align-items:center;
  gap:6px;
  min-width:0;
}

#page-chat .chat-conversation-preview-line span:last-child{
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

#page-chat .chat-conversation-status,
#page-chat .chat-bubble-status{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:12px;
  font-weight:900;
  letter-spacing:-1px;
  color:#64748b;
  line-height:1;
  flex-shrink:0;
}

#page-chat .chat-conversation-status.read,
#page-chat .chat-bubble-status.read{
  color:#0ea5e9;
}

#page-chat .chat-bubble-time-wrap{
  display:inline-flex;
  align-items:center;
  gap:6px;
  direction:ltr;
}

#page-chat .chat-mobile-back{
  display:none;
  width:38px;
  height:38px;
  border:none;
  border-radius:50%;
  background:rgba(15,23,42,.06);
  color:var(--text);
  font:inherit;
  font-size:18px;
  font-weight:900;
  cursor:pointer;
  flex-shrink:0;
}

body.dark #page-chat .chat-mobile-back,
html[data-theme="dark"] #page-chat .chat-mobile-back{
  background:rgba(148,163,184,.14);
  color:#f8fafc;
}

@media (max-width: 768px){
  #chat-fab,
  #chat-float-backdrop{
    display:none !important;
  }

  #page-chat{
    padding:0 !important;
    height:100%;
  }

  #page-chat .page-header{
    display:none;
  }

  #page-chat .chat-shell{
    display:block;
    min-height:calc(100dvh - 86px);
    height:calc(100dvh - 86px);
  }

  #page-chat .chat-sidebar,
  #page-chat .chat-main{
    height:100%;
  }

  #page-chat .chat-sidebar{
    display:block;
    padding:0;
    overflow:hidden;
  }

  #page-chat .chat-card{
    margin:0;
    border-radius:0;
    border:none;
    box-shadow:none;
    background:transparent;
    padding:0;
  }

  #page-chat .chat-card:first-child{
    padding:12px 12px 8px;
    background:var(--white);
    border-bottom:1px solid rgba(148,163,184,.12);
  }

  #page-chat .chat-card:last-child{
    padding:0;
    background:var(--white);
  }

  #page-chat .chat-card-title{
    padding:0 0 10px;
    margin:0;
    font-size:14px;
  }

  #page-chat .chat-search{
    padding-bottom:4px;
  }

  #page-chat .chat-search input{
    border-radius:999px;
    padding:12px 16px;
    background:#f1f5f9;
    border:none;
    box-shadow:inset 0 0 0 1px rgba(148,163,184,.14);
  }

  #page-chat .chat-list{
    max-height:none;
    height:calc(100dvh - 190px);
    overflow:auto;
    gap:0;
    background:var(--white);
  }

  #page-chat .chat-contact-item,
  #page-chat .chat-conversation-item{
    border:none;
    border-radius:0;
    background:var(--white);
    box-shadow:none;
    padding:12px 14px;
    border-bottom:1px solid rgba(148,163,184,.12);
  }

  #page-chat .chat-contact-item:hover,
  #page-chat .chat-conversation-item:hover,
  #page-chat .chat-conversation-item.active{
    transform:none;
    background:rgba(15,118,110,.06);
    box-shadow:none;
  }

  #page-chat .chat-conversation-row{
    flex-direction:row;
    align-items:center;
  }

  #page-chat .chat-main{
    display:none;
    grid-template-rows:auto 1fr auto;
    background:#efeae2;
  }

  #page-chat.chat-mobile-show-list .chat-sidebar{
    display:block;
  }

  #page-chat.chat-mobile-show-list .chat-main{
    display:none;
  }

  #page-chat.chat-mobile-show-chat .chat-sidebar{
    display:none;
  }

  #page-chat.chat-mobile-show-chat .chat-main{
    display:grid;
  }

  #page-chat .chat-panel-header{
    border-radius:0;
    border:none;
    box-shadow:none;
    padding:10px 12px;
    background:linear-gradient(180deg, #0f766e, #0d9488);
    color:#fff;
    position:relative;
    top:auto;
    z-index:auto;
  }

  #page-chat .chat-panel-header .chat-head-name,
  #page-chat .chat-panel-header .chat-head-meta{
    color:#fff !important;
  }

  #page-chat .chat-mobile-back{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    background:rgba(255,255,255,.18);
    color:#fff;
  }

  #page-chat .chat-head-actions .btn{
    min-width:auto;
    padding:8px 10px;
  }

  #page-chat .chat-message-list{
    min-height:0;
    max-height:none;
    height:100%;
    border:none;
    border-radius:0;
    box-shadow:none;
    padding:14px 10px;
    background:
      radial-gradient(circle at top right, rgba(16,185,129,.08), transparent 22%),
      linear-gradient(180deg, #efeae2, #e8e1d7);
  }

  #page-chat .chat-bubble{
    max-width:88%;
    border-radius:16px;
  }

  #page-chat .chat-composer{
    border-radius:0;
    border:none;
    box-shadow:none;
    padding:8px 10px calc(env(safe-area-inset-bottom, 0px) + 8px);
    background:#f0f2f5;
    position:relative;
    bottom:auto;
    z-index:auto;
  }

  #page-chat .chat-composer-controls{
    display:grid;
    grid-template-columns:1fr auto;
    gap:8px;
    align-items:end;
  }

  #page-chat .chat-composer textarea{
    min-height:46px;
    max-height:120px;
    border-radius:24px;
    padding:12px 16px;
    background:#fff;
    box-shadow:inset 0 0 0 1px rgba(148,163,184,.14);
  }

  #page-chat .chat-composer-actions{
    flex-wrap:nowrap;
    gap:6px;
  }

  #page-chat .chat-composer-actions .btn:not(#chat-send-btn){
    border-radius:50%;
    width:44px;
    height:44px;
    min-width:44px;
    padding:0;
    justify-content:center;
    font-size:0;
    position:relative;
  }

  #page-chat #chat-file-btn::before,
  #page-chat #chat-record-btn::before{
    content:'';
    position:absolute;
    inset:0;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:18px;
  }

  #page-chat #chat-file-btn::before{content:'📎';}
  #page-chat #chat-record-btn::before{content:'🎤';}
  #page-chat #chat-record-btn.btn-danger::before{content:'⏹';}

  #page-chat #chat-send-btn{
    width:auto;
    min-width:58px;
    border-radius:999px;
    padding:0 16px;
    font-size:13px;
  }

  #page-chat .chat-editing-row,
  #page-chat .chat-attachment-row{
    border-radius:14px;
    background:#fff;
    margin-bottom:8px;
  }

  #page-chat.chat-floating-open{
    padding:0 0 86px;
    background:#fff;
  }

  #page-chat.chat-floating-open .chat-shell{
    height:calc(100dvh - 86px);
    min-height:calc(100dvh - 86px);
    max-height:none;
  }

  #page-chat.chat-floating-open .chat-sidebar,
  #page-chat.chat-floating-open .chat-main{
    max-height:none;
  }

  #page-chat.chat-floating-open .page-header{
    display:none;
  }
}
