:root {
  --primary: #0066cc;
  --primary-light: #e8f0fe;
  --primary-dark: #004999;
  --bg: #f5f7fa;
  --white: #ffffff;
  --gray-100: #f0f2f5;
  --gray-200: #e4e6eb;
  --gray-400: #8a8d91;
  --gray-600: #606770;
  --gray-800: #1c1e21;
  --success: #28a745;
  --warning: #ff9800;
  --radius: 12px;
  --sidebar-width: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--gray-800);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.header-sub {
  font-size: 12px;
  opacity: 0.85;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.role-select {
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 6px;
  background: rgba(255,255,255,0.15);
  color: white;
  font-size: 13px;
  cursor: pointer;
}
.role-select option { color: var(--gray-800); background: white; }

/* ===== Mode Toggle ===== */
.mode-toggle {
  display: flex;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 6px;
  overflow: hidden;
}
.mode-btn {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
  transition: all 0.2s;
}
.mode-btn.active {
  background: rgba(255,255,255,0.3);
  color: white;
  font-weight: 600;
}
.mode-btn:hover:not(.active) {
  background: rgba(255,255,255,0.2);
  color: white;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
}

/* ===== Chat Area ===== */
.chat-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  gap: 10px;
  max-width: 80%;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.message.assistant .avatar {
  background: var(--primary);
  color: white;
}
.message.user .avatar {
  background: var(--gray-200);
  color: var(--gray-600);
}
.silhouette-icon {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.avatar .silhouette-icon {
  width: 20px;
  height: 20px;
  stroke-width: 1.8;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.65;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble strong {
  font-weight: 700;
}
.bubble .msg-heading {
  display: block;
  font-weight: 700;
  color: var(--gray-800);
  margin: 0.75em 0 0.35em 0;
  line-height: 1.4;
}
.bubble .msg-heading:first-child {
  margin-top: 0;
}
.bubble .msg-heading-h2 {
  font-size: 1.15em;
  border-bottom: 1px solid var(--gray-200);
  padding-bottom: 0.2em;
}
.bubble .msg-heading-h3 {
  font-size: 1.05em;
}
.bubble .msg-heading-inline {
  font-weight: 700;
  font-size: 1.05em;
}
.message.assistant .bubble {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-bottom-left-radius: 4px;
  white-space: normal;
}
.message.user .bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.message.assistant .bubble p {
  margin: 0 0 0.75em 0;
}
.message.assistant .bubble p:last-child,
.message.assistant .bubble ul:last-child,
.message.assistant .bubble ol:last-child,
.message.assistant .bubble pre:last-child,
.message.assistant .bubble blockquote:last-child,
.message.assistant .bubble table:last-child {
  margin-bottom: 0;
}
.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3,
.message.assistant .bubble h4,
.message.assistant .bubble h5,
.message.assistant .bubble h6 {
  margin: 0.85em 0 0.35em 0;
  line-height: 1.35;
  font-weight: 700;
}
.message.assistant .bubble h1:first-child,
.message.assistant .bubble h2:first-child,
.message.assistant .bubble h3:first-child,
.message.assistant .bubble h4:first-child,
.message.assistant .bubble h5:first-child,
.message.assistant .bubble h6:first-child {
  margin-top: 0;
}
.message.assistant .bubble h1,
.message.assistant .bubble h2 {
  border-bottom: 1px solid var(--gray-200);
  padding-bottom: 0.2em;
}
.message.assistant .bubble h1 { font-size: 1.22em; }
.message.assistant .bubble h2 { font-size: 1.15em; }
.message.assistant .bubble h3 { font-size: 1.08em; }
.message.assistant .bubble ul,
.message.assistant .bubble ol {
  margin: 0.35em 0 0.75em 1.4em;
  padding: 0;
}
.message.assistant .bubble li {
  margin: 0.2em 0;
}
.message.assistant .bubble blockquote {
  margin: 0.6em 0;
  padding: 0.45em 0.75em;
  border-left: 3px solid var(--primary);
  background: var(--primary-light);
  color: var(--gray-600);
  border-radius: 0 6px 6px 0;
}
.message.assistant .bubble pre {
  margin: 0.75em 0;
  padding: 10px 12px;
  overflow-x: auto;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  white-space: pre;
}
.message.assistant .bubble code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.92em;
  background: var(--gray-100);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
.message.assistant .bubble pre code {
  background: transparent;
  border-radius: 0;
  padding: 0;
}
.message.assistant .bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  display: block;
  overflow-x: auto;
}
.message.assistant .bubble th,
.message.assistant .bubble td {
  border: 1px solid var(--gray-200);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
.message.assistant .bubble th {
  background: var(--gray-100);
  font-weight: 700;
}
.message.assistant .bubble a {
  color: var(--primary);
  text-decoration: underline;
}

.meta {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 4px;
  padding-left: 46px;
}
.message.user .meta { text-align: right; padding-right: 46px; padding-left: 0; }

.sources {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--gray-100);
  border-radius: 6px;
  max-width: 80%;
}
.sources strong { color: var(--gray-600); }
.sources summary {
  color: var(--gray-600);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.5;
}
.sources summary::-webkit-details-marker {
  display: none;
}
.sources summary::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid currentColor;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.sources[open] summary::before {
  transform: rotate(90deg);
}
.sources-preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sources-list {
  margin: 6px 0 0;
  padding-left: 18px;
  max-height: 140px;
  overflow-y: auto;
  overflow-wrap: anywhere;
  line-height: 1.5;
}
.sources-list li + li {
  margin-top: 2px;
}

/* ===== FAQ Results ===== */
.faq-results {
  max-width: 90%;
  align-self: flex-start;
  animation: fadeIn 0.3s ease;
}
.faq-results-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
}
.faq-results-count {
  background: var(--primary);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.faq-item {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.faq-item:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,102,204,0.1);
}
.faq-item-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  margin-right: 8px;
  flex-shrink: 0;
}
.faq-item-question {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  display: flex;
  align-items: flex-start;
}
.faq-item-question-text {
  flex: 1;
}
.faq-item-answer {
  font-size: 13px;
  color: var(--gray-600);
  line-height: 1.6;
  margin-left: 32px;
  white-space: pre-wrap;
}
.faq-item-meta {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  margin-left: 32px;
  font-size: 11px;
  color: var(--gray-400);
}
.faq-item-url {
  color: var(--primary);
  text-decoration: none;
  font-size: 12px;
}
.faq-item-url:hover { text-decoration: underline; }
.faq-item-score {
  font-size: 11px;
  color: var(--gray-400);
}
.faq-item-id {
  font-size: 11px;
  color: var(--gray-400);
  font-family: monospace;
}

/* 一覧にないボタン */
.faq-not-found-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--gray-200);
}
.faq-action-btn {
  padding: 8px 16px;
  border: 1px solid var(--gray-200);
  border-radius: 20px;
  background: var(--white);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--gray-600);
}
.faq-action-btn:hover {
  border-color: var(--warning);
  color: var(--warning);
  background: #fff8e1;
}
.faq-action-btn.primary-action {
  border-color: var(--primary);
  color: var(--primary);
}
.faq-action-btn.primary-action:hover {
  background: var(--primary-light);
}

.faq-no-results {
  text-align: center;
  padding: 32px;
  color: var(--gray-400);
  font-size: 14px;
}

/* ===== Analysis Planner ===== */
.analysis-planner {
  max-width: 90%;
  align-self: flex-start;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  animation: fadeIn 0.3s ease;
}
.analysis-planner-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}
.analysis-planner-desc {
  font-size: 13px;
  color: var(--gray-600);
  line-height: 1.6;
  margin-bottom: 14px;
}
.analysis-option-section {
  margin-top: 12px;
}
.analysis-option-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-600);
  margin-bottom: 8px;
}
.analysis-option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.analysis-option-btn {
  padding: 10px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background: #fff;
  color: var(--gray-800);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.analysis-option-btn:hover,
.analysis-option-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 2px 8px rgba(0,102,204,0.08);
}
.analysis-option-name {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 3px;
}
.analysis-option-help {
  display: block;
  font-size: 12px;
  color: var(--gray-600);
  line-height: 1.45;
}
.analysis-planner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--gray-200);
}
.analysis-run-btn {
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.analysis-run-btn:hover {
  background: var(--primary-dark);
}
.analysis-secondary-btn {
  padding: 9px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background: #fff;
  color: var(--gray-600);
  cursor: pointer;
}
.analysis-secondary-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
@media (max-width: 640px) {
  .analysis-option-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Typing Indicator ===== */
.typing-indicator {
  display: none;
  align-self: flex-start;
  padding: 12px 18px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  margin-left: 46px;
}
.typing-indicator.show { display: flex; gap: 5px; }
.typing-indicator span {
  width: 8px; height: 8px;
  background: var(--gray-400);
  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); }
}
.bubble.stream-loading {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 58px;
  min-height: 42px;
}
.bubble.stream-loading span {
  width: 8px;
  height: 8px;
  background: var(--gray-400);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.bubble.stream-loading span:nth-child(2) { animation-delay: 0.2s; }
.bubble.stream-loading span:nth-child(3) { animation-delay: 0.4s; }

/* ===== Input Area ===== */
.input-area {
  padding: 16px 24px;
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.input-area textarea {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 120px;
  transition: border-color 0.2s;
}
.input-area textarea:focus { border-color: var(--primary); }
.input-area button {
  padding: 0 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.input-area button:hover { background: var(--primary-dark); }
.input-area button:disabled {
  background: var(--gray-400);
  cursor: not-allowed;
}

/* ===== Mode Indicator (input area) ===== */
.mode-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: #fff3e0;
  color: var(--warning);
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.mode-indicator.show { display: flex; }

/* ===== Welcome ===== */
.welcome {
  text-align: center;
  margin: auto;
  padding: 40px;
}
.welcome h2 { font-size: 22px; margin-bottom: 8px; color: var(--primary); }
.welcome p { color: var(--gray-600); font-size: 14px; line-height: 1.7; }
.welcome-mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 24px auto 18px;
  max-width: 620px;
}
.welcome-mode-card {
  min-height: 86px;
  padding: 14px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background: var(--white);
  color: var(--gray-800);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.welcome-mode-card:hover,
.welcome-mode-card.active {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 2px 8px rgba(0,102,204,0.08);
}
.welcome-mode-title {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}
.welcome-mode-desc {
  display: block;
  font-size: 12px;
  line-height: 1.45;
  color: var(--gray-600);
}
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 20px;
}
.quick-btn {
  padding: 8px 16px;
  border: 1px solid var(--gray-200);
  border-radius: 20px;
  background: var(--white);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--gray-600);
}
.quick-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
@media (max-width: 640px) {
  .welcome {
    padding: 28px 8px;
  }
  .welcome-mode-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Sidebar (Chat History) ===== */
.app-wrap {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  flex-shrink: 0;
  transition: width 0.2s, min-width 0.2s;
  overflow: hidden;
}
.sidebar-inner {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.2s;
}
.sidebar.closed {
  width: 0;
  min-width: 0;
  border-right-width: 0;
}
.sidebar.closed .sidebar-inner {
  transform: translateX(-12px);
}
/* 左端のサイドバー開閉ボタン（ChatGPT風・常に表示） */
.sidebar-toggle-strip {
  width: 48px;
  min-width: 48px;
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  flex-shrink: 0;
}
.sidebar-toggle-strip .sidebar-toggle {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background: var(--white);
  color: var(--gray-700);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.sidebar-toggle-strip .sidebar-toggle:hover {
  background: var(--gray-100);
  color: var(--primary);
}
.sidebar-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-new-chat {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 10px 16px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--white);
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-800);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-new-chat:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.btn-refresh-chat {
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background: var(--white);
  color: var(--gray-600);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.btn-refresh-chat:hover {
  background: var(--gray-100);
  color: var(--primary);
}
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.chat-list-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  text-align: left;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--gray-800);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 0;
  transition: background 0.15s;
}
.chat-list-item:hover {
  background: var(--gray-100);
}
.chat-list-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}
.chat-list-empty {
  padding: 16px;
  font-size: 12px;
  color: var(--gray-400);
  text-align: center;
}

/* ===== Main (Header + Chat + Input) ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
/* チャット欄を中央に（Gemini風の左右マージン） */
.chat-column {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ===== Input: Mode left, Mic right (Gemini style) ===== */
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 24px;
  min-height: 48px;
  transition: border-color 0.2s;
}
.input-row:focus-within {
  border-color: var(--primary);
  background: var(--white);
}
.input-row-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.input-row-left .mode-toggle-inline {
  display: flex;
  border: 1px solid var(--gray-200);
  border-radius: 16px;
  overflow: hidden;
  background: var(--white);
}
.input-row-left .mode-btn-inline {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--gray-600);
  transition: all 0.2s;
}
.input-row-left .mode-btn-inline.active {
  background: var(--primary-light);
  color: var(--primary);
}
.knowledge-scope-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--gray-600);
  white-space: nowrap;
}
.knowledge-scope-select {
  max-width: 150px;
  padding: 6px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 16px;
  background: var(--white);
  color: var(--gray-700);
  font-size: 12px;
  outline: none;
}
.knowledge-scope-select:disabled {
  background: var(--gray-100);
  color: var(--gray-400);
  cursor: not-allowed;
}
@media (max-width: 640px) {
  .input-row {
    flex-wrap: wrap;
    border-radius: 18px;
  }
  .input-row-left {
    width: 100%;
    flex-wrap: wrap;
  }
  .input-row-left .mode-toggle-inline {
    width: 100%;
  }
  .input-row-left .mode-btn-inline {
    flex: 1;
    padding: 7px 8px;
  }
  .knowledge-scope-label {
    width: 100%;
    justify-content: space-between;
  }
  .knowledge-scope-select {
    flex: 1;
    max-width: none;
  }
}
.input-row textarea.inline-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 4px;
  min-height: 28px;
  resize: none;
  outline: none;
  font-size: 14px;
}
.input-row-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-600);
  transition: background 0.2s, color 0.2s;
}
.icon-btn:hover {
  background: var(--gray-200);
  color: var(--gray-800);
}
.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.icon-btn.send-btn {
  background: var(--primary);
  color: white;
}
.icon-btn.send-btn::before {
  content: "";
  width: 0;
  height: 0;
  margin-left: 2px;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 11px solid currentColor;
}
.icon-btn.send-btn .silhouette-icon {
  display: none;
}
.icon-btn.send-btn:hover:not(:disabled) {
  background: var(--primary-dark);
}
.icon-btn.pause-btn {
  color: var(--warning);
}
.voice-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-600);
  font-size: 12px;
  font-weight: 600;
  transition: background 0.2s, color 0.2s;
}
.voice-btn:hover {
  background: var(--gray-200);
  color: var(--gray-800);
}
.voice-btn.listening {
  background: #ffebee;
  color: #c62828;
}
.voice-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
/* 音声入力バー（入力中・キャンセル・決定） */
.input-row-voice {
  display: none;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 12px;
  background: #fff8e1;
  border: 1px solid var(--warning);
  border-radius: 24px;
  min-height: 48px;
}
.input-row-voice.show {
  display: flex;
}
.voice-status-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
}
.voice-waveform {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 3px;
  min-height: 24px;
}
.voice-waveform span {
  width: 4px;
  height: 12px;
  background: var(--primary);
  border-radius: 2px;
  animation: voiceBar 0.6s ease-in-out infinite;
}
.voice-waveform span:nth-child(1) { animation-delay: 0s; }
.voice-waveform span:nth-child(2) { animation-delay: 0.1s; }
.voice-waveform span:nth-child(3) { animation-delay: 0.2s; }
.voice-waveform span:nth-child(4) { animation-delay: 0.3s; }
.voice-waveform span:nth-child(5) { animation-delay: 0.4s; }
.voice-waveform span:nth-child(6) { animation-delay: 0.15s; }
.voice-waveform span:nth-child(7) { animation-delay: 0.25s; }
.voice-waveform span:nth-child(8) { animation-delay: 0.35s; }
@keyframes voiceBar {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}
.voice-cancel-btn, .voice-confirm-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background 0.2s;
}
.voice-cancel-btn {
  background: var(--gray-200);
  color: var(--gray-700);
}
.voice-cancel-btn:hover {
  background: #ffcdd2;
  color: #c62828;
}
.voice-confirm-btn {
  background: var(--primary);
  color: white;
}
.voice-confirm-btn:hover {
  background: var(--primary-dark);
}

/* ===== Message actions (Good / Bad / Reload / Copy) ===== */
.message-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 6px;
  padding-left: 46px;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.message.user + .message-actions,
.message-actions:hover {
  opacity: 1;
}
.message-actions .icon-btn {
  width: 28px;
  height: 28px;
  color: var(--gray-500);
}
.message-actions .icon-btn:hover {
  color: var(--primary);
  background: var(--primary-light);
}
.message-actions .icon-btn.active {
  color: var(--primary);
  background: var(--primary-light);
}
.message-actions .icon-btn.copied {
  color: var(--success);
}
.faq-results .message-actions {
  padding-left: 0;
  margin-top: 8px;
}
.user-edit-link {
  font-size: 11px;
  color: var(--gray-400);
  cursor: pointer;
  margin-left: 8px;
}
.user-edit-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

@media (max-width: 640px) {
  html,
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .app-wrap {
    width: 100%;
    min-width: 0;
    position: relative;
  }

  .sidebar-toggle-strip {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 70;
    width: 38px;
    min-width: 38px;
    height: 38px;
    padding: 0;
    background: transparent;
    border-right: 0;
  }

  .sidebar-toggle-strip .sidebar-toggle {
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    width: min(84vw, 300px);
    min-width: 0;
    transform: translateX(0);
    transition: transform 0.2s;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.16);
  }

  .sidebar.closed {
    width: min(84vw, 300px);
    min-width: 0;
    border-right-width: 1px;
    transform: translateX(-100%);
  }

  .sidebar-inner {
    width: 100%;
    min-width: 0;
    padding-top: 58px;
    transform: none;
  }

  .sidebar.closed .sidebar-inner {
    transform: none;
  }

  .main {
    width: 100%;
    min-width: 0;
  }

  .header {
    min-height: 68px;
    padding: 10px 12px 10px 58px;
    gap: 8px;
    align-items: flex-start;
  }

  .header > div:first-child {
    min-width: 0;
  }

  .header h1 {
    font-size: 16px;
    line-height: 1.25;
    letter-spacing: 0;
    white-space: nowrap;
  }

  .header-sub {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    line-height: 1.35;
  }

  .header-right {
    flex-shrink: 0;
    gap: 6px;
    padding-top: 2px;
  }

  .role-select {
    width: 104px;
    padding: 6px 8px;
    font-size: 12px;
  }

  .chat-column {
    max-width: none;
    width: 100%;
    padding: 0 10px;
  }

  .chat-container {
    padding: 14px 0;
    gap: 12px;
  }

  .message {
    max-width: 100%;
    gap: 8px;
  }

  .message.user {
    max-width: 94%;
  }

  .avatar {
    width: 30px;
    height: 30px;
  }

  .avatar .silhouette-icon {
    width: 17px;
    height: 17px;
  }

  .bubble {
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.65;
  }

  .meta,
  .message-actions {
    padding-left: 38px;
  }

  .sources {
    max-width: calc(100% - 38px);
    margin-left: 38px;
  }

  .sources-list {
    max-height: 120px;
  }

  .faq-results,
  .analysis-planner {
    max-width: 100%;
  }

  .welcome {
    padding: 24px 4px;
  }

  .welcome h2 {
    font-size: 18px;
  }

  .welcome p {
    font-size: 13px;
  }

  .quick-actions {
    justify-content: flex-start;
  }

  .quick-btn {
    padding: 8px 12px;
    font-size: 12px;
  }

  .input-area {
    padding: 8px 10px 10px;
  }

  .input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: end;
    gap: 8px;
    padding: 12px 12px 10px;
    border-radius: 24px;
  }

  .input-row-left {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
  }

  .input-row-left .mode-toggle-inline {
    width: 100%;
  }

  .input-row-left .mode-btn-inline {
    flex: 1;
    padding: 7px 8px;
  }

  .input-row textarea.inline-input {
    grid-column: 1 / 3;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    padding: 6px 2px 8px;
    font-size: 14px;
    line-height: 1.5;
    max-height: 96px;
  }

  .input-row-right {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
  }

  .voice-btn {
    min-width: 54px;
    height: 36px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .input-row-voice {
    border-radius: 20px;
  }
}
