/* ==========================================================================
   ASIACOM Japan Desk – AI Assistant Widget (Yuri)
   Clean, conflict-resistant CSS (fixed bottom-right, JP/EN long text safe)
   ========================================================================== */

/* ---- Theme tokens ------------------------------------------------------- */
:root{
  --primary: #2563eb;   /* blue */
  --ink: #111;
  --muted: #64748b;     /* slate-500/600 */
  --bg: #ffffff;
  --panel-bg: #ffffff;
  --panel-muted: #f9fafb;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow-md: 0 6px 16px rgba(0,0,0,.2);
  --shadow-lg: 0 10px 24px rgba(0,0,0,.25);
  --z-widget: 2147483647;
  --font: system-ui,-apple-system,"Segoe UI",Roboto,"Noto Sans JP",Arial,"Hiragino Kaku Gothic ProN","Meiryo",sans-serif;
}

/* ---- Hard reset for widget scope --------------------------------------- */
#ac-root, #ac-root *{
  box-sizing: border-box;
  font-family: var(--font) !important;
}

/* Prevent global img { max-width:100% } side-effects within widget */
#ac-root img{
  max-width: none !important;
}

/* ---- Root placement: always bottom-right above all --------------------- */
#ac-root{
  position: fixed !important;
  inset: auto 20px 20px auto !important; /* top right bottom left */
  right: 20px !important;
  left: auto !important;
  bottom: 20px !important;
  z-index: var(--z-widget) !important;
  isolation: isolate; /* separate stacking context */
}

/* ---- Launcher button ---------------------------------------------------- */
#ac-open{
  display: inline-flex !important;
  align-items: center;
  gap: 10px;
  width: auto !important;
  min-width: 160px;
  height: 48px;
  padding: 0 14px;
  margin: 0 !important;
  border: none !important;
  border-radius: 999px !important;
  background: var(--primary) !important;
  color: #fff !important;
  font: 600 14px/1 var(--font) !important;
  text-decoration: none !important;
  cursor: pointer;
  box-shadow: var(--shadow-md) !important;

  /* cancel possible globals */
  float: none !important;
  transform: none !important;
  -webkit-appearance: none;
  appearance: none;
}

#ac-open .ac-avatar{
  width: 28px !important;
  height: 28px !important;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

/* ---- Dialog panel ------------------------------------------------------- */
#ac-panel{
  position: fixed !important;
  inset: auto 20px 80px auto !important; /* above the button */
  right: 20px !important;
  left: auto !important;
  bottom: 80px !important;

  width: 360px;
  max-width: calc(100vw - 24px);
  height: 520px;
  max-height: calc(100vh - 120px);

  background: var(--panel-bg) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important;
  overflow: hidden !important;

  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important; /* allow #ac-body to scroll */
}
#ac-panel[hidden]{ display: none !important; }

/* ---- Header ------------------------------------------------------------- */
#ac-header{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px !important;
  background: var(--primary) !important;
  color: #fff !important;
}

#ac-header .ac-avatar{
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.6);
}

#ac-header .ac-title{ min-width: 0; }
#ac-header .ac-name{
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#ac-header .ac-sub{
  color: #e0e7ff;
  font-size: 12px;
  line-height: 1.2;
}

#ac-close{
  margin-left: auto;
  width: 28px; height: 28px; line-height: 28px;
  border: none !important;
  border-radius: 6px;
  background: #fff !important;
  color: var(--primary) !important;
  cursor: pointer;
}

/* ---- Banner (injected by JS) ------------------------------------------- */
#ac-panel .ac-banner{
  padding: 10px 12px !important;
  border-bottom: 1px solid var(--border) !important;
  background: #eef2ff !important;
  color: #1e40af !important;
  font-size: 0.9rem !important;
  line-height: 1.5 !important;
  letter-spacing: .01em !important;
}
#ac-panel .ac-banner .ac-banner-quote{ font-weight: 600 !important; }
#ac-panel .ac-banner a{
  color: #1d4ed8 !important;
  text-decoration: underline !important;
  font-weight: 600 !important;
}
#ac-panel .ac-banner p{ margin: 0 0 4px !important; }
#ac-panel .ac-banner p:last-child{ margin-bottom: 0 !important; }

/* ---- Body & footer ------------------------------------------------------ */
#ac-body{
  flex: 1 1 auto;
  min-height: 0 !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  background: var(--panel-muted);
  font-size: 14px;
  color: var(--ink);
}

#ac-footer{
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

#ac-input{
  flex: 1 1 auto;
  height: 36px;
  padding: 6px 10px;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #d1d5db !important;
  border-radius: 8px !important;
  outline: none;
}

#ac-send{
  height: 36px;
  padding: 0 14px;
  border: none !important;
  border-radius: 8px !important;
  background: var(--primary) !important;
  color: #fff !important;
  font-weight: 700;
  cursor: pointer;
}

/* ---- Chat bubbles ------------------------------------------------------- */
.ac-msg{
  margin-bottom: 12px;
  display: flex;
}
.ac-msg.user{ justify-content: flex-end; }
.ac-msg.assistant{ justify-content: flex-start; }

.ac-msg .bubble{
  display: inline-block;
  max-width: 82%;
  padding: 10px 12px;
  border-radius: 12px;
  line-height: 1.6;
  font-size: .95rem;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.ac-msg.user .bubble{
  background: var(--primary);
  color: #fff;
}

.ac-msg.assistant .bubble{
  background: #f1f5f9;
  color: var(--ink);
}

/* Improve readability for mixed JP/EN greeting */
.ac-msg.assistant .bubble strong{ font-weight: 700; }
.ac-msg.assistant .bubble em{ font-style: italic; }

/* ---- Small screens ------------------------------------------------------ */
@media (max-width: 480px){
  #ac-open{ min-width: 140px; height: 44px; }
  #ac-panel{
    width: 92vw;
    inset: auto 4vw 12vh auto !important;
    height: 70vh;
  }
}

/* ---- Ultra-narrow label fallback --------------------------------------- */
#ac-open .ac-label{
  white-space: nowrap;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#ac-open .ac-label .role{ font-weight: 600; }

@media (max-width: 360px){
  #ac-open .ac-label{ white-space: normal; }
  #ac-header .ac-name{ white-space: normal; }
}

