/* Khung chat hai cột: bên trái là chức năng, bên phải là hội thoại và ô nhập. */
.agro-chat{--chat-green:#24743b;--chat-border:#d9e5dc;display:grid;grid-template-columns:260px minmax(0,1fr);grid-template-rows:minmax(0,1fr);height:min(720px,calc(100dvh - 140px));min-height:440px;min-width:0;background:#fff;color:#173d29;font:14px/1.5 'Segoe UI',Arial,sans-serif;border:1px solid var(--chat-border);border-radius:16px;overflow:hidden}
.agro-chat [hidden]{display:none!important}
.agro-chat button,.agro-chat textarea{font:inherit;box-sizing:border-box}
.agro-chat button{border:1px solid var(--chat-border);border-radius:8px;padding:8px 12px;background:#fff;color:#205e32;cursor:pointer}
.agro-chat button:disabled{opacity:.5;cursor:not-allowed}
.agro-chat a{color:var(--chat-green)}
.agro-chat button:focus-visible,.agro-chat a:focus-visible,.agro-chat textarea:focus-visible,.agro-chat summary:focus-visible{outline:2px solid var(--chat-green);outline-offset:2px}

/* ===== Cột chức năng ===== */
.agro-chat-side{display:flex;flex-direction:column;gap:14px;min-width:0;min-height:0;padding:16px 14px;background:#f0f8f1;border-right:1px solid var(--chat-border)}
.agro-chat-heading strong{display:block;font-size:18px;line-height:1.3}
.agro-chat-heading p{margin:4px 0 0;font-size:12px;color:#4d6154}
.agro-chat-tools{display:flex;gap:6px}
.agro-chat .agro-chat-new{flex:1;background:var(--chat-green);border-color:var(--chat-green);color:#fff;font-weight:600}
.agro-chat .agro-chat-menu-toggle{display:none}
/* Khách vãng lai không có hội thoại mới hay chức năng riêng. */
.agro-chat:not([data-identity^="customer"]) .agro-chat-tools{display:none}
.agro-chat-extras{display:flex;flex:1;flex-direction:column;gap:16px;min-height:0;overflow-y:auto}
.agro-chat-group{display:flex;flex-direction:column;gap:6px}
.agro-chat-group h3{margin:0;font-size:11px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:#617267}
.agro-chat .agro-chat-group button{text-align:left}
.agro-chat-list{display:flex;flex-direction:column;gap:4px}
.agro-chat-list:empty::after{content:'Chưa có hội thoại.';font-size:12px;color:#617267}
.agro-chat .agro-chat-list button{background:transparent;border-color:transparent;font-size:13px}
.agro-chat .agro-chat-list button:hover{background:#fff}
.agro-chat .agro-chat-list button[aria-current]{background:#fff;border-color:var(--chat-border);font-weight:600}
.agro-chat-item{display:flex;align-items:stretch;gap:4px}
.agro-chat-item [data-conversation]{flex:1;min-width:0}
.agro-chat .agro-chat-list .agro-chat-delete{flex:none;width:34px;padding:0;text-align:center;color:#7b8a80}
.agro-chat .agro-chat-list .agro-chat-delete:hover{background:#fdecea;border-color:#f3c6c0;color:#a12d24}
.agro-chat-keep{font-size:11px;line-height:1.5;color:#617267}
.agro-chat-notice{margin:auto 0 0;font-size:11px;line-height:1.5;color:#617267}

/* ===== Cột hội thoại ===== */
.agro-chat-main{display:flex;flex-direction:column;min-width:0;min-height:0}
.agro-chat-bar{flex:none;display:flex;align-items:center;min-height:54px;padding:0 64px 0 18px;border-bottom:1px solid var(--chat-border);font-weight:600}
.agro-chat .agro-chat-older{align-self:center;margin-top:8px;font-size:12px}
.agro-chat-messages{flex:1;display:flex;flex-direction:column;gap:12px;min-height:0;padding:16px 18px;overflow-y:auto;overscroll-behavior:contain;background:#fbfdfb}
.agro-chat-messages:empty::after{content:'Chào bạn! Bạn đang trồng cây gì và cần hỗ trợ ở giai đoạn nào?';margin:auto;max-width:340px;text-align:center;color:#617267}
.agro-chat-message{align-self:flex-start;flex-shrink:0;max-width:88%;min-width:0;padding:12px 14px;border:1px solid var(--chat-border);border-radius:14px 14px 14px 4px;background:#fff;overflow-wrap:anywhere}
.agro-chat-message p{white-space:pre-wrap;margin:0}
.agro-chat-message.user{align-self:flex-end;max-width:78%;border-radius:14px 14px 4px 14px;background:#e2f3e5}
.agro-chat-message small{display:block;margin-bottom:5px;font-size:11px;color:#617267}
.agro-chat-card{margin-top:10px;padding:12px;background:#f7fbf7;border:1px solid var(--chat-border);border-radius:8px}
.agro-chat-card h3{margin:0 0 7px;font-size:15px}
.agro-chat-card p{margin:4px 0;font-size:13px}
.agro-chat-card a{display:inline-block;margin:6px 8px 0 0}
.agro-chat .agro-chat-card button{margin:8px 6px 0 0;font-size:13px}
.agro-chat-card details{margin-top:8px}
.agro-chat-card summary{cursor:pointer;font-weight:600}
.agro-chat-error{margin:8px 14px 0;padding:10px;background:#fff0ee;border-radius:8px;color:#a12d24;font-size:13px}
.agro-chat-retry{display:flex;gap:6px;padding:0 14px}
.agro-chat-retry button:not([hidden]){margin-top:8px}

/* ===== Ô nhập ===== */
.agro-chat-form{flex:none;padding:10px 14px;border-top:1px solid var(--chat-border)}
.agro-chat-form label{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}
.agro-chat-form>div{display:flex;align-items:flex-end;gap:8px}
.agro-chat-form textarea{width:100%;min-width:0;height:42px;max-height:112px;padding:9px 14px;resize:none;border:1px solid var(--chat-border);border-radius:21px;background:#fff;color:#173d29;font-size:14px;line-height:22px}
.agro-chat .agro-chat-form button{flex:none;height:42px;min-width:72px;padding:0 16px;border-color:var(--chat-green);border-radius:21px;background:var(--chat-green);color:#fff;font-weight:600}

/* ===== Hộp thoại trên trang chủ ===== */
.agro-chat-dialog{width:min(1060px,calc(100vw - 24px));max-width:none;height:min(760px,calc(100dvh - 24px));max-height:none;padding:0;border:0;border-radius:18px;overflow:hidden}
.agro-chat-dialog[open]{display:flex;flex-direction:column}
.agro-chat-dialog::backdrop{background:rgba(15,45,25,.3)}
.agro-chat-dialog>.agro-chat-close{position:absolute;top:8px;right:14px;z-index:1;width:38px;height:38px;border:0;border-radius:50%;background:#f0f8f1;font-size:22px;line-height:1;cursor:pointer}
.agro-chat-dialog .agro-chat{flex:1;height:auto;min-height:0;border:0;border-radius:0;font-size:15px}

/* Trang tư vấn của đại lý */
.customer-chat-page .agro-chat{height:max(440px,calc(100dvh - 195px))}

/* ===== Màn hình hẹp: cột chức năng thu thành thanh phía trên ===== */
@media(max-width:700px){
  .agro-chat{grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr)}
  .agro-chat-side{gap:8px;padding:10px 12px;border-right:0;border-bottom:1px solid var(--chat-border)}
  .agro-chat-heading strong{font-size:16px}
  .agro-chat-heading p{display:none}
  .agro-chat-dialog .agro-chat-heading{padding-right:46px}
  .agro-chat-dialog .agro-chat[data-identity="guest"] .agro-chat-notice{padding-right:46px}
  .agro-chat .agro-chat-menu-toggle{display:block}
  .agro-chat-extras,.agro-chat-notice{display:none}
  .agro-chat.is-menu-open .agro-chat-extras{display:flex;flex:none;max-height:36dvh}
  .agro-chat.is-menu-open .agro-chat-notice,.agro-chat[data-identity="guest"] .agro-chat-notice{display:block;margin:0}
  .agro-chat-bar{display:none}
  .agro-chat-messages{padding:12px}
  .agro-chat-message,.agro-chat-message.user{max-width:94%}
  .agro-chat-dialog{width:calc(100vw - 12px);height:calc(100dvh - 12px)}
  .customer-chat-page .agro-chat{height:calc(100dvh - 130px)}
}
