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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #ffffff;
  height: 100vh;
  color: #333;
}

#app {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* --- サイドバー --- */
#sidebar {
  width: 260px;
  background: #f9f9f9;
  border-right: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  padding: 12px;
  flex-shrink: 0;
  transition: width 0.25s ease, padding 0.25s ease;
  overflow: hidden;
  position: relative;
}

#sidebar.collapsed {
  width: 0;
  padding: 0;
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

#new-chat-btn {
  flex: 1;
  padding: 10px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
  white-space: nowrap;
}

#new-chat-btn:hover {
  background: #f0f0f0;
}

#sidebar-toggle {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  cursor: pointer;
  color: #666;
  transition: background 0.2s;
}

#sidebar-toggle:hover {
  background: #f0f0f0;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
  gap: 8px;
  color: #767676;
  font-size: 0.8rem;
}

.history-loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #e5e5e5;
  border-top-color: #10a37f;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.history-item {
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.875rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s;
  flex-shrink: 0;
}

.history-item:hover {
  background: #f0f0f0;
}

.history-item.active {
  background: #ececec;
}

.history-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-delete-btn {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 4px;
  color: #767676;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.history-item:hover .history-delete-btn {
  opacity: 1;
}

.history-delete-btn:hover {
  background: #ddd;
  color: #555;
}

/* --- メインコンテンツ --- */
#chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #fff;
  overflow: hidden;
}

header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
  position: relative;
}

header h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

#sidebar-open {
  position: absolute;
  left: 12px;
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  cursor: pointer;
  color: #666;
  transition: background 0.2s;
}

#sidebar-open:hover {
  background: #f5f5f5;
}

#sidebar.collapsed ~ #chat-container #sidebar-open {
  display: flex;
}

#chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  scroll-behavior: smooth;
}

#messages {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* --- ウェルカム画面 --- */
#welcome {
  max-width: 400px;
  margin: 80px auto 40px;
  text-align: center;
  padding: 0 20px;
  color: #555;
}

#welcome .welcome-icon {
  width: 72px;
  height: 72px;
  background: #f0faf6;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  color: #10a37f;
}

#welcome h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: #333;
}

#welcome p {
  font-size: 0.95rem;
  line-height: 1.6;
  color: #767676;
}

#welcome.hidden {
  display: none;
}

/* --- メッセージ --- */
.message {
  display: flex;
  gap: 16px;
  width: 100%;
  animation: fadeSlideIn 0.25s ease both;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message .role {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.7rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.user .role {
  background: #5436da;
  color: #fff;
}

.message.assistant .role {
  background: #10a37f;
  color: #fff;
}

/* ユーザーメッセージを右寄せ */
.message.user {
  flex-direction: row-reverse;
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message.user .message-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message .bubble {
  line-height: 1.7;
  font-size: 1rem;
  word-break: break-word;
  padding-top: 4px;
}

/* ユーザーバブルは背景付きで右寄せ */
.message.user .bubble {
  background: #5436da;
  color: #fff;
  padding: 10px 14px;
  border-radius: 18px 18px 4px 18px;
  white-space: pre-wrap;
  max-width: 80%;
  display: inline-block;
}

/* Markdown レンダリング */
.message.assistant .bubble p {
  margin-bottom: 12px;
}

.message.assistant .bubble p:last-child {
  margin-bottom: 0;
}

.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3 {
  margin: 16px 0 8px;
  line-height: 1.4;
}

.message.assistant .bubble ul,
.message.assistant .bubble ol {
  padding-left: 24px;
  margin-bottom: 12px;
}

.message.assistant .bubble li {
  margin-bottom: 4px;
}

.message.assistant .bubble blockquote {
  border-left: 3px solid #ddd;
  padding-left: 12px;
  color: #666;
  margin: 12px 0;
}

.message.assistant .bubble code:not(pre code) {
  background: #f3f3f3;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.message.assistant .bubble pre {
  background: #f6f8fa;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
}

.message.assistant .bubble pre code {
  display: block;
  padding: 16px;
  font-size: 0.88em;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  background: none;
  border: none;
}

.message.error .bubble {
  color: #d00505;
}

.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 6px 14px;
  background: #fff;
  border: 1px solid #d00505;
  border-radius: 6px;
  color: #d00505;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.retry-btn:hover {
  background: #d00505;
  color: #fff;
}

/* --- メッセージアクション（コピーボタン） --- */
.message-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.15s;
}

.message:hover .message-actions {
  opacity: 1;
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: none;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  font-size: 0.78rem;
  color: #666;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.copy-btn:hover {
  background: #f5f5f5;
  color: #333;
}

.copy-btn.copied {
  color: #10a37f;
  border-color: #10a37f;
}

/* --- ステップインジケーター --- */
.step-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid #f0f0f0;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: #666;
  animation: fadeSlideIn 0.25s ease both;
}

.step-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0faf6;
  color: #10a37f;
  flex-shrink: 0;
}

.step-check {
  color: #10a37f;
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.step-pending {
  width: 14px;
  height: 14px;
  border: 2px solid #d0f0e6;
  border-top-color: #10a37f;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.step-time {
  font-size: 0.72rem;
  color: #767676;
  margin-left: 4px;
  flex-shrink: 0;
  min-width: 2.2em;
  text-align: right;
}

/* --- 参考資料 --- */
.sources-wrapper {
  margin-top: 12px;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.82rem;
}

.sources-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  color: #555;
  background: #fafafa;
  user-select: none;
  list-style: none;
}

.sources-summary::-webkit-details-marker { display: none; }

.sources-summary:hover {
  background: #f0f0f0;
}

.sources-wrapper[open] .sources-summary {
  border-bottom: 1px solid #e8e8e8;
}

.sources-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.source-item {
  padding: 8px 12px;
  border-bottom: 1px solid #f0f0f0;
}

.source-item:last-child {
  border-bottom: none;
}

.source-title {
  color: #333;
  font-weight: 500;
  word-break: break-all;
}

.source-title-link {
  color: #1a73e8;
  text-decoration: none;
  cursor: pointer;
}

.source-title-link:hover {
  text-decoration: underline;
  color: #1557b0;
}

.source-snippet {
  margin: 4px 0 0;
  color: #767676;
  font-size: 0.78rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- タイピングインジケーター --- */
.typing-indicator {
  display: flex;
  gap: 5px;
  padding-top: 8px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: #767676;
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}

/* --- スクロールダウンボタン --- */
#scroll-btn {
  position: absolute;
  bottom: 120px;
  right: 28px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #e5e5e5;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #555;
  transition: opacity 0.2s, transform 0.2s;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
}

#scroll-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

#scroll-btn:hover {
  background: #f5f5f5;
}

/* --- 入力エリア --- */
.input-area {
  max-width: 768px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 20px 20px;
  flex-shrink: 0;
}

#chat-form {
  position: relative;
  border: 1px solid #e5e5e5;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 0 15px rgba(0,0,0,0.06);
  display: flex;
  align-items: flex-end;
  transition: box-shadow 0.2s;
}

#chat-form:focus-within {
  box-shadow: 0 0 0 2px rgba(16,163,127,0.25), 0 0 15px rgba(0,0,0,0.06);
  border-color: #10a37f;
}

#input {
  flex: 1;
  padding: 14px 52px 14px 16px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.5;
}

#input::placeholder {
  color: #767676;
}

#send-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: #10a37f;
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#send-btn:hover:not(:disabled) {
  background: #0e9270;
}

#send-btn:active:not(:disabled) {
  transform: scale(0.93);
}

#send-btn:disabled {
  background: #e5e5e5;
  cursor: not-allowed;
}

#send-btn.is-sending,
#send-btn.is-sending:disabled {
  background: #10a37f;
  cursor: not-allowed;
}

.send-icon-spinner {
  display: none;
  position: relative;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
}

.send-icon-spinner::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  animation: send-spin 0.75s linear infinite;
}

@keyframes send-spin {
  to { transform: rotate(360deg); }
}

#send-btn.is-sending .send-icon-arrow {
  display: none;
}

#send-btn.is-sending .send-icon-spinner {
  display: flex;
}

.disclaimer {
  font-size: 0.75rem;
  color: #767676;
  text-align: center;
  margin-top: 10px;
}

.disclaimer kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 0.7rem;
  font-family: inherit;
  color: #666;
  background: #f3f3f3;
  border: 1px solid #d0d0d0;
  border-bottom-width: 2px;
  border-radius: 4px;
  line-height: 1.5;
}

.disclaimer .kbd-sep {
  margin: 0 1px;
  color: #767676;
}

/* --- サイドバー ユーザー表示 --- */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px;
  margin-top: 8px;
  border-top: 1px solid #e5e5e5;
  border-radius: 8px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
  transition: background 0.15s;
}

.sidebar-user:hover {
  background: #f0f0f0;
}

.user-chevron {
  flex-shrink: 0;
  color: #767676;
  transition: transform 0.2s;
}

.sidebar-user[aria-expanded="true"] .user-chevron {
  transform: rotate(180deg);
}

/* --- ユーザーメニューポップアップ --- */
.user-menu-popup {
  position: absolute;
  bottom: 60px;
  left: 8px;
  right: 8px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  z-index: 200;
  overflow: hidden;
}

.user-menu-popup.hidden {
  display: none;
}

.user-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: none;
  border: none;
  font-size: 0.875rem;
  color: #333;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.user-menu-item:hover {
  background: #f5f5f5;
}

.user-menu-item-danger {
  color: #d93025;
}

.user-menu-item-danger:hover {
  background: #fff5f5;
}

.user-menu-divider {
  height: 1px;
  background: #e5e5e5;
  margin: 2px 0;
}

.user-icon {
  flex-shrink: 0;
  color: #767676;
}

.user-name-text {
  flex: 1;
  font-size: 0.85rem;
  color: #555;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- 削除確認モーダル --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 24px 28px;
  width: 320px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.modal-message {
  font-size: 15px;
  color: #333;
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn {
  padding: 8px 18px;
  border-radius: 6px;
  border: 1px solid #ccc;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-btn-cancel {
  background: #fff;
  color: #555;
}

.modal-btn-cancel:hover {
  background: #f0f0f0;
}

.modal-btn-danger {
  background: #e53e3e;
  color: #fff;
  border-color: #e53e3e;
}

.modal-btn-danger:hover {
  background: #c53030;
}

.modal-btn-primary {
  background: #333;
  color: #fff;
  border-color: #333;
}

.modal-btn-primary:hover {
  background: #555;
}

.modal-box-wide {
  width: 480px;
  max-width: 90vw;
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 0.85rem;
  color: #767676;
  margin-bottom: 14px;
  line-height: 1.5;
}

.system-prompt-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d0d0d0;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
  line-height: 1.6;
  color: #333;
  margin-bottom: 16px;
  box-sizing: border-box;
}

.system-prompt-textarea:focus {
  border-color: #10a37f;
  box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}

/* --- トースト通知 --- */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #fff;
  color: #333;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.875rem;
  max-width: 340px;
  border: 1px solid #e5e5e5;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: auto;
  line-height: 1.5;
}

.toast.toast-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.toast-warning {
  border-left: 3px solid #e53e3e;
}

/* WCAG 2.2 — 2.4.11 フォーカスの外観: キーボードフォーカスリングを全インタラクティブ要素に保証 */
button:focus-visible,
[role="button"]:focus-visible,
[tabindex="0"]:focus-visible,
a:focus-visible {
  outline: 3px solid #10a37f;
  outline-offset: 2px;
  border-radius: 4px;
}

/* ─────────────────────────────────────────────────
   ヘッダーアクション (F3 エクスポート / F8 モニタリング)
───────────────────────────────────────────────── */
.header-actions {
  position: absolute;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  cursor: pointer;
  color: #666;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.header-icon-btn:hover {
  background: #f5f5f5;
  color: #333;
}

.header-icon-btn.active {
  background: #f0faf6;
  border-color: #10a37f;
  color: #10a37f;
}

/* ─────────────────────────────────────────────────
   F3: エクスポートドロップダウン
───────────────────────────────────────────────── */
.export-wrapper {
  position: relative;
}

.export-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  z-index: 500;
  overflow: hidden;
  min-width: 160px;
}

.export-dropdown.hidden {
  display: none;
}

.export-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: none;
  border: none;
  font-size: 0.875rem;
  color: #333;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.export-option:hover {
  background: #f5f5f5;
}

/* ─────────────────────────────────────────────────
   F8: AIモニタリングパネル
───────────────────────────────────────────────── */
.monitoring-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  background: #fff;
  border-left: 1px solid #e5e5e5;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
  z-index: 300;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.monitoring-panel.hidden {
  display: none;
}

.monitoring-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}

.monitoring-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #333;
}

.monitoring-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #767676;
  font-size: 1rem;
  transition: background 0.15s;
}

.monitoring-close:hover {
  background: #f0f0f0;
}

.monitoring-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.monitoring-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.monitoring-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #767676;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-card {
  background: #f9f9f9;
  border: 1px solid #efefef;
  border-radius: 8px;
  padding: 10px 12px;
}

.stat-card-wide {
  grid-column: span 2;
}

.stat-label {
  font-size: 0.7rem;
  color: #767676;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: #10a37f;
}

.stat-note {
  font-size: 0.65rem;
  color: #aaa;
  margin-top: 2px;
}

.stat-history {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-history-empty {
  font-size: 0.82rem;
  color: #aaa;
  padding: 8px 0;
  text-align: center;
}

.stat-history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: #555;
  padding: 6px 8px;
  background: #fafafa;
  border-radius: 6px;
}

.stat-history-time {
  color: #767676;
  flex-shrink: 0;
  width: 60px;
}

.stat-history-tokens {
  flex: 1;
  font-variant-numeric: tabular-nums;
}

.stat-history-latency {
  flex-shrink: 0;
  color: #10a37f;
  font-weight: 600;
}

.monitoring-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid #f0f0f0;
}

.monitoring-cw-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #1a73e8;
  text-decoration: none;
}

.monitoring-cw-link:hover {
  text-decoration: underline;
}

/* ─── セキュリティパネル ──────────────────────────────────────────────────── */

.security-status-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.security-status-item {
  display: grid;
  grid-template-columns: 20px 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #f8f9fa;
  border-left: 3px solid #ccc;
}

.security-status-item.security-ok {
  border-left-color: #34a853;
  background: #f0faf3;
}

.security-status-item.security-warn {
  border-left-color: #fbbc04;
  background: #fffbe6;
}

.security-status-item.security-error {
  border-left-color: #ea4335;
  background: #fff0ef;
}

.security-status-icon {
  grid-row: 1 / 3;
  grid-column: 1;
  align-self: center;
  font-size: 0.9rem;
  font-weight: bold;
  color: #34a853;
}

.security-status-item.security-warn .security-status-icon { color: #f9ab00; }
.security-status-item.security-error .security-status-icon { color: #ea4335; }

.security-status-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #202124;
}

.security-status-desc {
  grid-column: 2;
  font-size: 0.74rem;
  color: #5f6368;
  margin-top: 1px;
}

.monitoring-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
}

.security-refresh-btn {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: #5f6368;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}

.security-refresh-btn:hover { background: #f0f0f0; color: #1a73e8; }

.security-metric { font-size: 1.4rem; font-weight: 700; transition: color 0.3s; }
.security-metric.metric-ok    { color: #137333; }
.security-metric.metric-warn  { color: #b45309; }
.security-metric.metric-error { color: #c5221f; }

.security-fetch-time {
  font-size: 0.72rem;
  color: #9aa0a6;
  margin-top: 4px;
  text-align: right;
}

/* ─────────────────────────────────────────────────
   F5: テンプレートモーダル
───────────────────────────────────────────────── */
.modal-box-templates {
  width: 560px;
  max-width: 92vw;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.template-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px 16px;
  background: #fafafa;
  border: 1px solid #e8e8e8;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.template-card:hover {
  background: #f0faf6;
  border-color: #10a37f;
  transform: translateY(-1px);
}

.template-card-emoji {
  font-size: 1.4rem;
  line-height: 1;
  margin-bottom: 4px;
}

.template-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #333;
}

.template-card-desc {
  font-size: 0.75rem;
  color: #767676;
}

/* ─────────────────────────────────────────────────
   ウェルカム画面テンプレートクイックアクセス (F5)
───────────────────────────────────────────────── */
.welcome-templates {
  margin-top: 28px;
}

.welcome-templates-label {
  font-size: 0.78rem;
  color: #aaa;
  margin-bottom: 10px;
}

.welcome-template-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.welcome-template-btn {
  padding: 8px 14px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 20px;
  font-size: 0.85rem;
  color: #555;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.welcome-template-btn:hover {
  background: #f0faf6;
  border-color: #10a37f;
  color: #10a37f;
}

/* ─────────────────────────────────────────────────
   F1/F2: 添付プレビューエリア
───────────────────────────────────────────────── */
.attachment-preview {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px 0;
}

.attachment-preview.hidden {
  display: none;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  background: #f0faf6;
  border: 1px solid #b3e5d3;
  border-radius: 20px;
  font-size: 0.78rem;
  color: #0e9270;
  max-width: 240px;
}

.attachment-chip.hidden {
  display: none;
}

.attachment-thumb {
  width: 24px;
  height: 24px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.attachment-chip-remove {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 50%;
  color: #0e9270;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0;
  transition: background 0.15s;
}

.attachment-chip-remove:hover {
  background: rgba(14, 146, 112, 0.15);
}

/* ─────────────────────────────────────────────────
   F1/F2: ドロップゾーン
───────────────────────────────────────────────── */
.drop-zone {
  position: relative;
  display: flex;
  flex-direction: column;
}

.drop-zone-overlay {
  position: absolute;
  inset: 0;
  background: rgba(16, 163, 127, 0.1);
  border: 2px dashed #10a37f;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #10a37f;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 50;
  pointer-events: none;
}

.drop-zone-overlay.hidden {
  display: none;
}

/* ─────────────────────────────────────────────────
   F1: 添付ボタン（ペーパークリップ・テンプレート）
───────────────────────────────────────────────── */
.attach-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #767676;
  transition: background 0.15s, color 0.15s;
}

.attach-btn:hover {
  background: #f5f5f5;
  color: #333;
}

.input-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 4px;
}

.input-body {
  position: relative;
  display: flex;
  align-items: flex-end;
}

/* 入力フォームのレイアウト調整（添付ボタン対応） */
#chat-form {
  display: block;
  padding: 0;
}

#input {
  padding: 10px 48px 12px 12px;
  min-height: 80px;
}

/* ─────────────────────────────────────────────────
   F2: ユーザーバブル内の画像プレビュー
───────────────────────────────────────────────── */
.user-image-thumb {
  display: block;
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  margin-top: 8px;
  object-fit: contain;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.user-attachment-chip {
  font-size: 0.78rem;
  margin-top: 6px;
  opacity: 0.85;
}

/* ─────────────────────────────────────────────────
   F4: エビデンスハイライト（強化されたソース表示）
───────────────────────────────────────────────── */
.source-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: #10a37f;
  color: #fff;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
}

.source-score {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  color: #10a37f;
  background: #f0faf6;
  padding: 2px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}

.source-snippet-highlight {
  border-left: 3px solid #10a37f;
  padding-left: 8px;
  background: #f8fffe;
  border-radius: 0 4px 4px 0;
}

/* ─────────────────────────────────────────────────
   トースト通知（追加タイプ）
───────────────────────────────────────────────── */
.toast.toast-success {
  border-left: 3px solid #10a37f;
}

/* ─────────────────────────────────────────────────
   F3: 印刷スタイル（PDF エクスポート）
───────────────────────────────────────────────── */
@media print {
  body.print-mode #sidebar,
  body.print-mode #sidebar-open,
  body.print-mode header .header-actions,
  body.print-mode .input-area,
  body.print-mode #scroll-btn,
  body.print-mode .message-actions,
  body.print-mode .monitoring-panel,
  body.print-mode #toast-container {
    display: none !important;
  }

  body.print-mode #app {
    display: block;
    height: auto;
  }

  body.print-mode #chat-container {
    display: block;
    overflow: visible;
  }

  body.print-mode #chat-window {
    overflow: visible;
    height: auto;
  }

  body.print-mode #messages {
    max-width: 100%;
  }

  body.print-mode .message.user .bubble {
    background: #f0f0f0 !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body.print-mode .sources-wrapper {
    border: 1px solid #ccc;
  }
}

/* ─────────────────────────────────────────────────
   レスポンシブ（モバイル対応）
───────────────────────────────────────────────── */
@media (max-width: 640px) {
  .monitoring-panel {
    width: 100vw;
  }

  .template-grid {
    grid-template-columns: 1fr;
  }

  .modal-box-templates {
    width: 95vw;
  }

  .header-actions {
    gap: 4px;
  }

  .welcome-template-grid {
    gap: 6px;
  }
}

/* ============================================================
   ナレッジ管理パネル
   ============================================================ */

.knowledge-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

.knowledge-overlay.hidden {
  display: none;
}

.knowledge-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
}

.knowledge-panel {
  position: relative;
  width: 400px;
  max-width: 95vw;
  height: 100dvh;
  background: var(--bg-secondary, #1e1e2e);
  border-left: 1px solid var(--border-color, #2d2d3d);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Header --- */
.knowledge-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color, #2d2d3d);
  flex-shrink: 0;
}

.knowledge-panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary, #e0e0e0);
  flex: 1;
}

.knowledge-count-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent-color, #4a9eff);
  color: #fff;
}

.knowledge-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary, #888);
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
}

.knowledge-close-btn:hover {
  color: var(--text-primary, #e0e0e0);
  background: var(--hover-bg, rgba(255,255,255,.06));
}

/* --- Drop Zone --- */
.knowledge-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 14px 16px;
  padding: 20px 16px;
  border: 2px dashed var(--border-color, #3d3d55);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.knowledge-drop-zone:hover,
.knowledge-drop-zone.drag-over {
  border-color: var(--accent-color, #4a9eff);
  background: rgba(74, 158, 255, 0.06);
}

.knowledge-drop-zone.drag-over .knowledge-drop-icon {
  color: var(--accent-color, #4a9eff);
}

.knowledge-drop-icon {
  color: var(--text-secondary, #888);
  transition: color 0.15s;
}

.knowledge-drop-main {
  font-size: 13px;
  color: var(--text-primary, #e0e0e0);
  font-weight: 500;
}

.knowledge-drop-sub {
  font-size: 11px;
  color: var(--text-secondary, #888);
}

/* --- Error Banner --- */
.knowledge-error-banner {
  margin: 0 16px 10px;
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 6px;
  font-size: 12px;
  color: #f87171;
  flex-shrink: 0;
}

/* --- Search --- */
.knowledge-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 10px;
  padding: 7px 10px;
  background: var(--bg-input, #16162a);
  border: 1px solid var(--border-color, #2d2d3d);
  border-radius: 8px;
  flex-shrink: 0;
  color: var(--text-secondary, #888);
}

.knowledge-search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text-primary, #e0e0e0);
}

.knowledge-search-input::placeholder {
  color: var(--text-secondary, #888);
}

/* --- Stats --- */
.knowledge-stats {
  display: flex;
  gap: 12px;
  padding: 0 16px 10px;
  flex-shrink: 0;
}

.knowledge-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary, #888);
}

.knowledge-stat-ok { color: #4ade80; }
.knowledge-stat-loading { color: var(--accent-color, #4a9eff); }

/* --- Table --- */
.knowledge-table-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: 0 16px 16px;
  border: 1px solid var(--border-color, #2d2d3d);
  border-radius: 8px;
}

.knowledge-table-head {
  display: grid;
  grid-template-columns: 1fr auto auto 28px;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-input, #16162a);
  border-bottom: 1px solid var(--border-color, #2d2d3d);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary, #888);
  flex-shrink: 0;
}

.knowledge-file-list {
  flex: 1;
  overflow-y: auto;
}

.knowledge-empty {
  padding: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary, #888);
}

.knowledge-loading {
  font-style: italic;
}

.knowledge-error {
  color: #f87171;
}

.knowledge-file-row {
  position: relative;
  display: grid;
  grid-template-columns: 20px 1fr auto auto 28px;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color, #2d2d3d);
  transition: background 0.12s;
}

.knowledge-file-row:last-child {
  border-bottom: none;
}

.knowledge-file-row:hover {
  background: var(--hover-bg, rgba(255,255,255,.04));
}

.knowledge-file-icon {
  font-size: 14px;
  text-align: center;
}

.knowledge-file-name {
  font-size: 12px;
  color: var(--text-primary, #e0e0e0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.knowledge-file-size,
.knowledge-file-date {
  font-size: 11px;
  color: var(--text-secondary, #888);
  white-space: nowrap;
}

.knowledge-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary, #888);
  padding: 3px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s, background 0.12s;
}

.knowledge-delete-btn:hover {
  color: #f87171;
  background: rgba(239, 68, 68, 0.12);
}

.knowledge-delete-confirm {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-secondary, #1e1e2e);
  border: 1px solid rgba(239, 68, 68, 0.5);
  border-radius: 6px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary, #888);
  z-index: 10;
  white-space: nowrap;
}

.knowledge-delete-confirm-yes {
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}

.knowledge-delete-confirm-yes:hover {
  background: #dc2626;
}

.knowledge-delete-confirm-no {
  background: none;
  border: 1px solid var(--border-color, #3d3d55);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-secondary, #888);
  cursor: pointer;
}

.knowledge-delete-confirm-no:hover {
  background: var(--hover-bg, rgba(255,255,255,.06));
}

/* Spin animation for loading indicator */
@keyframes spin {
  to { transform: rotate(360deg); }
}
.spin {
  animation: spin 1s linear infinite;
}

@media (max-width: 768px) {
  .knowledge-panel {
    width: 100vw;
  }
}
