.mst-chat-root { z-index: 2147483647 !important; position: fixed !important; right: 0; top: 0; left: 0; bottom: 0; pointer-events: none; }
.mst-chat-button { position: fixed !important; right: 20px !important; bottom: 20px !important; width:56px; height:56px; border-radius:50%; background:#0ea5a4; color:#fff; border:none; box-shadow:0 6px 18px rgba(0,0,0,0.2); font-size:20px; cursor:pointer; z-index: 2147483647 !important; pointer-events:auto !important; transform: none !important; }
.mst-chat-panel { position: fixed !important; right: 20px !important; top: 20px !important; bottom: auto !important; width:320px; max-height:420px; background:#fff; border-radius:8px; box-shadow:0 10px 30px rgba(0,0,0,0.2); display:flex; flex-direction:column; overflow:visible; transform:translateY(-10px) !important; opacity:0; pointer-events:none; transition:all .18s ease-in-out; z-index: 2147483647 !important; backface-visibility: hidden !important; }
.mst-chat-panel.open { transform:translateY(0); opacity:1; pointer-events:auto; }
.mst-chat-header { background:#06b6d4; color:#fff; padding:10px 12px; font-weight:700; display:flex; justify-content:space-between; align-items:center; }
.mst-chat-close { background:transparent; border:none; color:#fff; font-size:14px; cursor:pointer; }
.mst-chat-messages { padding:8px 10px; overflow:auto; flex:1 1 auto; background:#f8fafc; }
.mst-chat-msg { margin-bottom:8px; padding:6px 8px; background:#fff; border-radius:6px; box-shadow:0 1px 0 rgba(0,0,0,0.03); }
.mst-chat-name { font-weight:700; margin-right:6px; }
.mst-chat-time { font-size:11px; color:#666; margin-top:4px; }
# Compact layout and prevent overflow
.mst-chat-panel { width: 360px !important; max-width: calc(100vw - 40px) !important; box-sizing: border-box !important; display:flex; flex-direction:column; max-height: calc(100vh - 40px) !important; padding-bottom:8px; }
.mst-chat-panel.minimized { width: 240px !important; height: 48px !important; overflow: hidden !important; }
.mst-chat-header { display:flex; justify-content:space-between; align-items:center; padding:8px 12px; }
.mst-chat-header-actions { display:flex; gap:6px; align-items:center; }
.mst-chat-minimize, .mst-chat-close { background:transparent; border:none; color:#fff; font-size:15px; cursor:pointer; }
# ensure messages area shrinks properly and form stays visible
.mst-chat-messages { padding:8px 10px; padding-bottom:90px; overflow:auto; flex:1 1 auto; background:#f8fafc; min-height:0; }
# make form area have extra right padding so buttons don't get clipped by roll-up or scrollbar
.mst-chat-form { display:flex; gap:6px; padding:8px 12px; border-top:1px solid #eee; box-sizing: border-box; flex:0 0 auto; flex-wrap:wrap; align-items:center; overflow:visible; }
/* Input should be flexible and able to shrink so buttons remain visible */
#mst-chat-input { flex:1 1 auto; padding:8px 10px; border:1px solid #ddd; border-radius:4px; min-width:0; box-sizing:border-box; }
#mst-chat-to { flex:0 0 120px; min-width:80px; max-width:140px; padding:8px; border:1px solid #ddd; border-radius:4px; box-sizing:border-box; }
.mst-chat-form button { background:#06b6d4; color:#fff; border:none; padding:8px 12px; border-radius:6px; cursor:pointer; }
.mst-chat-form button[type="button"] { flex:0 0 auto; width:40px; height:36px; padding:0; display:inline-flex; align-items:center; justify-content:center; border-radius:6px; }
.mst-chat-form button[type="submit"] { min-width:72px; padding:8px 12px; flex:0 0 auto; }
.mst-chat-form button { z-index:2147483660; position:relative; }
.mst-chat-attachments { margin-top:6px; }
.mst-chat-attachment { display:inline-block; margin-right:8px; background:#f1f5f9; padding:4px 8px; border-radius:4px; }
.mst-chat-msg { margin-bottom:8px; padding:6px 8px; background:#fff; border-radius:6px; box-shadow:0 1px 0 rgba(0,0,0,0.03); word-break:break-word; overflow-wrap:break-word; }
.mst-chat-meta { font-size:13px; color:#0f172a; margin-bottom:4px; }
.mst-chat-actions { margin-top:6px; }
.mst-chat-actions button { margin-right:6px; background:#e2e8f0; color:#0b1220; border: none; padding:4px 8px; border-radius:4px; cursor:pointer; }
.mst-chat-text { white-space: pre-wrap; word-break: break-word; }
.mst-chat-attachments a { display:inline-block; margin-right:6px; margin-top:4px; }
.mst-chat-attach-row { display:flex; align-items:center; gap:8px; margin-bottom:6px; }
.mst-chat-attach-row img { max-width:64px; max-height:48px; border-radius:4px; display:block; }
.mst-chat-attach-name { font-size:13px; }
.mst-chat-attach-size { color:#64748b; font-size:12px; margin-left:6px; }
.mst-chat-form select { padding:6px 8px; border-radius:4px; border:1px solid #ddd; margin:0 6px; flex:0 0 auto; min-width:80px; }

/* new: attach controls row */
.mst-chat-attach-controls { order: 3; width: 100%; display:flex; gap:8px; margin-top:6px; align-items:center; position:relative; z-index:2147483695; }
.mst-chat-attach-controls button { flex:0 0 44px; height:36px; padding:0; display:inline-flex; align-items:center; justify-content:center; background:#06b6d4; color:#fff; border:none; border-radius:6px; cursor:pointer; font-size:18px; }

/* Desktop: pin submit button so it never gets clipped and give input extra right padding */
@media (min-width: 641px) {
	.mst-chat-form { position: relative; padding-right: 56px; }
	.mst-chat-form button[type="submit"] { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); z-index:2147483680; }
	#mst-chat-input { padding-right: 84px; }
}

/* Mobile: make chat panel full-screen and pin form to bottom */
@media (max-width: 640px) {
	.mst-chat-panel {
		left: 0 !important;
		right: 0 !important;
		top: 0 !important;
		bottom: 0 !important;
		width: 100vw !important;
		height: 100vh !important;
		max-height: none !important;
		border-radius: 0 !important;
		margin: 0 !important;
		padding: 0 !important;
		box-sizing: border-box !important;
	}
	.mst-chat-panel.open { transform: none !important; opacity: 1 !important; pointer-events: auto !important; }
	.mst-chat-panel.minimized { display: none !important; }
	.mst-chat-header { border-radius: 0 !important; padding: 12px !important; }
	.mst-chat-messages {
		padding: 12px !important;
		padding-bottom: 160px !important; /* reserve space for pinned form */
		overflow: auto !important;
	}
	.mst-chat-form {
		position: fixed !important;
		left: 0 !important;
		right: 0 !important;
		bottom: 0 !important;
		padding: 10px !important;
		background: #fff !important;
		box-shadow: 0 -8px 24px rgba(0,0,0,0.08) !important;
		z-index: 2147483670 !important;
		display: flex !important;
		gap: 8px !important;
		align-items: center !important;
		flex-wrap: wrap !important;
	}
	#mst-chat-input { flex:1 1 auto !important; min-width:0 !important; }
	#mst-chat-to { display: none !important; } /* hide recipient dropdown on tiny screens to save space */
	.mst-chat-form button[type="button"] { width:44px !important; height:44px !important; }
	.mst-chat-form button[type="submit"] { min-width:64px !important; }
	.mst-chat-button { right: 12px !important; bottom: 12px !important; }
}
