/* ===== MALASADA チャットホーム (home.ts) ===== */
/* プレフィックス: .mchat- */
/* POKI (ax-dashboard styles/home.css) のレイアウト・寸法に統一（2026-08-07）。
   アクセントカラーだけマラサダのオレンジ(--accent)を維持する。 */

.mchat-home {
  width: 100%;
  /* POKI は #homeView(padding 左右20px) の内側に .home-inner(max-width 720px) を置くため
     コンテンツ実効幅が 720px になる。マラサダは1要素に集約しているので box-sizing: border-box の
     分（左右padding 20px×2）を足した 760px にしないと実効幅が 680px になり POKI より 40px 狭くなる。 */
  max-width: 760px;
  margin: 0 auto;
  min-height: calc(100vh - var(--header-h));
  display: flex;
  /* flex-direction: row (既定) のまま align-items: flex-start にすることで、
     縦位置は padding-top のみで決まる（POKIの #homeView と同じ実現方式）。
     flex-direction: column + justify-content: center にすると、そのフレックス自体の
     縦センタリングが padding-top に "二重" で加算され、POKIより約150px下にズレていた。 */
  align-items: flex-start;
  justify-content: center;
  /* POKIの #homeView 上パディング相当: ロゴ＋挨拶＋ボックス上半分の合計を差し引いて
     入力ボックスの中心が画面中央付近に来るように */
  padding: calc(50vh - 340px) 20px 40px;
}

/* ----- Intro（初期画面） ----- */
.mchat-intro {
  width: 100%;
  text-align: center;
}
.mchat-intro-logo {
  /* POKI の .home-poki は 120px だが、poki 画像はキャンバスに対してキャラが小さく余白が広い。
     malasada 画像はキャンバスいっぱいにキャラが入っているため、同じ 120px だと実際の絵が
     POKI より 1.3 倍ほど大きく見える（藤山さん指摘）。見た目の大きさを揃えるため縮める。 */
  width: 92px; height: 92px;
  object-fit: contain;
  margin: 0 auto 14px;
  display: block;
  filter: drop-shadow(0 6px 14px rgba(217, 119, 6, 0.18));
}
.mchat-greet-main {
  font-size: 22px; font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}
.mchat-greet-sub {
  font-size: 14px; color: var(--text-sub);
  line-height: 1.6;
  margin-bottom: 22px;
}

/* 入力ボックス: POKIの.home-searchと同じ大きな角丸ボックス（複数行・送信はボックス内右下） */
.mchat-intro-form {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px 16px 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.06);
  transition: border-color .15s, box-shadow .15s;
  text-align: left;
}
.mchat-intro-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 6px 28px rgba(217, 119, 6, 0.18);
}
.mchat-intro-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.55;
  resize: none;
  padding: 4px 4px 6px;
  min-height: 44px;
  max-height: 200px;
}
.mchat-intro-input::placeholder { color: var(--text-sub); }
.mchat-intro-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}
.mchat-intro-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.mchat-intro-send:hover { opacity: 0.9; }
.mchat-intro-send:active { transform: scale(0.94); }
.mchat-intro-send svg { width: 18px; height: 18px; }

.mchat-hint {
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-sub);
  letter-spacing: 0.1px;
  text-align: left;
}

.mchat-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 16px;
}
.mchat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, transform 0.15s;
}
.mchat-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ----- 入力ボックス下の子アプリリンク（M-Ad / M-Step） ----- */
.mchat-child-apps {
  margin-top: 26px;
  text-align: left;
}
.mchat-child-apps-title {
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 8px;
}
.mchat-child-apps-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.mchat-child-app-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px 6px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, opacity 0.15s;
}
.mchat-child-app-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.mchat-child-app-card.is-soon { opacity: 0.55; }
/* 権限制御 (applyHeaderAppPermissions) が付ける hidden 属性を display:inline-flex より優先する。
   これが無いと UA スタイルの [hidden]{display:none} が上の display:inline-flex に負け、
   権限のないカードが全員に見えてしまう (.nav-item[hidden] と同じパターン)。 */
.mchat-child-app-card[hidden] { display: none; }
.mchat-child-app-icon {
  width: 24px; height: 24px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
}

/* ----- Chat（チャットモード） ----- */
.mchat-chat {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  height: calc(100vh - var(--header-h) - 40px);
  flex-direction: column;
  padding: 20px 20px 24px;
}
/* display: flex を hidden 属性と両立させるための定義。
   これを指定しないと `display: flex` が `hidden` 属性の display: none を上書きしてしまい、
   intro状態でも下部のチャット入力欄が同時に見えるバグになる（POKIのhome.cssと同じ理由）。 */
.mchat-chat:not([hidden]) { display: flex; }

.mchat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 4px 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mchat-msg {
  display: flex;
  gap: 10px;
  max-width: 100%;
  animation: mchatMsgIn .18s ease-out;
}
@keyframes mchatMsgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.mchat-msg-user { justify-content: flex-end; }
.mchat-avatar {
  width: 34px; height: 34px;
  flex-shrink: 0;
  object-fit: contain;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.08));
}
.mchat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.65;
  max-width: 72%;
  word-break: break-word;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}
.mchat-msg-user .mchat-bubble {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  border-top-right-radius: 6px;
}
.mchat-msg-error .mchat-bubble {
  border-color: #ef4444;
  color: #ef4444;
}

.mchat-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 6px 4px 0 0;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.mchat-nav-btn:hover { background: var(--accent); color: #fff; }

.mchat-typing {
  display: inline-flex; gap: 4px;
  padding: 2px 0;
}
.mchat-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-sub);
  opacity: .35;
  animation: mchat-typing-bounce 1.2s infinite ease-in-out;
}
.mchat-typing span:nth-child(2) { animation-delay: 0.15s; }
.mchat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes mchat-typing-bounce {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.mchat-feedback {
  display: flex; align-items: center; gap: 6px;
  margin-top: 6px;
  margin-left: 44px; /* avatar幅 + gap */
}
.mchat-fb-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  opacity: .85;
}
.mchat-fb-btn:hover { background: var(--border); opacity: 1; }
.mchat-fb-btn:disabled { cursor: default; opacity: .5; }
.mchat-fb-btn.is-selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  opacity: 1;
  transform: scale(1.05);
}
.mchat-fb-note {
  font-size: 11px; color: var(--text-sub);
  margin-left: 4px;
}

/* 送信ボックス: POKIと同じ大きな角丸ボックス。送信ボタンはボックス内右下 */
.mchat-chat-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px 12px 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.04);
  transition: border-color .15s, box-shadow .15s;
  margin-top: 10px;
}
.mchat-chat-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 4px 20px rgba(217, 119, 6, 0.15);
}
.mchat-chat-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.55;
  resize: none;
  padding: 4px;
  min-height: 36px;
  max-height: 200px;
}
.mchat-chat-input::placeholder { color: var(--text-sub); }
.mchat-chat-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}
.mchat-chat-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.mchat-chat-send:hover { opacity: 0.9; }
.mchat-chat-send:active { transform: scale(0.94); }
.mchat-chat-send svg { width: 18px; height: 18px; }

/* モバイル（POKIのhome.css @mediaを踏襲） */
@media (max-width: 768px) {
  .mchat-home { padding: 24px 14px; }
  .mchat-intro-logo { width: 84px; height: 84px; }
  .mchat-greet-main { font-size: 18px; }
  .mchat-greet-sub  { font-size: 13px; }
  .mchat-intro-input { font-size: 14px; }
  .mchat-chat { padding: 14px 12px 16px; height: calc(100vh - var(--header-h) - 20px); }
  .mchat-bubble { max-width: 82%; font-size: 13.5px; }
  .mchat-avatar { width: 28px; height: 28px; }
}
