/* らくくん（AI ヘルパー）— It49-b。業務画面の邪魔をしない控えめな常駐 UI。接頭辞 rk- で既存 CSS と衝突しない。 */
.rk-root {
  --rk-plum: #4B3F8F;
  --rk-plum-deep: #3B3174;
  --rk-peach: #FFB27A;
  --rk-lav: #F5F1FF;
  --rk-lav-line: #E4DCFA;
  --rk-ink: #2E2A4F;
  --rk-mute: #756F99;
  --rk-err: #B3382F;
  --rk-ease: cubic-bezier(.2, .7, .2, 1);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  color: var(--rk-ink);
  font-size: 14px;
  line-height: 1.6;
  position: fixed; right: 20px; bottom: 20px; z-index: 8000;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  pointer-events: none; /* 子要素のみ操作可能にして背面の業務 UI を塞がない */
  -webkit-text-size-adjust: 100%;
}
.rk-root[hidden] { display: none; }
.rk-root *, .rk-root *::before, .rk-root *::after { box-sizing: border-box; }
.rk-root > * { pointer-events: auto; }
.rk-root button { font: inherit; color: inherit; }

/* ---- フローティングボタン ---- */
.rk-fab-wrap { position: relative; display: flex; align-items: center; justify-content: flex-end; }
.rk-fab { /* It50: らくくん（ミニ版）を白い丸に乗せる。紫地では体が溶けるため白地が必須 */
  width: 56px; height: 56px; padding: 0; border: 2px solid var(--rk-lav-line); border-radius: 50%; background: #fff; cursor: pointer;
  box-shadow: 0 4px 14px rgba(46, 42, 79, .22), 0 1px 3px rgba(46, 42, 79, .18);
  transition: transform 180ms var(--rk-ease), box-shadow 180ms var(--rk-ease), border-color 180ms;
  display: grid; place-items: center;
}
.rk-fab svg { width: 82%; height: 82%; display: block; transform: translate(-1%, 2%); }
.rk-fab:hover { border-color: var(--rk-peach); }
.rk-fab:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(46, 42, 79, .26), 0 2px 4px rgba(46, 42, 79, .18); }
.rk-fab:active { transform: translateY(0) scale(.97); }
.rk-fab:focus-visible { outline: 3px solid var(--rk-peach); outline-offset: 3px; }
.rk-tip {
  position: absolute; right: 60px; top: 50%; transform: translate(6px, -50%);
  background: var(--rk-ink); color: #fff; font-size: 12px; line-height: 1; white-space: nowrap;
  padding: 8px 12px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity 160ms var(--rk-ease), transform 160ms var(--rk-ease);
}
.rk-fab-wrap:hover .rk-tip, .rk-fab:focus-visible + .rk-tip { opacity: 1; transform: translate(0, -50%); }
.rk-root[data-open="1"] .rk-tip { display: none; }

/* ---- 先回りの吹き出し ---- */
.rk-nudge {
  position: relative; width: min(300px, calc(100vw - 40px)); background: #fff; border: 1px solid var(--rk-lav-line);
  border-radius: 16px; padding: 14px 14px 12px; box-shadow: 0 6px 24px rgba(46, 42, 79, .16);
  animation: rk-rise 200ms var(--rk-ease) both;
}
.rk-nudge::after { /* しっぽ（ボタン側） */
  content: ''; position: absolute; right: 20px; bottom: -6px; width: 12px; height: 12px; background: #fff;
  border-right: 1px solid var(--rk-lav-line); border-bottom: 1px solid var(--rk-lav-line); transform: rotate(45deg);
}
.rk-nudge[hidden] { display: none; }
.rk-nudge-body { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 10px; }
.rk-nudge-avatar { width: 50px; height: 50px; flex: none; margin: -6px 0 0 -4px; }
.rk-nudge-avatar svg { width: 100%; height: 100%; display: block; }
.rk-nudge-msg { margin: 0; padding-top: 2px; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.rk-nudge-actions { display: flex; gap: 8px; }

/* ---- 共通ボタン ---- */
.rk-btn {
  border: 1px solid var(--rk-lav-line); background: #fff; border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer;
  transition: background-color 150ms, border-color 150ms, transform 150ms var(--rk-ease);
}
.rk-btn:hover { background: var(--rk-lav); border-color: var(--rk-plum); }
.rk-btn:active { transform: scale(.97); }
.rk-btn:focus-visible { outline: 2px solid var(--rk-plum); outline-offset: 2px; }
/* .rk-root button { color: inherit } より詳細度を上げる（白文字が上書きされ、紫地に暗い文字で読めなかった）*/
.rk-root .rk-btn-primary { background: var(--rk-plum); border-color: var(--rk-plum); color: #fff; }
.rk-root .rk-btn-primary:hover { background: var(--rk-plum-deep); border-color: var(--rk-plum-deep); }

/* ---- パネル ---- */
.rk-panel {
  position: relative; width: 360px; max-height: 70vh; height: 560px; display: flex; flex-direction: column; background: var(--rk-lav);
  border: 1px solid var(--rk-lav-line); border-radius: 16px; overflow: hidden;
  box-shadow: 0 12px 40px rgba(46, 42, 79, .22), 0 2px 6px rgba(46, 42, 79, .12);
  animation: rk-rise 200ms var(--rk-ease) both;
}
.rk-panel[hidden] { display: none; }
/* It50: 見出しは白地（紫地ではらくくんの体が溶けるため）。キャラクターは囲まずにそのまま置く */
.rk-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 12px; background: #fff; color: var(--rk-ink); border-bottom: 1px solid var(--rk-lav-line); }
.rk-head-mark { width: 42px; height: 42px; flex: none; }
.rk-head-mark svg { width: 100%; height: 100%; display: block; }
.rk-head-title { flex: 1; min-width: 0; font-size: 15px; font-weight: 700; letter-spacing: .02em; line-height: 1.3; }
.rk-head-sub { display: block; font-size: 11px; font-weight: 400; color: var(--rk-mute); letter-spacing: 0; }
.rk-ibtn {
  width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--rk-mute); cursor: pointer; font-size: 18px; line-height: 1;
  display: grid; place-items: center; transition: background-color 150ms;
}
.rk-ibtn:hover { background: var(--rk-lav); color: var(--rk-ink); }
.rk-ibtn:focus-visible { outline: 2px solid var(--rk-peach); outline-offset: 0; }
.rk-menu {
  position: absolute; right: 8px; top: 52px; z-index: 2; min-width: 190px; background: #fff; color: var(--rk-ink);
  border: 1px solid var(--rk-lav-line); border-radius: 12px; padding: 6px; box-shadow: 0 8px 24px rgba(46, 42, 79, .2);
  animation: rk-fade 150ms ease both;
}
.rk-menu[hidden] { display: none; }
.rk-menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.rk-menu button:hover, .rk-menu button:focus-visible { background: var(--rk-lav); outline: none; }

/* ---- メッセージ ---- */
.rk-list { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; overscroll-behavior: contain; }
.rk-msg { display: flex; flex-direction: column; max-width: 88%; animation: rk-rise 180ms var(--rk-ease) both; }
.rk-msg-user { align-self: flex-end; align-items: flex-end; }
.rk-msg-bot { align-self: flex-start; align-items: flex-start; }
.rk-bubble { padding: 9px 13px; border-radius: 16px; overflow-wrap: anywhere; word-break: break-word; font-size: 14px; line-height: 1.65; }
.rk-msg-user .rk-bubble { background: var(--rk-plum); color: #fff; border-bottom-right-radius: 5px; white-space: pre-wrap; }
.rk-msg-bot .rk-bubble { background: #fff; color: var(--rk-ink); border: 1px solid var(--rk-lav-line); border-bottom-left-radius: 5px; }
.rk-msg-err .rk-bubble { border-color: #F0C4C0; color: var(--rk-err); }
.rk-bubble p { margin: 0; }
.rk-bubble p + p, .rk-bubble p + ol, .rk-bubble p + ul, .rk-bubble ol + p, .rk-bubble ul + p { margin-top: 8px; }
.rk-bubble ol, .rk-bubble ul { margin: 0; padding-left: 0; list-style: none; counter-reset: rk; }
.rk-bubble li { position: relative; padding-left: 26px; margin: 5px 0; }
.rk-bubble ol li { counter-increment: rk; }
.rk-bubble ol li::before {
  content: counter(rk); position: absolute; left: 0; top: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--rk-lav); color: var(--rk-plum); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.rk-bubble ul li::before { content: ''; position: absolute; left: 7px; top: 11px; width: 5px; height: 5px; border-radius: 50%; background: var(--rk-peach); }
.rk-bubble strong { font-weight: 700; }
.rk-q { background: var(--rk-lav); color: var(--rk-plum); border-radius: 5px; padding: 0 4px; font-weight: 600; }
.rk-meta { display: flex; align-items: center; gap: 4px; margin-top: 4px; min-height: 26px; }
.rk-fb {
  width: 28px; height: 26px; border: 1px solid transparent; border-radius: 8px; background: transparent; cursor: pointer; font-size: 14px; line-height: 1;
  opacity: .55; filter: grayscale(.4); transition: opacity 150ms, background-color 150ms, transform 150ms var(--rk-ease);
}
.rk-fb:hover { opacity: 1; background: #fff; }
.rk-fb:active { transform: scale(.9); }
.rk-fb:focus-visible { outline: 2px solid var(--rk-plum); }
.rk-fb[aria-pressed="true"] { opacity: 1; filter: none; background: #fff; border-color: var(--rk-lav-line); }
.rk-fb:disabled:not([aria-pressed="true"]) { opacity: .25; cursor: default; }
.rk-thanks { font-size: 11px; color: var(--rk-mute); margin-left: 4px; animation: rk-fade 150ms ease both; }
.rk-retry { margin-top: 6px; }

/* ---- 空状態・サジェスト ---- */
.rk-empty { padding: 6px 2px 0; }
.rk-empty-title { margin: 0 0 4px; font-size: 15px; font-weight: 700; }
.rk-empty-sub { margin: 0 0 12px; font-size: 13px; color: var(--rk-mute); }
.rk-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.rk-chip { border: 1px solid var(--rk-lav-line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; text-align: left; cursor: pointer; transition: border-color 150ms, transform 150ms var(--rk-ease); }
.rk-chip:hover { border-color: var(--rk-plum); transform: translateY(-1px); }
.rk-chip:focus-visible { outline: 2px solid var(--rk-plum); outline-offset: 2px; }

/* ---- 考え中 ---- */
.rk-typing { display: inline-flex; align-items: center; gap: 8px; color: var(--rk-mute); font-size: 13px; }
.rk-dots { display: inline-flex; gap: 3px; }
.rk-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--rk-plum); opacity: .35; animation: rk-blink 1.1s infinite ease-in-out; }
.rk-dots i:nth-child(2) { animation-delay: .15s; }
.rk-dots i:nth-child(3) { animation-delay: .3s; }

/* ---- 入力 ---- */
.rk-foot { flex: none; padding: 8px 12px 10px; background: var(--rk-lav); border-top: 1px solid var(--rk-lav-line); }
.rk-form { display: flex; align-items: flex-end; gap: 8px; background: #fff; border: 1px solid var(--rk-lav-line); border-radius: 14px; padding: 6px 6px 6px 12px; transition: border-color 150ms, box-shadow 150ms; }
.rk-form:focus-within { border-color: var(--rk-plum); box-shadow: 0 0 0 3px rgba(75, 63, 143, .14); }
.rk-input { flex: 1; min-width: 0; border: 0; outline: none; resize: none; background: transparent; color: var(--rk-ink); font: inherit; font-size: 14px; line-height: 1.5; padding: 5px 0; max-height: 96px; }
.rk-input::placeholder { color: #A39EC0; }
.rk-send { flex: none; width: 34px; height: 34px; border: 0; border-radius: 10px; background: var(--rk-plum); cursor: pointer; display: grid; place-items: center; transition: background-color 150ms, transform 150ms var(--rk-ease), opacity 150ms; }
.rk-send:hover:not(:disabled) { background: var(--rk-plum-deep); }
.rk-send:active:not(:disabled) { transform: scale(.94); }
.rk-send:disabled { opacity: .35; cursor: default; }
.rk-send:focus-visible { outline: 2px solid var(--rk-peach); outline-offset: 2px; }
.rk-send svg { width: 16px; height: 16px; }
.rk-note { margin: 6px 2px 0; font-size: 11px; color: var(--rk-mute); line-height: 1.5; }

/* ---- 非表示確認 ---- */
.rk-confirm { padding: 14px; background: #fff; border: 1px solid var(--rk-lav-line); border-radius: 14px; font-size: 13px; }
.rk-confirm p { margin: 0 0 10px; }
.rk-confirm .rk-nudge-actions { flex-wrap: wrap; }

.rk-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@keyframes rk-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes rk-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rk-blink { 0%, 80%, 100% { opacity: .3; transform: none; } 40% { opacity: 1; transform: translateY(-2px); } }

/* ---- モバイル（390px 想定）: 下端シート・全幅 ---- */
@media (max-width: 520px) {
  .rk-root { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .rk-fab { width: 48px; height: 48px; }
  .rk-tip { display: none; }
  .rk-root[data-open="1"] { right: 0; left: 0; bottom: 0; gap: 0; align-items: stretch; }
  .rk-root[data-open="1"] .rk-fab-wrap { display: none; }
  .rk-panel { width: 100%; height: 85vh; height: 85dvh; max-height: 85dvh; border-radius: 16px 16px 0 0; border-width: 1px 0 0; }
  .rk-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .rk-input { font-size: 16px; } /* iOS の自動ズーム防止 */
  .rk-msg { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .rk-root *, .rk-root *::before, .rk-root *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .rk-dots i { opacity: .7; }
}
@media print { .rk-root { display: none !important; } }
