:root{
  --yellow:#f4b640;
  --yellow-dark:#d88a00;
  --blue:#1ea59d;
  --deep:#0b6f73;
  --bg:#eaf7f5;
  --line:#d7ece8;
  --text:#163d41;
  --muted:#648689;
}
*{box-sizing:border-box}
html,body{
  width:100%;height:100%;margin:0;
  font-family:Inter,system-ui,-apple-system,"Segoe UI",sans-serif;
  color:var(--text);background:var(--bg)
}
body{overflow:hidden}
button,textarea,input{font:inherit}
.chat-page{
  width:100%;height:100dvh;
  display:grid;place-items:center;
  padding:20px
}
.chat-shell{
  width:min(390px,100%);
  height:min(720px,calc(100dvh - 40px));
  display:flex;flex-direction:column;
  overflow:hidden;
  background:#fff;
  border-radius:5px 5px 16px 16px;
  box-shadow:0 12px 35px rgba(0,0,0,.18)
}
.chat-header{
  height:72px;flex:0 0 72px;
  display:flex;align-items:center;gap:10px;
  padding:10px 14px;
  color:#fff;
  background:linear-gradient(135deg,var(--deep),#1aa89f);
  box-shadow:0 2px 5px rgba(0,0,0,.08);
  z-index:5
}
.avatar,.welcome-avatar{
  overflow:hidden;display:grid;place-items:center;
  border-radius:50%;
  background:var(--yellow);color:var(--deep);
  font-weight:900
}
.avatar{
  width:42px;height:42px;flex:0 0 42px;
  border:2px solid rgba(255,255,255,.9)
}
.avatar img,.welcome-avatar img{
  width:100%;height:100%;display:block;object-fit:cover
}
.agent-heading{min-width:0;flex:1}
.agent-heading b{
  display:block;
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
  font-size:15px;color:#fff
}
.status-line{
  margin-top:3px;color:rgba(255,255,255,.88);
  font-size:11px
}
.header-action{
  width:32px;height:32px;padding:0;border:0;
  display:grid;place-items:center;
  color:#fff;background:transparent;
  cursor:pointer
}
.menu-btn{margin-left:2px}
.close-btn{margin-left:-2px}

.welcome{
  flex:1;overflow:auto;
  padding:25px 20px;
  position:relative;
  background:
    linear-gradient(180deg,rgba(9,114,116,.32),rgba(9,114,116,.18)),
    url("/uploads/bic-chat-welcome-bg.png") center center / cover no-repeat
}
.welcome-card{
  position:relative;z-index:1;
  text-align:center;margin-bottom:18px;
  padding:18px 16px;
  border-radius:18px;
  background:rgba(255,255,255,.10);
  border:1px solid rgba(255,255,255,.22);
  backdrop-filter:blur(4px);
  box-shadow:0 10px 24px rgba(4,44,46,.14)
}
.welcome-avatar{
  width:64px;height:64px;margin:0 auto 11px;
  border:2px solid rgba(255,255,255,.45);box-shadow:0 10px 25px rgba(4,44,46,.22)
}
.welcome-card h1{margin:0;font-size:22px;color:#fff;text-shadow:0 2px 10px rgba(0,0,0,.18)}
.welcome-card p{
  margin:7px auto 0;max-width:320px;
  color:rgba(255,255,255,.92);font-size:13px;line-height:1.55
}
.field{display:block;margin:12px 0;position:relative;z-index:1}
.field span{
  display:block;margin-bottom:6px;
  color:#fff;font-size:12px;font-weight:700;text-shadow:0 1px 5px rgba(0,0,0,.22)
}
.field input{
  width:100%;height:45px;padding:0 12px;
  border:1px solid rgba(255,255,255,.72);border-radius:12px;
  outline:0;background:rgba(255,255,255,.92);
  color:var(--text);box-shadow:0 6px 14px rgba(4,44,46,.06)
}
.field input:focus{
  border-color:var(--blue);
  box-shadow:0 0 0 4px rgba(30,165,157,.20)
}
.start-btn{
  width:100%;height:45px;margin-top:8px;
  border:0;border-radius:7px;
  color:#fff;background:linear-gradient(135deg,var(--deep),var(--blue));
  box-shadow:0 12px 24px rgba(11,111,115,.26);
  font-weight:800
}
.form-error{min-height:18px;margin-top:7px;color:#bf3333;font-size:12px}

.chat{
  position:relative;
  flex:1;min-height:0;
  display:flex;flex-direction:column;
  background:#fff
}
.notice{
  padding:7px 12px;
  border-bottom:1px solid #eee;
  color:#5c7f81;background:#f6fbfa;
  text-align:center;font-size:10px
}
.messages{
  flex:1;min-height:0;
  overflow-y:auto;
  padding:18px 14px 22px;
  overscroll-behavior:contain;
  scroll-behavior:smooth;
  background:#fff
}
.messages::-webkit-scrollbar{width:5px}
.messages::-webkit-scrollbar-thumb{background:#d7d7d7;border-radius:999px}
.msg{
  display:flex;align-items:flex-end;
  max-width:86%;
  margin:10px 0
}
.msg.agent{margin-right:auto}
.msg.visitor{margin-left:auto;justify-content:flex-end}
.msg.system{
  max-width:86%;
  justify-content:flex-start;
  margin:10px 0 10px 0;
  color:inherit;
  font-size:inherit;
  font-style:normal;
  text-align:left
}
.msg.system .bubble{
  background:#eef8f6;
  color:#184448;
  border-radius:5px
}
.msg.system .bubble small{color:#aaa}
.bubble{
  padding:11px 13px;
  border:0;border-radius:5px;
  color:#184448;background:#eef8f6;
  box-shadow:none;
  line-height:1.48;
  font-size:13px;
  word-break:break-word
}
.visitor .bubble{
  min-width:48px;
  color:#fff;
  background:linear-gradient(135deg,#1aa89f,#0b6f73);
  border-radius:5px
}
.bubble>b{display:none}
.bubble small{
  display:block;margin-top:5px;
  color:#aaa;font-size:9px;text-align:right
}
.visitor .bubble small{color:rgba(255,255,255,.7)}
.read{
  margin-top:1px;text-align:right;
  color:rgba(255,255,255,.7);font-size:8px
}
.msg img{max-width:min(280px,100%);display:block;border-radius:6px}
.msg a{color:inherit}
.typing{
  padding:6px 13px;
  color:#6e8a8d;background:#fff;
  font-size:10px
}
.typing span{
  width:4px;height:4px;display:inline-block;
  margin-right:2px;border-radius:50%;
  background:#999;animation:dot 1.2s infinite
}
.typing span:nth-child(2){animation-delay:.15s}
.typing span:nth-child(3){animation-delay:.3s}
@keyframes dot{
  0%,60%,100%{transform:none;opacity:.4}
  30%{transform:translateY(-3px);opacity:1}
}
.new-message{
  position:absolute;left:50%;bottom:67px;
  transform:translateX(-50%);
  z-index:7;padding:7px 12px;
  border:0;border-radius:999px;
  color:#fff;background:linear-gradient(135deg,#1aa89f,#0b6f73);
  box-shadow:0 4px 14px rgba(0,0,0,.18);
  font-size:11px
}
.emoji-panel{
  position:absolute;right:8px;bottom:62px;
  z-index:8;
  width:205px;padding:8px;
  display:grid;grid-template-columns:repeat(4,1fr);gap:4px;
  border:1px solid #e5e5e5;border-radius:10px;
  background:#fff;box-shadow:0 8px 25px rgba(0,0,0,.16)
}
.emoji-panel button{
  height:36px;border:0;border-radius:7px;
  background:transparent;cursor:pointer;font-size:20px
}
.emoji-panel button:hover{background:#f4f4f4}

.composer{
  flex:0 0 auto;
  display:flex;align-items:center;gap:3px;
  padding:8px 9px max(8px,env(safe-area-inset-bottom));
  border-top:1px solid var(--line);
  background:#fff
}
.composer textarea{
  flex:1;min-width:0;
  height:39px;min-height:39px;max-height:105px;
  padding:10px 8px;
  resize:none;outline:0;
  border:0;background:#fff;
  color:#555
}
.composer textarea::placeholder{color:#aaa}
.composer-icon,.send-btn{
  color:#fff;background:linear-gradient(135deg,#1aa89f,#0b6f73);
  box-shadow:0 6px 16px rgba(11,111,115,.22)
}
.composer-icon:hover{background:#f2f2f2}

.send-btn{
  color:#fff;background:linear-gradient(135deg,#1aa89f,#0b6f73);
  box-shadow:0 6px 16px rgba(11,111,115,.22)
}
.rating{
  margin:auto;width:100%;padding:28px 18px;text-align:center
}
.rating-icon{
  width:52px;height:52px;margin:0 auto 12px;
  display:grid;place-items:center;border-radius:50%;
  color:#fff;background:linear-gradient(135deg,#1aa89f,#0b6f73);font-size:24px
}
.rating textarea{
  width:100%;min-height:85px;padding:10px;
  border:1px solid #ddd;border-radius:8px
}
.rating #stars button{
  border:0;background:transparent;
  color:#d3d3d3;font-size:30px;cursor:pointer
}
.rating #stars button.on{color:var(--yellow)}
.hidden{display:none!important}

body.embed-mode .chat-page{padding:0}
.embed-mode .chat-shell{
  width:100%;height:100dvh;
  border-radius:0;box-shadow:none
}
@media(max-width:520px){
  .chat-page{padding:0}
  .chat-shell{
    width:100%;height:100dvh;
    border-radius:0;box-shadow:none
  }
  .chat-header{height:70px;flex-basis:70px}
  .messages{padding:16px 12px 20px}
  .msg{max-width:88%}
}


/* Gửi file và ảnh */
.upload-panel{
  display:flex;align-items:center;gap:10px;
  padding:9px 11px;
  border-top:1px solid var(--line);
  background:#fff9ed;
}
.upload-preview{
  width:48px;height:48px;flex:0 0 48px;
  display:grid;place-items:center;overflow:hidden;
  border:1px solid #e4d997;border-radius:7px;
  background:#fff;font-size:24px
}
.upload-preview img{width:100%;height:100%;object-fit:cover}
.upload-info{min-width:0;flex:1}
.upload-info b{
  display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
  font-size:12px
}
.upload-info small{display:block;margin-top:2px;color:#888;font-size:10px}
.progress{
  height:4px;margin-top:6px;overflow:hidden;
  border-radius:999px;background:#e8e8e8
}
.progress span{
  display:block;width:0;height:100%;
  border-radius:999px;background:linear-gradient(135deg,#1aa89f,#0b6f73);
  transition:width .15s linear
}
.cancel-upload{
  width:28px;height:28px;padding:0;border:0;border-radius:50%;
  color:#777;background:#eee;cursor:pointer;font-size:20px
}
.drop-overlay{
  position:absolute;inset:72px 0 56px;
  z-index:30;display:grid;place-items:center;
  border:3px dashed var(--yellow);
  color:#6d5300;background:rgba(255,250,226,.94);
  text-align:center
}
.file-card{
  min-width:200px;
  display:flex;align-items:center;gap:10px
}
.file-icon{
  width:40px;height:40px;flex:0 0 40px;
  display:grid;place-items:center;
  border-radius:7px;
  background:rgba(255,255,255,.75);
  font-size:22px
}
.file-meta{min-width:0}
.file-meta strong{
  display:block;max-width:190px;
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
  font-size:12px
}
.file-meta span{display:block;margin-top:3px;font-size:9px;opacity:.7}
.file-download{
  display:inline-block;margin-top:5px;
  color:inherit;text-decoration:underline;font-size:10px
}
.chat-image{
  display:block;max-width:min(280px,100%);max-height:320px;
  border-radius:7px;cursor:zoom-in;object-fit:cover
}
.image-viewer{
  position:fixed;inset:0;z-index:99999;
  display:grid;place-items:center;padding:20px;
  background:rgba(0,0,0,.88)
}
.image-viewer img{max-width:95vw;max-height:92vh;object-fit:contain}
.image-viewer button{
  position:absolute;right:16px;top:10px;
  width:42px;height:42px;border:0;border-radius:50%;
  color:#fff;background:rgba(255,255,255,.15);
  cursor:pointer;font-size:31px
}
.composer.dragging{background:#fffbea}


.header-action svg{
  width:22px;height:22px;
  fill:none;stroke:currentColor;stroke-width:2;
  stroke-linecap:round;stroke-linejoin:round
}
.close-btn svg{width:23px;height:23px;stroke-width:1.9}
.composer-icon svg{
  width:23px;height:23px;
  fill:none;stroke:currentColor;stroke-width:1.8;
  stroke-linecap:round;stroke-linejoin:round
}
.like-icon svg{width:24px;height:24px;stroke-width:1.7}
.attach svg{
  width:25px;height:25px;
  transform:rotate(-3deg);
  stroke-width:1.75
}
.emoji-icon svg{width:23px;height:23px}
.send-btn svg{
  width:19px;height:19px;
  fill:currentColor;stroke:none;
  transform:translateX(1px)
}
.composer-icon:hover{
  color:#555;background:#f2f2f2
}
.attach:hover{
  color:#555;background:#f2f2f2
}
.composer-icon:active,.send-btn:active{transform:scale(.94)}




/* Bản sửa giao diện PC */
@media (min-width: 900px) {
  .chat-page{
    min-height:100vh;
    padding:28px;
  }

  .chat-shell{
    width:550px;
    height:min(850px,calc(100vh - 56px));
    border-radius:14px;
    box-shadow:0 18px 48px rgba(0,0,0,.18);
  }

  .chat-header{
    height:84px;
    flex-basis:84px;
    padding:14px 18px;
    gap:13px;
  }

  .avatar{
    width:54px;
    height:54px;
    flex-basis:54px;
    border:2px solid rgba(255,255,255,.95);
  }

  .agent-heading b{font-size:17px}
  .status-line{font-size:12px}

  .header-action{
    width:38px;
    height:38px;
    border-radius:50%;
  }

  .header-action:hover{
    background:rgba(255,255,255,.10);
  }

  .notice{
    padding:9px 14px;
    font-size:12px;
  }

  .messages{
    padding:24px 20px 28px;
  }

  .msg{
    max-width:78%;
    margin:12px 0;
  }

  .bubble{
    padding:12px 15px;
    font-size:15px;
    line-height:1.5;
    border-radius:10px;
  }

  .visitor .bubble{
    border-radius:10px;
  }

  .composer{
    min-height:70px;
    gap:4px;
    padding:10px 14px 12px;
    border-top:1px solid #e5e5e5;
  }

  .composer textarea{
    height:46px;
    min-height:46px;
    max-height:120px;
    padding:13px 10px;
    font-size:15px;
  }

  .composer-icon,
  .send-btn{
    width:38px;
    height:38px;
    flex-basis:38px;
    border:none;
    border-radius:50%;
    box-shadow:none;
  }

  .composer-icon{
    color:#666;
    background:transparent;
  }

  .composer-icon:hover{
    color:var(--deep);
    background:#e9f8f5;
  }

  .send-btn{
    color:#fff;
    background:linear-gradient(135deg,#1aa89f,#0b6f73);
    box-shadow:0 8px 18px rgba(11,111,115,.24);
  }

  .send-btn:hover{
    background:#0a7f82;
  }

  .composer-icon svg,
  .header-action svg,
  .send-btn svg{
    display:block;
    fill:none;
    stroke:currentColor;
    stroke-width:1.8;
    stroke-linecap:round;
    stroke-linejoin:round;
  }

  .composer-icon svg{
    width:24px;
    height:24px;
  }

  .attach svg{
    width:25px;
    height:25px;
  }

  .header-action svg{
    width:23px;
    height:23px;
  }

  .send-btn svg{
    width:20px;
    height:20px;
    fill:currentColor;
    stroke:none;
  }

  .chat-image{
    max-width:360px;
    max-height:420px;
  }

  .file-card{
    min-width:260px;
  }

  .welcome{
    padding:32px 38px;
  }

  .field input{
    height:50px;
    font-size:15px;
  }

  .start-btn{
    height:50px;
    font-size:15px;
  }
}

@media (max-width: 899px) {
  .composer-icon svg,
  .header-action svg,
  .send-btn svg{
    display:block;
    fill:none;
    stroke:currentColor;
    stroke-width:1.8;
    stroke-linecap:round;
    stroke-linejoin:round;
  }

  .composer-icon svg{width:22px;height:22px}
  .header-action svg{width:22px;height:22px}
  .send-btn svg{
    width:18px;height:18px;
    fill:currentColor;
    stroke:none;
  }
}


/* Căn giữa icon đính kèm với các nút còn lại */
.composer{
  align-items:center;
}

.composer-icon,
.attach,
.send-btn{
  align-self:center;
  line-height:0;
}

.attach{
  display:grid;
  place-items:center;
  margin:0;
  padding:0;
  vertical-align:middle;
}

.attach svg{
  display:block;
  margin:0;
  transform:none !important;
}

.composer-icon svg,
.send-btn svg{
  display:block;
  margin:auto;
}


/* Avatar nhân viên trong nội dung hội thoại */
.msg.agent{
  max-width:88%;
  display:flex;
  align-items:flex-end;
  gap:9px;
}

.agent-message-avatar{
  width:34px;
  height:34px;
  flex:0 0 34px;
  overflow:hidden;
  display:grid;
  place-items:center;
  border:1px solid #e6e6e6;
  border-radius:50%;
  color:#9b8100;
  background:#fff;
  font-size:11px;
  font-weight:800;
  box-shadow:0 2px 7px rgba(0,0,0,.08);
}

.agent-message-avatar img{
  width:100%;
  height:100%;
  display:block;
  object-fit:cover;
}

.agent-message-avatar.avatar-hidden{
  visibility:hidden;
}

.agent-message-content{
  min-width:0;
  max-width:calc(100% - 43px);
}

.message-sender-name{
  margin:0 0 5px 2px;
  color:#777;
  font-size:11px;
  font-weight:600;
}

.msg.agent.group-follow{
  margin-top:-5px;
}

.msg.agent.group-follow .bubble{
  border-top-left-radius:8px;
}

.msg.agent.group-start{
  margin-top:16px;
}

@media (min-width:900px){
  .agent-message-avatar{
    width:40px;
    height:40px;
    flex-basis:40px;
    font-size:12px;
  }

  .agent-message-content{
    max-width:calc(100% - 49px);
  }

  .message-sender-name{
    font-size:12px;
  }
}


/* Link Preview dùng chung do Admin tổng cấu hình */
.link-preview-url{
  display:block;
  margin-bottom:7px;
  color:var(--deep)!important;
  text-decoration:none;
  word-break:break-all;
  font-size:14px;
}
.visitor .link-preview-url{color:#fff!important}
.link-preview-card{
  min-width:260px;
  max-width:410px;
  overflow:hidden;
  display:grid;
  grid-template-columns:5px minmax(0,1fr) auto;
  border-radius:10px;
  color:var(--lp-text)!important;
  background:var(--lp-bg);
  text-decoration:none!important;
}
.link-preview-border{background:var(--lp-border)}
.link-preview-copy{
  min-width:0;
  padding:12px 13px;
}
.link-preview-copy strong{
  display:block;
  margin-bottom:4px;
  color:inherit;
  font-size:14px;
}
.link-preview-copy span{
  display:block;
  overflow:hidden;
  color:inherit;
  font-size:12px;
  line-height:1.45;
  opacity:.9;
}
.link-preview-media{
  width:94px;
  min-height:90px;
  margin:8px;
  overflow:hidden;
  display:grid;
  place-items:center;
  border-radius:8px;
  background:#fff;
}
.link-preview-media img{
  width:100%;
  height:100%;
  display:block;
  object-fit:contain;
}
.message-extra-text{margin-bottom:7px}
@media(max-width:520px){
  .link-preview-card{min-width:220px;max-width:100%}
  .link-preview-media{width:76px;min-height:76px}
}

/* Fix thanh nhập tin nhắn trên điện thoại/iOS */
@media (max-width: 899px) {
  .composer{
    width:100%;
    min-height:58px;
    gap:2px;
    padding:7px 8px max(7px, env(safe-area-inset-bottom));
    overflow:visible;
  }

  .composer textarea{
    flex:1 1 auto;
    width:auto;
    min-width:0;
    height:42px;
    min-height:42px;
    max-height:96px;
    padding:10px 7px;
    font-size:16px; /* tránh Safari tự zoom */
    line-height:22px;
  }

  .composer-icon,
  .composer .attach,
  .send-btn{
    -webkit-appearance:none;
    appearance:none;
    width:36px;
    height:36px;
    min-width:36px;
    flex:0 0 36px;
    margin:0;
    padding:0;
    display:grid;
    place-items:center;
    border:0;
    border-radius:50%;
    line-height:0;
    box-shadow:none;
    cursor:pointer;
    touch-action:manipulation;
  }

  .composer-icon,
  .composer .attach{
    color:var(--deep);
    background:transparent;
  }

  .composer-icon:hover,
  .composer-icon:focus,
  .composer .attach:hover,
  .composer .attach:focus{
    color:var(--deep);
    background:#e9f8f5;
    outline:none;
  }

  .send-btn{
    color:#fff;
    background:linear-gradient(135deg,#1aa89f,#0b6f73);
    box-shadow:0 2px 6px rgba(20,123,207,.24);
  }

  .send-btn:hover,
  .send-btn:focus{
    background:#0a7f82;
    outline:none;
  }

  .composer-icon svg,
  .composer .attach svg{
    width:22px;
    height:22px;
  }

  .send-btn svg{
    width:18px;
    height:18px;
  }
}

@media (max-width: 380px) {
  .composer{gap:1px;padding-left:5px;padding-right:5px}
  .composer-icon,
  .composer .attach,
  .send-btn{
    width:33px;
    height:33px;
    min-width:33px;
    flex-basis:33px;
  }
  .composer textarea{padding-left:5px;padding-right:5px}
}

/* Căn avatar của tin nhắn chào mừng theo đầu bong bóng, tránh bị tụt xuống dưới */
.msg.system.welcome-system-message{
  align-items:flex-start;
}
.msg.system.welcome-system-message .agent-message-avatar{
  align-self:flex-start;
  margin-top:20px;
}
@media (max-width:899px){
  .msg.system.welcome-system-message .agent-message-avatar{
    margin-top:18px;
  }
}


/* BIC theme overrides */
.welcome::before{
  content:"";
  position:absolute;inset:0;
  background:linear-gradient(180deg,rgba(255,255,255,.02),rgba(255,255,255,0));
  pointer-events:none
}
.welcome > *{position:relative;z-index:1}
.welcome .field input::placeholder{color:#7f9597}
.welcome .field input{backdrop-filter:blur(4px)}
.start-btn{
  border-radius:12px;
  letter-spacing:.2px
}
.start-btn:hover{filter:brightness(1.03)}
.chat-shell .btn{
  background:linear-gradient(135deg,var(--deep),var(--blue));
  box-shadow:0 12px 24px rgba(11,111,115,.22)
}
.chat-shell .btn:hover{filter:brightness(1.03)}
.notice{border-bottom:1px solid var(--line)}
.messages{background:linear-gradient(180deg,#fcfffe 0%,#f6fbfa 100%)}
.msg.agent .bubble{border:1px solid rgba(11,111,115,.08)}
.agent-message-avatar{
  border:1px solid rgba(11,111,115,.14);
  color:var(--deep);
  background:linear-gradient(180deg,#fff,#f5fbfa)
}
.message-sender-name{color:#5f8184}
.file-icon{background:rgba(255,255,255,.86)}
.composer{background:#fff}
.composer textarea{color:var(--text)}
.composer textarea::placeholder{color:#8ba2a4}
@media (min-width: 900px){
  .welcome{padding:32px 34px}
  .welcome-card{padding:22px 20px;margin-bottom:22px}
}
@media(max-width:520px){
  .welcome{padding:22px 16px}
  .welcome-card{padding:16px 14px}
}

.message-caption{margin-top:8px;white-space:pre-wrap;line-height:1.5}
