:root{
  --primary:#c00000;
  --bg:#fff; --text:#111; --border:#ddd;
}

/* 位置と最前面 */
#ac-root{ position:fixed; bottom:20px; right:20px; z-index:99999; }

/* ベンダー差異で崩れないボタンの基本 */
button#ac-open, #ac-close, #ac-send{
  -webkit-appearance:none; appearance:none;
  line-height:normal; outline:0;
}

/* === 起動ボタン（安定版）=== */
#ac-open.ac-open{
  display:inline-flex; align-items:center; gap:10px;
  background:var(--primary); color:#fff; border:none;
  border-radius:999px;
  height:48px; min-width:160px; /* ← 文字で横幅がぶれても高さは固定 */
  padding:0 14px;
  cursor:pointer; font:600 14px/1 system-ui,"Noto Sans TC","Noto Sans JP",Arial,sans-serif;
  box-shadow:0 6px 16px rgba(0,0,0,.2);
}

/* 画像が来た場合の見え方 */
.ac-avatar{
  width:28px; height:28px; flex:0 0 28px;
  border-radius:50%; object-fit:cover; display:block;
  background:#fff;
  /* 画像が404等で読み込めない場合のフォールバック（円形に “I” ） */
  background-image: url("data:image/svg+xml;utf8,\
  <svg xmlns='http://www.w3.org/2000/svg' width='64' height='64'>\
    <circle cx='32' cy='32' r='32' fill='white'/>\
    <text x='32' y='40' text-anchor='middle' font-size='32' font-family='Arial' fill='%23c00000'>I</text>\
  </svg>");
  background-size:cover; background-position:center;
}

/* === パネル === */
#ac-panel{
  display:none; flex-direction:column;
  position:fixed; bottom:80px; right:20px;
  width:360px; max-width:calc(100vw - 24px);
  height:520px; max-height:calc(100vh - 120px);
  background:var(--bg);
  border:1px solid var(--border); border-radius:12px;
  box-shadow:0 10px 24px rgba(0,0,0,.25);
}

/* ヘッダー */
#ac-header{
  background:var(--primary); color:#fff; padding:10px 12px;
  display:flex; justify-content:space-between; align-items:center;
}
#ac-header .ac-header-left{ display:flex; align-items:center; gap:10px; }
#ac-header .ac-title{ display:flex; flex-direction:column; }
#ac-header .ac-name{ font-weight:700; }
#ac-header .ac-sub{ font-size:12px; opacity:.9; }
#ac-header .ac-avatar{ border:2px solid rgba(255,255,255,.6); }

/* 本文・入力 */
#ac-body{ flex:1; overflow-y:auto; padding:10px; background:#fafafa; font-size:14px; }
#ac-footer{ display:flex; border-top:1px solid var(--border); }
#ac-input{ flex:1; border:none; padding:10px; font-size:14px; }
#ac-send{
  background:var(--primary); color:#fff; border:none;
  padding:0 16px; font-weight:700; cursor:pointer;
}

/* メッセージ */
.ac-msg{ margin-bottom:10px; }
.ac-msg.user .bubble{
  background:#eee; color:#111; padding:8px 12px; border-radius:12px; display:inline-block;
}
.ac-msg.assistant .bubble{
  background:#fceaea; color:#111; padding:8px 12px; border-radius:12px; display:inline-block;
}

/* モバイル最適化 */
@media (max-width:480px){
  #ac-open.ac-open{ min-width:140px; height:44px; }
  #ac-panel{ width:92vw; right:4vw; height:70vh; }
}
/* クリック不能を防止 */
#ac-open, #ac-panel, #ac-send, #ac-close { pointer-events: auto; }

/* ボタン高さが暴れるのを防止（iOS/Safari対策） */
#ac-open {
  -webkit-appearance: none; appearance: none;
  line-height: 1; height: 48px; min-width: 160px;
}

/* パネルが他要素の下に潜らないように */
#ac-root { z-index: 99999; }

/* 画像の共通対策：他CSSの max-width:100% に潰されないように */
.ac-avatar { max-width: none; display: block; }
