/* ============================================================
   main.css v4 — ユーザーエリア・LINE風リスト・モバイルパネル修正
   ============================================================ */

:root {
  --orange:       #f97316;
  --orange-dk:    #ea580c;
  --orange-lt:    #fff7ed;
  --orange-pale:  #fed7aa;

  --sidebar-bg:   #1c1d2e;
  --sidebar-h:    #282a3e;
  --sidebar-a:    #32354f;
  --sidebar-bd:   rgba(255,255,255,.08);
  --sidebar-bd2:  rgba(255,255,255,.05);

  --white:        #ffffff;
  --bg:           #f4f5f7;
  --bg2:          #eef0f3;
  --border:       #e5e7eb;
  --border-lt:    #f3f4f6;

  --text:         #111827;
  --text-sub:     #6b7280;
  --text-hint:    #9ca3af;
  --text-inv:     #e2e8f0;
  --text-inv-sub: #94a3b8;

  --sidebar-w:    260px;
  --panel-w:      320px;
  --header-h:     58px;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 20px;

  --sh-sm: 0 1px 4px rgba(0,0,0,.06);
  --sh-md: 0 4px 16px rgba(0,0,0,.10);
  --sh-lg: 0 8px 28px rgba(0,0,0,.15);

  --tr:   .15s ease;
  --font: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; outline: none; -webkit-appearance: none; }
input, textarea, select { font-family: inherit; font-size: inherit; border: none; outline: none; background: none; -webkit-appearance: none; }
a { color: inherit; text-decoration: none; }
svg { display: block; flex-shrink: 0; }

/* ============================================================
   アプリレイアウト
   ============================================================ */
#app {
  display: flex;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ============================================================
   ユーザー名入力モーダル
   ============================================================ */
.user-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.user-modal-box {
  background: var(--white);
  border-radius: var(--r-lg);
  padding: 28px 28px 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--sh-lg);
  animation: modalIn .25s ease;
}
@keyframes modalIn { from { opacity:0; transform: translateY(16px) scale(.97); } to { opacity:1; transform: none; } }

.user-modal-icon  { font-size: 34px; text-align: center; margin-bottom: 10px; }
.user-modal-title { font-size: 19px; font-weight: 700; text-align: center; margin-bottom: 5px; color: var(--text); }
.user-modal-desc  { font-size: 13px; color: var(--text-sub); text-align: center; line-height: 1.7; margin-bottom: 18px; }

/* Google ボタン */
.user-modal-google-wrap {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.user-modal-google-wrap > div {
  width: 100% !important;
}
/* Google のiframeを幅100%に */
.user-modal-google-wrap iframe {
  width: 100% !important;
}
.google-note {
  font-size: 11px;
  color: var(--text-hint);
  text-align: center;
}

/* 区切り線 */
.user-modal-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 16px;
  color: var(--text-hint);
  font-size: 12px;
}
.user-modal-divider::before,
.user-modal-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* フォーム */
.user-modal-form  { display: flex; flex-direction: column; gap: 12px; }

/* 2カラムレイアウト */
.modal-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-field { display: flex; flex-direction: column; gap: 4px; }
.modal-field label { font-size: 12px; font-weight: 600; color: var(--text); }
.modal-field .req  { color: var(--orange); margin-left: 2px; }

.modal-field input {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  transition: border-color var(--tr);
}
.modal-field input:focus { border-color: var(--orange); outline: none; background: var(--white); }
.modal-field input::placeholder { color: var(--text-hint); }

.modal-field-err {
  font-size: 11px;
  color: #ef4444;
  display: none;
}

.user-modal-btn {
  width: 100%;
  padding: 12px;
  background: var(--orange);
  color: #fff;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 700;
  transition: background var(--tr);
  margin-top: 2px;
}
.user-modal-btn:hover { background: var(--orange-dk); }

/* サイドバーのメール表示（小さめ） */
.user-email-display {
  font-size: 10px;
  color: var(--text-inv-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* スマホではモーダルを1カラムに */
@media (max-width: 500px) {
  .user-modal-box { padding: 22px 18px 20px; max-width: 100%; }
  .modal-row-2 { grid-template-columns: 1fr; gap: 10px; }
}

/* ============================================================
   LEFT SIDEBAR
   ============================================================ */
.sidebar {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  background: var(--sidebar-bg);
  overflow: hidden;
  z-index: 100;
  transition: transform var(--tr);
}

/* ---- ユーザー情報エリア（参考画像準拠） ---- */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--sidebar-bd);
  flex-shrink: 0;
}

.user-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.user-av {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--orange);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  transition: background var(--tr);
}

/* オンライン状態ドット */
.user-status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--sidebar-bg);
}

.user-info-text {
  flex: 1;
  min-width: 0;
}

.user-display-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-inv);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.user-company-name {
  font-size: 11px;
  color: var(--text-inv-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.btn-edit-user {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-inv-sub);
  flex-shrink: 0;
  transition: background var(--tr), color var(--tr);
}
.btn-edit-user:hover { background: rgba(255,255,255,.1); color: var(--text-inv); }

/* ---- 履歴ヘッダー ---- */
.sidebar-hist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
  flex-shrink: 0;
}

.hist-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-inv-sub);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: var(--r-sm);
  background: var(--orange);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: background var(--tr);
}
.btn-new-chat svg { width: 13px; height: 13px; flex-shrink: 0; }
.btn-new-chat:hover  { background: var(--orange-dk); }
.btn-new-chat:active { opacity: .85; }

/* ---- 検索 ---- */
.sidebar-search-wrap {
  display: flex;
  align-items: center;
  padding: 4px 10px 6px;
  flex-shrink: 0;
}
.sidebar-search-wrap svg { color: var(--text-inv-sub); margin-right: 7px; flex-shrink: 0; }
.sidebar-search-wrap input {
  flex: 1;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 12px;
  transition: background var(--tr);
}
.sidebar-search-wrap input::placeholder { color: var(--text-inv-sub); }
.sidebar-search-wrap input:focus        { background: rgba(255,255,255,.13); }

/* ---- 会話リスト ---- */
.conv-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 0;
}
.conv-list::-webkit-scrollbar       { width: 3px; }
.conv-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 2px; }

.list-loading {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 24px;
}
.list-loading span, .dot-loader span {
  display: block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-inv-sub);
  animation: dlB 1.2s infinite ease-in-out;
}
.list-loading span:nth-child(2), .dot-loader span:nth-child(2) { animation-delay: .2s; }
.list-loading span:nth-child(3), .dot-loader span:nth-child(3) { animation-delay: .4s; }
@keyframes dlB { 0%,80%,100%{ transform: translateY(0); } 40%{ transform: translateY(-6px); } }

.dot-loader { display: flex; gap: 5px; justify-content: center; padding: 16px; }

.list-empty { padding: 20px 12px; text-align: center; color: var(--text-inv-sub); font-size: 12px; line-height: 1.7; }

/* ---- 会話アイテム（LINE風） ---- */
.conv-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  position: relative;
  transition: background var(--tr);
  border-bottom: 1px solid var(--sidebar-bd2);
}
.conv-item:hover  { background: var(--sidebar-h); }
.conv-item.active { background: var(--sidebar-a); }
.conv-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--orange);
  border-radius: 0 2px 2px 0;
}

/* アバター */
.conv-av {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--orange);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

/* 情報エリア */
.conv-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-info-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.conv-user-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-inv);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 10px;
  color: var(--text-inv-sub);
  white-space: nowrap;
  flex-shrink: 0;
}

.conv-info-title {
  font-size: 12px;
  color: var(--text-inv-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item.active .conv-info-title { color: rgba(255,255,255,.6); }

.conv-info-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.conv-last-msg {
  font-size: 12px;
  color: var(--text-inv-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.conv-no-msg { opacity: .5; }

/* 未読バッジ */
.conv-unread {
  flex-shrink: 0;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--orange);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  animation: badgePop .2s cubic-bezier(.34,1.56,.64,1);
}
@keyframes badgePop { from { transform: scale(0); } to { transform: scale(1); } }

/* ---- フッターリンク ---- */
.sidebar-footer-links {
  padding: 6px 6px 10px;
  border-top: 1px solid var(--sidebar-bd);
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex-shrink: 0;
}
.footer-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  color: var(--text-inv-sub);
  font-size: 12px;
  cursor: pointer;
  transition: background var(--tr), color var(--tr);
}
.footer-link svg { flex-shrink: 0; }
.footer-link:hover { background: var(--sidebar-h); color: var(--text-inv); }

/* ============================================================
   CENTER CHAT AREA
   ============================================================ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

/* ウェルカム */
.chat-welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome-box {
  text-align: center;
  padding: 32px 24px;
  max-width: 400px;
  animation: fadeUp .4s ease;
}
@keyframes fadeUp { from { opacity:0; transform: translateY(14px); } to { opacity:1; transform: none; } }

.welcome-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: var(--sh-md);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
}
.welcome-icon svg { color: var(--orange); }
.welcome-box h2   { font-size: 20px; font-weight: 700; margin-bottom: 10px; }
.welcome-box p    { font-size: 14px; color: var(--text-sub); line-height: 1.7; margin-bottom: 24px; }

.btn-start {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 24px;
  border-radius: var(--r-lg);
  background: var(--orange);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  transition: background var(--tr);
}
.btn-start:hover { background: var(--orange-dk); }

/* チャットメイン */
.chat-main { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

/* チャットヘッダー */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--header-h);
  padding: 0 14px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--sh-sm);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.btn-back { display: none; }

.chat-header-title { flex: 1; min-width: 0; }
.chat-header-title h3 {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-meta { font-size: 11px; color: var(--text-hint); display: block; }

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  position: relative;
}

.status-tag {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.status-tag.open   { background: #dcfce7; color: #166534; }
.status-tag.closed { background: var(--border-lt); color: var(--text-sub); }

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  color: var(--text-sub);
  transition: background var(--tr), color var(--tr);
}
.btn-icon:hover { background: var(--bg2); color: var(--text); }

.more-wrap { position: relative; }
.dropdown {
  display: none;
  position: absolute;
  top: 40px; right: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  min-width: 140px;
  overflow: hidden;
  z-index: 200;
  animation: dropIn .15s ease;
}
.dropdown.open { display: block; }
@keyframes dropIn { from { opacity:0; transform: translateY(-6px); } to { opacity:1; transform: none; } }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  transition: background var(--tr);
  text-align: left;
}
.dropdown-item:hover { background: var(--bg); }

/* ============================================================
   メッセージエリア
   ============================================================ */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg);
}
.messages::-webkit-scrollbar       { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.date-div {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--text-hint);
  margin: 8px 0;
}
.date-div::before, .date-div::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msgIn .2s ease;
}
@keyframes msgIn { from { opacity:0; transform: translateY(6px); } to { opacity:1; transform: none; } }

.msg-row.customer { flex-direction: row-reverse; }
.msg-row.ai       { flex-direction: row; }

.msg-av {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #fff;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.msg-row.customer .msg-av { background: var(--orange); }
.msg-row.ai       .msg-av { background: #374151; }

.msg-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 70%;
  min-width: 0;
}
.msg-row.customer .msg-wrap { align-items: flex-end; }
.msg-row.ai       .msg-wrap { align-items: flex-start; }

.msg-sender { font-size: 11px; color: var(--text-hint); padding: 0 3px; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--r-xl);
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.customer .msg-bubble {
  background: var(--orange);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-row.ai .msg-bubble {
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--sh-sm);
}

.msg-time { font-size: 11px; color: var(--text-hint); padding: 0 3px; }

.typing-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px 10px;
}
.typing-av {
  width: 30px; height: 30px; border-radius: 50%;
  background: #374151;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.typing-bubble {
  display: flex; gap: 4px;
  padding: 11px 15px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  border-bottom-left-radius: 4px;
  box-shadow: var(--sh-sm);
}
.typing-bubble span {
  display: block;
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-hint);
  animation: tb 1.2s infinite ease-in-out;
}
.typing-bubble span:nth-child(2) { animation-delay: .2s; }
.typing-bubble span:nth-child(3) { animation-delay: .4s; }
@keyframes tb { 0%,80%,100%{ transform: translateY(0); opacity:.5; } 40%{ transform: translateY(-5px); opacity:1; } }

/* ============================================================
   入力エリア
   ============================================================ */
.input-area {
  padding: 10px 14px 14px;
  background: var(--white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-box {
  border: 1.5px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--bg);
  overflow: hidden;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.input-box:focus-within {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(249,115,22,.1);
}
.input-box textarea {
  display: block; width: 100%;
  padding: 12px 14px 4px;
  font-size: 14px; color: var(--text);
  resize: none; min-height: 42px; max-height: 130px;
  overflow-y: auto; background: transparent; line-height: 1.6;
}
.input-box textarea::placeholder { color: var(--text-hint); }

.input-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px 8px;
}
.input-hint-text { font-size: 11px; color: var(--text-hint); }

.btn-send {
  display: flex; align-items: center; gap: 5px;
  padding: 7px 16px; border-radius: 20px;
  background: var(--border); color: var(--text-hint);
  font-size: 13px; font-weight: 700;
  transition: background var(--tr), color var(--tr);
}
.btn-send svg { flex-shrink: 0; }
.btn-send:not(:disabled) { background: var(--orange); color: #fff; }
.btn-send:not(:disabled):hover  { background: var(--orange-dk); }
.btn-send:disabled { cursor: not-allowed; }

.closed-notice {
  text-align: center; padding: 12px;
  font-size: 13px; color: var(--text-sub);
  background: var(--bg); border-radius: var(--r-md);
  border: 1px dashed var(--border);
}

/* ============================================================
   RIGHT PANEL
   ============================================================ */
.ref-panel {
  display: flex;
  flex-direction: column;
  width: 0; min-width: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--white);
  border-left: 1px solid var(--border);
  overflow: hidden;
  overflow-y: auto;
  transition: width var(--tr), min-width var(--tr);
}
.ref-panel.open { width: var(--panel-w); min-width: var(--panel-w); }
.ref-panel::-webkit-scrollbar       { width: 4px; }
.ref-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.panel-head {
  display: flex; align-items: center; gap: 8px;
  height: var(--header-h); padding: 0 13px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
  background: var(--white); flex-shrink: 0;
}
.panel-head h3  { flex: 1; font-size: 13px; font-weight: 700; }
.panel-turn     { font-size: 11px; color: var(--text-hint); white-space: nowrap; }
.btn-panel-close:hover { background: var(--bg); }

.panel-search-bar {
  display: flex; align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-lt);
  position: sticky; top: var(--header-h); z-index: 4;
  background: var(--white); flex-shrink: 0;
}
.panel-search-bar svg { flex-shrink: 0; color: var(--text-hint); margin-right: 7px; }
.panel-search-bar input {
  flex: 1; padding: 7px 10px;
  border: 1.5px solid var(--border); border-radius: var(--r-sm);
  font-size: 12px; color: var(--text); background: var(--bg);
  transition: border-color var(--tr);
}
.panel-search-bar input:focus        { border-color: var(--orange); }
.panel-search-bar input::placeholder { color: var(--text-hint); }

.panel-sec { padding: 12px; border-bottom: 1px solid var(--border-lt); }
.panel-sec-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px; flex-wrap: wrap;
}

.sec-badge {
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
}
.badge-ai {
  background: var(--orange-lt); color: #c2410c;
  display: flex; align-items: center; gap: 5px;
}
.badge-ai::before {
  content: ''; display: block;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--orange);
  animation: pulse 1.6s infinite;
}
@keyframes pulse { 0%,100%{ opacity:1; } 50%{ opacity:.4; } }

.badge-qa   { background: #eff6ff; color: #1d4ed8; }
.badge-page { background: #f0fdf4; color: #166534; }
.sec-count  { font-size: 11px; color: var(--text-hint); }

.cat-sel {
  margin-left: auto;
  padding: 3px 20px 3px 7px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--bg); color: var(--text-sub); font-size: 11px; cursor: pointer;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239ca3af' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 5px center;
}

/* カード */
.ref-cards { display: flex; flex-direction: column; gap: 8px; }

.card {
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--white); overflow: hidden; cursor: pointer;
  transition: border-color var(--tr), box-shadow var(--tr);
  animation: cIn .2s ease;
}
@keyframes cIn { from { opacity:0; transform: translateY(4px); } to { opacity:1; transform: none; } }
.card:hover    { border-color: var(--orange); box-shadow: 0 2px 10px rgba(249,115,22,.1); }
.card.ai-card  { border-color: var(--orange); background: #fffcf9; }

.card-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--orange); color: #fff;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.card-head { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px 5px; }
.card-cat, .card-type-qa, .card-type-page {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 10px; font-weight: 600; white-space: nowrap; flex-shrink: 0;
}
.card-cat       { background: var(--orange-lt); color: var(--orange-dk); }
.card-type-qa   { background: #eff6ff; color: #1d4ed8; }
.card-type-page { background: #f0fdf4; color: #166534; }

.card-title { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.4; flex: 1; min-width: 0; }
.card-body  { padding: 0 12px 8px; }
.card-q     { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 4px; line-height: 1.5; }
.card-a     { font-size: 12px; color: var(--text-sub); line-height: 1.6; }
.card-a.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card.expanded .card-a { -webkit-line-clamp: unset; overflow: visible; }

.card-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 12px 9px; border-top: 1px solid var(--border-lt);
}

/* URLボタン（通常ページ・動画共通） */
.card-url-btn {
  display: -webkit-inline-flex;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  transition: background var(--tr), color var(--tr);
  flex-shrink: 0;
  /* 通常ページ：オレンジ枠 */
  border: 1.5px solid var(--orange);
  color: var(--orange);
  background: var(--white);
}
.card-url-btn:hover {
  background: var(--orange);
  color: #fff;
  text-decoration: none;
}

/* 動画ボタン：塗りつぶし */
.card-url-btn-video {
  background: #1c1d2e;
  color: #fff;
  border-color: #1c1d2e;
}
.card-url-btn-video:hover {
  background: #374151;
  border-color: #374151;
  color: #fff;
}

/* 旧スタイル（後方互換） */
.card-url {
  font-size: 11px; color: var(--orange);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 170px; text-decoration: none;
}
.card-url:hover { text-decoration: underline; }
.btn-expand {
  font-size: 11px; color: var(--text-sub);
  display: flex; align-items: center; gap: 3px;
  padding: 3px 8px; border-radius: var(--r-sm); flex-shrink: 0;
  transition: background var(--tr);
}
.btn-expand svg { width: 12px !important; height: 12px !important; }
.btn-expand:hover { background: var(--bg); color: var(--text); }

.panel-hint {
  font-size: 12px; color: var(--text-hint);
  text-align: center; line-height: 1.7; padding: 16px 8px;
}

/* ============================================================
   共通コンポーネント
   ============================================================ */
.toast-stack {
  position: fixed; bottom: 22px; right: 22px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 7px;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 16px; border-radius: var(--r-md);
  font-size: 13px; font-weight: 600; color: #fff;
  box-shadow: var(--sh-lg); max-width: 320px;
  animation: tIn .22s ease;
}
.toast.success { background: #064e3b; border-left: 3px solid #22c55e; }
.toast.error   { background: #7f1d1d; border-left: 3px solid #ef4444; }
.toast.info    { background: #431407; border-left: 3px solid var(--orange); }
.toast.removing { animation: tOut .2s ease forwards; }
@keyframes tIn  { from { opacity:0; transform: translateX(18px); } to { opacity:1; transform: none; } }
@keyframes tOut { to   { opacity:0; transform: translateX(18px); } }

/* ============================================================
   オーバーレイ（モバイル用）
   ▼ blur削除 + 半透明のみ。パネルの視認性を確保
   ============================================================ */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  /* backdrop-filter を削除してモザイク解消 */
  z-index: 90;
}
.overlay.show { display: block; }

/* モバイルメニューボタン */
#btn-mobile-menu {
  display: none;
  position: fixed;
  bottom: 18px; left: 18px;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--orange);
  color: #fff;
  box-shadow: var(--sh-lg);
  z-index: 200;
  align-items: center; justify-content: center;
}

/* ============================================================
   レスポンシブ
   ============================================================ */
@media screen and (max-width: 900px) {
  :root { --sidebar-w: 260px; --panel-w: 82vw; }

  /* サイドバー */
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    z-index: 100;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--sh-lg);
  }

  /* 右パネル: ★ z-index をオーバーレイ(90)より高く設定 ★ */
  .ref-panel {
    position: fixed;
    right: 0; top: 0; bottom: 0;
    width: 0 !important;
    min-width: 0 !important;
    z-index: 95;  /* overlay(90) より上 */
  }
  .ref-panel.open {
    width: var(--panel-w) !important;
    min-width: 0 !important;
    box-shadow: var(--sh-lg);
  }

  .btn-back          { display: flex; }
  #btn-mobile-menu   { display: flex; }

  .toast-stack { bottom: 76px; right: 10px; left: 10px; }
  .toast       { max-width: 100%; }
}

@media screen and (max-width: 480px) {
  :root { --panel-w: 100vw; }

  .messages    { padding: 12px 10px 8px; }
  .msg-wrap    { max-width: 85%; }
  .input-area  { padding: 8px 10px 12px; }
  .welcome-box { padding: 24px 16px; }

  /* スマホでパネルが全画面の場合、閉じるボタンを大きく */
  .btn-panel-close {
    width: 40px;
    height: 40px;
  }
}

/* ============================================================
   iOS Safari 入力欄隠れ問題の修正
   - 100dvh: Dynamic Viewport Height（iOS15.4+対応）
   - env(safe-area-inset-bottom): ホームバー対応
   - キーボード表示時も入力欄が確実に見える
   ============================================================ */
@supports (height: 100dvh) {
  #app,
  .sidebar,
  .chat-area,
  .ref-panel {
    height: 100dvh;
  }
}

@media screen and (max-width: 900px) {

  /* チャット全体を画面にフィット（アドレスバー・ナビバー考慮） */
  #app {
    height: 100vh;
    height: 100dvh;
    /* iOSのsafe areaに対応（ホームバーがある機種） */
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-bottom: constant(safe-area-inset-bottom, 0px); /* iOS 11.0 compat */
  }

  /* chat-area はflexで残り全体を使う */
  .chat-area {
    height: 100%;
    max-height: 100%;
  }

  /* chat-mainはflexで縦に積み、入力欄は最下部に固定 */
  .chat-main {
    height: 100%;
    min-height: 0;
  }

  /* messagesエリアがflexで残りを埋める（入力欄を押し出さない） */
  .messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* 入力エリアは常に最下部・flex-shrinkしない */
  .input-area {
    flex-shrink: 0;
    position: relative;
    /* iOSホームバー分の余白 */
    padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
    padding-bottom: max(14px, constant(safe-area-inset-bottom, 14px));
    background: var(--white);
  }

  /* タイピングインジケーターも縮まない */
  .typing-row {
    flex-shrink: 0;
  }

  /* welcomeボックスはスクロール可能にする */
  .chat-welcome {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media screen and (max-width: 480px) {
  /* テキストエリアの最大高さをスマホ向けに制限 */
  .input-box textarea {
    max-height: 80px;
  }

  /* 入力エリアのパディング調整 */
  .input-area {
    padding: 8px 10px max(12px, env(safe-area-inset-bottom, 12px));
    padding: 8px 10px max(12px, constant(safe-area-inset-bottom, 12px));
  }

  /* ヒントテキストをスマホでは非表示 */
  .input-hint-text {
    display: none;
  }
}

/* ============================================================
   --vh カスタムプロパティ（app.jsでJSがセット）
   dvh非対応の古いiOS Safari用フォールバック
   ============================================================ */
@supports not (height: 100dvh) {
  #app {
    height: calc(var(--vh, 1vh) * 100);
  }
  .sidebar,
  .chat-area,
  .ref-panel {
    height: calc(var(--vh, 1vh) * 100);
  }
}

/* ============================================================
   ログイン画面レスポンシブ強化
   ============================================================ */

/* ログインタブのボタンにアイコン込みで整える */
.user-modal-btn svg {
  display: inline;
  vertical-align: -2px;
}

/* タブが2つ並んだときに均等割り */
.user-modal-tabs {
  gap: 0;
}

/* モーダル全体を画面高さに合わせてスクロール可能に */
.user-modal {
  align-items: flex-start;
  padding: 16px;
}

@media (min-height: 600px) {
  .user-modal {
    align-items: center;
  }
}

/* スマホ: モーダルを画面幅いっぱいに */
@media (max-width: 500px) {
  .user-modal {
    padding: 0;
    align-items: flex-end;
  }
  .user-modal-box {
    border-radius: 16px 16px 0 0 !important;
    max-width: 100% !important;
    padding: 20px 16px 32px !important;
    max-height: 92dvh;
    overflow-y: auto;
  }
  .user-modal-icon { font-size: 28px; margin-bottom: 6px; }
  .user-modal-title { font-size: 17px; }
  .user-modal-tabs { margin-bottom: 14px; }
  .modal-form-group { margin-bottom: 8px; }
  .user-modal-btn { padding: 13px; font-size: 15px; }
}

/* ============================================================
   ログイン・新規登録フォーム — WordPressライクな入力欄スタイル
   ============================================================ */

/* フォームグループ */
.modal-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

/* ラベル: 太め・少し大きく */
.modal-form-group label {
  font-size: 13px;
  font-weight: 600;
  color: #3c434a;  /* WordPress風の落ち着いたグレー */
  letter-spacing: .01em;
}

/* 必須マーク */
.modal-form-group .req { color: var(--orange); margin-left: 3px; }

/* 入力欄: ボーダーをくっきりさせてWordPress風に */
.modal-form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #8c8f94;     /* WordPress と同じボーダー色 */
  border-radius: 4px;
  font-size: 15px;
  font-family: var(--font);
  color: var(--text);
  background: #fff;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.07);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  -webkit-appearance: none;
}
.modal-form-group input:focus {
  border-color: #2271b1;          /* WordPressのブルーフォーカス → オレンジに変更 */
  border-color: var(--orange);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.07), 0 0 0 3px rgba(249,115,22,.12);
  background: #fff;
}
.modal-form-group input::placeholder {
  color: #b4b9be;
  font-size: 14px;
}

/* エラーメッセージ */
.modal-field-err {
  font-size: 12px;
  color: #dc2626;
  display: none;
  margin-top: 2px;
}

/* パスワードラップ */
.pw-wrap {
  position: relative;
}
.pw-wrap input {
  padding-right: 44px;
}
.pw-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  padding: 2px 4px;
  line-height: 1;
  opacity: .55;
  transition: opacity .15s;
  color: #3c434a;
}
.pw-toggle:hover { opacity: 1; }

/* アラートボックス */
.modal-alert {
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 14px;
  line-height: 1.5;
}
.modal-alert-err {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-left: 3px solid #dc2626;
  color: #b91c1c;
}
.modal-alert-ok {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-left: 3px solid #16a34a;
  color: #15803d;
}

/* ログイン・登録ボタン */
.user-modal-btn {
  width: 100%;
  padding: 12px 16px;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  letter-spacing: .02em;
}
.user-modal-btn:hover {
  background: var(--orange-dk);
  box-shadow: 0 2px 8px rgba(249,115,22,.3);
}
.user-modal-btn:disabled {
  background: var(--border);
  color: var(--text-hint);
  cursor: not-allowed;
  box-shadow: none;
}

/* リンク（パスワード忘れ等） */
.modal-links {
  text-align: center;
  margin-top: 14px;
}
.modal-links a {
  font-size: 13px;
  color: #2271b1;
  color: var(--orange);
  text-decoration: none;
}
.modal-links a:hover { text-decoration: underline; }

/* 2カラムグリッド（新規登録） */
.modal-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* タブナビ */
.user-modal-tabs {
  display: flex;
  border: 1px solid #8c8f94;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 18px;
}
.user-modal-tab-btn {
  flex: 1;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #3c434a;
  background: #f6f7f7;
  border: none;
  cursor: pointer;
  transition: background .15s, color .15s;
  font-family: var(--font);
}
.user-modal-tab-btn:not(:last-child) {
  border-right: 1px solid #8c8f94;
}
.user-modal-tab-btn.active {
  background: var(--orange);
  color: #fff;
}

/* モーダルボックス */
.user-modal-box {
  background: var(--white);
  border-radius: 6px;
  padding: 28px 28px 24px;
  width: 100%;
  max-width: 380px;    /* WordPressに近い幅 */
  box-shadow: 0 1px 3px rgba(0,0,0,.13), 0 8px 28px rgba(0,0,0,.10);
  animation: modalIn .2s ease;
}

.user-modal-icon  { font-size: 32px; text-align: center; margin-bottom: 8px; }
.user-modal-title {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 18px;
  color: var(--text);
}
.user-modal-desc  { font-size: 13px; color: var(--text-sub); text-align: center; margin-bottom: 16px; }

/* Googleボタン */
.user-modal-google-wrap {
  margin-bottom: 10px;
  display: flex;
  justify-content: center;
}
.user-modal-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 16px;
  color: #8c8f94;
  font-size: 12px;
}
.user-modal-divider::before,
.user-modal-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e0e0e0;
}

/* スマホ */
@media (max-width: 500px) {
  .modal-row-2 { grid-template-columns: 1fr; gap: 0; }
  .user-modal-box {
    max-width: 100% !important;
    border-radius: 16px 16px 0 0 !important;
    padding: 22px 16px 28px !important;
  }
  .modal-form-group input { font-size: 16px; /* iOSでズームしない */ }
}