/* ========================================
   チャットページ専用スタイル
======================================== */

/* ========================================
   メイン背景色
======================================== */
body.chat-page {
  background: var(--color-bg-primary) !important;
}

body.chat-page .app {
  background: var(--color-bg-primary) !important;
}

/* ========================================
   メインレイアウト（2カラム）
======================================== */
.chat-page .main-layout {
  display: flex;
  flex-direction: row;
  margin-top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* ========================================
   サイドバー（左側）
======================================== */
.chat-page .sidebar {
  width: var(--sidebar-width);
  background: var(--color-bg-secondary);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px 16px 12px 16px;
  flex-shrink: 0;
}

.new-chat-btn {
  width: 100%;
  padding: 10px 16px;
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-radius: 24px;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.new-chat-btn:hover {
  background: var(--color-bg-primary);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-search {
  padding: 0 16px 12px 16px;
  flex-shrink: 0;
}

.sidebar-search .search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 24px;
  font-size: var(--font-size-sm);
  background: var(--color-bg-secondary);
  transition: all var(--transition-fast);
  background: var(--color-bg-input);
}

.sidebar-search .search-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.sidebar-search .search-input::placeholder {
  color: var(--color-text-muted);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 16px 16px;
}

/* ========================================
   チャット履歴が空の時
======================================== */
.chat-history-empty {
  padding: var(--space-xl) var(--space-md);
  text-align: center;
}

.chat-history-empty p {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* ========================================
   チャット履歴アイテム（共通）
======================================== */
.history-item,
.chat-history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s ease;
  margin-bottom: 2px;
  border-left: 3px solid transparent;
}

.history-item:hover,
.chat-history-item:hover {
  background: rgba(48, 48, 48, 0.1);
  border-left-color: rgba(48, 48, 48, 0.3);
}

.history-item.active,
.chat-history-item.active {
  background: rgba(48, 48, 48, 0.1);
  border-left-color: #303030;
}

[data-theme="dark"] .history-item:hover,
[data-theme="dark"] .chat-history-item:hover {
  background: rgba(48, 48, 48, 0.6);
  border-left-color: rgba(48, 48, 48, 0.8);
}

[data-theme="dark"] .history-item.active,
[data-theme="dark"] .chat-history-item.active {
  background: rgba(48, 48, 48, 0.6);
  border-left-color: #303030;
}

.history-item-content,
.chat-history-content {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.history-item-title,
.chat-history-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text-primary);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}

.history-item-date,
.chat-history-date {
  font-size: 11px;
  color: var(--color-text-muted);
  font-weight: 400;
  display: block;
  margin-top: 4px;
}

/* ========================================
   ⋮メニューボタン
======================================== */
.history-menu-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 20px;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  pointer-events: auto;
}

.history-item:hover .history-menu-btn,
.chat-history-item:hover .history-menu-btn {
  opacity: 1;
}

.history-menu-btn:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

[data-theme="dark"] .history-menu-btn {
  color: var(--color-text-muted);
}

[data-theme="dark"] .history-menu-btn:hover {
  background: var(--color-text-secondary);
  color: var(--color-bg-hover);
}

/* ========================================
   メインコンテンツ（右側）
======================================== */
.chat-page .main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-primary);
  position: relative;
  padding: 0 !important;
  margin: 0 !important;
}

/* ========================================
   チャット未選択時
======================================== */
.chat-empty {
  display: flex !important;
  align-items: center;
  justify-content: center;
  height: 100% !important;
  overflow: hidden !important;
  background: var(--color-bg-primary);
}

.chat-empty.hidden {
  display: none !important;
}

.chat-empty-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  overflow-y: auto;
  padding-bottom: 0 !important;
}

.chat-empty-content h2 {
  font-size: 24px;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  margin-bottom: 0;
  text-align: center;
}

/* ========================================
   チャットコンテンツエリア
======================================== */
.chat-content {
  padding: 0 !important;
  margin: 0 !important;
  display: none !important;
  flex-direction: column !important;
  height: 100% !important;
  overflow: hidden !important;
}

.chat-content.active {
  display: flex !important;
}

.chat-header {
  display: none !important;
}

/* ========================================
   メッセージ表示エリア
======================================== */
.chat-messages {
  flex: 1 !important;
  overflow-y: auto !important;
  padding: 24px !important;
  padding-bottom: 200px !important;
  background: var(--color-bg-primary) !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: flex-start !important;
  align-items: center !important;
  gap: 24px !important;
  min-height: 0 !important;
}

/* ========================================
   メッセージ
======================================== */
.message {
  display: flex;
  gap: 0;
  max-width: 1000px;
  width: 100%;
  animation: messageSlideIn 0.3s ease;
  align-self: center;
  padding: 0 !important;
  margin: 0 !important;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  display: none !important;
}

.message-content {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: calc(100% - 64px);
  padding: 0;
  margin: 0;
}

.message-time {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
  align-self: flex-start;
  display: block !important;
}

[data-theme="dark"] .message-time {
  color: var(--color-border-hover) !important;
}

.message.assistant .message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.message.assistant .message-sender {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.message.user .message-header {
  display: none;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 24px;
  font-size: 16px;
  line-height: 1.5;
  font-weight: 400;
  font-family: var(--font-family);
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  width: 100%;
  box-sizing: border-box;
  margin: 0;
}

.message.assistant .message-bubble {
  background: transparent;
  color: var(--color-text-primary);
  border: none;
  box-shadow: none;
  padding: 12px 0;
}

.message.user .message-bubble {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
}

[data-theme="dark"] .message.user .message-bubble {
  background: #181818 !important;
  color: var(--color-text-primary) !important;
  border: 1px solid var(--color-border) !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3) !important;
}

[data-theme="dark"] .message.assistant .message-bubble {
  background: transparent !important;
  color: var(--color-text-primary) !important;
  border: none !important;
  box-shadow: none !important;
  padding: 12px 0 !important;
}

/* ========================================
   入力エリア
======================================== */
.chat-input-area {
  position: fixed !important;
  bottom: 0 !important;
  left: var(--sidebar-width) !important;
  right: 0 !important;
  padding: 4px 24px 24px 24px !important;
  background: var(--color-bg-primary) !important;
  z-index: 100 !important;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05) !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
}

.chat-input-wrapper {
  display: flex;
  gap: var(--space-md);
  align-items: flex-end;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 0;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: 24px;
  font-size: 16px;
  font-weight: 400;
  font-family: var(--font-family);
  resize: none;
  height: 48px;
  min-height: 48px;
  max-height: 264px;
  overflow-y: auto;
  background: var(--color-bg-primary);
  transition: all var(--transition-fast);
  line-height: 1.5;
  margin: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  background: var(--color-bg-input);
}

.chat-input::-webkit-scrollbar {
  display: none;
}

.chat-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-input::placeholder {
  color: var(--color-text-muted);
}

.chat-send-btn {
  width: 48px;
  height: 48px;
  padding: 0;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  color: var(--color-text-primary);
  font-size: 20px;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.chat-send-btn:hover {
  background: var(--color-bg-secondary);
  transform: scale(1.05);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chat-send-btn:focus {
  outline: none;
  background: var(--color-bg-primary);
  transform: scale(1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.chat-send-btn:active {
  transform: scale(0.95);
}

.chat-send-btn:disabled {
  background: var(--color-border);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  opacity: 0.5;
}

.send-icon {
  display: block;
  line-height: 1;
}

/* ========================================
   スクロールバー
======================================== */
.sidebar-content::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar,
.mobile-history::-webkit-scrollbar {
  width: 8px;
}

.sidebar-content::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track,
.mobile-history::-webkit-scrollbar-track {
  background: var(--color-bg-secondary);
}

.sidebar-content::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb,
.mobile-history::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover,
.mobile-history::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* ========================================
   セッションメニュー（ドロップダウン）
======================================== */
.session-menu {
  position: fixed;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow:
    0 10px 25px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.05);
  z-index: 1000;
  min-width: 160px;
  overflow: hidden;
  animation: menuSlideIn 0.15s ease;
}

@keyframes menuSlideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

[data-theme="dark"] .session-menu {
  box-shadow:
    0 10px 25px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.05);
}

.session-menu .menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-primary);
  transition: background 0.15s ease;
}

.session-menu .menu-item:hover {
  background: var(--color-bg-hover);
}

[data-theme="dark"] .session-menu .menu-item {
  color: var(--color-text-primary);
}

[data-theme="dark"] .session-menu .menu-item:hover {
  background: var(--color-bg-hover);
}

.session-menu .menu-item.delete {
  color: var(--color-error);
}

.session-menu .menu-item.delete:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-error);
}

[data-theme="dark"] .session-menu .menu-item.delete:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* ========================================
   モーダル
======================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.2s;
}

[data-theme="dark"] .modal-overlay {
  background: rgba(0, 0, 0, 0.7);
}

.modal-content {
  background: var(--color-bg-primary);
  border-radius: 16px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
  box-shadow:
    0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);
  animation: modalSlideUp 0.2s ease;
}

[data-theme="dark"] .modal-content {
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0 0 16px 0;
  line-height: 1.4;
}

.modal-title.danger {
  color: var(--color-error);
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-message {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: 20px;
  line-height: 1.6;
}

.modal-message.danger {
  color: var(--color-error);
  font-weight: 500;
}

.modal-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--color-text-primary);
  background: var(--color-bg-secondary);
  margin-bottom: 20px;
  box-sizing: border-box;
  transition: all 0.2s ease;
}

.modal-input:focus {
  outline: none;
  border-color: var(--color-info);
  background: var(--color-bg-primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] .modal-input {
  background: var(--color-text-secondary);
  border-color: var(--color-text-secondary);
  color: var(--color-bg-secondary);
}

[data-theme="dark"] .modal-input:focus {
  border-color: var(--color-info);
  box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.1);
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-btn {
  padding: 10px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.modal-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* キャンセルボタン */
.modal-btn.cancel {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.modal-btn.cancel:hover {
  background: var(--color-border);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] .modal-btn.cancel {
  background: var(--color-text-primary);
  color: var(--color-bg-primary);
  border-color: var(--color-text-secondary);
}

[data-theme="dark"] .modal-btn.cancel:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

/* 保存ボタン */
.modal-btn.confirm {
  background: var(--color-text-primary);
  color: var(--color-bg-primary);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.3);
}

.modal-btn.confirm:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.4);
}

[data-theme="dark"] .modal-btn.confirm {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .modal-btn.confirm:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(255, 255, 255, 0.2);
}

/* 削除ボタン */
.modal-btn.delete {
  background: var(--color-error);
  color: white;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.modal-btn.delete:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

[data-theme="dark"] .modal-btn.delete {
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

[data-theme="dark"] .modal-btn.delete:hover {
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.5);
}

/* ========================================
   アニメーション
======================================== */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
  }

  to {
    transform: translateX(0);
  }
}

/* ========================================
   トースト通知
======================================== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: white;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 3000;
  animation: toastSlideIn 0.3s ease;
  opacity: 0;
  transition: opacity 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast.show {
  opacity: 1;
}

.toast.success {
  background: var(--color-success);
}

.toast.warning {
  background: var(--color-warning);
}

.toast.error {
  background: var(--color-error);
}

[data-theme="dark"] .toast {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* ========================================
   タイピングインジケーター
======================================== */
.typing-indicator {
  display: flex;
  gap: 0;
  max-width: 1000px;
  width: 100%;
  animation: messageSlideIn 0.3s ease;
  align-self: center;
  padding: 0 !important;
  margin: 0 !important;
}

.typing-indicator .message-content {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 0;
  margin: 0;
}

.typing-indicator .message-bubble {
  padding: 12px 0 !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  display: flex !important;
  gap: 0.5rem !important;
  align-items: center !important;
  width: auto !important;
  max-width: 80px !important;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-secondary);
  animation: typingAnimation 1.4s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingAnimation {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.7;
  }

  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

.typing-indicator.fade-out {
  animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

[data-theme="dark"] .typing-dot {
  background: var(--color-text-muted);
}

/* ========================================
   メッセージフェードイン
======================================== */
.message.fade-in {
  animation: messageFadeIn 0.3s ease forwards;
}

@keyframes messageFadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   メッセージアクションボタン
======================================== */
.message-wrapper {
  position: relative;
  width: 100%;
}

.message-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.message.assistant:hover .message-actions {
  opacity: 1;
}

.message-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.message-action-btn:hover {
  background: var(--color-bg-secondary);
  border-color: var(--color-border-hover);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.message-action-btn:active {
  transform: scale(0.98);
}

.message-action-btn.copied {
  background: var(--color-text-primary);
  color: var(--color-bg-primary);
  border-color: var(--color-text-primary);
}

.message-action-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

[data-theme="dark"] .message-action-btn {
  background: var(--color-bg-secondary);
  color: var(--color-text-primary);
  border-color: var(--color-border);
}

[data-theme="dark"] .message-action-btn.copied {
  background: var(--color-text-primary);
  color: var(--color-bg-primary);
  border-color: var(--color-text-primary);
}

/* ========================================
   検索ハイライト
======================================== */
.message.search-highlight {
  background: linear-gradient(
    90deg,
    rgba(255, 193, 7, 0.2) 0%,
    transparent 100%
  );
  border-left: 4px solid var(--color-warning);
  animation: highlight-pulse 0.5s ease;
  margin-left: -4px;
  padding-left: calc(12px + 4px);
}

@keyframes highlight-pulse {
  0%,
  100% {
    background: linear-gradient(
      90deg,
      rgba(255, 193, 7, 0.2) 0%,
      transparent 100%
    );
  }

  50% {
    background: linear-gradient(
      90deg,
      rgba(255, 193, 7, 0.4) 0%,
      transparent 100%
    );
  }
}

.search-keyword-highlight {
  background: var(--color-warning);
  color: var(--color-text-primary);
  padding: 2px 4px;
  border-radius: 3px;
  font-weight: 600;
}

[data-theme="dark"] .message.search-highlight {
  background: linear-gradient(
    90deg,
    rgba(255, 193, 7, 0.15) 0%,
    transparent 100%
  );
  border-left-color: var(--color-warning);
}

[data-theme="dark"] .search-keyword-highlight {
  background: var(--color-warning);
  color: var(--color-text-primary);
}

/* ========================================
   検索結果なし / ローディング
======================================== */
.search-no-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.search-no-results-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.search-no-results-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.search-no-results-message {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

[data-theme="dark"] .search-no-results-title {
  color: var(--color-border);
}

[data-theme="dark"] .search-no-results-message {
  color: var(--color-text-muted);
}

.search-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-info);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.search-loading p {
  font-size: 14px;
  color: var(--color-text-secondary);
}

[data-theme="dark"] .loading-spinner {
  border-color: var(--color-text-secondary);
  border-top-color: var(--color-info);
}

[data-theme="dark"] .search-loading p {
  color: var(--color-text-muted);
}

/* ========================================
   ファイル添付ボタン
======================================== */
.attach-file-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.attach-file-btn:hover {
  background: var(--color-bg-hover);
}

.attach-file-btn:active {
  transform: scale(0.95);
}

.attach-file-btn.active {
  background: var(--color-info);
  color: white;
}

/* ========================================
   ファイルプレビュー
======================================== */
.file-preview {
  padding: 12px;
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
  border-radius: 8px 8px 0 0;
  margin-bottom: -12px;
  width: 100%;
  max-width: 1000px;
}

.file-preview-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.file-preview-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--color-bg-secondary);
  border-radius: 6px;
  border: 1px solid var(--color-border);
  transition: background 0.2s;
}

.file-preview-item:hover {
  background: var(--color-bg-hover);
}

[data-theme="dark"] .file-preview-item {
  background: var(--color-text-primary);
  border-color: var(--color-text-secondary);
}

[data-theme="dark"] .file-preview-item:hover {
  background: var(--color-text-secondary);
}

.file-preview-item .file-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.file-preview-item .file-info {
  flex: 1;
  min-width: 0;
}

.file-preview-item .file-name {
  font-size: 14px;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.file-preview-item .file-size {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

[data-theme="dark"] .file-preview-item .file-name {
  color: var(--color-bg-secondary);
}

[data-theme="dark"] .file-preview-item .file-size {
  color: var(--color-text-muted);
}

.file-preview-item .remove-file-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--color-error);
  color: white;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 100;
  pointer-events: auto;
}

.file-preview-item .remove-file-btn:hover {
  transform: scale(1.1);
}

.file-preview-item .remove-file-btn:active {
  transform: scale(0.95);
}

.file-preview-summary {
  padding: 8px 12px;
  text-align: right;
  font-size: 12px;
  color: var(--color-text-secondary);
  border-top: 1px solid var(--color-border);
  margin-top: 4px;
  font-weight: 500;
}

[data-theme="dark"] .file-preview-summary {
  color: var(--color-text-muted);
  border-top-color: var(--color-text-secondary);
}

/* ========================================
   メッセージ内ファイル添付表示
======================================== */
.message-file-attachments {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 8px;
  border-left: 3px solid var(--color-info);
}

[data-theme="dark"] .message-file-attachments {
  background: rgba(255, 255, 255, 0.05);
}

.file-attachments-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.file-attachments-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-attachment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--color-bg-primary);
  border-radius: 6px;
  border: 1px solid var(--color-border);
}

.file-attachment-icon {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1;
}

.file-attachment-info {
  flex: 1;
  min-width: 0;
}

.file-attachment-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-attachment-size {
  font-size: 11px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.file-attachment-download {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 16px;
  background: #1e293b;
  color: #ffffff;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s;
}

.file-attachment-download:hover {
  background: #334155;
  transform: translateY(-1px);
}

.file-attachment-download:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

[data-theme="dark"] .file-attachment-download {
  background: #f1f5f9;
  color: #0f172a;
}

[data-theme="dark"] .file-attachment-download:hover {
  background: #e2e8f0;
}

/* ========================================
   参考資料・ナレッジ参照元
======================================== */
.message-references {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

.references-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.references-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.references-list li {
  padding: 8px 12px;
  margin-bottom: 6px;
  background: var(--color-bg-hover);
  border-radius: 6px;
  font-size: 13px;
  color: var(--color-text-secondary);
  border-left: 3px solid var(--color-primary);
  transition: all 0.2s;
  cursor: pointer;
}

.references-list li:hover {
  transform: translateX(4px);
}

/* ========================================
   チャット内検索バー
======================================== */
.chat-search-bar {
  display: none;
  gap: 8px;
  padding: 12px 24px;
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  align-items: center;
  flex-shrink: 0;
}

.chat-search-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 24px;
  font-size: 14px;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  transition: all 0.3s;
}

.chat-search-input:focus {
  outline: none;
  border-color: var(--color-info);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-search-input::placeholder {
  color: var(--color-text-muted);
}

.btn-search,
.btn-clear-search,
.btn-close-search {
  padding: 8px 16px;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-search {
  background: var(--color-text-primary);
  color: white;
}

.btn-search:hover {
  transform: translateY(-1px);
}

.btn-clear-search {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.btn-clear-search:hover {
  background: var(--color-border);
}

[data-theme="dark"] .btn-clear-search {
  background: var(--color-text-secondary);
  color: var(--color-bg-secondary);
}

.btn-close-search {
  background: transparent;
  color: var(--color-text-secondary);
  padding: 8px 12px;
}

.btn-close-search:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

[data-theme="dark"] .btn-close-search:hover {
  background: var(--color-text-secondary);
  color: var(--color-bg-secondary);
}

/* ========================================
   レスポンシブ: タブレット（1024px以下）
======================================== */
@media (max-width: 1024px) {
  .chat-page .sidebar {
    width: 250px;
  }

  .chat-input-area {
    left: 250px;
  }
}

/* ========================================
   レスポンシブ: モバイル（767px以下）
======================================== */
@media (max-width: 767px) {
  .chat-page .main-layout {
    flex-direction: column;
    height: calc(100vh - var(--header-height));
  }

  .chat-page .sidebar {
    display: none;
  }

  .chat-page .main-content {
    width: 100%;
    height: 100%;
  }

  .chat-empty-content {
    padding: var(--space-lg);
  }

  .chat-empty-content h2 {
    font-size: var(--font-size-xl);
  }

  .message,
  .message-content {
    max-width: 100% !important;
    width: 100% !important;
  }

  .message-bubble {
    width: 100% !important;
    font-size: 15px !important;
  }

  .chat-messages {
    padding: 16px !important;
    padding-bottom: 180px !important;
    gap: 16px !important;
    align-items: stretch !important;
  }

  .chat-input-area {
    left: 0 !important;
    right: 0 !important;
    padding: 8px 16px 16px 8px !important;
  }

  .chat-input-wrapper {
    max-width: 100% !important;
    width: 100% !important;
    gap: 8px !important;
  }

  .chat-input {
    font-size: 16px !important;
  }

  /* メニューボタンはモバイルで常に表示 */
  .history-menu-btn,
  .chat-history-item .history-menu-btn {
    opacity: 1;
    width: 40px;
    height: 40px;
    font-size: 24px;
  }

  /* メッセージアクションボタンはモバイルで常に表示 */
  .message-actions {
    opacity: 1;
  }

  .message-action-btn {
    font-size: 12px;
    padding: 5px 10px;
  }

  .modal-content {
    width: 95%;
    padding: 20px;
    border-radius: 12px;
  }

  .modal-title {
    font-size: 16px;
  }

  .modal-message {
    font-size: 13px;
  }

  .modal-btn {
    padding: 8px 16px;
    font-size: 13px;
  }

  .toast {
    bottom: 16px;
    right: 16px;
    left: 16px;
    text-align: center;
    justify-content: center;
  }

  .attach-file-btn {
    width: 36px;
    height: 36px;
  }

  .file-preview {
    padding: 8px;
  }

  .file-preview-item {
    padding: 10px 12px;
  }

  .file-preview-item .file-icon {
    font-size: 20px;
  }

  .file-preview-item .file-name {
    font-size: 13px;
  }

  .file-preview-item .file-size {
    font-size: 11px;
  }

  .file-preview-item .remove-file-btn {
    width: 28px;
    height: 28px;
    font-size: 18px;
  }

  .file-attachment-item {
    flex-wrap: wrap;
  }

  .file-attachment-download {
    width: 100%;
    justify-content: center;
    margin-top: 4px;
  }

  .chat-search-bar {
    padding: 8px 16px;
    flex-wrap: wrap;
  }

  .chat-search-input {
    flex: 1 1 100%;
    margin-bottom: 8px;
  }

  .btn-search,
  .btn-clear-search {
    flex: 1;
  }

  .btn-close-search {
    width: 100%;
  }
}

/* ========================================
   PC版表示（768px以上）
======================================== */
@media (min-width: 768px) {
  .chat-page .sidebar {
    display: flex !important;
  }
}
